示例#1
0
 public static function saveItem($data, $id = 0)
 {
     // Get relation model
     $relation = self::findOne($data['LetCategory']['relationId']);
     if ($relation === null) {
         return false;
     }
     // Get Model
     if ($id > 0) {
         // truong hop update
         $model = self::findOne($id);
         if ($model === null) {
             return false;
         }
     } else {
         // truong hop create
         $model = new LetCategory();
     }
     // Save Node
     $model->title = $data['LetCategory']['title'];
     echo $model->module = $relation->module;
     // Module trung voi module cua doi tuong can quan he
     //        $model->saveNode();
     // Category position
     if ($id > 0) {
         // truong hop update
         switch ($data['LetCategory']['position']) {
             case 'children':
                 $model->moveAsFirst($relation);
                 break;
             case 'before':
                 $model->moveBefore($relation);
                 break;
             case 'after':
                 $model->moveAfter($relation);
                 break;
         }
     } else {
         // truong hop create
         switch ($data['LetCategory']['position']) {
             case 'children':
                 $model->appendTo($relation);
                 break;
             case 'before':
                 $model->insertBefore($relation);
                 break;
             case 'after':
                 $model->insertAfter($relation);
                 break;
         }
     }
 }