Location: PHPKode > projects > phpAWE > phpAWE.0.4.beta.demo-page/awe/classes/TaweBaseListItem.php
<?php


abstract class TaweBaseListItem extends TaweBaseItem {

protected $navPrefix;

      abstract public function updateNewItem();
      abstract public function updateChangeItem();
      abstract public function makeAddress($itemId);

      function __construct($moduleName, $navPrefix, $parent) {
        parent::__construct($moduleName, $parent);
        $this->navPrefix = $navPrefix;
      }
      
      public function makeParentAddress($itemId) {
        global $aweSqlPrimaryKey;
        
        if (isset($this->parent)) {
          $parent = $this->getParent($itemId);
          $result = $this->parent->makeAddress($parent[0][$aweSqlPrimaryKey]);
        
          return $result;
        } else return false;
      }
      
      protected function makeListItem($dataLine, $itemTemplate, $templateName, $pictureExt = "") {
        global $templateAreola;
        global $aweSqlPrimaryKey;
        global $addressBase;
        global $parentAddrTemplateString;
        
        $result = parent::makeListItem($dataLine, $itemTemplate, $templateName, $pictureExt);
        
        // TODO
        /*
        $result = tempReplace( 
                              $parentAddrTemplateString,
                              $addressBase.$this->makePrevAddress($dataLine[$aweSqlPrimaryKey]),
                              $result, 
                              $templateAreola
                              );
        */
        return $result;
      }
      
      public function getItem($itemId) {
        global $aweDataTable;
        global $aweSqlPrimaryKey;
        
        $result = $this->aweQuery->select("", $this->moduleName.$aweDataTable, sqlText(equals, $aweSqlPrimaryKey, $itemId), "", "", 1);
        return $result;
      }
      
      protected function getParent($itemId) {
        global $aweDataTable;
        global $aweSqlPrimaryKey;
        global $aweSqlParentField;
       
        $itemData = $this->aweQuery->select("",$this->moduleName.$aweDataTable, sqlText(equals,$aweSqlPrimaryKey,$itemId)); 
        $result = $this->aweQuery->select("",$this->moduleName.$aweDataTable, sqlText(equals, $aweSqlPrimaryKey, $itemData[0][$aweSqlParentField]));
    
        if (is_array($result[0])) return $result;
        else return -1;      
      }
      
      public function updateMoveUp($itemId) {
      
        global $aweSqlParentField;
        global $aweDataTable;
        global $aweSqlPrimaryKey;
        global $aweSqlPositionField;
        
        $toMove = $this->aweQuery->select("*", $this->moduleName.$aweDataTable, sqlText(equals, $aweSqlPrimaryKey, $itemId), $limit =1); 
      
        $replace = $this->aweQuery->select("*", 
                                            $this->moduleName.$aweDataTable,
                                            sqlText("and",sqlText(equals,$aweSqlParentField, $toMove[0][$aweSqlParentField]), sqlText("lesser" ,$aweSqlPositionField ,$toMove[0][$aweSqlPositionField])), 
                                            $aweSqlPositionField, 
                                            "DESC", 
                                            1);       
                  
        if (is_array($replace[0])) {                        
            $this->aweQuery->update($this->moduleName.$aweDataTable, $aweSqlPositionField, $replace[0][$aweSqlPositionField], sqlText(equals, $aweSqlPrimaryKey, $toMove[0][$aweSqlPrimaryKey]), 1);
            $this->aweQuery->update($this->moduleName.$aweDataTable, $aweSqlPositionField, $toMove[0][$aweSqlPositionField], sqlText(equals, $aweSqlPrimaryKey, $replace[0][$aweSqlPrimaryKey]), 1);
        }
      }
      
      public function updateMoveDown($itemId) {
        global $aweSqlParentField;
        global $aweDataTable;
        global $aweSqlPrimaryKey;
        global $aweSqlPositionField;
        
        $toMove = $this->aweQuery->select("*", $this->moduleName.$aweDataTable, sqlText(equals, $aweSqlPrimaryKey, $itemId), $limit =1); 

        $replace = $this->aweQuery->select("*", 
                                            $this->moduleName.$aweDataTable,
                                            sqlText("and",sqlText(equals,$aweSqlParentField, $toMove[0][$aweSqlParentField]), sqlText("greater" ,$aweSqlPositionField ,$toMove[0][$aweSqlPositionField])),
                                            $aweSqlPositionField, 
                                            "ASC", 
                                            1);       
    
        if (is_array($replace[0])) {                        
            $this->aweQuery->update($this->moduleName.$aweDataTable, $aweSqlPositionField, $replace[0][$aweSqlPositionField], sqlText(equals, $aweSqlPrimaryKey, $toMove[0][$aweSqlPrimaryKey]), 1);
            $this->aweQuery->update($this->moduleName.$aweDataTable, $aweSqlPositionField, $toMove[0][$aweSqlPositionField], sqlText(equals, $aweSqlPrimaryKey, $replace[0][$aweSqlPrimaryKey]), 1);
            
        }
      }
      
      public function updateMoveTop($itemId) {
        global $aweSqlParentField;
        global $aweDataTable;
        global $aweSqlPrimaryKey;
        global $aweSqlPositionField;

        $toMove = $this->aweQuery->select("*", $this->moduleName.$aweDataTable, sqlText(equals, $aweSqlPrimaryKey, $itemId), $limit =1);
        
        $toMoveDown = $this->aweQuery->select("*", 
                                              $this->moduleName.$aweDataTable, 
                                              sqlText("and", sqlText(equals, $aweSqlParentField, $toMove[0][$aweSqlParentField]), sqlText(lesser, $aweSqlPositionField ,$toMove[0][$aweSqlPositionField])),
                                              $aweSqlPositionField,
                                              "ASC"
                                              );
        if (is_array($toMoveDown)) {
            $this->aweQuery->update($this->moduleName.$aweDataTable, $aweSqlPositionField, $aweSqlPositionField."+1", sqlText("and", sqlText(equals, $aweSqlParentField, $toMove[0][$aweSqlParentField]), sqlText(lesser, $aweSqlPositionField ,$toMove[0][$aweSqlPositionField]))); 
            $this->aweQuery->update($this->moduleName.$aweDataTable, $aweSqlPositionField, $toMoveDown[0][$aweSqlPositionField], sqlText(equals, $aweSqlPrimaryKey, $itemId) ,1); 
        }
      }
      
      public function updateMoveBottom($itemId) {
        global $aweSqlParentField;
        global $aweDataTable;
        global $aweSqlPrimaryKey;
        global $aweSqlPositionField;
        
        $toMove = $this->aweQuery->select("*", $this->moduleName.$aweDataTable, sqlText(equals, $aweSqlPrimaryKey, $itemId), $limit =1);
        
        $toMoveUp = $this->aweQuery->select("*", 
                                              $this->moduleName.$aweDataTable, 
                                              sqlText("and", sqlText(equals, $aweSqlParentField, $toMove[0][$aweSqlParentField]), sqlText(greater, $aweSqlPositionField ,$toMove[0][$aweSqlPositionField])),
                                              $aweSqlPositionField,
                                              "DESC"
                                              );
        if (is_array($toMoveUp)) {
            $this->aweQuery->update($this->moduleName.$aweDataTable, $aweSqlPositionField, $aweSqlPositionField."-1", sqlText("and", sqlText(equals, $aweSqlParentField, $toMove[0][$aweSqlParentField]), sqlText(greater, $aweSqlPositionField ,$toMove[0][$aweSqlPositionField]))); 
            $this->aweQuery->update($this->moduleName.$aweDataTable, $aweSqlPositionField, $toMoveUp[0][$aweSqlPositionField], sqlText(equals, $aweSqlPrimaryKey, $itemId) ,1); 
        }
      }
      
      public function updateChangeParent($itemId, $newParent) {
 
        global $aweSqlParentField;
        global $aweDataTable;
        global $aweSqlPrimaryKey;
        global $aweSqlPositionField;
      
        $toMove = $this->aweQuery->select("*", $this->moduleName.$aweDataTable, sqlText(equals, $aweSqlPrimaryKey, $itemId), $limit =1);
        
        if ($toMove[0][$aweSqlParentField] != $newParent) { 
            
            $newPosition = 1 + $this->aweQuery->getMax($this->moduleName.$aweDataTable, $aweSqlPositionField, sqlText(equals, $aweSqlParentField, $newParent));
            
            $this->aweQuery->update($this->moduleName.$aweDataTable, array($aweSqlPositionField, $aweSqlParentField), array($newPosition, $newParent), sqlText(equals, $aweSqlPrimaryKey, $itemId));
     
            $this->aweQuery->update($this->moduleName.$aweDataTable, $aweSqlPositionField, $aweSqlPositionField."-1", sqlText("and", sqlText(equals, $aweSqlParentField, $toMove[0][$aweSqlParentField]), sqlText(greater, $aweSqlPositionField ,$toMove[0][$aweSqlPositionField])));
        }      
      }
      
      public function updateRemoveItem($itemId) {
        global $aweDataTable;
        global $aweSqlPrimaryKey;
        global $aweSqlPositionField;
        global $aweSqlParentField;
       
        $toRemove = $this->aweQuery->select("*", $this->moduleName.$aweDataTable, sqlText(equals, $aweSqlPrimaryKey, $itemId), $limit =1);
      
        $this->aweQuery->remove($this->moduleName.$aweDataTable, sqlText(equals, $aweSqlPrimaryKey, $itemId), 1);  
        
        $this->aweQuery->update($this->moduleName.$aweDataTable, $aweSqlPositionField, $aweSqlPositionField."-1", sqlText("and", sqlText(equals, $aweSqlParentField, $toRemove[0][$aweSqlParentField]), sqlText(greater, $aweSqlPositionField ,$toRemove[0][$aweSqlPositionField])));
      }
}

?>
Return current item: phpAWE