Exemplo n.º 1
0
    /**
     * Creates a new tag
     *
     * @throws SwatException if no database connection is set on this tag
     *                        entry control.
     */
    protected function insertTag($title, $index)
    {
        if ($this->app === null) {
            throw new SwatException('An application must be set on the tag entry control during ' . 'the widget init phase.');
        }
        // check to see if the tag already exists
        $instance_id = $this->app->getInstanceId();
        $sql = sprintf('select * from
			PinholeTag where lower(title) = lower(%s)
				and instance %s %s', $this->app->db->quote($title, 'text'), SwatDB::equalityOperator($instance_id), $this->app->db->quote($instance_id, 'integer'));
        $tags = SwatDB::query($this->app->db, $sql, SwatDBClassMap::get('PinholeTagDataObjectWrapper'));
        // only insert if no tag already exists (prevents creating two tags on
        // reloading)
        if (count($tags) > 0) {
            $tag_obj = $tags->getFirst();
        } else {
            $tag_obj = new PinholeTagDataObject();
            $tag_obj->setDatabase($this->app->db);
            $tag_obj->instance = $instance_id;
            $tag_obj->title = $title;
            $tag_obj->save();
            $message = new SwatMessage(sprintf(Pinhole::_('“%s” tag has been added'), SwatString::minimizeEntities($tag_obj->title)));
            $message->content_type = 'text/xml';
            $message->secondary_content = sprintf(Pinhole::_('You can <a href="Tag/Edit?id=%d">edit this tag</a> ' . 'to customize it.'), $tag_obj->id);
            $this->app->messages->add($message);
        }
        $this->tag_array[$tag_obj->name] = $tag_obj->title;
        $this->selected_tag_array[$tag_obj->name] = $tag_obj->title;
    }
Exemplo n.º 2
0
 /**
  * Gets whether or not this tag is modified
  *
  * @return boolean true if this tag has been modified and false if this
  *                  tag has not been modified.
  */
 public function isModified()
 {
     $this->data_object->id = $this->id;
     $this->data_object->name = $this->name;
     $this->data_object->title = $this->title;
     $this->data_object->createdate = $this->createdate;
     return $this->data_object->isModified();
 }
Exemplo n.º 3
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)));
    }
Exemplo n.º 4
0
    private function addMetaDataTag($title)
    {
        $title = trim($title);
        // check to see if the tag already exists
        $instance_id = $this->image_set->instance === null ? null : $this->image_set->instance->id;
        $sql = sprintf('select * from
			PinholeTag where lower(title) = lower(%1$s)
				and instance %2$s %3$s', $this->db->quote($title, 'text'), SwatDB::equalityOperator($instance_id), $this->db->quote($instance_id, 'integer'));
        $tags = SwatDB::query($this->db, $sql, SwatDBClassMap::get('PinholeTagDataObjectWrapper'));
        if (count($tags) > 0) {
            $tag_obj = $tags->getFirst();
        } else {
            $tag_obj = new PinholeTagDataObject();
            $tag_obj->setDatabase($this->db);
            $tag_obj->setInstance($this->image_set->instance);
            $tag_obj->title = $title;
            $tag_obj->save();
        }
        return $tag_obj;
    }