/** * Get all resources associated with the current tag. * * @return array * @access public */ public function getResources() { $resList = array(); $sql = 'SELECT "resource".* FROM "resource_tags", "resource" ' . 'WHERE "resource"."id" = "resource_tags"."resource_id" ' . 'AND "resource_tags"."tag_id" = ' . "'" . $this->escape($this->id) . "'"; $res = new Resource(); $res->query($sql); if ($res->N) { while ($res->fetch()) { $resList[] = clone $res; } } return $resList; }
function getResources() { $resList = array(); $sql = "SELECT resource.* FROM resource_tags, resource " . "WHERE resource.id = resource_tags.resource_id " . "AND resource_tags.tag_id = '{$this->id}'"; /** @var Resource|object $res */ $res = new Resource(); $res->query($sql); if ($res->N) { while ($res->fetch()) { $resList[] = clone $res; } } return $resList; }
/** * レコードを取得する。 * * @param Resource $result クエリの結果セット。 * @return mixed レコードデータを含む連想配列を返す。レコードが無い場合はfalseを返す。 */ public function fetch($result) { $ret = $result->fetch(); if (get_magic_quotes_runtime()) { return array_map('stripslashes', $ret); } return $ret; }
static function getSuggestions($userId = -1) { global $configArray; if ($userId == -1) { global $user; $userId = $user->id; } //Load all titles the user is not interested in $notInterestedTitles = array(); $notInterested = new NotInterested(); $resource = new Resource(); $notInterested->joinAdd($resource); $notInterested->userId = $userId; $notInterested->find(); while ($notInterested->fetch()) { if ($notInterested->source == 'VuFind') { $fullId = $notInterested->record_id; } else { $fullId = 'econtentRecord' . $notInterested->record_id; } $notInterestedTitles[$fullId] = $fullId; } //Load all titles the user has rated (print) $allRatedTitles = array(); $allLikedRatedTitles = array(); $ratings = new UserRating(); $ratings->userid = $userId; $resource = new Resource(); $notInterested->joinAdd($resource); $ratings->joinAdd($resource); $ratings->find(); while ($ratings->fetch()) { $allRatedTitles[$ratings->record_id] = $ratings->record_id; if ($ratings->rating >= 4) { $allLikedRatedTitles[] = $ratings->record_id; } } //Load all titles the user has rated (eContent) $econtentRatings = new EContentRating(); $econtentRatings->userId = $userId; $econtentRatings->find(); while ($econtentRatings->fetch()) { $allRatedTitles['econtentRecord' . $econtentRatings->recordId] = 'econtentRecord' . $econtentRatings->recordId; if ($econtentRatings->rating >= 4) { $allLikedRatedTitles[] = 'econtentRecord' . $econtentRatings->recordId; } } // Setup Search Engine Connection $class = $configArray['Index']['engine']; $url = $configArray['Index']['url']; $db = new $class($url); if ($configArray['System']['debugSolr']) { $db->debug = true; } //Get a list of all titles the user has rated (3 star and above) $ratings = new UserRating(); $ratings->whereAdd("userId = {$userId}", 'AND'); $ratings->whereAdd('rating >= 3', 'AND'); $ratings->orderBy('rating DESC, dateRated DESC, id DESC'); //Use the 20 highest ratings to make real-time recommendations faster $ratings->limit(0, 5); $ratings->find(); $suggestions = array(); //echo("User has rated {$ratings->N} titles<br/>"); if ($ratings->N > 0) { while ($ratings->fetch()) { $resourceId = $ratings->resourceid; //Load the resource $resource = new Resource(); $resource->id = $resourceId; $resource->find(); if ($resource->N != 1) { //echo("Did not find resource for $resourceId<br/>"); } else { $resource->fetch(); //echo("Found resource for $resourceId - {$resource->title}<br/>"); $ratedTitles[$resource->record_id] = clone $ratings; $numRecommendations = 0; if ($resource->isbn) { //If there is an isbn for the title, we can load similar titles based on Novelist. $isbn = $resource->isbn; $numRecommendations = Suggestions::getNovelistRecommendations($ratings, $isbn, $resource, $allRatedTitles, $suggestions, $notInterestedTitles); //echo(" - Found $numRecommendations for $isbn from Novelist<br/>"); } if ($numRecommendations == 0) { Suggestions::getSimilarlyRatedTitles($db, $ratings, $userId, $allRatedTitles, $suggestions, $notInterestedTitles); //echo(" - Found $numRecommendations based on ratings from other users<br/>"); } } } } //Also get eContent the user has rated highly $econtentRatings = new EContentRating(); $econtentRatings->userId = $userId; $econtentRatings->whereAdd('rating >= 3'); $econtentRatings->orderBy('rating DESC, dateRated DESC'); $econtentRatings->limit(0, 5); $econtentRatings->find(); //echo("User has rated {$econtentRatings->N} econtent titles<br/>"); if ($econtentRatings->N > 0) { while ($econtentRatings->fetch()) { //echo("Processing eContent Rating {$econtentRatings->recordId}<br/>"); //Load the resource $resource = new Resource(); $resource->record_id = $econtentRatings->recordId; $resource->source = 'eContent'; $resource->find(); if ($resource->N != 1) { //echo("Did not find resource for $resourceId<br/>"); } else { $resource->fetch(); //echo("Found resource for $resourceId - {$resource->title}<br/>"); $ratedTitles[$resource->record_id] = clone $econtentRatings; $numRecommendations = 0; if ($resource->isbn) { //If there is an isbn for the title, we can load similar titles based on Novelist. $isbn = $resource->isbn; $numRecommendations = Suggestions::getNovelistRecommendations($ratings, $isbn, $resource, $allRatedTitles, $suggestions, $notInterestedTitles); //echo(" - Found $numRecommendations for $isbn from Novelist<br/>"); } if ($numRecommendations == 0) { Suggestions::getSimilarlyRatedTitles($db, $ratings, $userId, $allRatedTitles, $suggestions, $notInterestedTitles); //echo(" - Found $numRecommendations based on ratings from other users<br/>"); } } } } $groupedTitles = array(); foreach ($suggestions as $suggestion) { $groupingTerm = $suggestion['titleInfo']['grouping_term']; $groupedTitles[] = $groupingTerm; } //If the user has not rated anything, return nothing. if (count($allLikedRatedTitles) == 0) { return array(); } //Get recommendations based on everything I've rated using more like this functionality $class = $configArray['Index']['engine']; $url = $configArray['Index']['url']; /** @var Solr $db */ $db = new $class($url); //$db->debug = true; $moreLikeTheseSuggestions = $db->getMoreLikeThese($allLikedRatedTitles); //print_r($moreLikeTheseSuggestions); if (count($suggestions) < 30) { foreach ($moreLikeTheseSuggestions['response']['docs'] as $suggestion) { $groupingTerm = $suggestion['grouping_term']; if (array_key_exists($groupingTerm, $groupedTitles)) { //echo ($suggestion['grouping_term'] . " is already in the suggestions"); continue; } $groupedTitles[$groupingTerm] = $groupingTerm; //print_r($suggestion); if (!array_key_exists($suggestion['id'], $allRatedTitles) && !array_key_exists($suggestion['id'], $notInterestedTitles)) { $suggestions[$suggestion['id']] = array('rating' => $suggestion['rating'] - 2.5, 'titleInfo' => $suggestion, 'basedOn' => 'MetaData for all titles rated'); } if (count($suggestions) == 30) { break; } } } //print_r($groupedTitles); //sort suggestions based on score from ascending to descending uasort($suggestions, 'Suggestions::compareSuggestions'); //Only return up to 50 suggestions to make the page size reasonable $suggestions = array_slice($suggestions, 0, 30, true); //Return suggestions for use in the user interface. return $suggestions; }
/** * Load information from the resource table associated with this user. * * @param array $tags Array of tags to use as a filter (optional). * * @return array * @access public */ public function getResources($tags = null) { $resourceList = array(); $sql = 'SELECT DISTINCT "resource".*, "user_resource"."saved" FROM "resource", "user_resource" ' . 'WHERE "resource"."id" = "user_resource"."resource_id" ' . 'AND "user_resource"."user_id" = ' . "'" . $this->escape($this->id) . "'"; if ($tags) { for ($i = 0; $i < count($tags); $i++) { $sql .= ' AND "resource"."id" IN ' . '(SELECT DISTINCT "resource_tags"."resource_id" ' . 'FROM "resource_tags", "tags" WHERE ' . '"resource_tags"."tag_id"="tags"."id" AND "tags"."tag" = ' . "'" . $this->escape($tags[$i]) . "'" . ' AND "resource_tags"."user_id" = ' . "'" . $this->escape($this->id) . "')"; } } $resource = new Resource(); $resource->query($sql); if ($resource->N) { while ($resource->fetch()) { $resourceList[] = clone $resource; } } return $resourceList; }
/** * Given an array of item ids, remove them from a list * * @param array $ids IDs to remove from the list * @param string $source Type of resource identified by IDs * * @return bool True on success, false on error. * @access public */ public function removeResourcesById($ids, $source = 'VuFind') { $sqlIDS = array(); foreach ($ids as $id) { if (!empty($id)) { $sqlIDS[] = "'" . $this->escape($id) . "'"; } } // No work is needed if we have no IDs to delete: if (empty($sqlIDS)) { return true; } // Get Resource Ids $sql = 'SELECT "id" FROM "resource" WHERE ("record_id" = ' . implode(' OR "record_id" = ', $sqlIDS) . ") "; // Don't use source here, MetaLib records would fail // . 'AND "source" = ' . "'" . $this->escape($source) . "'"; $resources = new Resource(); $resources->query($sql); if ($resources->N) { while ($resources->fetch()) { $resourceList[] = "'" . $this->escape($resources->id) . "'"; } } // Remove Resource $sql = 'DELETE FROM "user_resource" ' . "WHERE \"user_id\" = '" . $this->escape($this->user_id) . "' " . "AND \"list_id\" = '" . $this->escape($this->id) . "' " . 'AND ("resource_id" =' . implode(' OR "resource_id" =', $resourceList) . ")"; $removeResource = new User_resource(); $removeResource->query($sql); // Remove Resource Tags $sql = 'DELETE FROM "resource_tags" ' . "WHERE \"user_id\" = '" . $this->escape($this->user_id) . "' " . "AND \"list_id\" = '" . $this->escape($this->id) . "' " . 'AND ("resource_id" =' . implode(' OR "resource_id" =', $resourceList) . ")"; $removeTags = new Resource_tags(); $removeTags->query($sql); // Update list modification date $this->updateModifiedDate(); // If we got this far, there were no fatal DB errors so report success return true; }
public function getMyTransactions($patron, $page = 1, $recordsPerPage = -1, $sortOption = 'dueDate') { global $configArray; global $timer; if (is_object($patron)) { $patron = get_object_vars($patron); } if (isset($this->transactions[$patron['id']])) { return $this->transactions[$patron['id']]; } if (!$this->useDb) { //Get transactions by parsing hip $transactions = $this->getMyTransactionsViaHIP($patron); $timer->logTime("Got transactions from HIP"); //return json_decode('[{"id":843869,"itemid":1466355,"duedate":"2011-03-29 12:00:00","checkoutdate":"2011-03-07 12:00:00","barcode":"33025015826504","renewCount":1,"request":null},{"id":944097,"itemid":1897017,"duedate":"2011-03-28 12:00:00","checkoutdate":"2011-03-07 12:00:00","barcode":"33025021052830","renewCount":0,"request":null},{"id":577167,"itemid":2057415,"duedate":"2011-03-29 12:00:00","checkoutdate":"2011-03-07 12:00:00","barcode":"33025021723778","renewCount":3,"request":null}]', true); } else { $transactions = $this->getMyTransactionsViaDB($patron); $timer->logTime("Got transactions from Database"); } if (isset($transactions)) { //Load information about titles from Resources table (for peformance) $recordIds = array(); foreach ($transactions as $i => $data) { $recordIds[] = "'" . $data['id'] . "'"; } //Get records from resource table $resourceInfo = new Resource(); if (count($recordIds) > 0) { $recordIdString = implode(",", $recordIds); $resourceSql = "SELECT * FROM resource where source = 'VuFind' AND record_id in ({$recordIdString})"; $resourceInfo->query($resourceSql); $timer->logTime('Got records for all titles'); //Load title author, etc. information while ($resourceInfo->fetch()) { foreach ($transactions as $key => $transaction) { if ($transaction['id'] == $resourceInfo->record_id) { $transaction['shortId'] = $transaction['id']; //Load title, author, and format information about the title $transaction['recordId'] = $transaction['id']; $transaction['title'] = isset($resourceInfo->title) ? $resourceInfo->title : 'Unknown'; $transaction['sortTitle'] = isset($resourceInfo->title_sort) ? $resourceInfo->title_sort : 'unknown'; $transaction['author'] = isset($resourceInfo->author) ? $resourceInfo->author : null; $transaction['format'] = isset($resourceInfo->format) ? $resourceInfo->format : null; $transaction['isbn'] = isset($resourceInfo->isbn) ? $resourceInfo->isbn : ''; $transaction['upc'] = isset($resourceInfo->upc) ? $resourceInfo->upc : ''; $transaction['format_category'] = isset($resourceInfo->format_category) ? $resourceInfo->format_category : ''; $transaction['renewIndicator'] = $transaction['barcode'] . '|'; $transactions[$key] = $transaction; } } } } //Get econtent info and hold queue length foreach ($transactions as $key => $transaction) { //Check for hold queue length $itemData = $this->_loadItemSIP2Data($transaction['barcode'], ''); $transaction['holdQueueLength'] = intval($itemData['holdQueueLength']); $transactions[$key] = $transaction; } } //Process sorting $sortKeys = array(); $i = 0; foreach ($transactions as $key => $transaction) { $sortTitle = isset($transaction['sortTitle']) ? $transaction['sortTitle'] : "Unknown"; if ($sortOption == 'title') { $sortKeys[$key] = $sortTitle; } elseif ($sortOption == 'author') { $sortKeys[$key] = (isset($transaction['author']) ? $transaction['author'] : "Unknown") . '-' . $sortTitle; } elseif ($sortOption == 'dueDate') { if (preg_match('/.*?(\\d{1,2})[-\\/](\\d{1,2})[-\\/](\\d{2,4}).*/', $transaction['duedate'], $matches)) { $sortKeys[$key] = $matches[3] . '-' . $matches[1] . '-' . $matches[2] . '-' . $sortTitle; } else { $sortKeys[$key] = $transaction['duedate'] . '-' . $sortTitle; } } elseif ($sortOption == 'format') { $sortKeys[$key] = (isset($transaction['format']) ? $transaction['format'] : "Unknown") . '-' . $sortTitle; } elseif ($sortOption == 'renewed') { $sortKeys[$key] = (isset($transaction['renewCount']) ? $transaction['renewCount'] : 0) . '-' . $sortTitle; } elseif ($sortOption == 'holdQueueLength') { $sortKeys[$key] = (isset($transaction['holdQueueLength']) ? $transaction['holdQueueLength'] : 0) . '-' . $sortTitle; } $sortKeys[$key] = $sortKeys[$key] . '-' . $i++; } array_multisort($sortKeys, $transactions); //Limit to a specific number of records $totalTransactions = count($transactions); if ($recordsPerPage != -1) { $startRecord = ($page - 1) * $recordsPerPage; $transactions = array_slice($transactions, $startRecord, $recordsPerPage); } $this->transactions[$patron['id']] = $transactions; return array('transactions' => $transactions, 'numTransactions' => $totalTransactions); }
function getTags() { $tagList = array(); $sql = "SELECT resource_tags.* FROM resource, resource_tags, user_resource " . "WHERE resource.id = user_resource.resource_id " . "AND resource.id = resource_tags.resource_id " . "AND user_resource.user_id = '{$this->user_id}' " . "AND user_resource.list_id = '{$this->id}'"; /** @var Resource|object $resource */ $resource = new Resource(); $resource->query($sql); if ($resource->N) { while ($resource->fetch()) { $tagList[] = clone $resource; } } return $tagList; }
/** * Return all resources that the user has saved * * @param string[] $tags Tags to filter the resources by * @return Resource[] */ function getResources($tags = null) { require_once 'User_resource.php'; $resourceList = array(); $sql = "SELECT DISTINCT resource.* FROM resource, user_resource " . "WHERE resource.id = user_resource.resource_id " . "AND user_resource.user_id = '{$this->id}'"; if ($tags) { for ($i = 0; $i < count($tags); $i++) { $sql .= " AND resource.id IN (SELECT DISTINCT resource_tags.resource_id " . "FROM resource_tags, tags " . "WHERE resource_tags.tag_id=tags.id AND tags.tag = '" . addslashes($tags[$i]) . "' AND resource_tags.user_id = '{$this->id}')"; } } /** @var Resource|object $resource */ $resource = new Resource(); $resource->query($sql); if ($resource->N) { while ($resource->fetch()) { $resourceList[] = clone $resource; } } return $resourceList; }
if ($res) { $object->busy = $busy; $object->mandatory = $mandatory; $result = $object->update_element_resource($user); if ($result >= 0) { setEventMessage($langs->trans('RessourceLineSuccessfullyUpdated')); Header("Location: " . $_SERVER['PHP_SELF'] . "?element=" . $element . "&element_id=" . $element_id); exit; } else { setEventMessage($object->error, 'errors'); } } } // Delete a resource linked to an element if ($action == 'confirm_delete_linked_resource' && $user->rights->resource->delete && GETPOST('confirm') == 'yes') { $res = $object->fetch(GETPOST('id')); if ($res) { $result = $object->delete_resource($lineid, $element); if ($result >= 0) { setEventMessage($langs->trans('RessourceLineSuccessfullyDeleted')); Header("Location: " . $_SERVER['PHP_SELF'] . "?element=" . $element . "&element_id=" . $element_id); exit; } else { setEventMessage($object->error, 'errors'); } } else { setEventMessage($object->error, 'errors'); } } $parameters = array('resource_id' => resource_id); $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action);
public function getMyHolds($patron = null, $page = 1, $recordsPerPage = -1, $sortOption = 'title') { global $timer; global $configArray; global $user; $patronDump = $this->driver->_getPatronDump($this->driver->_getBarcode()); //Load the information from millennium using CURL $sResult = $this->driver->_fetchPatronInfoPage($patronDump, 'holds'); $timer->logTime("Got holds page from Millennium"); $holds = $this->parseHoldsPage($sResult); $timer->logTime("Parsed Holds page"); //Get a list of all record id so we can load supplemental information $recordIds = array(); foreach ($holds as $holdSections) { foreach ($holdSections as $hold) { $recordIds[] = "'" . $hold['shortId'] . "'"; } } //Get records from resource table $resourceInfo = new Resource(); if (count($recordIds) > 0) { $recordIdString = implode(",", $recordIds); mysql_select_db($configArray['Database']['database_vufind_dbname']); $resourceSql = "SELECT * FROM resource where source = 'VuFind' AND shortId in (" . $recordIdString . ")"; $resourceInfo->query($resourceSql); $timer->logTime('Got records for all titles'); //Load title author, etc. information while ($resourceInfo->fetch()) { foreach ($holds as $section => $holdSections) { foreach ($holdSections as $key => $hold) { $hold['recordId'] = $hold['id']; if ($hold['shortId'] == $resourceInfo->shortId) { $hold['recordId'] = $resourceInfo->record_id; $hold['id'] = $resourceInfo->record_id; $hold['shortId'] = $resourceInfo->shortId; //Load title, author, and format information about the title $hold['title'] = isset($resourceInfo->title) ? $resourceInfo->title : 'Unknown'; $hold['sortTitle'] = isset($resourceInfo->title_sort) ? $resourceInfo->title_sort : 'unknown'; $hold['author'] = isset($resourceInfo->author) ? $resourceInfo->author : null; $hold['format'] = isset($resourceInfo->format) ? $resourceInfo->format : null; $hold['isbn'] = isset($resourceInfo->isbn) ? $resourceInfo->isbn : ''; $hold['upc'] = isset($resourceInfo->upc) ? $resourceInfo->upc : ''; $hold['format_category'] = isset($resourceInfo->format_category) ? $resourceInfo->format_category : ''; //Load rating information $hold['ratingData'] = $resourceInfo->getRatingData($user); $holds[$section][$key] = $hold; } } } } } //Process sorting //echo ("<br/>\r\nSorting by $sortOption"); foreach ($holds as $sectionName => $section) { $sortKeys = array(); $i = 0; foreach ($section as $key => $hold) { $sortTitle = isset($hold['sortTitle']) ? $hold['sortTitle'] : (isset($hold['title']) ? $hold['title'] : "Unknown"); if ($sectionName == 'available') { $sortKeys[$key] = $sortTitle; } else { if ($sortOption == 'title') { $sortKeys[$key] = $sortTitle; } elseif ($sortOption == 'author') { $sortKeys[$key] = (isset($hold['author']) ? $hold['author'] : "Unknown") . '-' . $sortTitle; } elseif ($sortOption == 'placed') { $sortKeys[$key] = $hold['createTime'] . '-' . $sortTitle; } elseif ($sortOption == 'format') { $sortKeys[$key] = (isset($hold['format']) ? $hold['format'] : "Unknown") . '-' . $sortTitle; } elseif ($sortOption == 'location') { $sortKeys[$key] = (isset($hold['location']) ? $hold['location'] : "Unknown") . '-' . $sortTitle; } elseif ($sortOption == 'holdQueueLength') { $sortKeys[$key] = (isset($hold['holdQueueLength']) ? $hold['holdQueueLength'] : 0) . '-' . $sortTitle; } elseif ($sortOption == 'position') { $sortKeys[$key] = str_pad(isset($hold['position']) ? $hold['position'] : 1, 3, "0", STR_PAD_LEFT) . '-' . $sortTitle; } elseif ($sortOption == 'status') { $sortKeys[$key] = (isset($hold['status']) ? $hold['status'] : "Unknown") . '-' . (isset($hold['reactivateTime']) ? $hold['reactivateTime'] : "0") . '-' . $sortTitle; } else { $sortKeys[$key] = $sortTitle; } //echo ("<br/>\r\nSort Key for $key = {$sortKeys[$key]}"); } $sortKeys[$key] = strtolower($sortKeys[$key] . '-' . $i++); } array_multisort($sortKeys, $section); $holds[$sectionName] = $section; } //Limit to a specific number of records if (isset($holds['unavailable'])) { $numUnavailableHolds = count($holds['unavailable']); if ($recordsPerPage != -1) { $startRecord = ($page - 1) * $recordsPerPage; $holds['unavailable'] = array_slice($holds['unavailable'], $startRecord, $recordsPerPage); } } else { $numUnavailableHolds = 0; } if (!isset($holds['available'])) { $holds['available'] = array(); } if (!isset($holds['unavailable'])) { $holds['unavailable'] = array(); } //Sort the hold sections so available holds are first. ksort($holds); $patronId = isset($patron) ? $patron['id'] : $this->driver->_getBarcode(); $this->holds[$patronId] = $holds; $timer->logTime("Processed hold pagination and sorting"); return array('holds' => $holds, 'numUnavailableHolds' => $numUnavailableHolds); }
if ($res) { $object->busy = $busy; $object->mandatory = $mandatory; $result = $object->update_element_resource($user); if ($result >= 0) { setEventMessage($langs->trans('RessourceLineSuccessfullyUpdated')); Header("Location: " . $_SERVER['PHP_SELF'] . "?element=" . $element . "&element_id=" . $element_id); exit; } else { setEventMessage($object->error, 'errors'); } } } // Delete a resource linked to an element if ($action == 'confirm_delete_linked_resource' && $user->rights->resource->delete && $confirm === 'yes') { $res = $object->fetch($id); if ($res > 0) { $result = $object->delete_resource($lineid, $element); if ($result >= 0) { setEventMessage($langs->trans('RessourceLineSuccessfullyDeleted')); Header("Location: " . $_SERVER['PHP_SELF'] . "?element=" . $element . "&element_id=" . $element_id); exit; } else { setEventMessage($object->error, 'errors'); } } else { setEventMessage($object->error, 'errors'); } } $parameters = array('resource_id' => $resource_id); $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action);