public function getMetaData() { $model = $this->getMetaModel(); $title = $model->title ?: $this->title; $description = $model->description ?: $this->short; $keywords = $model->keywords ?: implode(",", (array) ArrayHelper::getColumn($this->tags, "name")); return [$title, $description, $keywords]; }
public static function setModule($id, $config, $override = false) { $definitions = \Yii::$app->getModules(); if ($override == false) { \Yii::$app->setModule($id, ArrayHelper::merge($config, array_key_exists($id, $definitions) ? $definitions[$id] : [])); } else { \Yii::$app->setModule($id, ArrayHelper::merge(array_key_exists($id, $definitions) ? $definitions[$id] : [], $config)); } }
public function actionRead($id) { $taxonomy = Taxonomy::findByIdOrSlug($id); $children = $taxonomy->children()->all(); $ids = ArrayHelper::getColumn($children, "taxonomy_id"); array_unshift($ids, $taxonomy->getPrimaryKey()); $dataProvider = new ActiveDataProvider(['query' => TaxonomyIndex::find()->select(['entity', 'entity_id'])->distinct()->where(["taxonomy_id" => $ids])->orderBy(['taxonomy_index_id' => SORT_DESC]), 'pagination' => ['pageSize' => 15]]); list($title, $desc, $keys) = $taxonomy->getMetaData(); $this->getView()->setMetaData($title, $desc, $keys); return $this->render('view', ['taxonomyIndexs' => $dataProvider->getModels(), "pagination" => $dataProvider->getPagination(), "taxonomy" => $taxonomy]); }
/** * Creates a new Area model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionUpdate($id) { $base = $this->findModel($id); $type = $base->type; list($title, $model, $view) = AreaHelp::getBlockHook($type); $model = \Yii::createObject(array_merge(ArrayHelper::toArray($base), ["class" => $model])); $model->setIsNewRecord(false); $this->performAjaxValidation($model); if ($model->load(Yii::$app->request->post())) { if ($model->save()) { $this->flash('success', Yii::t('hass', 'updated success')); } else { $this->flash('error', Yii::t('hass', 'updated error. {0}', $model->formatErrors())); } return $this->refresh(); } return $this->render('update', ["items" => AreaHelp::getBlockNav($type), "title" => $title, "view" => $view, "model" => $model]); }
public function renderItems() { $options = $this->itemOptions; $tag = ArrayHelper::remove($options, 'tag', 'li'); $lines = []; $items = \hass\revolutionslider\models\Revolutionslider::find()->all(); if (!empty($items)) { RevolutionsliderAsset::register($this->view); } foreach ($items as $item) { $menu = $this->renderItem($item); if ($tag === false) { $lines[] = $menu; } else { $lines[] = Html::tag($tag, $menu, $options); } } return implode("\n", $lines); }
/** * Initializes the default button rendering callbacks. */ protected function initDefaultButtons() { ActionAsset::register($this->grid->view); parent::initDefaultButtons(); if (!isset($this->buttons['up'])) { $this->buttons['up'] = function ($url) { $options = ArrayHelper::merge(['title' => Yii::t('hass', 'Up'), 'aria-label' => Yii::t('hass', 'Up'), 'data-pjax' => '0'], $this->buttonOptions); Html::addCssClass($options, "move-up"); return Html::a('<span class="glyphicon glyphicon-arrow-up"></span>', $url, $options); }; } if (!isset($this->buttons['down'])) { $this->buttons['down'] = function ($url) { $options = ArrayHelper::merge(['title' => Yii::t('hass', 'Down'), 'aria-label' => Yii::t('hass', 'Down'), 'data-pjax' => '0'], $this->buttonOptions); Html::addCssClass($options, "move-down"); return Html::a('<span class="glyphicon glyphicon-arrow-down"></span>', $url, $options); }; } }
/** * 1.获取所有模块配置的权限(前台模块...怎么办?) */ public function actionPermissions($id) { $authManager = \Yii::$app->getAuthManager(); if (\Yii::$app->getRequest()->getIsPost()) { $oldPermissions = ArrayHelper::getColumn($authManager->getChildren($id), "name"); $postPermissions = array_keys(\Yii::$app->getRequest()->post("permissions", [])); $newChildren = array_diff($postPermissions, $oldPermissions); $delChildren = array_diff($oldPermissions, $postPermissions); $parent = $authManager->getRole($id); //@hass-todo 这里最好是用sql使用批量删除和添加..但是为了兼容phpmanager foreach ($delChildren as $name) { $authManager->removeChild($parent, $authManager->createPermission($name)); } foreach ($newChildren as $name) { $authManager->addChild($parent, $authManager->createPermission($name)); } return $this->refresh(); } $permissions = Hook::trigger(Module::EVENT_RBAC_PERMISSION)->parameters; return $this->render("permissions", ["permissions" => $permissions, "children" => $authManager->getChildren($id)]); }
public function getRelatedIds() { $attachments = AttachmentIndex::find()->where(['entity' => $this->getEntityClass(), 'entity_id' => $this->getEntityId(), 'attribute' => $this->attribute])->all(); return \hass\base\helpers\ArrayHelper::getColumn($attachments, 'attachment_id'); }
public function behaviors() { return ArrayHelper::merge(parent::behaviors(), ['verbs' => ['class' => VerbFilter::className(), 'actions' => ['get-form' => ['post']]]]); }
<div class="row"> <div class="col-md-4"> <?php echo $this->render("_form", ["model" => $model, "parentId" => null]); ?> </div> <div class="col-md-8"> <div class="box box-solid"> <div class="box-body no-padding"> <?php echo GridView::widget(['layout' => "{items}", 'dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'filterPosition' => GridView::FILTER_POS_HEADER, "tableOptions" => ['class' => 'table table-hover table-striped no-margin'], "columns" => [['attribute' => 'name', "format" => "html", 'value' => function ($model, $key, $index, $column) { $params = is_array($key) ? $key : ['id' => (string) $key]; $params[0] = "update"; $value = ArrayHelper::getValue($model, $column->attribute); return Html::a($value, $params); }], 'slug', ['class' => 'hass\\base\\misc\\grid\\SwitcherColumn', 'attribute' => 'status', 'filter' => StatusEnum::listData()], ['class' => 'hass\\base\\misc\\grid\\ActionColumn']]]); ?> </div> <div class="box-footer"> <div class="box-tools pull-right"> <?php echo yii\widgets\LinkPager::widget(['pagination' => $dataProvider->pagination, 'options' => ['class' => 'pagination pagination-sm inline']]); ?> </div> </div> </div> </div> </div>
/** * * @param \yii\web\Application $app */ public function initControllerMap() { \Yii::$app->controllerMap = ArrayHelper::merge(["site" => 'hass\\frontend\\controllers\\SiteController', "attachment" => 'hass\\frontend\\controllers\\AttachmentController', "comment" => 'hass\\frontend\\controllers\\CommentController', "offline" => 'hass\\frontend\\controllers\\OfflineController', "page" => 'hass\\frontend\\controllers\\PageController', "post" => 'hass\\frontend\\controllers\\PostController', "search" => 'hass\\frontend\\controllers\\SearchController', "tag" => 'hass\\frontend\\controllers\\TagController', "cat" => 'hass\\frontend\\controllers\\TaxonomyController'], \Yii::$app->controllerMap); }
public function bootstrap($app) { Hook::on(\hass\system\Module::EVENT_SYSTEM_GROUPNAV, [$this, "onSetGroupNav"]); \Yii::$app->controllerMap = ArrayHelper::merge(\Yii::$app->controllerMap, ["revolutionslider" => 'hass\\revolutionslider\\controllers\\RevolutionsliderController']); }
/** * 这里添加一个判断标准..即当有子的时候...是否显示该url * * @param array $item * the menu item to be rendered. Please refer to [[items]] to see what data might be in the item. * @return string the rendering result */ protected function renderItem($item) { if (!isset($item['url']) || $this->showParentUrl == false && isset($item["items"]) && count($item["items"]) > 0) { $template = ArrayHelper::getValue($item, 'template', $this->labelTemplate); return strtr($template, ['{label}' => $item['label']]); } $template = ArrayHelper::getValue($item, 'template', $this->linkTemplate); return strtr($template, ['{url}' => Html::encode(Url::to($item['url'])), '{label}' => $item['label']]); }
<div class="box box-solid"> <div class="box-header with-border"> <h3 class="box-title"> 评论列表 </h3> </div> <div class="box-body no-padding"> <?php echo GridView::widget(['layout' => "{items}", 'dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'filterPosition' => GridView::FILTER_POS_HEADER, "tableOptions" => ['class' => 'table table-hover table-striped no-margin'], "columns" => ['comment_id', ['attribute' => 'content', "format" => "html", 'value' => function ($model, $key, $index, $column) { $params = is_array($key) ? $key : ['id' => (string) $key]; $params[0] = "update"; $value = ArrayHelper::getValue($model, $column->attribute); return Html::a($value, $params); }], 'email', 'username', 'user_ip', ['attribute' => 'created_at', 'value' => 'createdDateTime'], ['label' => "源", 'value' => function ($model, $key, $index, $column) { return ArrayHelper::getValue($model, 'entity'); }], ['class' => 'hass\\base\\misc\\grid\\SwitcherColumn', 'attribute' => 'status', 'filter' => StatusEnum::listData()], ['class' => 'hass\\base\\misc\\grid\\ActionColumn', "template" => '{update} {delete}']]]); ?> </div> <div class="box-footer"> <div class="box-tools pull-right"> <?php echo yii\widgets\LinkPager::widget(['pagination' => $dataProvider->pagination, 'options' => ['class' => 'pagination pagination-sm inline']]); ?> </div> </div> </div>