/** * Returns the stored list of facets for the last search * * @param array $filter Array of field => on-screen description listing * all of the desired facet fields; set to null to get all configured values. * * @return array Facets data arrays */ public function getFacetList($filter = null) { // Make sure we have processed the search before proceeding: if (is_null($this->user)) { $this->performAndProcessSearch(); } // If there is no filter, we'll use all facets as the filter: if (is_null($filter)) { $filter = $this->getParams()->getFacetConfig(); } // Start building the facet list: $retVal = []; // Loop through every requested field: $validFields = array_keys($filter); foreach ($validFields as $field) { if (!isset($this->facets[$field])) { $this->facets[$field] = ['label' => $this->getParams()->getFacetLabel($field), 'list' => []]; switch ($field) { case 'tags': if ($this->list) { $tags = $this->list->getTags(); } else { $tags = $this->user ? $this->user->getTags() : []; } foreach ($tags as $tag) { $this->facets[$field]['list'][] = ['value' => $tag->tag, 'displayText' => $tag->tag, 'count' => $tag->cnt, 'isApplied' => $this->getParams()->hasFilter("{$field}:" . $tag->tag)]; } break; } } if (isset($this->facets[$field])) { $retVal[$field] = $this->facets[$field]; } } return $retVal; }
/** * Process the "edit list" submission. * * @param \VuFind\Db\Row\User $user Logged in user * @param \VuFind\Db\Row\UserList $list List being created/edited * * @return object|bool Response object if redirect is * needed, false if form needs to be redisplayed. */ protected function processEditList($user, $list) { // Process form within a try..catch so we can handle errors appropriately: try { $finalId = $list->updateFromRequest($user, $this->getRequest()->getPost()); // If the user is in the process of saving a record, send them back // to the save screen; otherwise, send them back to the list they // just edited. $recordId = $this->params()->fromQuery('recordId'); $recordSource = $this->params()->fromQuery('recordSource', 'VuFind'); if (!empty($recordId)) { $details = $this->getRecordRouter()->getActionRouteDetails($recordSource . '|' . $recordId, 'Save'); return $this->lightboxAwareRedirect($details['route'], $details['params']); } // Similarly, if the user is in the process of bulk-saving records, // send them back to the appropriate place in the cart. $bulkIds = $this->params()->fromPost('ids', $this->params()->fromQuery('ids', [])); if (!empty($bulkIds)) { $params = []; foreach ($bulkIds as $id) { $params[] = urlencode('ids[]') . '=' . urlencode($id); } $saveUrl = $this->getLightboxAwareUrl('cart-save'); $saveUrl .= strpos($saveUrl, '?') === false ? '?' : '&'; return $this->redirect()->toUrl($saveUrl . implode('&', $params)); } return $this->lightboxAwareRedirect('userList', ['id' => $finalId]); } catch (\Exception $e) { switch (get_class($e)) { case 'VuFind\\Exception\\ListPermission': case 'VuFind\\Exception\\MissingField': $this->flashMessenger()->setNamespace('error')->addMessage($e->getMessage()); return false; case 'VuFind\\Exception\\LoginRequired': return $this->forceLogin(); default: throw $e; } } }
/** * Retrieve the ID of the last list that was accessed, if any. * * @return mixed User_list ID (if set) or null (if not available). */ public function lastUsed() { return UserListRow::getLastUsed(); }
/** * Saves the properties to the database. * * This performs an intelligent insert/update, and reloads the * properties with fresh data from the table on success. * * @param \VuFind\Db\Row\User|bool $user Logged-in user (false if none) * * @return mixed The primary key value(s), as an associative array if the * key is compound, or a scalar if the key is single-column. * @throws ListPermissionException * @throws MissingFieldException */ public function save($user = false) { $this->finna_updated = date('Y-m-d H:i:s'); return parent::save($user); }