Example #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
			BlorgTag 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('BlorgTagWrapper'));
        // only insert if no tag already exists (prevents creating two tags on
        // reloading)
        if (count($tags) > 0) {
            $tag = $tags->getFirst();
        } else {
            $tag = new BlorgTag();
            $tag->setDatabase($this->app->db);
            $tag->instance = $instance_id;
            $tag->title = $title;
            $tag->save();
            if (isset($this->app->memcache)) {
                $this->app->memcache->flushNs('tags');
            }
            $message = new SwatMessage(sprintf(Blorg::_('The tag “%s” has been added.'), $tag->title));
            $this->app->messages->add($message);
        }
        $this->tag_array[$tag->shortname] = $tag->title;
        $this->selected_tag_array[$tag->shortname] = $tag->title;
    }
Example #2
0
 protected function initTag()
 {
     $class_name = SwatDBClassMap::get('BlorgTag');
     $this->tag = new $class_name();
     $this->tag->setDatabase($this->app->db);
     if (!$this->tag->loadByShortname($this->getArgument('shortname'), $this->app->getInstance())) {
         throw new SiteNotFoundException('Page not found.');
     }
 }
Example #3
0
 protected function buildInternal()
 {
     parent::buildInternal();
     $this->buildMessages();
     $ds = new SwatDetailsStore($this->tag);
     $ds->post_count = $this->tag->getPostCount();
     $details_view = $this->ui->getWidget('details_view');
     $details_view->data = $ds;
     $details_frame = $this->ui->getWidget('details_frame');
     $details_frame->title = Blorg::_('Tag');
     $details_frame->subtitle = $this->tag->title;
     $this->buildToolbar();
 }
Example #4
0
 protected function saveDBData()
 {
     $values = $this->ui->getValues(array('title', 'shortname'));
     $this->tag->title = $values['title'];
     -($this->tag->shortname = $values['shortname']);
     if ($this->id === null) {
         $now = new SwatDate();
         $now->toUTC();
         $this->tag->createdate = $now;
         $this->tag->instance = $this->app->getInstanceId();
     }
     if ($this->tag->isModified()) {
         $this->tag->save();
         if (isset($this->app->memcache)) {
             $this->app->memcache->flushNs('tags');
             // only clear the posts when editing an existing tag
             if ($this->id !== null) {
                 $this->app->memcache->flushNs('posts');
             }
         }
         $message = new SwatMessage(sprintf(Blorg::_('“%s” has been saved.'), $this->tag->title));
         $this->app->messages->add($message);
     }
 }