Example #1
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Rubric::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to return any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'parent_id' => $this->parent_id]);
     $query->andFilterWhere(['like', 'title', $this->title]);
     return $dataProvider;
 }
Example #2
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getRubrics()
 {
     return $this->hasMany(Rubric::className(), ['id' => 'rubric_id'])->viaTable('company_rubric', ['company_id' => 'id']);
 }
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getRubric()
 {
     return $this->hasOne(Rubric::className(), ['id' => 'rubric_id']);
 }
 public function actionRubrics()
 {
     $rubric_ids = $this->getIds('ids');
     $rubrics = Rubric::findRecursive($rubric_ids);
     if (!empty($rubrics)) {
         $rubrics = Rubric::buildTree($rubrics);
     }
     return $rubrics;
 }
 /**
  * Finds the Rubric model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Rubric the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Rubric::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
 private function distributeRubrics()
 {
     print_r("Distribute rubrics for company...");
     $companies = Company::find()->all();
     $rubrics = Rubric::findRecursive(array(), 'down', true);
     $rubrics_ids = ArrayHelper::getColumn($rubrics, 'id');
     $rubrics_ids_count = count($rubrics_ids);
     foreach ($companies as $company) {
         $this->faker->unique(true);
         $rubric_for_company_count = $this->faker->numberBetween(self::MIN_RUBRIC_FOR_COMPANY, self::MAX_RUBRIC_FOR_COMPANY);
         for ($i = 1; $i <= $rubric_for_company_count; $i++) {
             $company_rubric = new CompanyRubric();
             $company_rubric->company_id = $company->id;
             $company_rubric->rubric_id = $rubrics_ids[$this->faker->unique()->numberBetween(0, $rubrics_ids_count - 1)];
             $company_rubric->save();
         }
     }
     print_r("DONE" . PHP_EOL);
 }