/** * Run the database seeds. * * @return void */ public function run() { $faker = Factory::create(); for ($i = 0; $i < 10; $i++) { \App\Models\Cities::create(['country_id' => '1', 'city_name' => $faker->city]); } }
/** * Displays a single Customers model. * @param integer $id * @return mixed */ public function actionView($id) { $model = $this->findModel($id); $city = Cities::findOne($model->city); $suburb = Suburbs::findOne($city->id); return $this->render('view', ['model' => $model, 'city' => $city->name, 'suburb' => $suburb->name]); }
public function run() { \Illuminate\Support\Facades\DB::table('cities')->delete(); Model::unguard(); \App\Models\Cities::create(array('city_name' => 'Воркута')); \App\Models\Cities::create(array('city_name' => 'Инта')); }
public function run() { $faker = Faker\Factory::create(); DB::table('users')->delete(); $user = User::create(['email' => '*****@*****.**', 'password' => Hash::make('123456'), 'user_name' => 'admin', 'ads_rise' => 5, 'blocked' => 0, 'balance' => 0]); foreach (range(2, 30) as $index) { $user = User::create(['email' => $faker->email, 'password' => Hash::make('1234'), 'user_name' => $faker->userName, 'ads_rise' => 5, 'blocked' => rand(0, 1), 'balance' => 0]); $city_id = Cities::orderBy(DB::raw('RAND()'))->first()->id; \ZaWeb\Profile\Models\Profile::create(['user_id' => $user->id, 'name' => $faker->firstName, 'last_name' => $faker->lastName, 'about' => $faker->sentence(10), 'city_id' => $city_id]); } }
public static function FetchCity($code) { if (\Yii::$app->language == "en") { $field = 'title'; } else { $field = 'title_ar'; } $cities = Cities::find()->where('government_code=' . $code)->all(); $listData = ArrayHelper::map($cities, 'id', $field); return $listData; }
public function run() { $faker = Faker\Factory::create(); DB::table('advertisement')->delete(); foreach (range(1, 30) as $index) { $category_id = Category::orderBy(DB::raw('RAND()'))->first()->id; $city_id = Cities::orderBy(DB::raw('RAND()'))->first()->id; $type_id = AdType::orderBy(DB::raw('RAND()'))->first()->id; // $a_hash = AdsAttachment::orderBy(DB::raw('RAND()'))->first()->hash; Advertisement::create(['category_id' => $category_id, 'text' => $faker->paragraph(4), 'user_id' => 1, 'city_id' => $city_id, 'type_id' => $type_id, 'price' => 12345, 'approved' => rand(0, 1)]); } }
public function run() { $faker = Faker\Factory::create(); DB::table('shops')->delete(); foreach (range(1, 3) as $index) { $city_id = \App\Models\Cities::orderBy(DB::raw('RAND()'))->first()->id; $user_id = rand(1, 3); $profile_id = \ZaWeb\Shops\Models\ShopProfile::orderBy(DB::raw('RAND()'))->first()->id; $attachment_id = \App\Models\Attachment::orderBy(DB::raw('RAND()'))->first()->id; \ZaWeb\Shops\Models\Shops::create(['user_id' => $user_id, 'city_id' => $city_id, 'capacity' => 300, 'attachment_id' => $attachment_id, 'profile_id' => $profile_id, 'created_at' => date('Y-m-d G:i:s'), 'updated_at' => date('Y-m-d G:i:s')]); } }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Cities::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', 'name_en', $this->name_en]); return $dataProvider; }
echo $form->field($model, 'email')->textInput(['maxlength' => true, 'placeholder' => $model->getAttributeLabel('email')])->label(false); ?> </div> </div> </div> <div class="col-lg-1"></div> </div> <div class="row"> <div class="col-lg-3"> <p>Address information</p> </div> <div class="col-lg-8"> <div class="row"> <div class="col-lg-6"> <?php echo $form->field($model, 'city')->dropDownList(ArrayHelper::map(Cities::find()->all(), 'id', 'name'), ['prompt' => 'Choose a City', 'onchange' => '$.post("' . Yii::$app->urlManager->createUrl('customers/lists') . '",{id:$(this).val()}, function( data ) { $( "select#customers-suburb" ).html( data ); });'])->label(false); ?> </div> <div class="col-lg-6"> <?php echo $form->field($model, 'street')->textInput(['maxlength' => true, 'placeholder' => $model->getAttributeLabel('street')])->label(false); ?> </div> </div> <div class="row"> <div class="col-lg-6"> <?php echo $form->field($model, 'suburb')->dropDownList(ArrayHelper::map(Suburbs::find()->asArray()->all(), 'id', 'name'), ['prompt' => 'Choose a suburb'])->label(false);
/** * Finds the Cities model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Cities the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Cities::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
public function __construct() { $this->categories = Category::lists('title', 'id'); $this->cities = Cities::get()->toArray(); $this->ad_types = AdType::lists('name', 'id'); }
<h3>delivery details</h3> <div class="row"> <div class="col-lg-9"> <div class="row"> <div class="col-lg-12"> <?php echo $form->field($model, 'address')->textInput(['maxlength' => true, 'placeholder' => $model->getAttributeLabel('address')])->label(false); ?> </div> </div> <div class="row"> <div class="col-lg-6"> <?php echo $form->field($model, 'city')->dropDownList(ArrayHelper::map(Cities::find()->all(), 'id', 'name'), ['prompt' => 'Choose a City'])->label(false); ?> </div> <div class="col-lg-6"> <?php echo $form->field($model, 'zipcode')->textInput(['maxlength' => true, 'placeholder' => $model->getAttributeLabel('zipcode')])->label(false); ?> </div> </div> <div class="row"> <div class="col-lg-12"> <?php echo $form->field($model, 'comments')->textarea(['rows' => 6, 'placeholder' => $model->getAttributeLabel('comments')])->label(false); ?> </div> </div>
/** * @param Advertisement $advertisement * @param Request $request * @return mixed */ public function index(Advertisement $advertisement, Request $request) { $ads = $advertisement::orderBy('top', 'desc')->orderBy('id', 'desc'); $input = \Input::all(); if ($request->input('search')) { $ads = $advertisement->where('text', 'LIKE', '%' . $request->input('search') . '%')->orderBy('top', 'desc')->orderBy('id', 'desc'); } if ($request->input('category_id')) { if ($input['category_id'] != 'null') { $category = Category::findOrFail(\Input::get('category_id')); $ads = Advertisement::with('category')->where('category_id', '=', $category->id)->orderBy('top', 'desc')->orderBy('id', 'desc'); } } if ($request->input('city_id')) { if ($input['city_id'] != 'null') { $city = Cities::findOrFail(\Input::get('city_id')); $ads = Advertisement::with('city')->where('city_id', '=', $city->id)->orderBy('top', 'desc')->orderBy('id', 'desc'); } } if ($request->input('type_id')) { if ($input['type_id'] != 'null') { $type = AdType::findOrFail(\Input::get('type_id')); $ads = Advertisement::with('type')->where('type_id', '=', $type->id)->orderBy('top', 'desc')->orderBy('id', 'desc'); } } if ($request->input('category_id') && $request->input('type_id')) { if ($input['category_id'] != 'null' && $input['type_id'] != 'null') { $category = Category::findOrFail(\Input::get('category_id')); $type = AdType::findOrFail(\Input::get('type_id')); $ads = Advertisement::with('category')->with('type')->where('category_id', '=', $category->id)->where('type_id', '=', $type->id)->orderBy('top', 'desc')->orderBy('id', 'desc'); } } if ($request->input('city_id') && $request->input('category_id')) { if ($input['category_id'] != 'null' && $input['city_id'] != 'null') { $category = Category::findOrFail(\Input::get('category_id')); $city = Cities::findOrFail(\Input::get('city_id')); $ads = Advertisement::with('city')->with('category')->where('city_id', '=', $city->id)->where('category_id', '=', $category->id)->orderBy('top', 'desc')->orderBy('id', 'desc'); } } if ($request->input('city_id') && $request->input('type_id')) { if ($input['city_id'] != 'null' && $input['type_id'] != 'null') { $city = Cities::findOrFail(\Input::get('city_id')); $type = AdType::findOrFail(\Input::get('type_id')); $ads = Advertisement::with('city')->with('type')->where('city_id', '=', $city->id)->where('type_id', '=', $type->id)->orderBy('top', 'desc')->orderBy('id', 'desc'); } } if ($request->input('city_id') && $request->input('category_id') && $request->input('type_id')) { if ($input['category_id'] != 'null' && $input['city_id'] != 'null' && $input['type_id'] != 'null') { $category = Category::findOrFail(\Input::get('category_id')); $city = Cities::findOrFail(\Input::get('city_id')); $type = AdType::findOrFail(\Input::get('type_id')); $ads = Advertisement::with('city')->with('category')->with('type')->where('city_id', '=', $city->id)->where('category_id', '=', $category->id)->where('type_id', '=', $type->id)->orderBy('top', 'desc')->orderBy('id', 'desc'); } } if ($_SERVER['HTTP_HOST'] == env('HOST')) { $ads = $ads->paginate(10); } else { $ads = $ads->paginate(20); } return View::make('welcome', compact('ads'))->with('input', \Input::all()); }
<?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(''); ?> </div> <div class="col-md-4"> <?php if (isset($filterForm->government) and $filterForm->government != '') { $cities = \app\models\Cities::find()->where('government_code="' . $filterForm->government . '"')->all(); $listData = \yii\helpers\ArrayHelper::map($cities, 'id', 'title'); } else { $listData = []; } ?> <?php echo $form->field($filterForm, 'district')->dropDownList($listData, ['prompt' => Yii::t('easyii', 'District'), 'class' => 'btn btn-findUs dropdown-toggle'])->label(''); ?> </div> <div class="row"> <div class="col-md-12"> <!-- <img src="--><?php
/** * Remove the specified resource from storage. * * @param int $id * @return Response */ public function destroy($id) { Cities::find($id)->delete(); return redirect()->back(); }
public function actionCities() { $code = $_REQUEST['code']; if (\Yii::$app->language == "en") { $field = 'title'; } else { $field = 'title_ar'; } $cities = Cities::find()->where('government_code="' . $code . '"')->all(); if (count($cities) > 0) { echo "<option value=''>" . Yii::t('easyii', 'District') . "</option>"; foreach ($cities as $city) { echo "<option value='" . $city->id . "'>" . $city->{$field} . "</option>"; } } else { echo "<option>--</option>"; } }
public function getCities() { return $this->hasMany(Cities::className(), ['category_id' => 'country_id']); }
public function getCities() { return response()->json(Cities::all()); }
public function compose($view) { $cities = Cities::all(); $view->with('cities', $cities); }
public function actionUploadCities() { $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 $cityobj = new Cities(); $cityobj->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); // echo $fillData[0][0].'----'.$fillData[0][1].'-----'.$fillData[0][2]."<br/>"; if ($fillData[0][0] != "gov_code" and $fillData[0][0] != '') { $cityobj = new Cities(); $cityobj->title = $cityobj->title_ar = $fillData[0][2]; $cityobj->government_code = $fillData[0][0]; $cityobj->id = $fillData[0][1]; if (!$cityobj->save()) { // var_dump($cityobj->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]); } }