Example #1
0
 public function getColumns()
 {
     $admin = $this->admin;
     $adminClass = $admin->classNameShort();
     $moduleName = $this->moduleName;
     $rawColumns = $this->_dynamicColumns;
     if ($this->linkColumn) {
         if (isset($rawColumns[$this->linkColumn])) {
             unset($rawColumns[$this->linkColumn]);
         }
         $columns = array_merge([$this->linkColumn => ['class' => AdminLinkColumn::className(), 'name' => $this->linkColumn, 'admin' => $admin, 'moduleName' => $moduleName, 'currentOrder' => $this->currentOrder, 'html' => ['align' => 'left'], 'route' => function ($record) use($moduleName, $adminClass) {
             $urlManager = Mindy::app()->urlManager;
             if (is_a($record, TreeModel::className())) {
                 if ($record->isLeaf() === false) {
                     return $urlManager->reverse('admin:list_nested', ['moduleName' => $moduleName, 'adminClass' => $adminClass, 'pk' => $record->pk]);
                 }
             }
             return null;
         }]], $rawColumns);
     } else {
         $columns = $rawColumns;
     }
     if ($this->showPkColumn) {
         $columns = array_merge(['pk' => ['class' => AdminLinkColumn::className(), 'name' => $admin->getModel()->getPkName(), 'admin' => $admin, 'moduleName' => $moduleName, 'currentOrder' => $this->currentOrder, 'html' => ['class' => 'td-id', 'align' => 'left'], 'route' => function ($record) use($moduleName, $adminClass) {
             // 'admin:update' moduleName adminClass model.pk
             // 'admin:list_nested' moduleName adminClass model.pk
             return Mindy::app()->urlManager->reverse('admin:update', ['moduleName' => $moduleName, 'adminClass' => $adminClass, 'pk' => $record->pk]);
         }]], $columns);
     }
     if ($this->sortingColumn) {
         $columns = array_merge(['check' => ['class' => CheckColumn::className(), 'length' => $this->count()], 'sorting' => ['class' => SortingColumn::className()]], $columns);
     } else {
         $columns = array_merge(['check' => ['class' => CheckColumn::className(), 'length' => $this->count()]], $columns);
     }
     $columns = array_merge($columns, ['actions' => ['class' => TemplateColumn::className(), 'template' => $this->actionsTemplate, 'title' => '', 'html' => ['class' => 'actions'], 'extra' => ['admin' => $admin, 'adminClass' => $adminClass, 'moduleName' => $moduleName], 'virtual' => true]]);
     return $columns;
 }
Example #2
0
 /**
  * @param TreeModel $target .
  * @param int $key .
  * @param int $levelUp .
  * @throws Exception.
  * @throws \Exception.
  * @return boolean.
  */
 private function moveNode($target, $key, $levelUp)
 {
     if ($this->getIsNewRecord()) {
         throw new Exception('The node should not be new record.');
     }
     if ($this->getIsDeletedRecord()) {
         throw new Exception('The node should not be deleted.');
     }
     if ($target->getIsDeletedRecord()) {
         throw new Exception('The target node should not be deleted.');
     }
     if ($this->pk == $target->pk) {
         throw new Exception('The target node should not be self.');
     }
     if ($target->isDescendantOf($this)) {
         throw new Exception('The target node should not be descendant.');
     }
     if (!$levelUp && $target->isRoot()) {
         throw new Exception('The target node should not be root.');
     }
     $left = $this->lft;
     $right = $this->rgt;
     $levelDelta = $target->level - $this->level + $levelUp;
     if ($this->root !== $target->root) {
         foreach (['lft', 'rgt'] as $attribute) {
             $this->objects()->filter([$attribute . '__gte' => $key, 'root' => $target->root])->update([$attribute => new Expression($attribute . sprintf('%+d', $right - $left + 1))]);
         }
         $delta = $key - $left;
         $this->objects()->filter(['lft__gte' => $left, 'rgt__lte' => $right, 'root' => $this->root])->update(['lft' => new Expression('lft' . sprintf('%+d', $delta)), 'rgt' => new Expression('rgt' . sprintf('%+d', $delta)), 'level' => new Expression('level' . sprintf('%+d', $levelDelta)), 'root' => $target->root]);
         $this->shiftLeftRight($right + 1, $left - $right - 1);
     } else {
         $delta = $right - $left + 1;
         $this->shiftLeftRight($key, $delta);
         if ($left >= $key) {
             $left += $delta;
             $right += $delta;
         }
         $this->objects()->filter(['lft__gte' => $left, 'rgt__lte' => $right, 'root' => $this->root])->update(['level' => new Expression('level' . sprintf('%+d', $levelDelta))]);
         foreach (['lft', 'rgt'] as $attribute) {
             $this->objects()->filter([$attribute . '__gte' => $left, $attribute . '__lte' => $right, 'root' => $this->root])->update([$attribute => new Expression($attribute . sprintf('%+d', $key - $left))]);
         }
         $this->shiftLeftRight($right + 1, -$delta);
     }
     return true;
 }
 public static function getFields()
 {
     return array_merge(parent::getFields(), ['name' => ['class' => CharField::className()], 'slug' => ['class' => AutoSlugField::className(), 'source' => 'name']]);
 }