Example #1
0
 function getPurchaseOptions()
 {
     global $interface;
     if (isset($_REQUEST['id'])) {
         $id = $_REQUEST['id'];
         $interface->assign('id', $id);
         $eContentRecord = new EContentRecord();
         $eContentRecord->id = $id;
         if ($eContentRecord->find(true)) {
             $purchaseLinks = array();
             if ($eContentRecord->purchaseUrl != null) {
                 $purchaseLinks[] = array('link' => $eContentRecord->purchaseUrl, 'linkText' => 'Buy from ' . $eContentRecord->publisher, 'storeName' => $eContentRecord->publisher, 'field856Index' => 1);
             }
             if (count($purchaseLinks) > 0) {
                 $interface->assign('purchaseLinks', $purchaseLinks);
             } else {
                 $title = $eContentRecord->title;
                 $author = $eContentRecord->author;
                 require_once ROOT_DIR . '/services/Record/Purchase.php';
                 $purchaseLinks = Record_Purchase::getStoresForTitle($title, $author);
                 if (count($purchaseLinks) > 0) {
                     $interface->assign('purchaseLinks', $purchaseLinks);
                 } else {
                     $interface->assign('errors', array("Sorry we couldn't find any stores that offer this title."));
                 }
             }
         } else {
             $errors = array("Could not load record for that id.");
             $interface->assign('errors', $errors);
         }
     } else {
         $errors = array("You must provide the id of the title to be purchased. ");
         $interface->assign('errors', $errors);
     }
     echo $interface->fetch('EcontentRecord/ajax-purchase-options.tpl');
 }
Example #2
0
 function getPurchaseOptions()
 {
     global $interface;
     if (isset($_REQUEST['id'])) {
         $id = $_REQUEST['id'];
         $interface->assign('id', $id);
         $marcRecord = MarcLoader::loadMarcRecordByILSId($id);
         if ($marcRecord) {
             $linkFields = $marcRecord->getFields('856');
             $purchaseLinks = array();
             if ($linkFields) {
                 $field856Index = 0;
                 /** @var File_MARC_Data_Field[] $linkFields */
                 foreach ($linkFields as $marcField) {
                     $field856Index++;
                     //Get the link
                     if ($marcField->getSubfield('u')) {
                         $link = $marcField->getSubfield('u')->getData();
                         if ($marcField->getSubfield('3')) {
                             $linkText = $marcField->getSubfield('3')->getData();
                         } elseif ($marcField->getSubfield('y')) {
                             $linkText = $marcField->getSubfield('y')->getData();
                         } elseif ($marcField->getSubfield('z')) {
                             $linkText = $marcField->getSubfield('z')->getData();
                         } else {
                             $linkText = $link;
                         }
                         //Process some links differently so we can either hide them
                         //or show them in different areas of the catalog.
                         if (preg_match('/purchase|buy/i', $linkText) || preg_match('/barnesandnoble|tatteredcover|amazon\\.com/i', $link)) {
                             if (preg_match('/barnesandnoble/i', $link)) {
                                 $purchaseLinks[] = array('link' => $link, 'linkText' => 'Buy from Barnes & Noble', 'storeName' => 'Barnes & Noble', 'image' => '/images/barnes_and_noble.png', 'field856Index' => $field856Index);
                             } else {
                                 if (preg_match('/tatteredcover/i', $link)) {
                                     $purchaseLinks[] = array('link' => $link, 'linkText' => 'Buy from Tattered Cover', 'storeName' => 'Tattered Cover', 'image' => '/images/tattered_cover.png', 'field856Index' => $field856Index);
                                 } else {
                                     if (preg_match('/amazon\\.com/i', $link)) {
                                         $purchaseLinks[] = array('link' => $link, 'linkText' => 'Buy from Amazon', 'storeName' => 'Amazon', 'image' => '/images/amazon.png', 'field856Index' => $field856Index);
                                     } else {
                                         if (preg_match('/smashwords\\.com/i', $link)) {
                                             $purchaseLinks[] = array('link' => $link, 'linkText' => 'Buy from Smashwords', 'storeName' => 'Smashwords', 'image' => '/images/smashwords.png', 'field856Index' => $field856Index);
                                         } else {
                                             $purchaseLinks[] = array('link' => $link, 'linkText' => $linkText, 'storeName' => 'Smashwords', 'image' => '', 'field856Index' => $field856Index);
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
             //End checking for purchase information in the marc record
             if (count($purchaseLinks) > 0) {
                 $interface->assign('purchaseLinks', $purchaseLinks);
             } else {
                 $resource = new Resource();
                 $resource->record_id = $id;
                 $resource->source = 'VuFind';
                 if ($resource->find(true)) {
                     $title = $resource->title;
                     $author = $resource->author;
                     require_once ROOT_DIR . '/services/Record/Purchase.php';
                     $purchaseLinks = Record_Purchase::getStoresForTitle($title, $author);
                     if (count($purchaseLinks) > 0) {
                         $interface->assign('purchaseLinks', $purchaseLinks);
                     } else {
                         $interface->assign('errors', array("Sorry we couldn't find any stores that offer this title."));
                     }
                 } else {
                     $interface->assign('errors', array("Sorry we couldn't find a resource for that id."));
                 }
             }
         } else {
             $errors = array("Could not load marc information for that id.");
             $interface->assign('errors', $errors);
         }
     } else {
         $errors = array("You must provide the id of the title to be purchased. ");
         $interface->assign('errors', $errors);
     }
     echo $interface->fetch('Record/ajax-purchase-options.tpl');
 }