/** * Create a category */ public function actionCreate() { try { $parent_id = (int) ArrayHelper::getValue($_POST, 'parent_id', 0); $module = ArrayHelper::getValue($_POST, 'module', null); $title = ArrayHelper::getValue($_POST, 'title', ''); if (!empty($module)) { $modelParent = LetCategory::findOne($parent_id); $model = new LetCategory(); $model->title = $title; $model->module = $module; $model->appendTo($modelParent); echo $model->id; } else { echo 0; } } catch (ErrorException $e) { echo 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; } } }