public function getAllTags($principalId, $objectId = null)
 {
     // All tags from principal
     if ($objectId === null) {
         $data = array(TagManager::KEY_PRINCIPALID => $principalId);
         $sqlQuery = 'SELECT ' . TagManager::KEY_TAGID . ', ' . TagManager::KEY_LABEL . ', ' . TagManager::KEY_COLOR . ' FROM ' . self::TAGS_TABLE_NAME . ' WHERE ' . TagManager::KEY_PRINCIPALID . ' = :' . TagManager::KEY_PRINCIPALID;
     } else {
         $data = array(TagManager::KEY_PRINCIPALID => $principalId, TagManager::KEY_TAGGABLEID => $objectId);
         $sqlQuery = 'SELECT ' . self::TAGS_TABLE_NAME . '.' . TagManager::KEY_TAGID . ', ' . TagManager::KEY_LABEL . ', ' . TagManager::KEY_COLOR . ' FROM ' . self::TAGS_TABLE_NAME . ', ' . self::TAGOBJECTASSIGNATIONS_TABLE_NAME . ' WHERE ' . TagManager::KEY_PRINCIPALID . ' = :' . TagManager::KEY_PRINCIPALID . ' AND ' . TagManager::KEY_TAGGABLEID . ' = :' . TagManager::KEY_TAGGABLEID . ' AND ' . self::TAGS_TABLE_NAME . '.' . TagManager::KEY_TAGID . ' = ' . self::TAGOBJECTASSIGNATIONS_TABLE_NAME . '.' . TagManager::KEY_TAGID;
     }
     try {
         $dbHandler = $this->getConnection();
         $stmt = $dbHandler->prepare($sqlQuery);
         $stmt->execute($data);
         $results = $stmt->fetchAll(PDO::FETCH_ASSOC);
         $return = array();
         foreach ($results as $result) {
             $tag = new BasicTag($result[TagManager::KEY_LABEL], $result[TagManager::KEY_COLOR]);
             $tag->setId($result[TagManager::KEY_TAGID]);
             $return[] = $tag;
         }
         return $return;
     } catch (PDOException $e) {
         $this->destroyConnection();
         throw new EyeTagException('An error occured while retrieving tags from the database.', 0, $e);
     }
     $this->destroyConnection();
 }
Exemplo n.º 2
0
 /**
  * Unassign tags from a file.
  *
  * @param array $params (
  * 		path => string,
  * 		tagIds => array(
  *			tagId1, tagId2, ...
  *		)
  * )
  */
 public function removeAllTags($params)
 {
     if ($params === null) {
         throw new EyeInvalidArgumentException('Missing $params');
     }
     if (!isset($params['path']) || !is_string($params['path'])) {
         throw new EyeInvalidArgumentException('Missing or invalid $params[\'path\']');
     }
     if (!isset($params['tagIds']) || !is_array($params['tagIds'])) {
         throw new EyeInvalidArgumentException('Missing or invalid $params[\'tagIds\']');
     }
     $file = FSI::getFile($params['path']);
     $TM = TagManager::getInstance();
     $tags = array();
     foreach ($params['tagIds'] as $tagId) {
         $tag = new BasicTag();
         $tag->setId($tagId);
         $TM->getTag($tag);
         $tags[] = $tag;
     }
     $TM->removeAllTags($file, $tags);
 }