예제 #1
0
 public function loadModel($id)
 {
     if (!($model = Tag::findOne($id))) {
         throw new NotFoundHttpException(Yii::t('gromver.platform', 'The requested tag does not exist.'));
     }
     return $model;
 }
예제 #2
0
 protected function launch()
 {
     if (!$this->tag instanceof Tag) {
         $this->tag = Tag::findOne(intval($this->tag));
     }
     if (empty($this->tag)) {
         throw new InvalidConfigException(Yii::t('gromver.platform', 'Tag must be set.'));
     }
     echo $this->render($this->layout, ['dataProvider' => new ActiveDataProvider(['query' => $this->getQuery(), 'pagination' => ['pageSize' => $this->pageSize], 'sort' => ['defaultOrder' => [$this->sort => (int) $this->dir]]]), 'itemLayout' => $this->itemLayout, 'model' => $this->tag]);
 }
예제 #3
0
 protected function launch()
 {
     if (!$this->tag instanceof Tag) {
         $this->tag = Tag::findOne(intval($this->tag));
     }
     if (empty($this->tag)) {
         throw new InvalidConfigException(Yii::t('gromver.platform', 'Tag not found.'));
     }
     echo $this->render($this->layout, ['dataProvider' => new ActiveDataProvider(['query' => $this->tag->getTagToItems(), 'pagination' => ['pageSize' => $this->pageSize]]), 'itemLayout' => $this->itemLayout, 'model' => $this->tag]);
     $this->tag->hit();
 }
예제 #4
0
 /**
  * @param $event \Yii\base\Event
  */
 public function afterSave($event)
 {
     $this->owner->getDb()->transaction(function ($db) use($event) {
         if (isset($this->_tags) && is_array($this->_tags)) {
             $oldTags = ArrayHelper::map($this->owner->tags, 'id', 'id');
             $this->owner->setIsNewRecord(false);
             $toAppend = array_diff($this->_tags, $oldTags);
             $toRemove = array_diff($oldTags, $this->_tags);
             foreach ($toAppend as $id) {
                 $tag = Tag::findOne($id);
                 $this->owner->link('tags', $tag, ['item_class' => $this->owner->className()]);
             }
             if ($event->name == BaseActiveRecord::EVENT_AFTER_UPDATE) {
                 foreach ($toRemove as $id) {
                     $tag = Tag::findOne($id);
                     $this->owner->unlink('tags', $tag, true);
                 }
             }
         }
     });
 }
예제 #5
0
 /**
  * Finds the Tag model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Tag the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Tag::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException(Yii::t('gromver.platform', 'The requested page does not exist.'));
     }
 }