/** * Display a listing of the resource. * * @return Response */ public function index() { // $AZArea = AZArea::orderBy('name', 'ASC')->get(); return response()->json($AZArea->toArray()); # return view('AZArea.index', compact('AZArea')); }
public function byArea($id) { // if (is_numeric($id)) { $model = AZSubject::where('area_id', '=', $id)->orderBy('name', 'ASC')->get(); } else { $id = str_replace("-", " ", $id); $model = AZArea::whereRaw('LOWER(name) = ?', [$id])->orderBy('name', 'ASC')->first(); $model = AZSubject::where('area_id', '=', $model->id)->orderBy('name', 'ASC')->get(); } //$model = AZSubject::all(); return response()->json($model->toArray()); }
/** * Display a listing of the resource. * * @return Response */ public function index() { // define('STDIN', fopen("php://stdin", "r")); function ArtMigr() { try { \Artisan::call('migrate:refresh'); #\Artisan::call('migrate', ['--quiet' => true, '--force' => true]); } catch (Exception $e) { echo $e; } } ArtMigr(); $client = new \Phpoaipmh\Client("https://ap01-a.alma.exlibrisgroup.com/view/oai/61SUT_INST/request/oai"); $myEndpoint = new \Phpoaipmh\Endpoint($client); $recs = $myEndpoint->listRecords('marc21', null, null, 'LSS'); $area_subject_map = array(); echo "\n\t\t<head><title>Swinburne AZ Database list</title>\n\t\t\t\t<link href='//netdna.bootstrapcdn.com/twitter-bootstrap/2.3.1/css/bootstrap-combined.min.css' rel='stylesheet'>\n\t\t\t</head>\n\t\t<body>\n\t\t<div class='container'>\n\t\t<h3>Swinburne: A-Z Database list</h3>\n\t\t<table class='table table-striped'>\n\t\t<tbody>\n\t\t"; foreach ($recs as $item) { $data = simplexml_load_string($item->asXML()); if (isset($data->metadata->record->leader)) { echo "<br />"; echo "<br />"; $titles = array(); echo "<tr><td>"; $title = ''; $alt_title = ''; $alt_title_type = ''; $url = ''; $description = ''; $user = ''; $metadata = ''; $area = ''; $area_map = array(); $subject = ''; $mmsID = ''; $subject_map = array(); foreach ($data->metadata->record->controlfield as $mm) { if (substr($mm, 0, 2) == '99') { $mmsID = $mm; break; } } //$mmsID = $data->metadata->record->controlfield[2][0]; $database_area_subject_map = array(); foreach ($data->metadata->record->datafield as $field) { $alt_title_type = ''; switch ((string) $field['tag']) { case '245': foreach ($field->subfield as $sub) { switch ((string) $sub['code']) { case 'a': $title = $sub; break; case 'b': $title = $title . ' : ' . $sub; break; } } array_push($titles, (string) $title); echo '<i>Title: </i><b>' . $title . "</b><br />"; echo 'MMS ID: ' . $mmsID . "<br />"; break; case '246': //alt title foreach ($field->subfield as $sub) { switch ((string) $sub['code']) { case 'a': $alt_title = $sub; break; } } switch ((string) $field['ind1']) { case '1': //real alt title array_push($titles, (string) $alt_title); $alt_title_type = 'Additional record'; $metadata .= $alt_title . " : "; break; case '3': //searchable -= add to metatdata $alt_title_type = 'searchable'; $metadata .= $alt_title . " : "; break; case ' ': //mistake - add to metadata $alt_title_type = 'ERROR'; $metadata .= $alt_title . " : "; break; default: $alt_title_type = 'NO DATA:' . $field['ind1']; $metadata .= $alt_title . " : "; break; } echo '<i>Alt Title (' . $alt_title_type . '): </i>' . $alt_title . "<br />"; break; case '917': //url foreach ($field->subfield as $sub) { switch ((string) $sub['code']) { case 'u': $url = $sub; break; } } echo '<i>URL: </i>' . $url . "</br >"; break; case '520': //descriptionitle foreach ($field->subfield as $sub) { switch ((string) $sub['code']) { case 'a': $description = $sub; break; } } echo 'Description: </i>' . $description . "<br />"; break; case '500': //uer limit $user = ''; foreach ($field->subfield as $sub) { switch ((string) $sub['code']) { case 'a': if (stristr($sub, 'Concurrent')) { $user = $sub; } break; } } if ($user) { echo '<i>User: </i>' . $user . "<br />"; } break; case '960': $area = ''; $subject = ''; foreach ($field->subfield as $sub) { switch ((string) $sub['code']) { case 'a': $area = trim($sub); //array_push($area_map,$area); $area_map[$area][] = ''; //if code !in aera array add it break; case 'b': $subject = trim($sub); echo 'Area:' . $area; echo 'Subject:' . $subject; $area_map[$area][] = $subject; //if subejct !in subejctaera array add it break; } } //add subject to database-area mape echo '<i>Area: </i>' . $area . "<br />"; if ($subject) { echo '<i>-- Subject: </i>' . $subject . "<br />"; } break; } echo "</td></tr>"; } echo "</tbody></table>"; //do the import stuff //Area //$flight =AZArea::firstOrCreate(['name' => $area]); foreach ($titles as $az_database_title) { $db_new = new AZDatabase(); $db_new->name = $az_database_title; $db_new->description = $description; $db_new->user = $user; $db_new->url = $url; $db_new->metadata = $metadata; $db_new->save(); if ($area_map) { foreach ($area_map as $area_key => $area_value) { if (is_string($area_key) and $area_key !== '') { $area_db = AZArea::firstOrCreate(array('name' => $area_key)); //insert =db into db area map $db_area_new = new AZDatabaseArea(); $db_area_new->database_id = $db_new->id; $db_area_new->area_id = $area_db->id; $db_area_new->save(); foreach ($area_map[$area_key] as $subject_key => $subject_value) { if (is_string($subject_value) and $subject_value !== '') { $subject_db = AZSubject::where('name', '=', $subject_value)->where('area_id', '=', $area_db->id)->first(); if (!$subject_db) { $subject_db = AZSubject::create(array('area_id' => $area_db->id, 'name' => $subject_value)); } //insert db into db area map $db_area_new = new AZDatabaseSubject(); $db_area_new->database_id = $db_new->id; $db_area_new->subject_id = $subject_db->id; $db_area_new->save(); } } } } } } // print_r($area_map); } } }
public function byAreaSubject($area_id, $subject_id) { // if (is_numeric($subject_id)) { $model = DB::table('az_database')->join('az_database_subject', 'az_database_subject.database_id', '=', 'az_database.id')->join('az_subject', 'az_subject.id', '=', 'az_database_subject.subject_id')->where('az_subject.id', '=', $subject_id)->orderBy('az_database.name', 'ASC')->select('az_database.name as name', 'az_database.url as url', 'az_database.user as user', 'az_subject.name as subject', 'az_database.description as description')->get(); } else { $area_id = str_replace("-", " ", $area_id); $subject_id = str_replace("-", " ", $subject_id); $a_model = AZArea::whereRaw('LOWER(name) = ?', [$area_id])->first(); $s_model = AZSubject::where('area_id', '=', $a_model->id)->whereRaw('LOWER(name) = ?', [$subject_id])->first(); $model = DB::table('az_database')->join('az_database_subject', 'az_database_subject.database_id', '=', 'az_database.id')->join('az_subject', 'az_subject.id', '=', 'az_database_subject.subject_id')->where('az_subject.id', '=', $s_model->id)->orderBy('az_database.name', 'ASC')->select('az_database.name as name', 'az_database.url as url', 'az_database.user as user', 'az_subject.name as subject', 'az_database.description as description')->get(); } //$model = AZSubject::where('area_id', '=', $id)->get(); //$model = AZSubject::all(); return response()->json($model); }