コード例 #1
0
 /**
  * Show the application login form.
  *
  * @return \Illuminate\Http\Response
  */
 public function getLogin()
 {
     if (view()->exists('auth.authenticate')) {
         return view('auth.authenticate');
     }
     $tae = Courier::where('code', 'TAE')->get()->first();
     return view('auth.login', ['institutions' => $tae->institutions()->orderBy('name')->get()->lists('full_name', 'id')]);
 }
コード例 #2
0
 /**
  * Show the form for editing the specified resource.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function edit($id)
 {
     # We only want each user to edit their own password (or admins)
     if (!Auth::user()->admin && Auth::user()->id != $id) {
         return Redirect::route('home');
     }
     $tae = Courier::where('code', 'TAE')->with('institutions')->get()->first();
     return view('users.edit', ['user' => User::find($id), 'institutions' => $tae->institutions->lists('full_name', 'id')]);
 }
コード例 #3
0
 public function run()
 {
     DB::table('couriers')->delete();
     $prefs = ['additional_label_field' => null, 'code1' => 'courier_code', 'code2' => 'site_code', 'code3' => 'hub', 'use_address1' => true, 'use_address2' => false];
     Courier::create(array('name' => 'Trans Amigos Express', 'code' => 'TAE', 'label_preferences_json' => $prefs));
     $prefs['use_address2'] = true;
     Courier::create(array('name' => 'KLE', 'code' => 'KS', 'label_preferences_json' => $prefs));
     $prefs['code2'] = 'hub';
     $prefs['code3'] = 'site_code';
     $prefs['use_address2'] = false;
     Courier::create(array('name' => 'Mobius', 'code' => 'MOB', 'label_preferences_json' => $prefs));
     $prefs['code2'] = null;
     $prefs['code3'] = null;
     $prefs['additional_label_field'] = 'MALA HUB CODE:   :hub';
     Courier::create(array('name' => 'MALA', 'code' => 'MALA', 'label_preferences_json' => $prefs));
 }
コード例 #4
0
 /**
  * Remove all institutions relations for the specified resource.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function removeInstitutions($id)
 {
     $courier = Courier::withTrashed()->with('institutions')->find($id);
     foreach ($courier->institutions as $institution) {
         $institution->delete();
     }
     return Redirect::route('couriers.index');
 }
コード例 #5
0
 public function get($courier_id)
 {
     $courier = Courier::find($courier_id);
     $existing = ['by_oclc' => [], 'by_codes' => [], 'by_name' => []];
     foreach ($courier->institutions as $inst) {
         if (!isset($existing['by_oclc'][$inst->oclc])) {
             $existing['by_oclc'][$inst->oclc] = $inst;
         } else {
             $existing['by_oclc'][$inst->oclc] = null;
         }
         $code_key = "{$inst->hub}_{$inst->site_code}";
         if (!isset($existing['by_codes'][$code_key])) {
             $existing['by_codes'][$code_key] = $inst;
         } else {
             $existing['by_codes'][$code_key] = null;
         }
         if (!isset($existing['by_name'][$inst->name])) {
             $existing['by_name'][$inst->name] = $inst;
         } else {
             $existing['by_name'][$inst->name] = null;
         }
     }
     $results = ['added' => 0, 'updated' => 0, 'skipped' => 0];
     Excel::load(Input::file('institutionFile'), function ($reader) use($courier, $existing, &$results) {
         $done = false;
         // We only want to do the first sheet so we track it (hack-ishly) like this
         $reader->each(function ($sheet) use($courier, $existing, &$results, &$done) {
             if ($done) {
                 return;
             }
             $sheet->each(function ($row) use($courier, $existing, &$results) {
                 // Bail out if the row doesn't have a state.
                 if (!isset($row['state']) || is_null($row['state'])) {
                     return;
                 }
                 $mapping = array('site_code' => ['site', 'site_code'], 'hub' => ['hub', 'hub_code'], 'oclc' => ['oclc', 'oclc_symbol'], 'type' => ['type'], 'service_length' => ['service'], 'name' => ['institution', 'institution_name', 'library_name', 'name'], 'address1' => ['address1', 'address'], 'address2' => ['address2'], 'city' => ['city'], 'state' => ['state'], 'postal_code' => ['postalcode', 'zip_code'], 'notes' => ['special_notes', 'notes']);
                 $ints = ['service_length'];
                 $properties = array();
                 foreach ($mapping as $key => $tokens) {
                     $properties[$key] = null;
                     foreach ($tokens as $token) {
                         if (isset($row->{$token})) {
                             if (in_array($key, $ints)) {
                                 $properties[$key] = intval($row->{$token});
                             } elseif (!empty($row->{$token})) {
                                 $val = trim($row->{$token});
                                 if (!empty($properties[$key])) {
                                     $properties[$key] .= ', ' . $val;
                                 } else {
                                     $properties[$key] = $val;
                                 }
                                 trim($properties[$key]);
                             }
                         }
                     }
                 }
                 // Now that we have determined the properties, lets see if the
                 // institution is already in the DB and upate it if so.
                 $code_key = $properties['hub'] . '_' . $properties['site_code'];
                 // First check by OCLC
                 if (isset($existing['by_oclc'][$properties['oclc']]) && !is_null($existing['by_oclc'][$properties['oclc']])) {
                     $existing['by_oclc'][$properties['oclc']]->update($properties);
                     $results['updated'] += 1;
                 } elseif (isset($existing['by_codes'][$code_key]) && !is_null($existing['by_codes'][$code_key])) {
                     $existing['by_codes'][$code_key]->update($properties);
                     $results['updated'] += 1;
                 } elseif (isset($existing['by_name'][$properties['name']]) && !is_null($existing['by_name'][$properties['name']])) {
                     $existing['by_name'][$properties['name']]->update($properties);
                     $results['updated'] += 1;
                 } else {
                     $institution = $courier->institutions()->create($properties);
                     // If new TAE, create a user as well
                     if ($courier->code == 'TAE') {
                         $username = preg_replace("/[^a-zA-Z0-9]+/", "", $institution->name);
                         $password = "******";
                         $institution->users()->create(['username' => $username, 'password' => bcrypt($password)]);
                     }
                     $results['added'] += 1;
                 }
             });
             $done = true;
         });
     });
     return $results;
 }
コード例 #6
0
 public function import(InstitutionListImport $import)
 {
     // get the imported data
     $courier_id = Input::get('courier_id');
     $results = $import->get($courier_id);
     return view('institutions.index', ['institutions' => Institution::with('courier')->where('courier_id', $courier_id)->get(), 'results' => $results, 'courier_id' => $courier_id, 'couriers' => Courier::orderBy('name')->lists('name', 'id')]);
 }