bib as $item) { $mms_id = $item->mms_id; //mms_id is found here $mms_list .= $mms_id . ","; //mms_id added to string followed by comma } $mms_list = rtrim($mms_list, ","); //trims last comma //echo "$mms_list"; //Debug /*Alma API - Get Bib Call */ $ch = curl_init(); $url = 'https://api-na.hosted.exlibrisgroup.com/almaws/v1/bibs'; $queryParams = '?' . urlencode('mms_id') . '=' . urlencode($mms_list) . '&' . urlencode('expand') . '=' . urlencode('None') . '&' . urlencode('apikey') . '=' . urlencode('l7xx26a73bf36a614bfc89dd84217dc17466'); curl_setopt($ch, CURLOPT_URL, $url . $queryParams); curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); curl_setopt($ch, CURLOPT_HEADER, FALSE); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET'); $init_response = curl_exec($ch); curl_close($ch); unset($mms_list); //Clears out mms_id list for next call //Removes xml heading and combines with exisiting data if($i > 0){ $init_response = str_replace('','', $init_response); $init_response = preg_replace('(<.[^(><.)]+>)','', $init_response); } //Removes closing tag to allow for more data - change number if total databases exceed this number if($i < 200){ $init_response = str_replace('','', $init_response); } echo $url . $queryParams; echo substr($init_response, 0, 100); //Debug $bib_response .= $init_response; //var_dump($response); //Debug } //Takes Bib Data from combined calls and creates xml element $db_xml = new SimpleXMLElement($bib_response); //Converts API response to XML Element /*Initialize arrays */ $azDB = array(); //Database array exclusive to LibGuides AZ import CSV template $allDB = array(); //Program list - duplicates removed $titleDB = array(); //2D array $titlelist = array(); //stores titles /*Static Variables */ $today = date("Y-m-d H:i:s"); $today_dt = new DateTime($today); /* LibGuide Resource Icons */ $licensed_icon = '17071'; $openaccess_icon = '17072'; $mobileapp_icon = '19127'; /*Goes through each item*/ foreach ($db_xml->bib as $database) { /*Default Variables */ $title = ''; $url = ''; $mobile_url = ''; $vendor = ''; $desc_short = ''; $desc_long = ''; $desc_pos = '1'; $enable_trial = '0'; $enable_new = '0'; //Static disabled $enable_popular = '0'; $enable_hidden = '0'; $types = ''; //Database Format $keywords = ''; $target = '2'; // Static New Window $subjects = ''; $current_subject = ''; $enableProxy = '0'; //static disabled $bestbets = ''; $content_id = ''; //ID in LibGuides $resource_icons = ''; $title = $database->title->__toString(); //title $mms_id = $database->mms_id->__toString(); //mms_id $internal_note = "Last sync: " . $today_dt->format('Y-m-d H:i:s') . " from Alma MMS_ID " . $mms_id; $titleDB = array(); //new array per db array_push($titlelist, $title); /* Subjects */ foreach ($database->record->datafield as $record) { /*Locates Subjects and Best Bets */ if ($record->attributes()->tag == 960){ foreach ($record->subfield as $subfield){ if($subfield->attributes()->code == "a"){ $current_subject = $subfield->__toString(); //used for preferred }//End If if($subfield->attributes()->code == "b"){ $current_bestbet = $subfield->__toString(); //used for preferred } else { $current_bestbet = NULL; }//End If }//END Foreach if($current_bestbet != "Preferred"){ $subjects .= $current_subject; $subjects .= "; "; } else { $bestbets .= $current_subject; //Subfield B will have "Preferred" to indicate best bet $bestbets .= "; "; } //End If //Clear variable unset($current_subject); unset($current_bestbet); } //Finished IF /* Locates URL and Vendor */ if ($record->attributes()->tag == 917 AND $record->attributes()->ind2 == 0){ foreach ($record->subfield as $subfield){ if($subfield->attributes()->code == "z"){ $org = $subfield->__toString(); }//End IF if($subfield->attributes()->code == "u"){ $current_url = $subfield->__toString(); //URL } //End If if($subfield->attributes()->code == 3){ $current_vendor = $subfield->__toString(); //Vendor } //End If }//End Foreach //Check for ETSU Link if($org == "ETSU") { $url = $current_url; $vendor = $current_vendor; } unset($org); unset($current_url); unset($current_vendor); } //Finished IF /* Locates Mobile Version of Resource */ if ($record->attributes()->tag == 917 AND $record->attributes()->ind2 == 1){ foreach ($record->subfield as $subfield){ if($subfield->attributes()->code == "z"){ $org = $subfield->__toString(); }//End IF if($subfield->attributes()->code == "u"){ $current_url = $subfield->__toString(); //URL } //End If if($subfield->attributes()->code == 2){ $current_version = strtolower($subfield->__toString()); //Vendor } //End If }//End Foreach //Check for ETSU Link if($org == "ETSU" AND $current_version == "mobile") { $mobile_url = $current_url; $resource_icons .= $mobileapp_icon; $resource_icons .= "; "; } unset($org); unset($current_url); } //Finished IF /* Locates Descriptions */ if ($record->attributes()->tag == 520){ foreach ($record->subfield as $subfield){ if($subfield->attributes()->code == "a"){ $desc_short = $subfield->__toString(); //Short Description } //End If if($subfield->attributes()->code == "b"){ $desc_long = $subfield->__toString(); //Long Description } //End If }//End Foreach } //Finished IF /* Locates Format Type */ if ($record->attributes()->tag == 963){ foreach ($record->subfield as $subfield){ if($subfield->attributes()->code == "a"){ $types .= $subfield->__toString(); //Database Format $types .= "; "; } //End If }//End Foreach } //Finished IF /*Locates Keywords */ if ($record->attributes()->tag == 653){ foreach ($record->subfield as $subfield){ if($subfield->attributes()->code == "a"){ $keywords .= $subfield->__toString(); //Keyword $keywords .= "; "; } //End If }//End Foreach } //Finished IF /*Icons */ if ($record->attributes()->tag == 914){ foreach ($record->subfield as $subfield){ if($subfield->attributes()->code == "a"){ $subfield914a = $subfield->__toString(); // if($subfield914a == "Licensed"){ // $resource_icons .= $licensed_icon; //Keyword // $resource_icons .= "; "; // } //END If if($subfield914a == "Open Access"){ $resource_icons .= $openaccess_icon; //Keyword $resource_icons .= "; "; } //END If } //End If }//End Foreach } //Finished IF /*LibGuide content ID, New, Trial, Popular */ if ($record->attributes()->tag == 913){ foreach ($record->subfield as $subfield){ //Content ID if($subfield->attributes()->code == "a"){ $content_id = $subfield->__toString(); } //End If //Trial Expiration Flag if($subfield->attributes()->code == "b"){ $subfield913b = $subfield->__toString(); $trial_expiration = new DateTime($subfield913b); if($trial_expiration > $today_dt){ $enable_trial = '1'; //Enabled } //END If } //End If //New Expiration Flag if($subfield->attributes()->code == "c"){ $subfield913c = $subfield->__toString(); $new_expiration = new DateTime($subfield913c); if($new_expiration > $today_dt){ $enable_new = '1'; //Enabled } //END If } //End If //Popular Flag if($subfield->attributes()->code == "d"){ $subfield913d = $subfield->__toString(); $subfield913d = strtolower($subfield913d); //lower case if($subfield913d == "popular"){ $enable_popular = '1'; //Enabled } //END If } //End If //Hidden Flag if($subfield->attributes()->code == "e"){ $subfield913e = $subfield->__toString(); $subfield913e = strtolower($subfield913e); //lower case if($subfield913e == "hidden"){ $enable_hidden = '1'; //Enabled } //END If } //End If }//End Foreach } //Finished IF } //Finishes datafields for loop /* Add Database to Array */ $allDB[] = array("vendor" => $vendor, "title" => $title, "url" => $url, "enableProxy" => $enableProxy, "desc_short" => $desc_short, "desc_long" => $desc_long, "enable_new" => $enable_new, "enable_trial" => $enable_trial, "types" => $types, "target" => $target, "best_bets" => $bestbets, "subjects" => $subjects, "desc_pos" => $desc_pos, "enable_popular" => $enable_popular, "enable_hidden" => $enable_hidden, "internal_note" => $internal_note, "resource_icons" => $resource_icons, "content_id" => $content_id, "mobile_url" => $mobile_url); /* Another Array formated to work with Springshare AZ CSV import */ $azDB[] = array("vendor" => $vendor, "title" => $title, "url" => $url, "enableProxy" => $enableProxy, "desc_short" => $desc_short, "desc_long" => $desc_long, "enable_new" => $enable_new, "enable_trial" => $enable_trial, "types" => $types, "target" => $target, "best_bets" => $bestbets, "subjects" => $subjects, "desc_pos" => $desc_pos, "enable_popular" => $enable_popular, "enable_hidden" => $enable_hidden, "internal_note" => $internal_note, "resource_icons" => $resource_icons, "content_id" => $content_id); /*Clear variables*/ unset($titleDB); // Clears list of titles for next loop unset($types); unset($subjects); unset($keywords); unset($vendor); unset($bestbets); unset($resource_icons); unset($content_id); unset($mobile_url); }//End of bib loop /*Test Output*/ // var_dump($allDB); //used for debugging /* Updates db_array.txt file using Alma API Call Script Travis Clamon - clamon@etsu.edu */ /*File Output*/ file_put_contents('db_array_test.txt', '