/** * Actual run function for all widget classes extending BaseWidget * * @return mixed */ public function widgetRun() { $pages = Page::getDb()->cache(function ($db) { return Page::find()->where(['parent_id' => $this->parent_id])->orderBy([$this->order_by => $this->order])->limit($this->limit)->all(); }, 86400, new TagDependency(['tags' => [ActiveRecordHelper::getObjectTag(Page::className(), $this->parent_id)]])); return $this->render($this->view_file, ['pages' => $pages, 'parent_id' => $this->parent_id, 'more_pages_label' => $this->more_pages_label, 'display_date' => $this->display_date, 'date_format' => $this->date_format]); }
protected function pagesSitemap($parentId = 1) { // @todo exclude subdomain urls $pages = Page::find()->select(['id', 'slug_compiled'])->where(['parent_id' => $parentId, 'published' => 1])->asArray(true)->all(); array_reduce($pages, function ($carry, $item) { $this->sitemap->addUrl('/' . $item['slug_compiled']); $this->pagesSitemap($item['id']); }); }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Page::find()->where(['language' => Language::getCurrent()]); $dataProvider = new ActiveDataProvider(['query' => $query]); if (!($this->load($params) && $this->validate())) { return $dataProvider; } $query->andFilterWhere(['id' => $this->id]); $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'layout', $this->layout])->andFilterWhere(['like', 'template', $this->template])->andFilterWhere(['like', 'active', $this->active]); return $dataProvider; }
/** * @param string $route * @return string * @throws \yii\web\NotFoundHttpException */ public function actionRoute($route = 'index') { /* @var $dp Page */ $page = Page::parse($route); $dp = Page::find()->where('name = :name AND active = :active AND language = :language', [':name' => $page, ':active' => Page::ACTIVE_YES, ':language' => Language::getCurrent()])->one(); if ($dp === null) { throw new NotFoundHttpException(Yii::t('yii', 'Page not found.')); } $this->registerLayout($dp->layout); return $this->render($dp->template, ['dp' => $dp]); }
/** * Show different standard pages. * * @param $alias * @return string|\yii\web\Response * @throws NotFoundHttpException */ public function actionPage($alias) { $this->layout = Constants::LAYOUT_MAIN; $page = Page::find()->where(['alias' => $alias])->one(); if ($page !== null && ($template = $page->getTemplate()->one()) !== null) { $this->setSeo($page); return $this->render('front/' . $template->file_name, compact('page')); } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Page::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to return any records when validation fails // $query->where('0=1'); return $dataProvider; } $query->andFilterWhere(['id' => $this->id, 'template_id' => $this->template_id, 'index_page' => $this->index_page, 'in_menu' => $this->in_menu, 'weight_in_menu' => $this->weight_in_menu]); $query->andFilterWhere(['like', 'alias', $this->alias])->andFilterWhere(['like', 'header', $this->header])->andFilterWhere(['like', 'body', $this->body])->andFilterWhere(['like', 'seo_title', $this->seo_title])->andFilterWhere(['like', 'seo_description', $this->seo_description])->andFilterWhere(['like', 'seo_keywords', $this->seo_keywords]); return $dataProvider; }
public function run() { if ($this->model === null) { $this->model = Page::findById($this->parent_id); } if ($this->model === null) { return "<!-- can't render - model is null -->"; } $children = Page::find()->where(['parent_id' => $this->model->id])->orderBy('date_added DESC'); if (null !== $this->limit) { $children->limit($this->limit); } $children = $children->all(); return $this->render($this->viewFile, ['model' => $this->model, 'children' => $children, 'more_pages_label' => $this->more_pages_label]); }
public function getActualNewsForSubsctibe($subscribe) { $actualNews = []; /** @var Page[]|HasProperties[] $pages */ $pages = Page::find(['is_deleted' => '0', 'published' => '1'])->andWhere("date_added > '{$subscribe->last_notify}'")->all(); if (count($pages) > 0) { foreach ($pages as $page) { $prop = $page->getPropertyValuesByKey("mailingType"); if ($prop == 'news') { $n = ['name' => $page->h1, 'announce' => $page->announce, 'date_added' => $page->date_added]; array_push($actualNews, $n); } } } return $actualNews; }
/** * @inheritdoc * @return string */ public function run() { if ($this->model === null) { $this->model = Page::findById($this->parent_id); } if ($this->model === null) { return "<!-- can't render - model is null -->"; } $cacheKey = 'PagesListWidget:' . $this->model->id . ':limit:' . $this->limit; $children = Yii::$app->cache->get($cacheKey); if ($children === false) { $children = Page::find()->where(['parent_id' => $this->model->id])->orderBy(['date_added' => SORT_DESC]); if (null !== $this->limit) { $children->limit($this->limit); } $children = $children->all(); Yii::$app->cache->set($cacheKey, $children, 86400, new TagDependency(['tags' => [ActiveRecordHelper::getCommonTag(Page::className())]])); } return $this->render($this->viewFile, ['model' => $this->model, 'children' => $children, 'more_pages_label' => $this->more_pages_label]); }
/** * @param int $id * @param int $is_published * @return mixed */ public static function findById($id, $is_published = 1) { if (!is_numeric($id)) { return null; } if (!isset(static::$identity_map[$id])) { $cacheKey = "Page:{$id}:{$is_published}"; static::$identity_map[$id] = Yii::$app->cache->get($cacheKey); if (!is_object(static::$identity_map[$id])) { static::$identity_map[$id] = Page::find()->where(['id' => $id, 'published' => $is_published])->with('images')->one(); if (is_object(static::$identity_map[$id])) { Yii::$app->cache->set($cacheKey, static::$identity_map[$id], 86400, new TagDependency(['tags' => [ActiveRecordHelper::getCommonTag(static::className())]])); } } } return static::$identity_map[$id]; }
/** * @return array * @throws ForbiddenHttpException */ public function actionSearch() { /** * @param $module \app\modules\page\PageModule */ if (!Yii::$app->request->isAjax) { throw new ForbiddenHttpException(); } $model = new Search(); $model->load(Yii::$app->request->get()); $cacheKey = 'PageSearchIds: ' . $model->q; $ids = Yii::$app->cache->get($cacheKey); if ($ids === false) { $ids = $model->searchPagesByDescription(); Yii::$app->cache->set($cacheKey, $ids, 86400, new TagDependency(['tags' => ActiveRecordHelper::getCommonTag(Page::className())])); } $pages = new Pagination(['defaultPageSize' => $this->module->searchResultsLimit, 'forcePageParam' => false, 'pageSizeLimit' => [$this->module->minPagesPerList, $this->module->maxPagesPerList], 'totalCount' => count($ids)]); $cacheKey .= ' : ' . $pages->offset; $pagelist = Yii::$app->cache->get($cacheKey); if ($pagelist === false) { $pagelist = Page::find()->where(['in', '`id`', array_slice($ids, $pages->offset, $pages->limit)])->addOrderBy('sort_order')->with('images')->all(); Yii::$app->cache->set($cacheKey, $pagelist, 86400, new TagDependency(['tags' => ActiveRecordHelper::getCommonTag(Page::className())])); } Yii::$app->response->format = Response::FORMAT_JSON; return ['view' => $this->renderPartial('search', ['model' => $model, 'pagelist' => $pagelist, 'pages' => $pages]), 'totalCount' => count($ids)]; }
public function actionRemoveAll($parent_id) { $items = Yii::$app->request->post('items', []); if (!empty($items)) { $items = Page::find()->where(['in', 'id', $items])->all(); foreach ($items as $item) { $item->delete(); } } return $this->redirect(['index', 'parent_id' => $parent_id]); }
/** * Return main page. * @return array|null|\yii\db\ActiveRecord */ public static function getIndexPage() { return Page::find()->where(['index_page' => true])->one(); }
/** * @return string */ public function run() { return Json::encode(ArrayHelper::merge([['name' => Yii::t('imperavi', 'Link to the page'), 'url' => '#']], ArrayHelper::getColumn(Page::find()->where(['language' => Language::getCurrent()])->asArray()->all(), function ($row) { return ['name' => $row['title'], 'url' => Yii::$app->getUrlManager()->createUrl($row['name'])]; }))); }
<div class="form-group"> <?php echo $form->field($model, 'menu')->dropDownList($model->listOfMenus(), ['id' => 'menu', 'class' => 'form-control', 'prompt' => 'Выберите меню']); ?> </div> </div> </div> <?php echo $form->field($model, 'parent_id')->widget(DepDrop::classname(), ['options' => ['id' => 'parent-id'], 'pluginOptions' => ['depends' => ['menu'], 'placeholder' => 'Select...', 'url' => Url::to(['/page/menu-point/menu'])]]); ?> <div class="row"> <div class="col-md-5"> <?php echo $form->field($model, 'page_id')->dropDownList(ArrayHelper::map(Page::find()->all(), 'id', 'header'), ['class' => 'form-control', 'prompt' => 'Выберите страницу']); ?> </div> <div class="col-md-2 text-center" style="margin-top: 30px;"> <b>ИЛИ</b> </div> <div class="col-md-5"> <?php echo $form->field($model, 'link')->textInput(['maxlength' => true]); ?> </div> </div> <div class="form-group"> <?php echo Html::submitButton($model->isNewRecord ? 'Create' : 'Update', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']);