Exemplo n.º 1
0
 /**
  * Parses this tag from a tag string
  *
  * This tag parses with any alphanumeric string.
  *
  * @param string $string the tag string to parse.
  * @param MDB2_Driver_Common $db the database connection used to parse the
  *                                tag string.
  * @param SiteInstance the site instance used to parse the tag string.
  *
  * @return boolean true if the tag string could be parsed and false if the
  *                  tag string could not be parsed.
  */
 public function parse($string, MDB2_Driver_Common $db, SiteInstance $instance = null)
 {
     $valid = false;
     $this->data_object = new PinholeTagDataObject();
     $this->setDatabase($db);
     $this->setInstance($instance);
     $this->name = $string;
     if (preg_match('/^[a-z0-9-]+$/i', $string) == 1) {
         if ($this->data_object->loadByName($this->name, $this->instance)) {
             $this->id = $this->data_object->id;
             $this->title = $this->data_object->title;
             $this->createdate = $this->data_object->createdate;
         }
         $valid = true;
     }
     return $valid;
 }
Exemplo n.º 2
0
    protected function processDBData()
    {
        parent::processDBData();
        $tags = $this->ui->getWidget('dst_tag')->getSelectedTagArray();
        $dst_tag = new PinholeTagDataObject();
        $dst_tag->setDatabase($this->app->db);
        $dst_tag->loadByName(key($tags), $this->app->getInstance());
        // delete intersection tagged photos
        $sql = sprintf('delete from pinholephototagbinding where tag = %s
			and photo in (select photo from pinholephototagbinding
				where pinholephototagbinding.tag = %s)', $this->app->db->quote($this->source_tag->id, 'integer'), $this->app->db->quote($dst_tag->id, 'integer'));
        SwatDB::exec($this->app->db, $sql);
        // add source_tagged photos to dst_tagged photos
        $sql = sprintf('insert into pinholephototagbinding (photo, tag)
			select pinholephototagbinding.photo, %s
			from pinholephototagbinding where tag = %s', $this->app->db->quote($dst_tag->id, 'integer'), $this->app->db->quote($this->source_tag->id, 'integer'));
        SwatDB::exec($this->app->db, $sql);
        // delete source_tag
        $this->source_tag->delete();
        $this->app->messages->add(new SwatMessage(sprintf(Pinhole::_('“%s” has been merged into “%s”'), $this->source_tag->title, $dst_tag->title)));
    }