Пример #1
0
 public function run()
 {
     $item = Items::find()->where(['id' => $this->id])->one();
     return '<div class="articleWidget articleWidget-' . $this->id . ' ' . $this->classes . '">
             <h3><a href="' . $item->getItemUrl() . '" title="' . Html::encode($item->title) . '">' . Html::encode($item->title) . '</a></h3>
             <div class="widgetText">' . HtmlPurifier::process($item->introtext) . '</div>
         </div>';
 }
Пример #2
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Items::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'catid' => $this->catid, 'userid' => $this->userid, 'published' => $this->published, 'access' => $this->access, 'ordering' => $this->ordering, 'hits' => $this->hits, 'created' => $this->created, 'created_by' => $this->created_by, 'modified' => $this->modified, 'modified_by' => $this->modified_by]);
     $query->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'alias', $this->alias])->andFilterWhere(['like', 'introtext', $this->introtext])->andFilterWhere(['like', 'fulltext', $this->fulltext])->andFilterWhere(['like', 'language', $this->language])->andFilterWhere(['like', 'image', $this->image])->andFilterWhere(['like', 'image_caption', $this->image_caption])->andFilterWhere(['like', 'image_credits', $this->image_credits])->andFilterWhere(['like', 'video', $this->video])->andFilterWhere(['like', 'video_type', $this->video_type])->andFilterWhere(['like', 'video_caption', $this->video_caption])->andFilterWhere(['like', 'video_credits', $this->video_credits])->andFilterWhere(['like', 'params', $this->params])->andFilterWhere(['like', 'metadesc', $this->metadesc])->andFilterWhere(['like', 'metakey', $this->metakey])->andFilterWhere(['like', 'robots', $this->robots])->andFilterWhere(['like', 'author', $this->author])->andFilterWhere(['like', 'copyright', $this->copyright]);
     return $dataProvider;
 }
Пример #3
0
 /**
  * Creates data provider instance with search query applied
  * @param array $params
  * @return ActiveDataProvider
  * @throws ForbiddenHttpException
  */
 public function search($params)
 {
     if (Yii::$app->user->can('index-his-articles')) {
         $query = Items::find()->where(['created_by' => Yii::$app->user->identity->id]);
     } elseif (Yii::$app->user->can('index-all-articles')) {
         $query = Items::find();
     } else {
         throw new ForbiddenHttpException();
     }
     $query->joinWith('category');
     $query->joinWith('createdby');
     $query->joinWith('modifiedby');
     $query->joinWith('user');
     $dataProvider = new ActiveDataProvider(['query' => $query, 'sort' => ['defaultOrder' => ['id' => SORT_DESC]]]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'userid' => $this->userid, 'published' => $this->published, 'access' => $this->access, 'ordering' => $this->ordering, 'hits' => $this->hits, 'created' => $this->created, 'modified' => $this->modified]);
     $query->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'alias', $this->alias])->andFilterWhere(['like', 'category.name', $this->catid])->andFilterWhere(['like', 'createdby.username', $this->created_by])->andFilterWhere(['like', 'modifiedby.username', $this->modified_by])->andFilterWhere(['like', 'introtext', $this->introtext])->andFilterWhere(['like', 'fulltext', $this->fulltext])->andFilterWhere(['like', 'language', $this->language])->andFilterWhere(['like', 'image', $this->image])->andFilterWhere(['like', 'image_caption', $this->image_caption])->andFilterWhere(['like', 'image_credits', $this->image_credits])->andFilterWhere(['like', 'video', $this->video])->andFilterWhere(['like', 'video_type', $this->video_type])->andFilterWhere(['like', 'video_caption', $this->video_caption])->andFilterWhere(['like', 'video_credits', $this->video_credits])->andFilterWhere(['like', 'params', $this->params])->andFilterWhere(['like', 'metadesc', $this->metadesc])->andFilterWhere(['like', 'metakey', $this->metakey])->andFilterWhere(['like', 'robots', $this->robots])->andFilterWhere(['like', 'author', $this->author])->andFilterWhere(['like', 'copyright', $this->copyright]);
     return $dataProvider;
 }
Пример #4
0
 public function getUsersSelect2($userid, $username)
 {
     $sql = 'SELECT id,username FROM {{%user}} WHERE id != ' . $userid;
     $users = Items::findBySql($sql)->asArray()->all();
     $array[$userid] = $username;
     foreach ($users as $user) {
         $array[$user['id']] = $user['username'];
     }
     return $array;
 }
Пример #5
0
 /**
  * Finds the Items model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Items the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Items::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
Пример #6
0
 /**
  * Get Items by Category ID
  * @param integer $catid
  * @param string $order
  * @return Items
  */
 public function getItemsByCategory($catid, $order = 'title')
 {
     $items = Items::find()->where(['catid' => $catid])->andWhere(['state' => 1])->andWhere(['or', ['language' => 'All'], ['SUBSTRING(language,1,2)' => Yii::$app->language]])->orderBy($order)->all();
     return $items;
 }
Пример #7
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getItem()
 {
     return $this->hasOne(Items::className(), ['id' => 'itemid']);
 }
Пример #8
0
 /**
  * Return array with all Items
  * @return array
  */
 public function getItemsSelect2()
 {
     $array = array();
     $items = Items::find()->select(['id', 'title'])->all();
     foreach ($items as $item) {
         $array[$item['id']] = $item['title'];
     }
     return $array;
 }