Пример #1
0
 public function run()
 {
     $allblocks = Block::find()->all();
     if (count($allblocks) == 0) {
         Config::set('rc1_block_classes_renameing', true);
     }
     if (!Config::has('rc1_block_classes_renameing')) {
         throw new Exception("You have to run the cmsadmin/updater/classes command in order to run the importer!");
     }
     $exists = [];
     foreach ($this->getImporter()->getDirectoryFiles('blocks') as $file) {
         $ns = $file['ns'];
         $model = Block::find()->where(['class' => $ns])->one();
         $blockObject = $this->createBlockObject($file['ns']);
         $blockGroupId = $this->getBlockGroupId($blockObject);
         if (!$model) {
             $block = new Block();
             $block->scenario = 'commandinsert';
             $block->setAttributes(['group_id' => $blockGroupId, 'class' => $ns]);
             $block->insert();
             $this->addLog($ns . ' new block has been added to database.');
         } else {
             $model->updateAttributes(['group_id' => $blockGroupId]);
             $exists[] = $model->id;
         }
     }
     foreach ($allblocks as $block) {
         if (!in_array($block->id, $exists)) {
             $this->addLog('block id ' . $block->id . ' removed from database.');
             $block->delete();
         }
     }
 }
Пример #2
0
 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 actionIndex($callback, $id)
 {
     $model = NavItemPageBlockItem::findOne($id);
     if (!$model) {
         throw new Exception("Unable to find item id.");
     }
     $block = Block::objectId($model->block_id, $model->id, 'callback');
     if (!$block) {
         throw new Exception("Unable to find block object.");
     }
     return ObjectHelper::callMethodSanitizeArguments($block, 'callback' . Inflector::id2camel($callback), Yii::$app->request->get());
 }
Пример #4
0
 public function actionClasses()
 {
     if (Config::has('rc1_block_classes_renameing')) {
         return $this->outputError("You already have run the classes updater, so your system should be up-to-date already.");
     }
     foreach (Block::find()->all() as $block) {
         $ns = $block->class;
         foreach ($this->_classMapping as $old => $new) {
             if (StringHelper::startsWith($ns, $old)) {
                 $this->outputError('old: ' . $ns);
                 $newNs = StringHelper::replaceFirst($old, $new, $ns);
                 $block->updateAttributes(['class' => $newNs]);
                 $this->outputSuccess('new: ' . $newNs);
             }
         }
     }
     Config::set('rc1_block_classes_renameing', true);
     return $this->outputSuccess('OK. You can now run the import command.');
 }
 /**
  * Get the block for the page block item
  *
  * @return ActiveQuery
  */
 public function getBlock()
 {
     return $this->hasOne(Block::className(), ['id' => 'block_id']);
 }
Пример #6
0
 public static function getBlock($blockId)
 {
     $blockItem = (new Query())->select('*')->from('cms_nav_item_page_block_item')->where(['id' => $blockId])->one();
     $blockObject = Block::objectId($blockItem['block_id'], $blockItem['id'], 'admin', NavItem::findOne($blockItem['nav_item_page_id']));
     if ($blockObject === false) {
         return false;
     }
     $blockItem['json_config_values'] = json_decode($blockItem['json_config_values'], true);
     $blockItem['json_config_cfg_values'] = json_decode($blockItem['json_config_cfg_values'], true);
     $blockValue = $blockItem['json_config_values'];
     $blockCfgValue = $blockItem['json_config_cfg_values'];
     $blockObject->setVarValues(empty($blockValue) ? [] : $blockValue);
     $blockObject->setCfgValues(empty($blockCfgValue) ? [] : $blockCfgValue);
     $placeholders = [];
     foreach ($blockObject->getConfigPlaceholdersExport() as $pk => $pv) {
         $pv['nav_item_page_id'] = $blockItem['nav_item_page_id'];
         $pv['prev_id'] = $blockItem['id'];
         $placeholderVar = $pv['var'];
         $pv['__nav_item_page_block_items'] = static::getPlaceholder($placeholderVar, $blockItem['nav_item_page_id'], $blockItem['id']);
         $placeholder = $pv;
         $placeholders[] = $placeholder;
     }
     if (empty($blockItem['json_config_values'])) {
         $blockItem['json_config_values'] = ['__e' => '__o'];
     }
     if (empty($blockItem['json_config_cfg_values'])) {
         $blockItem['json_config_cfg_values'] = ['__e' => '__o'];
     }
     return ['is_dirty' => (int) $blockItem['is_dirty'], 'is_container' => (int) $blockObject->getIsContainer(), 'id' => $blockItem['id'], 'is_hidden' => $blockItem['is_hidden'], 'name' => $blockObject->name(), 'icon' => $blockObject->icon(), 'full_name' => $blockObject->icon() === null ? $blockObject->name() : '<i class="material-icons">' . $blockObject->icon() . '</i> <span>' . $blockObject->name() . '</span>', 'twig_admin' => $blockObject->renderAdmin(), 'vars' => $blockObject->getConfigVarsExport(), 'cfgs' => $blockObject->getConfigCfgsExport(), 'extras' => $blockObject->getExtraVarValues(), 'values' => $blockItem['json_config_values'], 'field_help' => $blockObject->getFieldHelp(), 'cfgvalues' => $blockItem['json_config_cfg_values'], '__placeholders' => $placeholders];
 }