function removeTag() { global $user; if ($user === false) { return json_encode(array('success' => false, 'message' => 'Sorry, you must be logged in to remove tags.')); } require_once ROOT_DIR . '/sys/LocalEnrichment/UserTag.php'; $id = $_REQUEST['id']; $tag = $_REQUEST['tag']; $userTag = new UserTag(); $userTag->tag = $tag; $userTag->userId = $user->id; $userTag->groupedRecordPermanentId = $id; if ($userTag->find(true)) { //This is a new tag $userTag->delete(); return json_encode(array('success' => true, 'message' => 'Removed your tag from the title. Refresh to view updated tag list.')); } else { //This tag has already been added return json_encode(array('success' => true, 'message' => 'We could not find that tag for this record.')); } }
/** * Process a search for a particular tag. * * @access private * @param string $lookfor The tag to search for * @return array A revised searchTerms array to get matching Solr records * (empty if no tag matches found). */ private function processTagSearch($lookfor) { // Include the app database objects require_once ROOT_DIR . '/sys/LocalEnrichment/UserTag.php'; require_once ROOT_DIR . '/sys/Grouping/GroupedWork.php'; // Find our tag in the database $tag = new UserTag(); $tag->tag = $lookfor; $tag->selectAdd(null); $tag->selectAdd('DISTINCT(groupedRecordPermanentId) as groupedRecordPermanentId'); $newSearch = array(); $newSearch[0] = array('join' => 'OR', 'group' => array()); $tag->find(); while ($tag->fetch()) { // Grab the list of records tagged with this tag $id = $tag->groupedRecordPermanentId; $newSearch[0]['group'][] = array('field' => 'id', 'lookfor' => $id, 'bool' => 'OR'); } return $newSearch; }
public function getTags() { global $user; /** @var UserTag[] $tags */ $tags = array(); require_once ROOT_DIR . '/sys/LocalEnrichment/UserTag.php'; $userTags = new UserTag(); $userTags->groupedRecordPermanentId = $this->getPermanentId(); $userTags->find(); while ($userTags->fetch()) { if (!isset($tags[$userTags->tag])) { $tags[$userTags->tag] = clone $userTags; $tags[$userTags->tag]->userAddedThis = false; } $tags[$userTags->tag]->cnt++; if (!$user) { return false; } else { if ($user->id == $tags[$userTags->tag]->userId) { $tags[$userTags->tag]->userAddedThis = true; } } } return $tags; }