Example #1
0
function test_tag($string)
{
    $tag = PinholeTagFactory::get($string);
    if ($tag) {
        echo "=> ", $tag, ': "', $tag->getTitle(), "\"\n";
        echo "   Photos: ";
        foreach ($tag->getPhotos() as $photo) {
            echo $photo->id, ' ';
        }
        echo "\n";
        if ($tag instanceof PinholeIterableTag) {
            echo "   Iterable: ", $tag->prev()->getTitle(), " <=> ", $tag->next()->getTitle(), "\n";
        }
    } else {
        echo "=> {$string}: *** error loading tag ***\n";
    }
}
Example #2
0
 /**
  * Sets the default database used by the tag factory
  *
  * @param MDB2_Driver_Common the default database used by the tag factory.
  */
 public static function setDefaultDatabase(MDB2_Driver_Common $db)
 {
     self::$default_database = $db;
 }
Example #3
0
 /**
  * Adds a tag to this tag list
  *
  * If this list has a database set through the
  * {@link PinholeTagList::setDatabase()} method and the tag to be
  * added is not already contained in this list, the database will be
  * set on the added tag as well.
  *
  * @param string|PinholeAbstractTag $tag either a tag string or a tag
  *                                        object to add to this list.
  *
  * @return PinholeAbstractTag the added tag object, or the existing tag
  *                             object if this list already contains the
  *                             given tag. If the added tag is specified as
  *                             a tag string and the tag string could not be
  *                             parsed, null is returned.
  *
  * @throws SwatInvalidClassException if the <i>$tag</i> parameter is
  *                                    neither a string nor a
  *                                    PinholeAbstractTag.
  */
 public function add($tag)
 {
     $added_tag = null;
     if (is_string($tag)) {
         $tag = PinholeTagFactory::get($tag, $this->db, $this->app->getInstance());
     } elseif ($tag instanceof PinholeTagDataObject) {
         $tag = new PinholeTag($this->app->getInstance(), $tag);
     } elseif (!$tag instanceof PinholeAbstractTag) {
         throw new SwatInvalidClassException('$tag must be either a string or a PinholeAbstractTag', 0, $tag);
     }
     if ($tag !== null) {
         if ($this->contains($tag)) {
             $added_tag = $this->get($tag);
         } else {
             if ($this->db instanceof MDB2_Driver_Common) {
                 $tag->setDatabase($this->db);
             }
             $this->tag_keys[] = $tag->__toString();
             $this->tags[$tag->__toString()] = $tag;
             $added_tag = $tag;
         }
     }
     return $added_tag;
 }