Ejemplo n.º 1
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = EquipmentType::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     if (!($this->load($params) && $this->validate())) {
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id]);
     $query->andFilterWhere(['like', 'name', $this->name]);
     return $dataProvider;
 }
 public function edit($id)
 {
     if (Auth::user()->can('update-equipment')) {
         $data['equipment'] = Equipment::find($id);
         $data['title'] = $data['equipment']->company->name . " - Equipment " . $data['equipment']->name;
         $data['equipment_types'] = EquipmentType::orderBy("name")->get();
         $data['company'] = Company::find($data['equipment']->company_id);
         $data['company']->company_id = $data['company']->id;
         return view('equipment/edit', $data);
     } else {
         return redirect()->back()->withErrors(['Access denied to equipment edit page']);
     }
 }
Ejemplo n.º 3
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = EquipmentType::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     if (!($this->load($params) && $this->validate())) {
         return $dataProvider;
     }
     /* 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, 'active' => $this->active]);
     $query->andFilterWhere(['like', 'name', $this->name]);
     return $dataProvider;
 }
Ejemplo n.º 4
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getType()
 {
     return $this->hasOne(EquipmentType::className(), ['id' => 'type_id']);
 }
Ejemplo n.º 5
0
echo $form->field($model, 'status_id')->dropDownList(ArrayHelper::map(Status::find()->all(), 'id', 'status'));
?>

    <?php 
echo $form->field($model, 'room_id')->dropDownList(ArrayHelper::map(Room::find()->all(), 'id', 'name'));
?>

    <?php 
echo $form->field($model, 'location')->textInput(['maxlength' => 45]);
?>

    <?php 
echo $form->field($model, 'available')->Checkbox([], true);
?>

    <?php 
echo $form->field($model, 'type_id')->dropDownList(ArrayHelper::map(EquipmentType::find()->all(), 'id', 'name'));
?>

    <div class="form-group">
        <?php 
echo Html::submitButton($model->isNewRecord ? 'Create' : 'Update', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']);
?>
    </div>

    <?php 
ActiveForm::end();
?>

</div>
 /**
  * Finds the EquipmentType model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param string $id
  * @return EquipmentType the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = EquipmentType::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }