public function run() { $row = 1; if (($handle = fopen(storage_path() . "/csvs/breweries.csv", "r")) !== FALSE) { while (($data = fgetcsv($handle)) !== FALSE) { $zip = $data[6]; // echo $zip . PHP_EOL; try { // echo Location::where('postalCode',$zip)->toSql(); $loc = Location::where('postalCode', $zip)->firstOrFail(); $locId = $loc->locId; $brewery = new Brewery(); $brewery->brewery_id = $data[0]; $brewery->name = $data[1]; $brewery->address = $data[2]; $brewery->phone = $data[8]; $brewery->website = $data[9]; $brewery->description = $data[11]; $brewery->locId = $locId; $brewery->save(); } catch (Exception $e) { // echo $e->getMessage(); // throw $e; } } fclose($handle); } else { echo 'false?'; } }
/** * Execute the console command. * * @todo DON'T UPDATE LOCATIONS IF THEY'RE ALREADY SET * * @return mixed */ public function fire() { $Bodmin = Area::firstOrCreate(['name' => 'Bodmin']); // Ensure current locations are saved. foreach (array_unique(Interview::where('location_id', '=', '')->lists('location')) as $location) { if (strlen($location) === 0) { continue; // don't want to clobber real locations } $L = Location::firstOrNew(['name' => $location]); if ($L->exists) { continue; } $L->area()->associate($Bodmin); $L->save(); } Interview::all()->each(function ($Interview) { $Location = Location::where('name', '=', $Interview->location); if ($Location->count() <= 0) { \Log::error("This location not found despite having just been confirmed a few lines above", $Interview->toArray()); return; } $Interview->location_id = $Location->first()->id; $Interview->save(); }); }
public function searchCities($key) { //$key = $_REQUEST['term']; if (isset($key)) { $locations = Location::where('city', 'like', '%' . $key . '%')->get(); if (isset($locations) && count($locations) > 0) { return json_encode(array('message' => 'found', 'locations' => $locations->toArray())); } else { return json_encode(array('message' => 'empty')); } } else { return json_encode(array('message' => 'invalid')); } }
public function allLocationsByVendor() { if (isset($_GET['vendor_id'])) { if (sizeof(Vendor::find($_GET['vendor_id'])) == 1) { $data = array('status' => 'ok', 'locations' => Location::where('vendor_id', '=', $_GET['vendor_id'])->get()); return $data; } else { $data = array('status' => 'failed', 'error_msg' => 'Vendor specified does not exist'); return $data; } } else { $data = array('status' => 'failed', 'error_msg' => 'Vendor ID was not specified'); return $data; } }
public function create() { $menu = 'registration'; $generations = Generation::all(); $classifications = Classification::where('category', '=', 'Registration')->get(); $locations = Location::where('id', '<>', Auth::user()->location_id)->get(); $employees = Employee::all(); $courses = Course::where('project_id', '=', Auth::user()->curr_project_id)->where('location_id', '=', Auth::user()->location_id)->where('availability', '=', 1)->where('active', '=', 1)->get(); $discounts = Discount::all(); $promotions = Promotion::all(); $vouchers = Voucher::all(); $charges = Charge::all(); $partners = Partner::where('location_id', '=', Auth::user()->location_id)->get(); return View::make('registrations.create', compact('classifications', 'locations', 'employees', 'generations', 'courses', 'charges', 'discounts', 'promotions', 'vouchers', 'partners', 'menu')); }
public function getCities($state) { $adminId = Session::get('admin_id'); if (!isset($adminId)) { return json_encode(array('message' => 'not logged')); } if (isset($state)) { $locations = Location::where('state', '=', $state)->where('status', '=', 'active')->get(); if (isset($locations) && count($locations) > 0) { return json_encode(array('message' => 'found', 'locations' => $locations->toArray())); } else { return json_encode(array('message' => 'empty')); } } else { return json_encode(array('message' => 'invalid')); } }
private function getNearbyUsers($latitude, $longitude, $distance, $userId) { $locations = Location::where('updated_at', '>', date("Y-m-d H:i:s", time() - self::LAST_ACTIVE_THRESHOLD_IN_SECONDS))->with("user", "user.contact", "user.bodyInformation")->get(); if ($locations->isEmpty()) { return Response::json(array("status" => "ok", "users" => array(), "msg" => "No users recently active in your area.")); } $users = array(); foreach ($locations as $location) { if ($location->user_id == $userId) { continue; } $distanceFromUser = Distances::distanceInMiles($latitude, $longitude, $location->latitude, $location->longitude); if ($distanceFromUser <= $distance) { $location['distance'] = $distanceFromUser; array_push($users, $location); } } return Response::json(array("status" => "ok", "users" => $users, "msg" => "This is all the active users near you right now!")); }
public function change() { $this->layout->body_class = 'home'; $zip_code = Input::get('zip_code', ''); $distance = Input::get('distance', '50'); Session::put('zip_code', $zip_code); Session::put('distance', $distance); $location_info = 'change location'; if (!empty($zip_code)) { $locations = Location::where('zip_code', '=', $zip_code); if ($locations->count()) { $location = Location::where('zip_code', '=', $zip_code)->first(); $city = $location->city; $state = $location->state; if (!empty($city) && !empty($state)) { $location_info = $distance . ' miles from ' . $city . ', ' . $state . ' (change)'; } } } $data = array('zip_code' => $zip_code, 'distance' => $distance, 'location_info' => $location_info); $this->layout->contents = View::make('home/home', $data); }
/** * Execute the console command. * * @return mixed */ public function fire() { $filename = $this->argument('filename'); if (!$this->option('testrun') == 'true') { $this->comment('======= Importing Assets from ' . $filename . ' ========='); } else { $this->comment('====== TEST ONLY Asset Import for ' . $filename . ' ===='); $this->comment('============== NO DATA WILL BE WRITTEN =============='); } if (!ini_get("auto_detect_line_endings")) { ini_set("auto_detect_line_endings", '1'); } $csv = Reader::createFromPath($this->argument('filename')); $csv->setNewline("\r\n"); $csv->setOffset(1); $duplicates = ''; // Loop through the records $nbInsert = $csv->each(function ($row) use($duplicates) { $status_id = 1; // Let's just map some of these entries to more user friendly words // User's name if (array_key_exists('0', $row)) { $user_name = trim($row[0]); } else { $user_name = ''; } // User's email if (array_key_exists('1', $row)) { $user_email = trim($row[1]); } else { $user_email = ''; } // User's email if (array_key_exists('2', $row)) { $user_username = trim($row[2]); } else { $user_username = ''; } // Asset Name if (array_key_exists('3', $row)) { $user_asset_asset_name = trim($row[3]); } else { $user_asset_asset_name = ''; } // Asset Category if (array_key_exists('4', $row)) { $user_asset_category = trim($row[4]); } else { $user_asset_category = ''; } // Asset Name if (array_key_exists('5', $row)) { $user_asset_name = trim($row[5]); } else { $user_asset_name = ''; } // Asset Manufacturer if (array_key_exists('6', $row)) { $user_asset_mfgr = trim($row[6]); } else { $user_asset_mfgr = ''; } // Asset model number if (array_key_exists('7', $row)) { $user_asset_modelno = trim($row[7]); } else { $user_asset_modelno = ''; } // Asset serial number if (array_key_exists('8', $row)) { $user_asset_serial = trim($row[8]); } else { $user_asset_serial = ''; } // Asset tag if (array_key_exists('9', $row)) { $user_asset_tag = trim($row[9]); } else { $user_asset_tag = ''; } // Asset location if (array_key_exists('10', $row)) { $user_asset_location = trim($row[10]); } else { $user_asset_location = ''; } // Asset notes if (array_key_exists('11', $row)) { $user_asset_notes = trim($row[11]); } else { $user_asset_notes = ''; } // Asset purchase date if (array_key_exists('12', $row)) { if ($row[12] != '') { $user_asset_purchase_date = date("Y-m-d 00:00:01", strtotime($row[12])); } else { $user_asset_purchase_date = ''; } } else { $user_asset_purchase_date = ''; } // Asset purchase cost if (array_key_exists('13', $row)) { if ($row[13] != '') { $user_asset_purchase_cost = trim($row[13]); } else { $user_asset_purchase_cost = ''; } } else { $user_asset_purchase_cost = ''; } // Asset Company Name if (array_key_exists('14', $row)) { if ($row[14] != '') { $user_asset_company_name = trim($row[14]); } else { $user_asset_company_name = ''; } } else { $user_asset_company_name = ''; } // A number was given instead of a name if (is_numeric($user_name)) { $this->comment('User ' . $user_name . ' is not a name - assume this user already exists'); $user_username = ''; // No name was given } elseif ($user_name == '') { $this->comment('No user data provided - skipping user creation, just adding asset'); $first_name = ''; $last_name = ''; //$user_username = ''; } else { $user_email_array = User::generateFormattedNameFromFullName($this->option('email_format'), $user_name); $first_name = $user_email_array['first_name']; $last_name = $user_email_array['last_name']; if ($user_email == '') { $user_email = $user_email_array['username'] . '@' . Config::get('app.domain'); } if ($user_username == '') { if ($this->option('username_format') == 'email') { $user_username = $user_email; } else { $user_name_array = User::generateFormattedNameFromFullName($this->option('username_format'), $user_name); $user_username = $user_name_array['username']; } } } $this->comment('Full Name: ' . $user_name); $this->comment('First Name: ' . $first_name); $this->comment('Last Name: ' . $last_name); $this->comment('Username: '******'Email: ' . $user_email); $this->comment('Category Name: ' . $user_asset_category); $this->comment('Item: ' . $user_asset_name); $this->comment('Manufacturer ID: ' . $user_asset_mfgr); $this->comment('Model No: ' . $user_asset_modelno); $this->comment('Serial No: ' . $user_asset_serial); $this->comment('Asset Tag: ' . $user_asset_tag); $this->comment('Location: ' . $user_asset_location); $this->comment('Purchase Date: ' . $user_asset_purchase_date); $this->comment('Purchase Cost: ' . $user_asset_purchase_cost); $this->comment('Notes: ' . $user_asset_notes); $this->comment('Company Name: ' . $user_asset_company_name); $this->comment('------------- Action Summary ----------------'); if ($user_username != '') { if ($user = User::MatchEmailOrUsername($user_username, $user_email)->whereNotNull('username')->first()) { $this->comment('User ' . $user_username . ' already exists'); } else { // Create the user $user = Sentry::createUser(array('first_name' => $first_name, 'last_name' => $last_name, 'email' => $user_email, 'username' => $user_username, 'password' => substr(str_shuffle("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"), 0, 12), 'activated' => true, 'permissions' => array('admin' => 0, 'user' => 1), 'notes' => 'User imported through asset importer')); // Find the group using the group id $userGroup = Sentry::findGroupById(3); // Assign the group to the user $user->addGroup($userGroup); $this->comment('User ' . $first_name . ' created'); } } else { $user = new User(); } // Check for the location match and create it if it doesn't exist if ($location = Location::where('name', e($user_asset_location))->first()) { $this->comment('Location ' . $user_asset_location . ' already exists'); } else { $location = new Location(); if ($user_asset_location != '') { $location->name = e($user_asset_location); $location->address = ''; $location->city = ''; $location->state = ''; $location->country = ''; $location->user_id = 1; if (!$this->option('testrun') == 'true') { if ($location->save()) { $this->comment('Location ' . $user_asset_location . ' was created'); } else { $this->comment('Something went wrong! Location ' . $user_asset_location . ' was NOT created'); } } else { $this->comment('Location ' . $user_asset_location . ' was (not) created - test run only'); } } else { $this->comment('No location given, so none created.'); } } if (e($user_asset_category) == '') { $category_name = 'Unnamed Category'; } else { $category_name = e($user_asset_category); } // Check for the category match and create it if it doesn't exist if ($category = Category::where('name', e($category_name))->where('category_type', 'asset')->first()) { $this->comment('Category ' . $category_name . ' already exists'); } else { $category = new Category(); $category->name = e($category_name); $category->category_type = 'asset'; $category->user_id = 1; if ($category->save()) { $this->comment('Category ' . $user_asset_category . ' was created'); } else { $this->comment('Something went wrong! Category ' . $user_asset_category . ' was NOT created'); } } // Check for the manufacturer match and create it if it doesn't exist if ($manufacturer = Manufacturer::where('name', e($user_asset_mfgr))->first()) { $this->comment('Manufacturer ' . $user_asset_mfgr . ' already exists'); } else { $manufacturer = new Manufacturer(); $manufacturer->name = e($user_asset_mfgr); $manufacturer->user_id = 1; if ($manufacturer->save()) { $this->comment('Manufacturer ' . $user_asset_mfgr . ' was created'); } else { $this->comment('Something went wrong! Manufacturer ' . $user_asset_mfgr . ' was NOT created'); } } // Check for the asset model match and create it if it doesn't exist if ($asset_model = Model::where('name', e($user_asset_name))->where('modelno', e($user_asset_modelno))->where('category_id', $category->id)->where('manufacturer_id', $manufacturer->id)->first()) { $this->comment('The Asset Model ' . $user_asset_name . ' with model number ' . $user_asset_modelno . ' already exists'); } else { $asset_model = new Model(); $asset_model->name = e($user_asset_name); $asset_model->manufacturer_id = $manufacturer->id; $asset_model->modelno = e($user_asset_modelno); $asset_model->category_id = $category->id; $asset_model->user_id = 1; if ($asset_model->save()) { $this->comment('Asset Model ' . $user_asset_name . ' with model number ' . $user_asset_modelno . ' was created'); } else { $this->comment('Something went wrong! Asset Model ' . $user_asset_name . ' was NOT created'); } } // Check for the asset company match and create it if it doesn't exist if ($user_asset_company_name != '') { if ($company = Company::where('name', e($user_asset_company_name))->first()) { $this->comment('Company ' . $user_asset_company_name . ' already exists'); } else { $company = new Company(); $company->name = e($user_asset_company_name); if ($company->save()) { $this->comment('Company ' . $user_asset_company_name . ' was created'); } else { $this->comment('Something went wrong! Company ' . $user_asset_company_name . ' was NOT created'); } } } else { $company = new Company(); } // Check for the asset match and create it if it doesn't exist if ($asset = Asset::where('asset_tag', e($user_asset_tag))->first()) { $this->comment('The Asset with asset tag ' . $user_asset_tag . ' already exists'); } else { $asset = new Asset(); $asset->name = e($user_asset_asset_name); if ($user_asset_purchase_date != '') { $asset->purchase_date = $user_asset_purchase_date; } else { $asset->purchase_date = NULL; } if ($user_asset_purchase_cost != '') { $asset->purchase_cost = ParseFloat(e($user_asset_purchase_cost)); } else { $asset->purchase_cost = 0.0; } $asset->serial = e($user_asset_serial); $asset->asset_tag = e($user_asset_tag); $asset->model_id = $asset_model->id; $asset->assigned_to = $user->id; $asset->rtd_location_id = $location->id; $asset->user_id = 1; $asset->status_id = $status_id; $asset->company_id = $company->id; if ($user_asset_purchase_date != '') { $asset->purchase_date = $user_asset_purchase_date; } else { $asset->purchase_date = NULL; } $asset->notes = e($user_asset_notes); if ($asset->save()) { $this->comment('Asset ' . $user_asset_name . ' with serial number ' . $user_asset_serial . ' was created'); } else { $this->comment('Something went wrong! Asset ' . $user_asset_name . ' was NOT created'); } } $this->comment('====================================='); return true; }); }
public function buildFilterQuery($exclude) { $and = array(); $zip_code = Input::query('zip_code', ''); $distance = Input::query('distance', '50'); if (!empty($zip_code) && !empty($distance)) { $locations = Location::where('zip_code', '=', $zip_code); if ($locations->count()) { $location = Location::where('zip_code', '=', $zip_code)->first(); $latitude = $location->latitude; $longitude = $location->longitude; $distance = $distance * 1.609344 . 'km'; array_push($and, array("geo_distance" => array("pin.location" => array("lat" => $latitude, "lon" => $longitude), "distance" => $distance))); } } if ($exclude != 'make') { $and = $this->utility_make->buildFilterQuery($and, Input::get('make', '')); } if ($exclude != 'model') { $and = $this->utility_model->buildFilterQuery($and, Input::get('model', '')); } if ($exclude != 'price') { $and = $this->utility_price->buildFilterQuery($and, Input::get('price', '')); $and = $this->utility_price->buildCustomFilterQuery($and, Input::get('price-custom', '')); } if ($exclude != 'mileage') { $and = $this->utility_mileage->buildFilterQuery($and, Input::get('mileage', '')); $and = $this->utility_mileage->buildCustomFilterQuery($and, Input::get('mileage-custom', '')); } if ($exclude != 'photo') { $and = $this->utility_photo->buildFilterQuery($and, Input::get('photo', '')); } if ($exclude != 'transmission') { $and = $this->utility_transmission->buildFilterQuery($and, Input::get('transmission', '')); } if ($exclude != 'year') { $and = $this->utility_year->buildFilterQuery($and, Input::get('year', '')); $and = $this->utility_year->buildCustomFilterQuery($and, Input::get('year-custom', '')); } if ($exclude != 'status') { $and = $this->utility_status->buildFilterQuery($and, Input::get('status', '')); } if ($exclude != 'body') { $and = $this->utility_body->buildFilterQuery($and, Input::get('body', '')); } if ($exclude != 'certified') { $and = $this->utility_certified->buildFilterQuery($and, Input::get('certified', '')); } if ($exclude != 'doors') { $and = $this->utility_doors->buildFilterQuery($and, Input::get('doors', '')); } if ($exclude != 'cylinders') { $and = $this->utility_cylinders->buildFilterQuery($and, Input::get('cylinders', '')); } if ($exclude != 'fuel') { $and = $this->utility_fuel->buildFilterQuery($and, Input::get('fuel', '')); } if ($exclude != 'drive') { $and = $this->utility_drive->buildFilterQuery($and, Input::get('drive', '')); } if ($exclude != 'interior') { $and = $this->utility_interior->buildFilterQuery($and, Input::get('interior', '')); } if ($exclude != 'exterior') { $and = $this->utility_exterior->buildFilterQuery($and, Input::get('exterior', '')); } $filter = array(); if (sizeof($and) > 0) { $filter['and'] = $and; return $filter; } else { return false; } }
public function getLocationBySeasonId() { $inputs = Input::all(); $location_data = Location::where('season_id', '=', $inputs['seasonId'])->get(); return Response::json(array('status' => 'success', 'data' => $location_data)); }
public static function getLocationBySeasonId($seasonId) { return Location::where('season_id', '=', $seasonId)->get(); }
public function stateCity($id) { $this->layout->body_class = ''; $state = null; foreach ($this->getStates() as $entity) { if (explode("-", $id)[0] == $entity['code']) { $state = $entity; break; } } $columns = array(array(), array(), array()); $cities = DB::select(DB::raw("SELECT DISTINCT city FROM vehicle WHERE state = :state ORDER BY city"), array('state' => $state['code'])); foreach ($cities as $key => $value) { $location = Location::where('state', '=', $state['code'])->where('city', '=', $value->city); if ($location->count()) { $zip = $location->first()->zip_code; $link = '/search?zip_code=' . $zip . '&distance=50&page=1&sort=price-1'; $title = 'Cars for sale near ' . $value->city . ', ' . $state['code']; $city = array('link' => $link, 'title' => $title); array_push($columns[$key % 3], $city); } } $data = array('search_text' => '', 'state' => $state, 'columns' => $columns); $this->layout->contents = View::make('browse/state-city', $data); }
public function geelong() { $locations = Location::where('name', '=', 'geelong')->get(); return View::make('locations.geelong', compact('locations')); }
/** * Calcuate the number of physicians within a certain number of * miles of a ZIP code. * * @param string * @return string */ public function withinDistance(Request $request) { if (!$request->has(['miles', 'zip'])) { app()->abort(404); } $location = Location::where('zip', '=', $request->zip)->get(); $lat = $location[0]->lat; $lon = $location[0]->lon; //$haversineSelectStmt = //$this->haversineSelect($lat, $lon); //$physicians = Physician::select(DB::raw($haversineSelectStmt)) //->having('distance', '<', $request->miles) //->orderBy('distance', 'asc') //->get(); $physicians = Physician::withinRadius($lat, $lon, $searchDistance)->orderBy('distance', 'asc')->paginate($limit); $count = (string) count($physicians); return json_encode(['count' => $count]); }
/** * Execute the console command. * * @return mixed */ public function fire() { $filename = $this->argument('filename'); if (!$this->option('testrun') == 'true') { $this->comment('======= Importing ' . $filename . ' ========='); } else { $this->comment('====== TEST ONLY Import for ' . $filename . ' ===='); $this->comment('============== NO DATA WILL BE WRITTEN =============='); } if (!ini_get("auto_detect_line_endings")) { ini_set("auto_detect_line_endings", '1'); } $csv = Reader::createFromPath($this->argument('filename')); $csv->setNewline("\r\n"); $csv->setOffset(1); $duplicates = ''; // Loop through the records $nbInsert = $csv->each(function ($row) use($duplicates) { $status_id = 1; // Let's just map some of these entries to more user friendly words if (array_key_exists('0', $row)) { $user_name = $row[0]; } else { $user_name = ''; } if (array_key_exists('1', $row)) { $user_email = $row[1]; } else { $user_email = ''; } if (array_key_exists('2', $row)) { $user_asset_category = $row[2]; } else { $user_asset_category = ''; } if (array_key_exists('3', $row)) { $user_asset_name = $row[3]; } else { $user_asset_name = ''; } if (array_key_exists('4', $row)) { $user_asset_mfgr = $row[4]; } else { $user_asset_mfgr = ''; } if (array_key_exists('5', $row)) { $user_asset_modelno = $row[5]; } else { $user_asset_modelno = ''; } if (array_key_exists('6', $row)) { $user_asset_serial = $row[6]; } else { $user_asset_serial = ''; } if (array_key_exists('7', $row)) { $user_asset_tag = $row[7]; } else { $user_asset_tag = ''; } if (array_key_exists('8', $row)) { $user_asset_location = $row[8]; } else { $user_asset_location = ''; } if (array_key_exists('9', $row)) { $user_asset_notes = $row[9]; } else { $user_asset_notes = ''; } if (array_key_exists('10', $row)) { if ($row[10] != '') { $user_asset_purchase_date = date("Y-m-d 00:00:01", strtotime($row[10])); } else { $user_asset_purchase_date = ''; } } else { $user_asset_purchase_date = ''; } // A number was given instead of a name if (is_numeric($user_name)) { $this->comment('User ' . $user_name . ' is not a name - assume this user already exists'); // No name was given } elseif ($user_name == '') { $this->comment('No user data provided - skipping user creation, just adding asset'); $first_name = ''; $last_name = ''; } else { $name = explode(" ", $user_name); $first_name = $name[0]; $email_last_name = ''; if (!array_key_exists(1, $name)) { $last_name = ''; $email_last_name = $last_name; $email_prefix = $first_name; } else { $last_name = str_replace($first_name, '', $user_name); if ($this->option('email_format') == 'filastname') { $email_last_name .= str_replace(' ', '', $last_name); $email_prefix = $first_name[0] . $email_last_name; } elseif ($this->option('email_format') == 'firstname.lastname') { $email_last_name .= str_replace(' ', '', $last_name); $email_prefix = $first_name . '.' . $email_last_name; } elseif ($this->option('email_format') == 'firstname') { $email_last_name .= str_replace(' ', '', $last_name); $email_prefix = $first_name; } } // Generate an email based on their name if no email address is given if ($user_email == '') { if ($first_name == 'Unknown') { $status_id = 7; } $email = strtolower($email_prefix) . '@' . $this->option('domain'); $user_email = str_replace("'", '', $email); } } $this->comment('Full Name: ' . $user_name); $this->comment('First Name: ' . $first_name); $this->comment('Last Name: ' . $last_name); $this->comment('Email: ' . $user_email); $this->comment('Category Name: ' . $user_asset_category); $this->comment('Item: ' . $user_asset_name); $this->comment('Manufacturer ID: ' . $user_asset_mfgr); $this->comment('Model No: ' . $user_asset_modelno); $this->comment('Serial No: ' . $user_asset_serial); $this->comment('Asset Tag: ' . $user_asset_tag); $this->comment('Location: ' . $user_asset_location); $this->comment('Purchase Date: ' . $user_asset_purchase_date); $this->comment('Notes: ' . $user_asset_notes); $this->comment('------------- Action Summary ----------------'); if ($user_email != '') { if ($user = User::where('email', $user_email)->first()) { $this->comment('User ' . $user_email . ' already exists'); } else { // Create the user $user = Sentry::createUser(array('first_name' => $first_name, 'last_name' => $last_name, 'email' => $user_email, 'password' => substr(str_shuffle("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"), 0, 10), 'activated' => true, 'permissions' => array('admin' => 0, 'user' => 1), 'notes' => 'Imported user')); // Find the group using the group id $userGroup = Sentry::findGroupById(3); // Assign the group to the user $user->addGroup($userGroup); $this->comment('User ' . $first_name . ' created'); } } else { $user = new User(); } // Check for the location match and create it if it doesn't exist if ($location = Location::where('name', $user_asset_location)->first()) { $this->comment('Location ' . $user_asset_location . ' already exists'); } else { $location = new Location(); $location->name = e($user_asset_location); $location->address = ''; $location->city = ''; $location->state = ''; $location->country = ''; $location->user_id = 1; if (!$this->option('testrun') == 'true') { if ($location->save()) { $this->comment('Location ' . $user_asset_location . ' was created'); } else { $this->comment('Something went wrong! Location ' . $user_asset_location . ' was NOT created'); } } else { $this->comment('Location ' . $user_asset_location . ' was (not) created - test run only'); } } // Check for the category match and create it if it doesn't exist if ($category = Category::where('name', $user_asset_category)->where('category_type', 'asset')->first()) { $this->comment('Category ' . $user_asset_category . ' already exists'); } else { $category = new Category(); $category->name = e($user_asset_category); $category->category_type = 'asset'; $category->user_id = 1; if ($category->save()) { $this->comment('Category ' . $user_asset_category . ' was created'); } else { $this->comment('Something went wrong! Category ' . $user_asset_category . ' was NOT created'); } } // Check for the manufacturer match and create it if it doesn't exist if ($manufacturer = Manufacturer::where('name', $user_asset_mfgr)->first()) { $this->comment('Manufacturer ' . $user_asset_mfgr . ' already exists'); } else { $manufacturer = new Manufacturer(); $manufacturer->name = e($user_asset_mfgr); $manufacturer->user_id = 1; if ($manufacturer->save()) { $this->comment('Manufacturer ' . $user_asset_mfgr . ' was created'); } else { $this->comment('Something went wrong! Manufacturer ' . $user_asset_mfgr . ' was NOT created'); } } // Check for the asset model match and create it if it doesn't exist if ($asset_model = Model::where('name', $user_asset_name)->where('modelno', $user_asset_modelno)->where('category_id', $category->id)->where('manufacturer_id', $manufacturer->id)->first()) { $this->comment('The Asset Model ' . $user_asset_name . ' with model number ' . $user_asset_modelno . ' already exists'); } else { $asset_model = new Model(); $asset_model->name = e($user_asset_name); $asset_model->manufacturer_id = $manufacturer->id; $asset_model->modelno = e($user_asset_modelno); $asset_model->category_id = $category->id; $asset_model->user_id = 1; if ($asset_model->save()) { $this->comment('Asset Model ' . $user_asset_name . ' with model number ' . $user_asset_modelno . ' was created'); } else { $this->comment('Something went wrong! Asset Model ' . $user_asset_name . ' was NOT created'); } } // Check for the asset match and create it if it doesn't exist $asset = new Asset(); $asset->name = e($user_asset_name); $asset->serial = e($user_asset_serial); $asset->asset_tag = e($user_asset_tag); $asset->model_id = $asset_model->id; $asset->assigned_to = $user->id; $asset->rtd_location_id = $location->id; $asset->user_id = 1; $asset->status_id = $status_id; if ($user_asset_purchase_date != '') { $asset->purchase_date = $user_asset_purchase_date; } else { $asset->purchase_date = NULL; } $asset->notes = e($user_asset_notes); if ($asset->save()) { $this->comment('Asset ' . $user_asset_name . ' with serial number ' . $user_asset_serial . ' was created'); } else { $this->comment('Something went wrong! Asset ' . $user_asset_name . ' was NOT created'); } $this->comment('====================================='); return true; }); }
/** * @param $per_page * @param string $order_by * @param string $sort * @param int $status * @return mixed */ public function searchLocations($q, $search_by, $order_by = 'name', $sort = 'asc') { $order_by = null !== Input::get('field') ? Input::get('field') : $order_by; $sort = null !== Input::get('sort') ? Input::get('sort') : $sort; return Location::where('type', $search_by)->search($q)->orderBy($order_by, $sort)->get(); }
/** * Execute the console command. * * @return mixed */ public function fire() { $filename = $this->argument('filename'); if (!$this->option('testrun') == 'true') { $this->comment('======= Importing ' . $filename . ' ========='); } else { $this->comment('====== TEST ONLY Import for ' . $filename . ' ===='); $this->comment('============== NO DATA WILL BE WRITTEN =============='); } if (!ini_get("auto_detect_line_endings")) { ini_set("auto_detect_line_endings", '1'); } $csv = Reader::createFromPath($this->argument('filename')); $csv->setNewline("\r\n"); $csv->setOffset(1); $duplicates = ''; // Loop through the records $nbInsert = $csv->each(function ($row) use($duplicates) { $status_id = 1; if (is_numeric($row[0])) { $this->comment('User ' . $row[0] . ' is not a name - assume this user already exists'); } elseif ($row[0] == '') { $this->comment('No user data provided - skipping user creation, just adding asset'); } else { // Generate an email based on their name $name = explode(" ", $row[0]); $first_name = $name[0]; $last_name = ''; $email_last_name = ''; if ($first_name == 'Unknown') { $status_id = 7; } if (!array_key_exists(1, $name)) { $last_name = ''; $email_last_name = $last_name; $email_prefix = $first_name; } else { // Loop through the rest of the explode so you don't truncate for ($x = 0; $x < count($name); $x++) { if ($x > 0 && $name[$x] != '') { $last_name .= ' ' . $name[$x]; $email_last_name .= $name[$x]; } } $email_prefix = $first_name[0] . $email_last_name; } $email = strtolower(str_replace('.', '', $email_prefix)) . '@' . $this->option('domain'); $email = str_replace("'", '', $email); $this->comment('Full Name: ' . $row[0]); $this->comment('First Name: ' . $first_name); $this->comment('Last Name: ' . $last_name); $this->comment('Email: ' . $email); $this->comment('Category Name: ' . $row[1]); $this->comment('Item: ' . $row[2]); $this->comment('Manufacturer ID: ' . $row[3]); $this->comment('Model No: ' . $row[4]); $this->comment('Serial No: ' . $row[5]); $this->comment('Asset Tag: ' . $row[6]); $this->comment('Location: ' . $row[7]); } $this->comment('------------- Action Summary ----------------'); if (isset($email)) { if ($user = User::where('email', $email)->first()) { $this->comment('User ' . $email . ' already exists'); } else { // Create the user $user = Sentry::createUser(array('first_name' => $first_name, 'last_name' => $last_name, 'email' => $email, 'password' => substr(str_shuffle("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"), 0, 10), 'activated' => true, 'permissions' => array('admin' => 0, 'user' => 1), 'notes' => 'Imported user')); // Find the group using the group id $userGroup = Sentry::findGroupById(3); // Assign the group to the user $user->addGroup($userGroup); $this->comment('User ' . $first_name . ' created'); } } else { $user = new User(); } // Check for the location match and create it if it doesn't exist if ($location = Location::where('name', $row[7])->first()) { $this->comment('Location ' . $row[7] . ' already exists'); } else { $location = new Location(); $location->name = e($row[7]); $location->address = ''; $location->city = ''; $location->state = ''; $location->country = ''; $location->user_id = 1; if (!$this->option('testrun') == 'true') { if ($location->save()) { $this->comment('Location ' . $row[7] . ' was created'); } else { $this->comment('Something went wrong! Location ' . $row[1] . ' was NOT created'); } } else { $this->comment('Location ' . $row[7] . ' was (not) created - test run only'); } } // Check for the category match and create it if it doesn't exist if ($category = Category::where('name', $row[1])->where('category_type', 'asset')->first()) { $this->comment('Category ' . $row[1] . ' already exists'); } else { $category = new Category(); $category->name = e($row[1]); $category->category_type = 'asset'; $category->user_id = 1; if ($category->save()) { $this->comment('Category ' . $row[1] . ' was created'); } else { $this->comment('Something went wrong! Category ' . $row[1] . ' was NOT created'); } } // Check for the manufacturer match and create it if it doesn't exist if ($manufacturer = Manufacturer::where('name', $row[3])->first()) { $this->comment('Manufacturer ' . $row[3] . ' already exists'); } else { $manufacturer = new Manufacturer(); $manufacturer->name = e($row[3]); $manufacturer->user_id = 1; if ($manufacturer->save()) { $this->comment('Manufacturer ' . $row[3] . ' was created'); } else { $this->comment('Something went wrong! Manufacturer ' . $row[3] . ' was NOT created'); } } // Check for the asset model match and create it if it doesn't exist if ($asset_model = Model::where('name', $row[2])->where('modelno', $row[4])->where('category_id', $category->id)->where('manufacturer_id', $manufacturer->id)->first()) { $this->comment('The Asset Model ' . $row[2] . ' with model number ' . $row[4] . ' already exists'); } else { $asset_model = new Model(); $asset_model->name = e($row[2]); $asset_model->manufacturer_id = $manufacturer->id; $asset_model->modelno = e($row[4]); $asset_model->category_id = $category->id; $asset_model->user_id = 1; if ($asset_model->save()) { $this->comment('Asset Model ' . $row[2] . ' with model number ' . $row[4] . ' was created'); } else { $this->comment('Something went wrong! Asset Model ' . $row[2] . ' was NOT created'); } } // Check for the asset match and create it if it doesn't exist $asset = new Asset(); $asset->name = e($row[2]); $asset->serial = e($row[5]); $asset->asset_tag = e($row[6]); $asset->model_id = $asset_model->id; $asset->assigned_to = $user->id; $asset->rtd_location_id = $location->id; $asset->user_id = 1; $asset->status_id = $status_id; if ($asset->save()) { $this->comment('Asset ' . $row[2] . ' with serial number ' . $row[5] . ' was created'); } else { $this->comment('Something went wrong! Asset ' . $row[5] . ' was NOT created'); } $this->comment('====================================='); return true; }); }
public function getBatchData() { $inputs = Input::all(); $franchisee_id = Session::get('franchiseId'); $batch_data = Batches::getAllBatchesbySeasonId($franchisee_id, $inputs['session_id']); for ($i = 0; $i < count($batch_data); $i++) { $batch_data[$i]['preferred_time'] = date("h:i", strtotime($batch_data[$i]['preferred_time'])); $batch_data[$i]['preferred_end_time'] = date("h:i", strtotime($batch_data[$i]['preferred_end_time'])); $location_data = Location::where('id', '=', $batch_data[$i]['location_id'])->get(); $batch_data[$i]['location_name'] = $location_data[0]['location_name']; $batch_data[$i]['created'] = date("Y-m-d", strtotime($batch_data[$i]['created_at'])); $batch_data[$i]['day'] = date('l', strtotime($batch_data[$i]['start_date'])); if ($batch_data[$i]['lead_instructor'] != '') { $user_data = User::find($batch_data[$i]['lead_instructor']); $batch_data[$i]['instructor_name'] = $user_data['first_name'] . '' . $user_data['last_name']; } else { $batch_data[$i]['instructor_name'] = ''; } $batch_data[$i]['count'] = StudentClasses::where('batch_id', '=', $batch_data[$i]['id'])->count(); } if ($batch_data) { return Response::json(array('status' => 'success', 'data' => $batch_data)); } else { return Response::json(array('status', 'failure')); } }
public function getSearchLocations($key) { if (isset($key)) { $locations = Location::where('name', 'like', '%' . $key . '%')->get(); if (isset($locations)) { return json_encode(array('message' => 'found', 'locations' => $locations->toArray())); } else { return json_encode(array('message' => 'empty')); } } else { return json_encode(array('message' => 'invalid')); } }
/** * function name : delete * edit data location * get */ public function delete($id) { if (Auth::check()) { $result = Location::where('location_id', $id)->delete(); if ($result) { return Redirect::to('admin/locations')->with('success_message', 'ลบข้อมูลเรียบร้อยแล้ว'); } else { return Redirect::to('admin/locations')->with('error_message', 'ไม่สามารถลบข้อมูลได้ กรุณาแจ้งผู้ดูแลระบบ'); } } else { return View::make('users.index'); } }