/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $this->scenario = 'search'; $query = Template::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])->andFilterWhere(['like', 'path', $this->path]); return $dataProvider; }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Template::find(); // add conditions that should always apply here $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; } // grid filtering conditions $query->andFilterWhere(['id' => $this->id]); $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'description', $this->description]); return $dataProvider; }
public static function GenerateRandomLayout($num = 1) { $data = ['label' => Yii::t('app', 'Группа макетов {num}', ['num' => $num]), 'background_color' => '#FFFFFF', 'background_image' => null, 'template_ids' => []]; $templates = Template::find()->orderBy(['count_placeholder' => SORT_DESC])->all(); if (!empty($templates)) { Yii::getLogger()->log('tmple:' . print_r($templates, true), YII_DEBUG); $max_count_placeholder = $templates[0]->count_placeholder; for ($i = 1; $i <= $max_count_placeholder; $i++) { $templates = Template::find()->where(['count_placeholder' => $i])->all(); $index = rand(0, count($templates) - 1); $data['template_ids']['ph_count_' . $i] = $templates[$index]->id; } return $data; } else { return $data; } }
public function actionGetTemplatesByPhCount() { $result = []; $this->layout = 'json'; $ph_count = Yii::$app->request->get('ph_count', 0); if ($ph_count > 0) { $conditions = []; $conditions['count_placeholder'] = $ph_count; $templates = Template::find()->where($conditions)->all(); $newtemplates = []; foreach ($templates as $key => $template) { $newtemplates[] = ['url' => Url::toRoute(['templates/view-svg', 'id' => $template->id]), 'id' => $template->id]; } $result = ['response' => ['status' => true, 'templates' => $newtemplates]]; } else { $result = ['error' => ['msg' => Yii::t('app', 'Не верный параметр')]]; } return $this->render('json', ['result' => $result]); }
public function actionAdd() { $this->layout = 'default'; $count = Template::find()->count(); $count++; $model = new Template(); $model->count_placeholder = 0; $model->weight = $count; if ($model->save()) { $model->name = '#' . $model->id; if ($model->update(false)) { $this->redirect(Url::toRoute(['templates/edit', 'id' => $model->id])); } else { Yii::$app->getSession()->setFlash('error', Yii::t('app', 'Не удалось обновить имя макета.')); $this->redirect(Url::toRoute(['templates/edit', 'id' => $model->id])); } } else { Yii::$app->getSession()->setFlash('error', Yii::t('app', 'Не удалось сохранить макет.')); $this->redirect(Url::toRoute(['templates/index'])); } return; }
private function getMapTemplates() { $templates = Template::find()->where(['publish' => 1])->all(); $mapTemplates = []; foreach ($templates as $key => $template) { //$template->json=json_decode($template->json, true); $template_arr = ['json' => json_decode($template->json, true), 'count_placeholder' => $template->count_placeholder, 'text_object' => $template->text_object, 'passepartout' => $template->passepartout, 'svg' => $template->svg, 'pb' => $template->pb]; if (empty($mapTemplates[$template->count_placeholder])) { $mapTemplates[$template->count_placeholder] = []; $mapTemplates[$template->count_placeholder][] = $template_arr; } else { $mapTemplates[$template->count_placeholder][] = $template_arr; } } return $mapTemplates; }
/** * @return array */ public static function getAll() { $templates = []; $model = Template::find()->all(); if ($model) { foreach ($model as $m) { $templates[$m->id] = $m->name . " (" . $m->id . ")"; } } return $templates; }