Changeset 28 for database_list.php


Ignore:
Timestamp:
Dec 8, 2008, 11:06:23 AM (16 years ago)
Author:
george
Message:
  • Upraveno: Systém ukládání dat do databáze přepracován na jednodušší. Původní záměr počítal s verzováním položek seznamů čímž se komplikovaly SQL dotazy. Systém sledování změn bude později řešen přes tabulku Audit.
  • Odebráno: Sloupce tabulek Author, ItemId, CreationTime, DeletionTime, ValidtTimeFrom a ValidTimeTo.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • database_list.php

    r24 r28  
    77  function AddItem($TableId, $Values)
    88  {
    9     $DbResult = $this->Database->query('SELECT TableName FROM SystemList WHERE ItemId='.$TableId.' ORDER BY Id DESC LIMIT 1');
     9    $DbResult = $this->Database->query('SELECT TableName FROM SystemList WHERE Id='.$TableId);
    1010    $DbRow = $DbResult->fetch_assoc();
    1111    $TableName = $DbRow['TableName'];
    1212
    13     $Values['Author'] = $this->System->Modules['User']->User['ItemId'];
    14     $Values['CreationTime'] = 'NOW()';
    15     $Values['ValidTimeFrom'] = 'NOW()';
    16     $DbResult = $this->Database->select($TableName, 'MAX(ItemId)');
    17     $DbRow = $DbResult->fetch_row();
    18     $AutoincrementId = $DbRow[0];
    19     $Values['ItemId'] = $AutoincrementId + 1;
    2013    $this->Database->insert($TableName, $Values);
    21     return($Values['ItemId']);
     14    return($this->Database->insert_id);
    2215  }
    2316
    2417  function DeleteItem($TableId, $ItemId)
    2518  {
    26     $DbResult = $this->Database->query('SELECT TableName FROM SystemList WHERE ItemId='.$TableId.' ORDER BY Id DESC LIMIT 1');
     19    $DbResult = $this->Database->query('SELECT TableName FROM SystemList WHERE Id='.$TableId);
    2720    $DbRow = $DbResult->fetch_assoc();
    2821    $TableName = $DbRow['TableName'];
    29 
    30     $DbResult = $this->Database->select($TableName, 'Id', 'ItemId='.$ItemId.' ORDER BY Id DESC LIMIT 1');
    31     $DbRow = $DbResult->fetch_assoc();
    32     $this->Database->update($TableName, 'Id='.$DbRow['Id'], array('DeletionTime' => 'NOW()'));
     22    $this->Database->delete($TableName, 'Id='.$ItemId, array('DeletionTime' => 'NOW()'));
    3323  }
    3424
    3525  function EditItem($TableId, $Values, $ItemId)
    3626  {
    37     $DbResult = $this->Database->query('SELECT TableName FROM SystemList WHERE ItemId='.$TableId.' ORDER BY Id DESC LIMIT 1');
     27    $DbResult = $this->Database->query('SELECT TableName FROM SystemList WHERE Id='.$TableId);
    3828    $DbRow = $DbResult->fetch_assoc();
    3929    $TableName = $DbRow['TableName'];
    4030    $this->DeleteItem($TableId, $ItemId);
    41     $Values['ItemId'] = $ItemId;
    42     $Values['Author'] = $this->System->Modules['User']->User['ItemId'];
    43     $Values['CreationTime'] = 'NOW()';
    44     $Values['ValidTimeFrom'] = 'NOW()';
    45     $this->Database->insert($TableName, $Values);
     31    $Values['Id'] = $ItemId;
     32    $this->Database->replace($TableName, $Values);
    4633  }
    4734}
Note: See TracChangeset for help on using the changeset viewer.