/** * Save the record specified by GET parameters. * * @param object $user User who is saving the record. * * @return bool True on success, false on failure. * @access public */ public static function saveRecord($user) { // Fail if the user is not logged in: if (!$user) { return false; } $list = new User_list(); if (isset($_GET['list']) && $_GET['list'] != '') { $list->id = $_GET['list']; } else { if (isset($_POST['list']) && $_POST['list'] != '') { $list->id = $_POST['list']; } else { $list->user_id = $user->id; $list->title = "My Favorites"; if (!$list->find(true)) { $list->insert(); } } } // Remember that the list was used so it can be the default in future // dialog boxes: $list->rememberLastUsed(); // Setup Search Engine Connection $db = ConnectionManager::connectToIndex('MetaLib'); // Get Record Information $record = $db->getRecord($_GET['id']); if (!$record) { return false; } $resource = new Resource(); $resource->record_id = $_GET['id']; $resource->source = 'MetaLib'; if (!$resource->find(true)) { $resource->data = serialize($record); $resource->insert(); } else { $resource->data = serialize($record); $resource->update(); } preg_match_all('/"[^"]*"|[^ ]+/', isset($_GET['mytags']) ? $_GET['mytags'] : '', $tagArray); return $user->addResource($resource, $list, $tagArray[0], isset($_GET['notes']) ? $_GET['notes'] : ''); }
/** * Export record to RefWorks or EndNote. * * @param array $record Record * @param string $format Export format (refworks or endnote). * @param boolean $render Return rendered template output or the template name? * * @return void|string * @access public */ public function export($record, $format, $render = false) { global $configArray; global $interface; if ($record['author']) { $record['author2'] = array_slice($record['author'], 1); } $formats = null; $tpl = null; if ($format == 'refworks') { // Save record to the database, so that also // restricted records can be retrieved by RefWorks. $resource = new Resource(); $resource->record_id = $record['id']; $resource->source = 'PCI'; if (!$resource->find(true)) { $resource->data = serialize($record); $resource->insert(); } else { $resource->data = serialize($record); $resource->update(); } $exportUrl = $configArray['Site']['url'] . '/PCI/Record?id=' . urlencode($record['id']) . '&export=refworks_data'; $url = $configArray['RefWorks']['url'] . '/express/expressimport.asp'; $url .= '?vendor=' . urlencode($configArray['RefWorks']['vendor']); $url .= '&filter=RefWorks%20Tagged%20Format&url=' . urlencode($exportUrl); header("Location: {$url}"); die; } else { if ($format == 'refworks_data') { header('Content-type: text/plain; charset=utf-8'); if ($record['format']) { $formats = array('article' => 'Journal Article', 'audio' => 'Sound Recording', 'video' => 'Video/ DVD', 'book' => 'Book, Whole', 'book_chapter' => 'Book Section', 'journal' => 'Journal, Electronic'); } $record['format'] = array_key_exists($record['format'], $formats) ? $formats[$record['format']] : 'General'; $tpl = 'PCI/export-refworks.tpl'; } else { if ($format == 'endnote') { header("Pragma: public"); header("Expires: 0"); header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); header("Cache-Control: private", false); header('Content-type: application/x-endnote-refer'); header("Content-Disposition: attachment; filename=\"vufind.enw\";"); if ($record['format']) { $formats = array('article' => 'Journal Article', 'audio' => 'Audiovisual Material', 'audio_video' => 'Audiovisual Material', 'video' => 'Audiovisual Material', 'book' => 'Book', 'book_chapter' => 'Book Section', 'conference_proceeding' => 'Conference Proceedings', 'database' => 'Online Database', 'journal' => 'Journal'); } $record['format'] = array_key_exists($record['format'], $formats) ? $formats[$record['format']] : 'Generic'; $tpl = 'PCI/export-endnote.tpl'; } } } if ($tpl) { $interface->assign('record', $record); if ($render) { echo $interface->fetch($tpl); exit; } else { return $tpl; } } return false; }
/** * Test update should update data in DB * * @test */ public function testUpdateShouldUpdateDB() { $this->migrate('testbench_mysql'); $stubValue = 'tata'; \Resource::update(1, ['stubValue' => $stubValue]); $response = \Resource::show(1); $this->assertTrue($response['stubValue'] == $stubValue); }
/** * Assign all necessary values to the interface. * * @return void * @access public */ public function assign() { global $interface; $currentSort = isset($_REQUEST['sort']) ? $_REQUEST['sort'] : 'saved'; if (!isset($this->sortOptions[$currentSort])) { $currentSort = 'saved'; } $interface->assign('listEditAllowed', $this->_allowEdit); // Get html for the records $resourceList = array(); $searchObjects = array(); $searchObject = SearchObjectFactory::initSearchObject(); foreach ($this->_favorites as $favorite) { $source = $favorite->source; $data = $favorite->data; if (!empty($data)) { $data = unserialize($data); } $sortKey = $favorite->saved; if ($this->_publicList) { $interface->assign('listNotes', $favorite->notes); } if ($source == 'VuFind') { if (empty($data)) { // Fetch data from index for backwards compatibility and store it in the resource $data = $searchObject->getIndexEngine()->getRecord($favorite->record_id); if ($data) { $resource = new Resource(); $resource->id = $favorite->id; $resource->source = $favorite->source; if ($resource->find(true)) { $resource->data = serialize($data); $resource->update(); } } } $record = RecordDriverFactory::initRecordDriver($data); $tpl = $this->_publicList ? $record->getSearchResult($this->_viewType) : $record->getListEntry($this->_user, $this->_listId, $this->_allowEdit); $html = $interface->fetch($tpl); switch ($currentSort) { case 'title': $sortKey = isset($data['title_sort']) ? $data['title_sort'] : ''; break; case 'author': $sortKey = isset($data['author']) ? $data['author'] : ''; break; case 'date': $sortKey = isset($data['main_date_str']) ? $data['main_date_str'] : isset($data['publishDate'][0]) ? $data['publishDate'][0] : ''; break; case 'format': $sortKey = isset($data['format'][0]) ? translate($data['format'][0]) : ''; break; } } else { if (!isset($searchObjects[$source])) { $searchObjects[$source] = SearchObjectFactory::initSearchObject($source); if ($searchObjects[$source] === false) { error_log("Could not create search object for source '{$source}'"); continue; } } $html = $this->_publicList ? $searchObjects[$source]->getPublicListHTML($data, $this->_viewType) : $searchObjects[$source]->getResultHTML($data, $this->_user, $this->_listId, $this->_allowEdit); if ($source == 'MetaLib') { switch ($currentSort) { case 'title': $sortKey = isset($data['Title'][0]) ? $data['Title'][0] : ' '; break; case 'author': $sortKey = isset($data['Author'][0]) ? $data['Author'][0] : ' '; break; case 'date': $sortKey = isset($data['main_date_str']) ? $data['main_date_str'] : isset($data['publicationDate'][0]) ? $data['publicationDate'][0] : ' '; break; case 'format': $sortKey = isset($data['format'][0]) ? translate($data['format'][0]) : ' '; break; } } else { switch ($currentSort) { case 'title': $sortKey = isset($data['title']) ? $data['title'] : ' '; break; case 'author': $sortKey = isset($data['author'][0]) ? $data['author'][0] : ' '; break; case 'date': $sortKey = isset($data['main_date_str']) ? $data['main_date_str'] : isset($data['publicationDate']) ? $data['publicationDate'] : ' '; break; case 'format': $sortKey = isset($data['format']) ? translate($data['format']) : ' '; break; } } } $sortKey = mb_strtolower($sortKey, 'UTF-8'); $sortKey .= '_' . $favorite->record_id; $resourceList[$sortKey] = $html; } // Setup paging variables if (isset($_REQUEST['page'])) { $page = $_REQUEST['page']; $page = intval($page); if ($page < 1) { $page = 1; } } else { $page = 1; } $searchObject->init(); $perPage = $searchObject->getLimit(); $recordCount = count($this->_favorites); $startRecord = ($page - 1) * $perPage; // Sort and slice the array ksort($resourceList); $resourceList = array_slice($resourceList, $startRecord, $perPage, true); $html = array(); $interface->assign('resourceList', $resourceList); // Set up paging of list contents: $endRecord = $startRecord + $perPage; if ($endRecord > $recordCount) { $endRecord = $recordCount; } $interface->assign('recordCount', $recordCount); $interface->assign('recordStart', $startRecord + 1); $interface->assign('recordEnd', $endRecord); $options = array('totalItems' => $recordCount, 'perPage' => $perPage, 'fileName' => $searchObject->renderLinkPageTemplate()); $pager = new VuFindPager($options); $interface->assign('pageLinks', $pager->getLinks()); // Sorting options $sortList = array(); foreach ($this->sortOptions as $sort => $desc) { $sortList[$sort] = array('sortUrl' => $searchObject->renderLinkWithSort($sort), 'desc' => $desc, 'selected' => $sort == $currentSort); } $interface->assign('sortList', $sortList); $interface->assign('limitList', $searchObject->getLimitList()); }