/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = District::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, 'village_id' => $this->village_id, 'number' => $this->number, 'size' => $this->size, 'price' => $this->price, 'is_sold' => $this->is_sold, 'is_house' => $this->is_house]); $query->andFilterWhere(['like', 'date_ready', $this->date_ready])->andFilterWhere(['like', 'image', $this->image]); return $dataProvider; }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = District::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(['district_id' => $this->district_id, 'municipality_id' => $this->municipality_id]); $query->andFilterWhere(['like', 'district_name', $this->district_name]); return $dataProvider; }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = District::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to any records when validation fails // $query->where('0=1'); return $dataProvider; } $query->andFilterWhere(['id' => $this->id, 'city_id' => $this->city_id]); $query->andFilterWhere(['like', 'title_az', $this->title_az])->andFilterWhere(['like', 'title_ru', $this->title_ru])->andFilterWhere(['like', 'title_en', $this->title_en]); return $dataProvider; }
public function actionSelection() { $request = Yii::$app->request; $query = District::find(); $status = $request->get('is_sold', array()); $house = $request->get('is_house', array()); $village = $request->get('village_id'); $ready = $request->get('date_ready'); $price = $request->get('price'); $size = $request->get('size'); if ($status == array('0') || $status == array('1')) { $query->where(['is_sold' => $status]); } if ($house == array('0') || $house == array('1')) { $query->andWhere(['is_house' => $house]); } if (isset($village)) { $query->andWhere(['village_id' => $village]); } if (isset($ready)) { $query->andWhere(['date_ready' => $ready]); } $prices = array(100, 7000); if (isset($price) && preg_match("/^\\d+;\\d+\$/", $price)) { $prices = explode(";", $price); $query->andWhere(['>=', 'price', $prices[0]]); $query->andWhere(['<=', 'price', $prices[1]]); } $sizes = array(4, 26); if (isset($size) && preg_match("/^\\d+;\\d+\$/", $size)) { $sizes = explode(";", $size); $query->andWhere(['>=', 'size', $sizes[0]]); $query->andWhere(['<=', 'size', $sizes[1]]); } $districts = $query->orderBy('price')->all(); return $this->render('selection', ['districts' => $districts, 'status' => $status, 'house' => $house, 'village' => $village, 'ready' => $ready, 'prices' => $prices, 'sizes' => $sizes]); }
/** * DB => JSON */ public function actionExport() { echo "Export to data.json..."; $data = []; // Parties $data['parties'] = []; foreach (Party::find()->all() as $party) { $data['parties'][] = ['name' => $party->name, 'deputies' => $party->deputyCount, 'lawTagsInfo' => $party->lawTagsInfo]; } usort($data['parties'], function ($a, $b) { return $b['deputies'] - $a['deputies']; }); // Laws $data['laws'] = []; foreach (Law::find()->orderBy('(dateVoting IS NOT NULL), dateVoting DESC')->all() as $law) { $lawData = ['id' => $law->id, 'no' => $law->no, 'name' => $law->name, 'url' => $law->url, 'urlVoting' => $law->urlVoting, 'good' => $law->good, 'tagYes' => $law->tagYes, 'descYes' => $law->descYes, 'tagNo' => $law->tagNo, 'descNo' => $law->descNo, 'date' => strtotime($law->dateVoting)]; if (!$law->urlVoting) { unset($lawData['urlVoting']); } if (!$law->dateVoting) { unset($lawData['date']); } $data['laws'][] = $lawData; } // Law tags $data['lawTags'] = []; foreach (LawTag::find()->orderBy('order')->all() as $lawTag) { $data['lawTags'][] = ['name' => $lawTag->name, 'desc' => $lawTag->desc, 'type' => $lawTag->type, 'opposite' => $lawTag->opposite, 'order' => $lawTag->order, 'laws' => $lawTag->lawCount]; } // Deputies $data['deputies'] = []; foreach (Deputy::find()->orderBy('name')->all() as $deputy) { $deputyData = ['id' => $deputy->id, 'name' => $deputy->name, 'party' => $deputy->partyName, 'phones' => $deputy->phones ? explode(',', $deputy->phones) : [], 'residence' => $deputy->residence, 'dateAuthorityStart' => strtotime($deputy->dateAuthorityStart)]; if ($deputy->dateAuthorityStop) { $deputyData['dateAuthorityStop'] = strtotime($deputy->dateAuthorityStop); } if ($deputy->facebook) { $deputyData['facebook'] = $deputy->facebook; } if ($deputy->district) { $deputyData['district'] = ['id' => $deputy->district->id, 'region' => $deputy->district->region, 'text' => $deputy->district->text]; } // Deputy laws $deputyData['laws'] = []; $deputyData['laws']['відвідуваність'] = $deputy->registrationRate; foreach ($deputy->laws as $deputyLaw) { $deputyData['laws'][$deputyLaw->lawId] = $deputyLaw->vote; } // Deputy law tags and info $deputyData['lawTags'] = $deputy->lawTags; $deputyData['lawTagsInfo'] = $deputy->lawTagsInfo; $data['deputies'][] = $deputyData; } // Search suggestions $tags = array(); $tagsDeputyName = array(); $tagsDeputyDistrict = array(); foreach (LawTag::find()->orderBy('name')->all() as $lawTag) { $tags[] = array('name' => $lawTag->name, 'type' => 'law-tag', 'typeOrder' => 1, 'lawTagType' => $lawTag->type); } foreach (Party::find()->orderBy('name')->all() as $party) { $tags[] = array('name' => $party->name, 'type' => 'party', 'typeOrder' => 2); } foreach (Deputy::find()->orderBy('name')->all() as $deputy) { $tagsDeputyName[] = array('name' => $deputy->name, 'type' => 'deputy-name', 'typeOrder' => 3, 'deputyId' => $deputy->id, 'dateAuthorityStop' => $deputy->dateAuthorityStop ? $deputy->dateAuthorityStop : ''); } foreach (District::find()->orderBy('id')->all() as $district) { $tagsDeputyDistrict[] = array('name' => "Виборчий округ №{$district->id} ({$district->region})", 'type' => 'district', 'typeOrder' => 4, 'districtId' => (int) $district->id); } $data['searchSuggestions'] = array_merge($tags, $tagsDeputyName, $tagsDeputyDistrict); // Array data to json $json = json_encode($data, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT); // Save data chdir(\yii::getAlias('@frontend')); file_put_contents('data/data.json', $json); file_put_contents('js/data.js', "VVKP_DATA = {$json};"); $this->actionStatic(); $this->actionGzip(); }
echo $form->field($model, 'cat_3')->dropDownList(ArrayHelper::map(Cats::find()->all(), 'id', 'title_az'), ['prompt' => '', 'onchange' => ' $.post( "/found/list/' . '"+$(this).val(), function( data ) { $( "select#found-cat_id" ).html( data ); });']); ?> <?php echo $form->field($model, 'cat_id')->dropDownList(ArrayHelper::map(Cats::find()->all(), 'id', 'title_az'), ['prompt' => '']); ?> <?php echo $form->field($model, 'city_id')->dropDownList(ArrayHelper::map(City::find()->all(), 'id', 'title_az'), ['prompt' => '']); ?> <?php echo $form->field($model, 'district_id')->dropDownList(ArrayHelper::map(District::find()->all(), 'id', 'title_az'), ['prompt' => '', 'onchange' => ' $.post( "/lost/location/' . '"+$(this).val(), function( data ) { $( "select#found-street_id" ).html( data ); });']); ?> <?php echo $form->field($model, 'street_id')->dropDownList(ArrayHelper::map(Street::find()->all(), 'id', 'title_az'), ['prompt' => '']); ?> <?php echo $form->field($model, 'metro_id')->dropDownList(ArrayHelper::map(Metro::find()->all(), 'id', 'title_az'), ['prompt' => '']); ?> <?php echo DateTimePicker::widget(['model' => $model, 'attribute' => 'date', 'language' => 'en', 'size' => 'ms', 'inline' => true, 'template' => '<div class="well well-sm" style="background-color: #fff; width:250px">{input}</div>', 'clientOptions' => ['autoclose' => true, 'format' => 'yyyy-mm-dd - HH:ii:ss P', 'todayBtn' => true]]);
public static function district() { $alias = static::getCategory('district'); $temp = District::find()->with('content')->all(); $origin = []; foreach ($temp as $t) { $origin[$t->content->name] = $t->id; } return array_merge($origin, $alias); }
/** * Lists all District models. * @return mixed */ public function actionIndex() { $dataProvider = new ActiveDataProvider(['query' => District::find()]); return $this->render('index', ['dataProvider' => $dataProvider]); }
$form = ActiveForm::begin(); ?> <?php echo $form->field($model, 'title_az')->textInput(['maxlength' => 255]); ?> <?php echo $form->field($model, 'title_ru')->textInput(['maxlength' => 255]); ?> <?php echo $form->field($model, 'title_en')->textInput(['maxlength' => 255]); ?> <?php echo $form->field($model, 'district_id')->dropDownList(ArrayHelper::map(District::find()->all(), 'id', 'title_az'), ['promt' => 'Select District']); ?> <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>
/* @var $form yii\widgets\ActiveForm */ ?> <div class="barangay-form"> <?php $form = ActiveForm::begin(); ?> <?php echo $form->field($model, 'barangay')->textInput(['maxlength' => true]); ?> <?php $district = District::find()->all(); $listData = ArrayHelper::map($district, 'district_id', 'district_name'); echo $form->field($model, 'district_id')->dropDownList($listData, ['prompt' => 'Select your District']); ?> <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>