public static function FetchDistrict($code) { if (\Yii::$app->language == "en") { $field = 'title'; } else { $field = 'title_ar'; } $cities = Govenment::find()->where('government_code=' . $code)->all(); $listData = ArrayHelper::map($cities, 'district', 'district'); return $listData; }
public function actionGovernment() { $code = $_REQUEST['code']; if (\Yii::$app->language == "en") { $field = 'title'; } else { $field = 'title_ar'; } $governments = Govenment::find()->where('country_code="' . $code . '"')->all(); if (count($governments) > 0) { echo "<option value=''>" . Yii::t('easyii', 'City') . "</option>"; foreach ($governments as $govern) { echo "<option value='" . $govern->government_code . "'>" . $govern->{$field} . "</option>"; } } else { echo "<option>--</option>"; } }
<?php echo $form->field($filterForm, 'country')->dropDownList(\app\models\Stores::FetchCountries(), ['prompt' => Yii::t('easyii', 'Country'), 'class' => 'btn btn-findUs dropdown-toggle', 'onchange' => ' $.post( "' . Yii::$app->urlManager->createUrl('stores/government?code=') . '"+$(this).val(), function( data ) { $( "select#gadgetsstoresfilterform-government" ).html( data ); })'])->label(''); ?> </div> <div class="col-md-4"> <?php if (isset($filterForm->country) and $filterForm->country != '') { $government = \app\models\Govenment::find()->where('country_code="' . $filterForm->country . '"')->all(); $listData = \yii\helpers\ArrayHelper::map($government, 'government_code', 'title'); } else { $listData = []; } ?> <?php echo $form->field($filterForm, 'government')->dropDownList($listData, ['prompt' => Yii::t('easyii', 'Governorate'), 'class' => 'btn btn-findUs dropdown-toggle', 'onchange' => ' $.post( "' . Yii::$app->urlManager->createUrl('stores/cities?code=') . '"+$(this).val(), function( data ) { $( "select#gadgetsstoresfilterform-district" ).html( data ); })'])->label(''); ?>
public function actionUploadGovernrate() { $model = new XlsxFile(); $filecsv = ''; if ($model->load(Yii::$app->request->post())) { $file = UploadedFile::getInstance($model, 'file'); $filename = 'Data.' . $file->extension; $upload = $file->saveAs('uploads/csv/' . $filename); define('CSV_PATH', 'uploads/csv/'); $inputFileName = CSV_PATH . $filename; try { $inputFileType = \PHPExcel_IOFactory::identify($inputFileName); $objReader = \PHPExcel_IOFactory::createReader($inputFileType); $objPHPExcel = $objReader->load($inputFileName); } catch (Exception $e) { die('Error loading file "' . pathinfo($inputFileName, PATHINFO_BASENAME) . '": ' . $e->getMessage()); } // Get worksheet dimensions $sheet = $objPHPExcel->getSheet(0); $highestRow = $sheet->getHighestRow(); $highestColumn = $sheet->getHighestColumn(); //Delet old governrates $goverObj = new Govenment(); $goverObj->deleteAll(); // Loop through each row of the worksheet in turn for ($row = 1; $row <= $highestRow; $row++) { // Read a row of data into an array $fillData = $sheet->rangeToArray('A' . $row . ':' . $highestColumn . $row, NULL, TRUE, FALSE); if ($fillData[0][0] != "gov_code" and $fillData[0][0] != '') { // echo $fillData[0][0].'----'.$fillData[0][1]."<br/>"; $goverObj = new Govenment(); $goverObj->title = $goverObj->title_ar = $fillData[0][1]; $goverObj->country_code = isset($fillData[0][3]) ? $fillData[0][3] : 'EGY'; $goverObj->government_code = $fillData[0][0]; if (!$goverObj->save()) { //var_dump($goverObj->getErrors()); } } // foreach($fillData[0] as $k=>$v) // echo "Row: ".$row."- Col: ".($k+1)." = ".$v."<br />"; // echo $v."<br/>"; // $oCustomer= new Item(); // $oCustomer->title=$fillData[0][1]; // $oCustomer->save(); } unlink('uploads/csv/' . $filename); $this->flash('success', Yii::t('easyii/customers', 'Data Imported successfully')); return $this->redirect(['/admin/customers/items/1']); } else { return $this->render('uploadcsv', ['model' => $model, 'filecsv' => $filecsv]); } }