Esempio n. 1
0
 public function actionAbc($a, $b, $c)
 {
     if (($app = Applications::find()->where(['name' => $a])->one()) !== null) {
         if (($parent_cat = Categories::find()->where(['app_id' => $app->id, 'alias' => $b])->one()) !== null) {
             // приложение -> категория по алиасу
             if (($category = Categories::find()->where(['app_id' => $app->id, 'parent_id' => $parent_cat->id, 'alias' => $c])->one()) !== null) {
                 return $this->renderCategory($category);
             } elseif (($model = Items::find()->where(['app_id' => $app->id, 'alias' => $c])->one()) !== null) {
                 // приложение -> материал по алиасу
                 return $this->renderItem($model);
             } elseif (($model = Items::find()->where(['app_id' => $app->id, 'id' => $c])->one()) !== null) {
                 // приложение -> материал по ID
                 return $this->renderItem($model);
             }
         }
     } else {
         if (($category = Categories::find()->where(['app_id' => 1, 'alias' => $a])->one()) !== null) {
             if (($model = Items::find()->where(['app_id' => 1, 'alias' => $b])->one()) !== null && $model->parentCategory->alias == $a) {
                 // приложение -> материал по алиасу
                 return $this->renderItem($model);
             } elseif (($model = Items::find()->where(['app_id' => 1, 'id' => $b])->one()) !== null && $model->parentCategory->alias == $a) {
                 // приложение -> материал по ID
                 return $this->renderItem($model);
             }
         }
         // категория дефолтного приложения -> материал
     }
     throw new NotFoundHttpException('The requested page does not exist.');
 }
Esempio n. 2
0
 public function getApp()
 {
     return $this->hasOne(Applications::className(), ['id' => 'app_id']);
 }
Esempio n. 3
0
 public function getApplications()
 {
     return Applications::find()->select(['title'])->indexBy('id')->column();
 }
Esempio n. 4
0
 public function getApp()
 {
     return $this->hasOne(Applications::className(), ['id' => 'app_id'])->with('elements')->inverseOf('items');
 }
Esempio n. 5
0
 public function getUrl()
 {
     if ($this->type == 4) {
         return \yii\helpers\Json::decode($this->url);
     } elseif ($this->type == 5) {
         return $this->url;
     } elseif ($this->type == 1) {
         if (($application = Applications::findOne($this->application_id)) !== null) {
             return $application->url;
         }
     } elseif ($this->type == 2) {
         if (($category = Categories::findOne($this->category_id)) !== null) {
             return $category->url;
         }
     } elseif ($this->type == 3) {
         $item = Items::find()->where([Items::tablename() . '.id' => $this->item_id])->one();
         if ($item !== null) {
             return $item->url;
         }
     }
     return '#';
 }
Esempio n. 6
0
 public function afterDelete()
 {
     $db = Yii::$app->db;
     foreach ($this->elements as $element) {
         $element->delete();
     }
     foreach ($this->categories as $element) {
         $element->delete();
     }
     foreach ($this->items as $element) {
         $element->delete();
     }
     unlink(Yii::getAlias('@app/controllers/' . $this->controllerName . '.php'));
     if ($this->modelName !== null) {
         if (is_file(Yii::getAlias('@app/models/' . $this->modelName . '.php'))) {
             unlink(Yii::getAlias('@app/models/' . $this->modelName . '.php'));
         }
         if (is_file(Yii::getAlias('@app/models/Search' . $this->modelName . '.php'))) {
             unlink(Yii::getAlias('@app/models/Search' . $this->modelName . '.php'));
         }
     }
     $controller = strtolower($this->name);
     $files = \yii\helpers\FileHelper::findFiles(Yii::getAlias('@app/views/' . $controller));
     if (!empty($controller) && count($files)) {
         foreach ($files as $file) {
             unlink($file);
         }
     }
     rmdir(Yii::getAlias('@app/views/' . $controller));
     parent::afterDelete();
 }
Esempio n. 7
0
 public function getApplications()
 {
     return Applications::find()->where(['app_alias' => [$this->frontendPath, '@app']])->indexBy('id')->all();
 }