예제 #1
0
 /**
  *
  * @param unknown $navId
  * @param unknown $langId
  * @param unknown $title
  * @param unknown $alias
  * @param unknown $layoutId
  * @param unknown $description
  * @return boolean
  */
 public function createPageItem($navId, $langId, $title, $alias, $layoutId, $description)
 {
     $_errors = [];
     $navItem = new NavItem();
     $navItem->parent_nav_id = self::findOne($navId)->parent_nav_id;
     $navItemPage = new NavItemPage();
     $navItem->attributes = ['nav_id' => $navId, 'lang_id' => $langId, 'title' => $title, 'alias' => $alias, 'description' => $description, 'nav_item_type' => 1];
     $navItemPage->attributes = ['nav_item_id' => 0, 'layout_id' => $layoutId, 'create_user_id' => Module::getAuthorUserId(), 'timestamp_create' => time(), 'version_alias' => Module::VERSION_INIT_LABEL];
     if (!$navItem->validate()) {
         $_errors = ArrayHelper::merge($navItem->getErrors(), $_errors);
     }
     if (!$navItemPage->validate()) {
         $_errors = ArrayHelper::merge($navItemPage->getErrors(), $_errors);
     }
     if (!empty($_errors)) {
         return $_errors;
     }
     $navItemPage->save();
     $navItem->nav_item_type_id = $navItemPage->id;
     $navItemId = $navItem->save();
     $navItemPage->updateAttributes(['nav_item_id' => $navItem->id]);
     return $navItemId;
 }
 protected function ensureInputValues($event)
 {
     // sort index fixture
     if (!$this->isNewRecord) {
         $this->_olds = $this->getOldAttributes();
     }
     // its a negative value, so its a last item, lets find the last index for current config
     if ($this->sort_index < 0) {
         $last = self::originalFind()->andWhere(['nav_item_page_id' => $this->nav_item_page_id, 'placeholder_var' => $this->placeholder_var, 'prev_id' => $this->prev_id])->orderBy('sort_index DESC')->one();
         if (!$last) {
             $this->sort_index = 0;
         } else {
             $this->sort_index = $last->sort_index + 1;
         }
     } else {
         // its not a negative value, we have to find the positions after the current sort index and update to a higher level
         $higher = self::originalFind()->where('sort_index >= :index', ['index' => $this->sort_index])->andWhere(['nav_item_page_id' => $this->nav_item_page_id, 'placeholder_var' => $this->placeholder_var, 'prev_id' => $this->prev_id])->all();
         foreach ($higher as $item) {
             $newSortIndex = $item->sort_index + 1;
             Yii::$app->db->createCommand()->update(self::tableName(), ['sort_index' => $newSortIndex], ['id' => $item->id])->execute();
         }
     }
     // manipulate timestamps
     if ($this->isNewRecord) {
         $this->timestamp_create = time();
         $this->timestamp_update = time();
         $this->create_user_id = Module::getAuthorUserId();
     } else {
         $this->deleteHasCache(['blockcache', (int) $this->id]);
         $this->is_dirty = 1;
         $this->update_user_id = Module::getAuthorUserId();
         $this->timestamp_update = time();
     }
 }
예제 #3
0
 public function eventBeforeUpdate()
 {
     $this->timestamp_update = time();
     $this->update_user_id = Module::getAuthorUserId();
     $this->slugifyAlias();
 }