コード例 #1
0
ファイル: TableBrowser.php プロジェクト: ankaau/GathBandhan
 /**
  * Compacts the ordering sequence of the selected records
  *
  * @param  array           $cid                 array of string  table key ids which need to get saved ($row[]->ordering contains old ordering and $cid contains new ordering)
  * @param  TableInterface  $row                 derived from TableInterface of corresponding class
  * @param  array           $order               ?
  * @param  string          $conditionStatement  Additional "WHERE" query to limit ordering to a particular subset of records
  * @param  string          $orderingField       Field name for this ordering
  */
 protected function saveOrder($cid, &$row, &$order, $conditionStatement, $orderingField = 'ordering')
 {
     global $_CB_framework;
     $total = count($cid);
     $conditions = array();
     $cidsChanged = array();
     // update ordering values
     for ($i = 0; $i < $total; $i++) {
         $row->load($cid[$i]);
         if ($row->{$orderingField} != $order[$i]) {
             $row->{$orderingField} = $order[$i];
             if (!$row->store()) {
                 $_CB_framework->enqueueMessage(CBTxt::T('CANNOT_ORDER_ROW_ID_ID_BECAUSE_ERROR', 'Cannot order row id [id] because: [error]', array('[id]' => $cid, '[error]' => $row->getError())), 'error');
                 return;
             }
             // if
             $cidsChanged[] = $cid[$i];
             // remember to updateOrder this group if multiple groups (conditionStatement gives the group)
             if ($conditionStatement) {
                 $condition = null;
                 // to make php checker happy: the next line defines $condition
                 eval($conditionStatement);
                 //TODO remove eval() use (it's used a single time!)
                 $found = false;
                 foreach ($conditions as $cond) {
                     if ($cond[1] == $condition) {
                         $found = true;
                         break;
                     }
                 }
                 // if
                 if (!$found) {
                     $conditions[] = array($cid[$i], $condition);
                 }
             }
         }
         // if
     }
     // for
     if ($conditionStatement) {
         // execute updateOrder for each group
         foreach ($conditions as $cond) {
             $row->load($cond[0]);
             if ($row->hasFeature('ordered', $orderingField)) {
                 /** @var CheckedOrderedTable $row */
                 $row->updateOrder($cond[1], $cidsChanged, $orderingField);
             }
         }
     } else {
         if ($cidsChanged) {
             $row->load($cidsChanged[0]);
             if ($row->hasFeature('ordered', $orderingField)) {
                 /** @var CheckedOrderedTable $row */
                 $row->updateOrder(null, $cidsChanged, $orderingField);
             }
         }
     }
 }