Exemple #1
0
 public static function getUserIDFromLibraryID($libraryID, $libraryType = null)
 {
     if (isset(self::$libraryUserIDs[$libraryID])) {
         return self::$libraryUserIDs[$libraryID];
     }
     $cacheKey = 'libraryUserID_' . $libraryID;
     $userID = Z_Core::$MC->get($cacheKey);
     if ($userID) {
         self::$libraryUserIDs[$libraryID] = $userID;
         return $userID;
     }
     if ($libraryType == null) {
         $libraryType = Zotero_Libraries::getType($libraryID);
     }
     switch ($libraryType) {
         case 'user':
             $sql = "SELECT userID FROM users WHERE libraryID=?";
             break;
         case 'publications':
             $sql = "SELECT userID FROM userPublications WHERE libraryID=?";
             break;
         case 'group':
             $sql = "SELECT userID FROM groupUsers JOIN groups USING (groupID) " . "WHERE libraryID=? AND role='owner'";
             break;
     }
     $userID = Zotero_DB::valueQuery($sql, $libraryID);
     if (!$userID) {
         if (!Zotero_Libraries::exists($libraryID)) {
             throw new Exception("Library {$libraryID} does not exist");
         }
         // Wrong library type passed
         error_log("Wrong library type passed for library {$libraryID} " . "in Zotero_Users::getUserIDFromLibraryID()");
         return self::getUserIDFromLibraryID($libraryID);
     }
     self::$libraryUserIDs[$libraryID] = $userID;
     Z_Core::$MC->set($cacheKey, $userID);
     return $userID;
 }