/**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Material::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]);
     $query->andFilterWhere(['like', 'name', $this->name]);
     return $dataProvider;
 }
Beispiel #2
0
 public function actionIndex()
 {
     $query = Material::find()->where(['public_id' => $this->pid]);
     $countQuery = clone $query;
     $pages = new Pagination(['totalCount' => $countQuery->count(), 'pageSize' => 20]);
     $models = $query->offset($pages->offset)->limit($pages->limit)->orderBy(['create_time' => SORT_DESC])->all();
     $data = [];
     if (!empty($models)) {
         foreach ($models as $k => $v) {
             $data[$k] = $v->attributes;
             $data[$k]['create_time'] = date('Y-m-d H:s', $v['create_time']);
         }
     }
     return $this->render('index', ['models' => $data, 'pages' => $pages]);
 }
Beispiel #3
0
 /**
  * Updates an existing Supplies model.
  * If update is successful, the browser will be redirected to the 'view' page.
  * @param integer $id
  * @return mixed
  */
 public function actionUpdate($id)
 {
     $model = $this->findModel($id);
     $media = Media::find()->orderBy('id DESC')->all();
     $type_mat = Material::find()->all();
     $type_blind = array(0 => 'Выберите тип жалюзеу', 1 => 'горизонтальные', 2 => 'рулонные', 3 => 'вертикальные');
     $arr_tmat[0] = 'Выберите тип материала';
     foreach ($type_mat as $v) {
         $arr_tmat[$v->id] = $v->name;
     }
     $color = Color::find()->all();
     $arr_color[0] = 'Выберите цвет';
     foreach ($color as $v) {
         $arr_color[$v->id] = $v->value;
     }
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['update', 'id' => $model->id]);
     } else {
         return $this->render('update', ['model' => $model, 'media' => $media, 'type_mat' => $arr_tmat, 'type_blind' => $type_blind, 'color' => $arr_color]);
     }
 }
 /**
  * Finds the Material model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Material the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Material::find()->where(['id' => $id])->with('sites')->asArray()->one()) !== null) {
         return $model;
     } else {
         Yii::$app->response->format = 'json';
         Yii::$app->response->setStatusCode(404);
         return ['message' => 'Record not found'];
     }
 }
Beispiel #5
0
 public static function getOneAddSupplies($id, $title)
 {
     $supl = \backend\modules\supplies\models\Supplies::find()->where(['id' => $id])->one();
     $html = '';
     $html .= '<tr class="itemPage" page-id="' . $title . '" materials-id="' . $supl->id . '" item-type="materials">';
     $html .= '<td><img src="' . $supl->images . '" style = "width:100px;"/></td>';
     $html .= '<td>' . $supl->code . '</td>';
     $type_materials = Material::find()->where(['id' => $supl->type_mat])->one();
     $html .= '<td>' . $type_materials->name . '</td>';
     if ($supl->type_blind == 1) {
         $html .= '<td>Горизонтальные</td>';
     }
     if ($supl->type_blind == 2) {
         $html .= '<td>Вертикальные</td>';
     }
     if ($supl->type_blind == 3) {
         $html .= '<td>Рулонные</td>';
     }
     $html .= '<td>' . $supl->type_width . '</td>';
     $color = Color::find()->where(['id' => $supl->color])->one();
     $html .= '<td><div class="colorSuplies" style="width:50px;height:25px;background: ' . $color->value . '"></div></td>';
     $html .= '<td>' . $supl->price . '</td>';
     $html .= '<td><a id-materials="' . $supl->id . '"class = "delSuplies" href="#">Открепить</a></td>';
     $html .= '</tr>';
     return $html;
 }