Esempio n. 1
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Version::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     if (!($this->load($params) && $this->validate())) {
         return $dataProvider;
     }
     if ($this->created_at) {
         $query->andWhere('{{%core_version}}.created_at >= :timestamp', ['timestamp' => $this->created_at]);
     }
     $query->andFilterWhere(['{{%core_version}}.id' => $this->id, '{{%core_version}}.item_id' => $this->item_id, '{{%core_version}}.character_count' => $this->character_count, '{{%core_version}}.created_by' => $this->created_by]);
     $query->andFilterWhere(['like', '{{%core_version}}.item_class', $this->item_class])->andFilterWhere(['like', '{{%core_version}}.version_note', $this->version_note])->andFilterWhere(['like', '{{%core_version}}.version_hash', $this->version_hash])->andFilterWhere(['like', '{{%core_version}}.version_data', $this->version_data])->andFilterWhere(['like', '{{%core_version}}.keep_forever', $this->keep_forever]);
     return $dataProvider;
 }
 /**
  * Finds the Version model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Version the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Version::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
 /**
  * @param $version_id integer
  * @return bool
  */
 public function checkout($version_id)
 {
     /** @var Version $version */
     $version = Version::find(['id' => $version_id, 'item_id' => $this->owner->getPrimaryKey(), 'item_class' => $this->owner->className()]);
     if ($version->restore()) {
         $this->owner->refresh();
         return true;
     }
     return false;
 }