public function update($id) { // save updated $record = $this->records->find($id); if (!$record) { Part::create(Input::all()); return $this->respond($record); } $record->fill(Input::all())->save(); return $this->respond($record); }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Part::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); $query->joinWith('manufacturerFk AS manufacturerFk'); $dataProvider->sort->attributes['manufacturerFk.manufacturer_name'] = ['asc' => ['manufacturerFk.manufacturer_name' => SORT_ASC], 'desc' => ['manufacturerFk.manufacturer_name' => SORT_DESC]]; $query->joinWith('roleFk AS roleFk'); $dataProvider->sort->attributes['roleFk.role'] = ['asc' => ['roleFk.role' => SORT_ASC], 'desc' => ['roleFk.role' => SORT_DESC]]; $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(['part_id' => $this->part_id, 'manufacturer_fk' => $this->manufacturer_fk, 'role_fk' => $this->role_fk, 'overal_rating' => $this->overal_rating, 'price' => $this->price]); $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'part_number', $this->part_number])->andFilterWhere(['like', 'model', $this->model])->andFilterWhere(['like', 'more_info', $this->more_info]); $query->andFilterWhere(['like', 'manufacturerFk.manufacturer_name', $this->getAttribute('manufacturerFk.manufacturer_name')]); $query->andFilterWhere(['like', 'roleFk.role', $this->getAttribute('roleFk.role')]); return $dataProvider; }
/** * @return \yii\db\ActiveQuery */ public function getPartFk() { return $this->hasOne(Part::className(), ['part_id' => 'part_fk']); }
/** * Remove the specified resource from storage. * * @param int $id * * @return Response */ public function destroy($id) { Part::destroy($id); Session::flash('flash_message', 'Part deleted!'); return redirect('parts'); }
/** * @return \yii\db\ActiveQuery */ public function getParts() { return $this->hasMany(Part::className(), ['role_fk' => 'role_id']); }
/** * @return \yii\db\ActiveQuery */ public function getParts() { return $this->hasMany(Part::className(), ['manufacturer_fk' => 'manufacturer_id']); }
/** * @return \yii\db\ActiveQuery */ public function getParts() { return $this->hasMany(Part::className(), ['part_id' => 'part_fk'])->viaTable('build_part', ['build_guide_fk' => 'build_guide_id']); }
public function getParts() { return $this->hasMany(Part::className(), ['parameter_fk' => 'parameter_id'])->viaTable('part_parameter', ['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]); }