/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = BuildGuide::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(['build_guide_id' => $this->build_guide_id, 'user_fk' => $this->user_fk, 'visibility_fk' => $this->visibility_fk, 'last_update' => $this->last_update, 'in_order' => $this->in_order]); $query->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'guide', $this->guide]); return $dataProvider; }
public function actionIndex() { $lastBuildGuide = BuildGuide::getNewestBuildGuide(); if (Yii::$app->user->identity) { if (Yii::$app->user->identity->isStaff()) { $lastAnnounsment = Announcement::getNewestAnnounsment(); $newOrderCount = Order::getNewOrders(); return $this->render('staffIndex', ['lastAnnounsment' => $lastAnnounsment, 'newOrderCount' => $newOrderCount]); } else { $myBuild = BuildGuide::getMyNewestBuild(); return $this->render('index', ['lastBuildGuide' => $lastBuildGuide, 'myBuild' => $myBuild]); } } else { return $this->render('index', ['lastBuildGuide' => $lastBuildGuide, 'myBuild' => NULL]); } }
/** * @return \yii\db\ActiveQuery */ public function getBuildGuides() { return $this->hasMany(BuildGuide::className(), ['visibility_fk' => 'visibility_id']); }
public static function getMyNewestBuild() { $lastBuildGuide = BuildGuide::find()->where(['user_fk' => Yii::$app->user->identity->user_id])->orderBy('last_update DESC')->one(); return $lastBuildGuide; }
/** * @return \yii\db\ActiveQuery */ public function getBuildGuides() { return $this->hasMany(BuildGuide::className(), ['user_fk' => 'user_id']); }
/** * @return \yii\db\ActiveQuery */ public function getBuildFk() { return $this->hasOne(BuildGuide::className(), ['build_guide_id' => 'build_fk']); }
/** * Finds the BuildGuide model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return BuildGuide the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = BuildGuide::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
/** * @return \yii\db\ActiveQuery */ public function getBuilds() { return $this->hasMany(BuildGuide::className(), ['build_guide_id' => 'build_guide_fk'])->viaTable('build_part', ['part_fk' => 'part_id']); }
public function actionLinkPart($build_id, $part_id) { $oldLink = BuildPart::findOne(['part_fk' => Yii::$app->session['old_part_id'], 'build_guide_fk' => $build_id]); if ($oldLink != NULL) { $oldLink->part_fk = $part_id; $oldLink->update(); } else { $build = BuildGuide::find()->where(['build_guide_id' => $build_id])->one(); $part = Part::find()->where(['part_id' => $part_id])->one(); $part->link('builds', $build); } return $this->redirect(['/build-guide/view', 'id' => $build_id]); }