Esempio n. 1
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  * @param bool $unimproved
  *
  * @return ActiveDataProvider
  */
 public function search($params = [], $unimproved = false)
 {
     $query = Release::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, 'mod_id' => $this->mod_id, 'status' => $this->status, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at]);
     $query->andFilterWhere(['<', 'publish_at', $this->publish_at]);
     $query->andFilterWhere(['like', 'version', $this->version]);
     $query->andFilterWhere(['like', 'file_name', $this->version]);
     if ($unimproved) {
         $models = $dataProvider->getModels();
         $keys = $dataProvider->getKeys();
         $unimproved = $this->mod->getUnimprovedReleases($models);
         foreach ($unimproved as $release) {
             array_unshift($models, $release);
             $keys[] = key($models);
         }
         $dataProvider->setModels($models);
         $dataProvider->setKeys($keys);
     }
     return $dataProvider;
 }
Esempio n. 2
0
 public function loadModel($id)
 {
     if (($model = Release::findOne($id)) === null) {
         throw new yii\web\NotFoundHttpException('Release not found');
     }
     if (!Yii::$app->user->can('managementReleases') && !$model->isPublished() || !Yii::$app->user->can('viewProjectModReleases', ['mod' => $model->mod])) {
         throw new yii\web\ForbiddenHttpException();
     }
     return $model;
 }
Esempio n. 3
0
 /**
  * @param array|null $improves
  * @return array unimproved releases
  */
 public function getUnimprovedReleases($improves = null)
 {
     if ($improves === null) {
         $improves = $this->releases;
     }
     $path = Yii::getAlias($this->module->basePathReleases . '/' . $this->getFullAlias(count($this->project->mods) > 1 ? true : false));
     FileHelper::createDirectory($path);
     $listFolderFiles = scandir($path);
     $listTableFiles = ArrayHelper::map($improves, 'id', 'file_name');
     foreach ($listTableFiles as $i => $file) {
         if (($key = array_search($file, $listFolderFiles)) !== false) {
             unset($listFolderFiles[$key]);
         }
     }
     $unimproved = [];
     foreach ($listFolderFiles as $file) {
         if ($file != '.' && $file != '..') {
             $release = Release::createObject(['mod_id' => $this->id, 'file_name' => $file]);
             $release->parseFile();
             $unimproved[] = $release;
         }
     }
     return $unimproved;
 }
 public function loadModel($id, $group = null, $project = null, $mod = null)
 {
     if (($model = Release::findOne($id)) === null) {
         throw new NotFoundHttpException('Release not found');
     }
     if ($group !== null && $project !== null && $mod !== null) {
         if ($mod == 'default') {
             $mod = null;
         }
         if ($model->mod->alias != $mod || $model->mod->project->alias != $project || $model->mod->project->group->alias != $group) {
             throw new NotFoundHttpException('Release not found');
         }
     }
     return $model;
 }