コード例 #1
0
ファイル: AJAX.php プロジェクト: victorfcm/VuFind-Plus
 function saveTag()
 {
     global $user;
     if ($user === false) {
         return json_encode(array('success' => false, 'message' => 'Sorry, you must be logged in to add tags.'));
     }
     require_once ROOT_DIR . '/sys/LocalEnrichment/UserTag.php';
     $id = $_REQUEST['id'];
     // Parse apart the tags and save them in association with the resource:
     preg_match_all('/"[^"]*"|[^,]+/', $_REQUEST['tag'], $words);
     foreach ($words[0] as $tag) {
         $tag = trim(strtolower(str_replace('"', '', $tag)));
         $userTag = new UserTag();
         $userTag->tag = $tag;
         $userTag->userId = $user->id;
         $userTag->groupedRecordPermanentId = $id;
         if (!$userTag->find(true)) {
             //This is a new tag
             $userTag->dateTagged = time();
             $userTag->insert();
         } else {
             //This tag has already been added
         }
     }
     return json_encode(array('success' => true, 'message' => 'All tags have been added to the title.  Refresh to view updated tag list.'));
 }