public function run()
 {
     $handled = [];
     foreach ($this->getImporter()->getDirectoryFiles('blockgroups') as $file) {
         $obj = new $file['ns']();
         if (!$obj) {
             $this->addLog('Unable to create file object for: ' . $file['ns']);
             continue;
         }
         $model = BlockGroup::find()->where(['identifier' => $obj->identifier()])->one();
         if ($model) {
             $model->updateAttributes(['name' => $obj->label(), 'is_deleted' => 0]);
             $this->addLog('update blockgroup name: ' . $obj->label());
             $handled[] = $model->id;
         } else {
             $model = new BlockGroup();
             $model->name = $obj->label();
             $model->identifier = $obj->identifier();
             $model->created_timestamp = time();
             $model->save(false);
             $this->addLog('added blockgroup with name: ' . $obj->label());
             $handled[] = $model->id;
         }
     }
     foreach (BlockGroup::find()->where(['not in', 'id', $handled])->all() as $oldBlockGroup) {
         if ($oldBlockGroup->delete()) {
             $this->addLog('Old blockgroup has been deleted: ' . $oldBlockGroup->name);
         }
     }
 }
 public function actionDataBlocks()
 {
     $favs = Yii::$app->adminuser->identity->setting->get("blockfav", []);
     $groups = [];
     foreach (BlockGroup::find()->asArray()->all() as $group) {
         $blocks = [];
         $groupPosition = null;
         foreach (Block::find()->where(['group_id' => $group['id']])->all() as $block) {
             $obj = Block::objectId($block['id'], 0, 'admin');
             if (!$obj || in_array(get_class($obj), Yii::$app->getModule('cmsadmin')->hiddenBlocks)) {
                 continue;
             }
             if ($groupPosition == null) {
                 $groupObject = Yii::createObject($obj->blockGroup());
                 $groupPosition = $groupObject->getPosition();
             }
             $blocks[] = ['id' => $block['id'], 'name' => $obj->name(), 'full_name' => $obj->icon() === null ? $obj->name() : '<i class="material-icons">' . $obj->icon() . '</i> <span>' . $obj->name() . '</span>', 'favorized' => array_key_exists($block['id'], $favs)];
         }
         if (empty($blocks)) {
             continue;
         }
         $group['is_fav'] = 0;
         $group['toggle_open'] = (int) Yii::$app->adminuser->identity->setting->get("togglegroup.{$group['id']}", 1);
         $groups[] = ['groupPosition' => $groupPosition, 'group' => $group, 'blocks' => $blocks];
     }
     if (!empty($favs)) {
         $favblocks = [];
         foreach ($favs as $fav) {
             $favblocks[] = $fav;
         }
         array_unshift($groups, ['group' => ['toggle_open' => (int) Yii::$app->adminuser->identity->setting->get("togglegroup.99999", 1), 'id' => '99999', 'is_fav' => 1, 'name' => Module::t('block_group_favorites'), 'identifier' => 'favs', 'position' => 0], 'groupPosition' => 0, 'blocks' => $favblocks]);
     }
     return $groups;
 }
示例#3
0
 public function ngRestAttributeTypes()
 {
     return ['group_id' => ['selectModel', 'modelClass' => BlockGroup::className(), 'valueField' => 'id', 'labelField' => 'name'], 'class' => 'text'];
 }
示例#4
0
 private function getBlockGroupId($blockObject)
 {
     $groupClassName = $blockObject->blockGroup();
     $identifier = Yii::createObject(['class' => $groupClassName])->identifier();
     return BlockGroup::findOne(['identifier' => $identifier])->id;
 }