/** * Run the database seeds. * * @return void */ public function run() { DB::table('counties')->truncate(); $counties = ['Bucuresti - Sector 1', 'Bucuresti - Sector 2', 'Bucuresti - Sector 3', 'Bucuresti - Sector 4', 'Bucuresti - Sector 5', 'Bucuresti - Sector 6', 'Alba', 'Arad', 'Arges', 'Bacau', 'Bihor', 'Bistrita Nasaud', 'Botosani', 'Braila', 'Brasov', 'Buzau', 'Calarasi', 'Caras Severin', 'Cluj', 'Constanta', 'Covasna', 'Dambovita', 'Dolj', 'Galati', 'Giurgiu', 'Gorj', 'Harghita', 'Hunedoara', 'Ialomita', 'Iasi', 'Ilfov', 'Maramures', 'Mehedinti', 'Mures', 'Neamt', 'Olt', 'Prahova', 'Salaj', 'Satu Mare', 'Sibiu', 'Suceava', 'Teleorman', 'Timis', 'Vaslui', 'Valcea', 'Tulcea', 'Vrancea']; foreach ($counties as $oneRow) { \App\Models\County::create(['name' => $oneRow]); } // }
/** * Show the application dashboard to the user. * * @return Response */ public function index() { //echo storage_path().'\framework\sessions';exit; $baits = Bait::lists('id', 'name_ro'); $fishs = Fish::where('enabled', 1)->orderBy('name_hu')->get(); $county = County::orderBy('name', 'asc')->get(); // print_r($county);exit; return view('home')->with(['baits' => $baits, 'fishs' => $fishs, 'county' => $county]); }
/** * @return \yii\db\ActiveQuery */ public function getCounty() { return $this->hasOne(County::className(), ['id' => 'county_id']); }
public function create() { $lake = new Lake(); if (Request::isMethod('post')) { $rules = array('name' => 'required', 'description' => 'required', 'address' => 'required', 'phone' => 'required', 'email' => 'required|email', 'website' => 'required', 'tax' => 'required', 'access' => 'required', 'contact_person' => 'required', 'latitude' => 'required|numeric', 'longitude' => 'required|numeric'); $validator = Validator::make(Input::all(), $rules); // process the login if ($validator->fails()) { return Redirect::to('admin/lake/create/')->withErrors($validator)->withInput(); } else { if (empty(Input::get('seo_url'))) { $seo_url = Helper::seo_url(Input::get('name')); } else { $seo_url = $Input::get('seo_url'); } // store $lake->name = Input::get('name'); $lake->description = Input::get('description'); $lake->tax = Input::get('tax'); $lake->status = Input::get('status') == 'on' ? 1 : 0; $lake->latitude = Input::get('latitude'); $lake->longitude = Input::get('longitude'); $lake->address = Input::get('address'); $lake->phone = Input::get('phone'); $lake->email = Input::get('email'); $lake->website = Input::get('website'); $lake->contact_person = Input::get('contact_person'); $lake->url = Input::get('url'); $lake->emphasized = Input::get('emphasized') == 'on' ? 1 : 0; $lake->seo_url = $seo_url; $lake->access = Input::get('access'); $lake->updated_at = date("Y-m-d H:i:s"); $lake->save(); $directory = Helper::lake_directory(Input::get('name')); $path = Config::get('constants.IMAGES_ABSOLUTE_URL') . '/lakes/' . $directory . '/'; $images = []; if (file_exists($path)) { //Read iamges from file if ($handle = opendir($path)) { while (false !== ($file = readdir($handle))) { if (strpos(strtolower($file), ".jpg") || strpos(strtolower($file), ".gif") || strpos(strtolower($file), ".png")) { $images[] = $file; } } closedir($handle); } $imageIds = []; $lakeID = $lake->id; if (!empty($images)) { foreach ($images as $key => $img) { $lakeImg = new LakeImage(); $lakeImg->url = $directory . '/' . $img; $lakeImg->enabled = 1; $lakeImg->uploaded = date("Y-m-d H:i:s"); $lakeImg->save(); $imageIds[] = $lakeImg->id; } if (!empty($imageIds)) { foreach ($imageIds as $key => $id) { $lakeHasImage = new LakeHasImage(); $lakeHasImage->lake_id = $lakeID; $lakeHasImage->lake_image_id = $id; $lakeHasImage->enabled = 1; $lakeHasImage->save(); } } } } // redirect Session::flash('message', 'Successfully created Lake'); return Redirect::to('/admin/lakes'); } } $counties = County::lists('name', 'id'); return view('admin.lake.create')->with(['lake' => $lake, 'counties' => $counties]); }
/** * Remove the specified county from storage. * * @param DeleteCountyRequest $request * * @param County $county * @return Response * @throws \Exception */ public function destroy(DeleteCountyRequest $request, County $county) { $this->data = $county->delete(); return $this->handleRedirect($request, route('backend.counties.index')); }
public function actionUpdateRegion() { /** * check if the user is already logged in * if so, do nothing and return them to the home screen */ if (\Yii::$app->user->isGuest) { return $this->goHome(); } $model = new UpdateRegionForm(); $stateList = State::find()->all(); $countyList = County::find()->orderBy('name')->all(); if ($model->load(Yii::$app->request->post())) { $subHead = 'You must select a region.'; if ($model->validate()) { $subHead = 'Region Successfully Changed'; $post = Yii::$app->db->createCommand()->delete('access', ['user_id' => Yii::$app->user->getId()])->execute(); foreach ($model->access as $county => $id) { if ($id != "multiselect-all") { $post = Yii::$app->db->createCommand()->insert('access', ['county_id' => $id, 'user_id' => Yii::$app->user->getId()])->execute(); } } } $access = Access::findAll(['user_id' => Yii::$app->user->getId()]); $access = ArrayHelper::getColumn($access, 'county_id'); return $this->render('update-region', ['access' => $access, 'model' => $model, 'stateList' => $stateList, 'countyList' => $countyList, 'subHead' => $subHead]); } $access = Access::findAll(['user_id' => Yii::$app->user->getId()]); $access = ArrayHelper::getColumn($access, 'county_id'); return $this->render('update-region', ['access' => $access, 'model' => $model, 'stateList' => $stateList, 'countyList' => $countyList, 'subHead' => '']); }
/** * @return \yii\db\ActiveQuery */ public function getCounties() { return $this->hasMany(County::className(), ['state_id' => 'id']); }
/** * actionRegister * * the Register action contains most of the logic behind user registration. * When it is called it checks to see if any data can be loaded into the * RegistrationForm model. If not then that means the user has not yet been * taken to the registration page, so it collects the data need to render * the registration page/form (all of the states and counties needed to fill * in the dropdowns, etc.) and renders view/site/registration. If however * data is able to be loaded into the RegistrationForm model, then that * means that the user has already submitted a filled out form, so it calls * model->validate() to make sure that all of the input is good and to make * sure that the entered username and email address have not already been * taken. If that does not return any errors then newUser(), a member * function of SiteController, is called and the RegistrationForm model is * passed in. After that, registration-confirm is rendered. */ public function actionRegister() { /** * check if the user is already logged in * if so, do nothing and return them to the home screen */ if (!\Yii::$app->user->isGuest) { return $this->goHome(); } /** * loads model that will store all data entered into the ActiveForm * on register.php and contains all front-end validation rules */ $model = new RegistrationForm(); /* Used to populate 'select state' dropdown and 'select region' section */ $stateList = State::find()->all(); /* Used to populate the 'select region' multiselects */ $countyList = County::find()->orderBy('name')->all(); /** * if the user has made a 'post' request AND registration form model * is able to succesfully register the user based on the inputted information */ if ($model->load(Yii::$app->request->post()) && $model->validate()) { /* Calls member function newUser() and passes in a populated model */ $this->newUser($model); /* registration was successful, go back to registration-confirm view */ return $this->render('registration-confirm', ['model' => $model]); } else { /** * The user has not yet been taken to the registration form so * render the registration view and pass in an empty RegistrationForm * model that is stored in $model */ return $this->render('register', ['model' => $model, 'stateList' => $stateList, 'countyList' => $countyList]); } }