Пример #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;
    }
    protected function getSegments()
    {
        $sql = 'select * from MailingListCampaignSegment
			where %s and instance %s %s';
        $sql = sprintf($sql, $this->force_all ? '1 = 1' : sprintf('enabled = %s', $this->db->quote(true, 'boolean')), SwatDB::equalityOperator($this->getInstanceId()), $this->db->quote($this->getInstanceId(), 'integer'));
        return SwatDB::query($this->db, $sql, SwatDBClassMap::get('DeliveranceCampaignSegmentWrapper'));
    }
Пример #3
0
    /**
     * Loads this comment
     *
     * @param integer $id the database id of this comment.
     * @param SiteInstance $instance optional. The instance to load the comment
     *                                in. If the application does not use
     *                                instances, this should be null. If
     *                                unspecified, the instance is not checked.
     *
     * @return boolean true if this comment and false if it was not.
     */
    public function load($id, SiteInstance $instance = null)
    {
        $this->checkDB();
        $loaded = false;
        $row = null;
        if ($this->table !== null && $this->id_field !== null) {
            $id_field = new SwatDBField($this->id_field, 'integer');
            $sql = sprintf('select %1$s.* from %1$s
				inner join PinholePhoto on %1$s.photo = PinholePhoto.id
				inner join ImageSet on ImageSet.id = PinholePhoto.image_set
				where %1$s.%2$s = %3$s', $this->table, $id_field->name, $this->db->quote($id, $id_field->type));
            $instance_id = $instance === null ? null : $instance->id;
            if ($instance_id !== null) {
                $sql .= sprintf(' and ImageSet.instance %s %s', SwatDB::equalityOperator($instance_id), $this->db->quote($instance_id, 'integer'));
            }
            $rs = SwatDB::query($this->db, $sql, null);
            $row = $rs->fetchRow(MDB2_FETCHMODE_ASSOC);
        }
        if ($row !== null) {
            $this->initFromRow($row);
            $this->generatePropertyHashes();
            $loaded = true;
        }
        return $loaded;
    }
Пример #4
0
 protected function getWhereClause()
 {
     $where_clause = parent::getWhereClause();
     $instance_id = $this->app->getInstanceId();
     $where_clause .= sprintf(' and instance %s %s', SwatDB::equalityOperator($instance_id), $this->app->db->quote($instance_id, 'integer'));
     return $where_clause;
 }
Пример #5
0
    protected function initSideBar()
    {
        $this->sidebar = new SiteSidebar();
        $gadget_instances = false;
        if (isset($this->app->memcache)) {
            $gadget_instances = $this->app->memcache->get('gadget_instances');
        }
        if ($gadget_instances === false) {
            $sql = sprintf('select * from GadgetInstance
				where instance %s %s
				order by displayorder', SwatDB::equalityOperator($this->app->getInstanceId()), $this->app->db->quote($this->app->getInstanceId(), 'integer'));
            $gadget_instances = SwatDB::query($this->app->db, $sql, SwatDBClassMap::get('SiteGadgetInstanceWrapper'));
            $gadget_instances->loadAllSubRecordsets('setting_values', SwatDBClassMap::get('SiteGadgetInstanceSettingValueWrapper'), 'GadgetInstanceSettingValue', 'gadget_instance');
            if (isset($this->app->memcache)) {
                $this->app->memcache->set('gadget_instances', $gadget_instances);
            }
        } else {
            $gadget_instances->setDatabase($this->app->db);
        }
        foreach ($gadget_instances as $gadget_instance) {
            $gadget = SiteGadgetFactory::get($this->app, $gadget_instance);
            $this->sidebar->add($gadget);
        }
        $this->sidebar->init();
    }
Пример #6
0
    protected function buildInternal()
    {
        parent::buildInternal();
        $item_list = $this->getItemList('integer');
        $instance_id = $this->app->getInstanceId();
        $dep = new AdminListDependency();
        $dep->setTitle(Blorg::_('post'), Blorg::_('posts'));
        $sql = sprintf('select id, title, bodytext from BlorgPost
			where instance %s %s and id in (%s)
			order by publish_date desc, title', SwatDB::equalityOperator($instance_id), $this->app->db->quote($instance_id, 'integer'), $item_list);
        $posts = SwatDB::query($this->app->db, $sql, 'BlorgPostWrapper');
        $entries = array();
        foreach ($posts as $post) {
            $entry = new AdminDependencyEntry();
            $entry->id = $post->id;
            $entry->title = $post->getTitle();
            $entry->status_level = AdminDependency::DELETE;
            $entry->parent = null;
            $entries[] = $entry;
        }
        $dep->entries = $entries;
        $message = $this->ui->getWidget('confirmation_message');
        $message->content = $dep->getMessage();
        $message->content_type = 'text/xml';
        if ($dep->getStatusLevelCount(AdminDependency::DELETE) == 0) {
            $this->switchToCancelButton();
        }
    }
Пример #7
0
    /**
     * Gets the metadata for display
     *
     * @return SwatTableModel with metadata information.
     */
    protected function getTableModel(SwatView $view)
    {
        $sql = 'select * from PinholeMetaData
			where PinholeMetaData.instance %s %s
			order by %s';
        $instance_id = $this->app->getInstanceId();
        $sql = sprintf($sql, SwatDB::equalityOperator($instance_id), $this->app->db->quote($instance_id, 'integer'), $this->getOrderByClause($view, 'visible desc, displayorder, title'));
        $metadata = SwatDB::query($this->app->db, $sql);
        $store = new SwatTableStore();
        foreach ($metadata as $data) {
            $ds = new SwatDetailsView();
            $ds->title = $data->title;
            $ds->shortname = $data->shortname;
            $ds->id = $data->id;
            $ds->visible = $data->visible;
            $ds->machine_tag = $data->machine_tag;
            if ($ds->visible) {
                $ds->group_title = 'Shown';
            } else {
                $ds->group_title = 'Not Shown';
            }
            $store->add($ds);
        }
        return $store;
    }
Пример #8
0
    protected function getPhoto($filename)
    {
        $sql = sprintf('select PinholePhoto.*
			from PinholePhoto
			inner join ImageSet on PinholePhoto.image_set = ImageSet.id
			where PinholePhoto.filename = %s and ImageSet.instance %s %s', $this->app->db->quote($filename, 'text'), SwatDB::equalityOperator($this->app->getInstanceId()), $this->app->db->quote($this->app->getInstanceId(), 'integer'));
        $wrapper_class = SwatDBClassMap::get('PinholePhotoWrapper');
        $photos = SwatDB::query($this->app->db, $sql, $wrapper_class);
        if (count($photos) == 0) {
            $instance = $this->app->getInstance();
            if ($instance === null) {
                $message = sprintf("Photo with filename '%s' does not exist.", $filename);
            } else {
                $message = sprintf("Photo with filename '%s' does not exist " . "in the instance '%s'.", $filename, $instance->shortname);
            }
            throw new SiteNotFoundException($message);
        }
        $photo = $photos->getFirst();
        if ($photo->private && !$this->app->session->isLoggedIn()) {
            $message = sprintf("Photo with filename '%s' is private and user " . "is not logged in.", $filename);
            throw new SiteNotFoundException($message);
        }
        $photo->setFileBase('../photos');
        return $photo;
    }
Пример #9
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;
    }
Пример #10
0
    /**
     * Creates a new author index page
     *
     * @param SiteWebApplication $app the application.
     * @param SiteLayout $layout
     */
    public function __construct(SiteWebApplication $app, SiteLayout $layout, array $arguments = array())
    {
        parent::__construct($app, $layout, $arguments);
        $instance_id = $this->app->getInstanceId();
        $sql = sprintf('select * from BlorgAuthor
			where instance %s %s and visible = %s', SwatDB::equalityOperator($instance_id), $this->app->db->quote($instance_id, 'integer'), $this->app->db->quote(true, 'boolean'));
        $this->authors = SwatDB::query($this->app->db, $sql, SwatDBClassMap::get('BlorgAuthorWrapper'));
    }
Пример #11
0
    protected function getArticles()
    {
        $sql = sprintf('select title, shortname, description from Article
			where enabled = %s and visible = %s and parent is null
				and instance %s %s
			order by title asc', $this->app->db->quote(true, 'boolean'), $this->app->db->quote(true, 'boolean'), SwatDB::equalityOperator($this->app->getInstanceId()), $this->app->db->quote($this->app->getInstanceId(), 'integer'));
        $wrapper = SwatDBClassMap::get('SiteArticleWrapper');
        return SwatDB::query($this->app->db, $sql, $wrapper);
    }
Пример #12
0
    protected function validateShortname($shortname)
    {
        $sql = 'select shortname from BlorgTag
			where shortname = %s and id %s %s and instance %s %s';
        $instance_id = $this->app->getInstanceId();
        $sql = sprintf($sql, $this->app->db->quote($shortname, 'text'), SwatDB::equalityOperator($this->id, true), $this->app->db->quote($this->id, 'integer'), SwatDB::equalityOperator($instance_id), $this->app->db->quote($instance_id, 'integer'));
        $query = SwatDB::query($this->app->db, $sql);
        return count($query) == 0;
    }
Пример #13
0
    protected function validateShortname($shortname)
    {
        $instance_id = $this->app->getInstanceId();
        $sql = sprintf('select count(id) from Article
			where shortname = %s and
				instance %s %s and
				parent %s %s
				and id %s %s', $this->app->db->quote($shortname, 'text'), SwatDB::equalityOperator($instance_id), $this->app->db->quote($instance_id, 'integer'), SwatDB::equalityOperator($this->parent), $this->app->db->quote($this->parent, 'integer'), SwatDB::equalityOperator($this->id, true), $this->app->db->quote($this->id, 'integer'));
        return SwatDB::queryOne($this->app->db, $sql) == 0;
    }
Пример #14
0
 protected function getWhereClause()
 {
     if ($this->where_clause === null) {
         $where = parent::getWhereClause();
         $instance_id = $this->app->getInstanceId();
         $where .= sprintf(' and post in (select id from BlorgPost where instance %s %s)', SwatDB::equalityOperator($instance_id), $this->app->db->quote($instance_id, 'integer'));
         $this->where_clause = $where;
     }
     return $this->where_clause;
 }
Пример #15
0
    /**
     * Marks a file as not attached
     *
     * @param integer $file_id the id of the file to mark as not attached.
     *
     * @return boolean true.
     */
    public function detach($file_id)
    {
        $instance_id = $this->app->getInstanceId();
        $sql = sprintf('update BlorgFile set visible = %s
			where instance %s %s and id = %s', $this->app->db->quote(false, 'boolean'), SwatDB::equalityOperator($instance_id), $this->app->db->quote($instance_id, 'integer'), $this->app->db->quote($file_id, 'integer'));
        $num = SwatDB::exec($this->app->db, $sql);
        if ($num > 0 && isset($this->app->memcache)) {
            $this->app->memcache->flushNS('posts');
        }
        return true;
    }
Пример #16
0
 protected function loadData()
 {
     $instance_id = $this->app->getInstanceId();
     $where_clause = sprintf('visible = %s and instance %s %s', $this->app->db->quote($this->parent, 'boolean'), SwatDB::equalityOperator($instance_id), $this->app->db->quote($instance_id, 'integer'));
     $order_widget = $this->ui->getWidget('order');
     $order_widget->addOptionsByArray(SwatDB::getOptionArray($this->app->db, 'PinholeMetaData', 'title', 'id', 'displayorder, title', $where_clause));
     $sql = 'select sum(displayorder) from PinholeMetaData where ' . $where_clause;
     $sum = SwatDB::queryOne($this->app->db, $sql, 'integer');
     $options_list = $this->ui->getWidget('options');
     $options_list->value = $sum == 0 ? 'auto' : 'custom';
 }
Пример #17
0
    protected function getWhereClause()
    {
        if ($this->where_clause === null) {
            $where = parent::getWhereClause();
            $instance_id = $this->app->getInstanceId();
            $where .= sprintf(' and photo in (select PinholePhoto.id from PinholePhoto
					inner join ImageSet on ImageSet.id = PinholePhoto.image_set
					where instance %s %s)', SwatDB::equalityOperator($instance_id), $this->app->db->quote($instance_id, 'integer'));
            $this->where_clause = $where;
        }
        return $this->where_clause;
    }
Пример #18
0
 public function buildInternal()
 {
     parent::buildInternal();
     $item_list = $this->getItemList('integer');
     $instance_id = $this->app->getInstanceId();
     $where_clause = sprintf('id in (%s) and instance %s %s', $item_list, SwatDB::equalityOperator($instance_id), $this->app->db->quote($instance_id, 'integer'));
     $dep = new AdminListDependency();
     $dep->setTitle(Pinhole::_('photographer'), Pinhole::_('photographers'));
     $dep->entries = AdminListDependency::queryEntries($this->app->db, 'PinholePhotographer', 'integer:id', null, 'text:fullname', 'fullname', $where_clause, AdminDependency::DELETE);
     $message = $this->ui->getWidget('confirmation_message');
     $message->content = $dep->getMessage();
     $message->content_type = 'text/xml';
 }
Пример #19
0
    /**
     * Gets photographer data
     *
     * @return SwatTableModel with photographer information.
     */
    protected function getTableModel(SwatView $view)
    {
        $sql = 'select * from PinholePhotographer
			where instance %s %s
			order by %s';
        $instance_id = $this->app->getInstanceId();
        $sql = sprintf($sql, SwatDB::equalityOperator($instance_id), $this->app->db->quote($instance_id, 'integer'), $this->getOrderByClause($view, 'id'));
        $rs = SwatDB::query($this->app->db, $sql);
        foreach ($rs as $row) {
            $row->status_title = PinholePhotographer::getStatusTitle($row->status);
        }
        return $rs;
    }
Пример #20
0
    protected function getWhereClause()
    {
        if ($this->where_clause === null) {
            $instance_id = $this->app->getInstanceId();
            $where = sprintf('PinholePhoto.status in (%s, %s)
				and ImageSet.instance %s %s', $this->app->db->quote(PinholePhoto::STATUS_PUBLISHED, 'integer'), $this->app->db->quote(PinholePhoto::STATUS_UNPUBLISHED, 'integer'), SwatDB::equalityOperator($instance_id), $this->app->db->quote($instance_id, 'integer'));
            $clause = new AdminSearchClause('date:photo_date');
            $clause->table = 'PinholePhoto';
            $clause->value = $this->ui->getWidget('search_start_date')->value;
            $clause->operator = AdminSearchClause::OP_GTE;
            $where .= $clause->getClause($this->app->db, 'and');
            $clause = new AdminSearchClause('date:photo_date');
            $clause->table = 'PinholePhoto';
            $clause->value = $this->ui->getWidget('search_end_date')->value;
            $clause->operator = AdminSearchClause::OP_LT;
            $where .= $clause->getClause($this->app->db, 'and');
            if ($this->ui->getWidget('search_non_geo_tagged')->value) {
                $where .= sprintf(' and PinholePhoto.gps_latitude is null ');
            }
            $status = $this->ui->getWidget('search_status')->value;
            if ($status !== null) {
                switch ($status) {
                    case 'published':
                        $where .= sprintf(' and PinholePhoto.status = %s', $this->app->db->quote(PinholePhoto::STATUS_PUBLISHED, 'integer'));
                        break;
                    case 'hidden':
                        $where .= sprintf(' and PinholePhoto.status = %s', $this->app->db->quote(PinholePhoto::STATUS_UNPUBLISHED, 'integer'));
                        break;
                    case 'private':
                    case 'public':
                        $where .= sprintf(' and PinholePhoto.private = %s', $this->app->db->quote($status == 'private', 'boolean'));
                        break;
                    case 'for_sale':
                    case 'not_for_sale':
                        $where .= sprintf(' and PinholePhoto.for_sale = %s', $this->app->db->quote($status == 'for_sale', 'boolean'));
                        break;
                }
            }
            $tags = $this->ui->getWidget('search_tags')->getSelectedTagArray();
            foreach ($tags as $name => $title) {
                $where .= sprintf(' and PinholePhoto.id in (select photo from
					PinholePhotoTagBinding inner join PinholeTag on
					PinholeTag.id = PinholePhotoTagBinding.tag
					where PinholeTag.name = %s)', $this->app->db->quote($name, 'text'));
            }
            $this->where = $where;
        }
        return $this->where;
    }
Пример #21
0
 /**
  * Loads a set from the database with a shortname and instance
  *
  * @param string $shortname the shortname of the set
  *
  * @return boolean true if a set was successfully loaded and false if
  *                  no set was found at the specified shortname.
  */
 public function loadByShortname($shortname)
 {
     $this->checkDB();
     $instance_id = $this->instance === null ? null : $this->instance->id;
     $found = false;
     $sql = 'select * from %s where shortname = %s and instance %s %s';
     $sql = sprintf($sql, $this->table, $this->db->quote($shortname, 'text'), SwatDB::equalityOperator($instance_id), $this->db->quote($instance_id, 'integer'));
     $row = SwatDB::queryRow($this->db, $sql);
     if ($row !== null) {
         $this->initFromRow($row);
         $this->generatePropertyHashes();
         $found = true;
     }
     return $found;
 }
Пример #22
0
    protected function getMetaData()
    {
        static $meta_data;
        if ($meta_data === null) {
            $sql = 'select title, id, value, machine_tag, visible
				from PinholeMetaData
				left outer join PinholePhotoMetaDataBinding
					on photo = %s and meta_data = id
				where PinholeMetaData.instance %s %s
				order by visible desc, displayorder, title';
            $instance_id = $this->app->getInstanceId();
            $sql = sprintf($sql, $this->app->db->quote($this->photo->id, 'integer'), SwatDB::equalityOperator($instance_id), $this->app->db->quote($instance_id, 'integer'));
            $meta_data = SwatDB::query($this->app->db, $sql);
        }
        return $meta_data;
    }
Пример #23
0
    private function initTags()
    {
        $instance_id = $this->app->getInstanceId();
        $sql = sprintf('select BlorgTag.title, BlorgTag.shortname,
					count(BlorgPost.id) as post_count
				from BlorgTag
					inner join BlorgPostTagBinding on
						BlorgTag.id = BlorgPostTagBinding.tag
					inner join BlorgPost on
						BlorgPostTagBinding.post = BlorgPost.id
					left outer join Instance on BlorgTag.instance = Instance.id
				where BlorgTag.instance %s %s and BlorgPost.enabled = %s
					group by BlorgTag.title, BlorgTag.shortname
					order by BlorgTag.title', SwatDB::equalityOperator($instance_id), $this->app->db->quote($instance_id, 'integer'), $this->app->db->quote(true, 'boolean'));
        $this->tags = SwatDB::query($this->app->db, $sql);
    }
Пример #24
0
 protected function buildInternal()
 {
     AdminDBDelete::buildInternal();
     $item_list = $this->getItemList('integer');
     $instance_id = $this->app->getInstanceId();
     $where_clause = sprintf('id in (%s) and instance %s %s', $item_list, SwatDB::equalityOperator($instance_id), $this->app->db->quote($instance_id, 'integer'));
     $dep = new AdminListDependency();
     $dep->setTitle(Site::_('article'), Site::_('articles'));
     $dep->entries = AdminListDependency::queryEntries($this->app->db, 'Article', 'integer:id', null, 'text:title', 'title', $where_clause, AdminDependency::DELETE);
     $this->getDependencies($dep, $item_list);
     $message = $this->ui->getWidget('confirmation_message');
     $message->content = $dep->getMessage();
     $message->content_type = 'text/xml';
     if ($dep->getStatusLevelCount(AdminDependency::DELETE) === 0) {
         $this->switchToCancelButton();
     }
 }
Пример #25
0
    private function getBoundingBox($photo_ids)
    {
        // a box is easier for now, but we might have to do a radius
        // to be more accurate
        $instance_id = $this->app->getInstance() === null ? null : $this->app->getInstanceId();
        $sql = sprintf('select
				max(PinholePhoto.gps_latitude) as max_latitude,
				min(PinholePhoto.gps_latitude) as min_latitude,
				max(PinholePhoto.gps_longitude) as max_longitude,
				min(PinholePhoto.gps_longitude) as min_longitude
			from PinholePhoto
			inner join ImageSet on PinholePhoto.image_set = ImageSet.id
			where PinholePhoto.status = %s and ImageSet.instance %s %s
				and PinholePhoto.id in (%s)', $this->app->db->quote(PinholePhoto::STATUS_PUBLISHED, 'integer'), SwatDB::equalityOperator($instance_id), $this->app->db->quote($instance_id, 'integer'), $this->app->db->implodeArray($photo_ids, 'integer'));
        $row = SwatDB::queryRow($this->app->db, $sql);
        return array('max_latitude' => $row->max_latitude, 'min_latitude' => $row->min_latitude, 'max_longitude' => $row->max_longitude, 'min_longitude' => $row->min_longitude);
    }
Пример #26
0
    protected function getPhotos()
    {
        $item_list = $this->getItemList('integer');
        $instance_id = $this->app->getInstanceId();
        $sql = sprintf('select PinholePhoto.* from PinholePhoto
				inner join ImageSet on PinholePhoto.image_set = ImageSet.id
				where ImageSet.instance %s %s', SwatDB::equalityOperator($instance_id), $this->app->db->quote($instance_id, 'integer'));
        // note the only page with an extended-selection that accesses this
        // is the pending photos page - so enforce status here.
        if ($this->extended_selected) {
            $sql .= sprintf(' and PinholePhoto.status = %s', $this->app->db->quote(PinholePhoto::STATUS_PENDING, 'integer'));
        } else {
            $sql .= sprintf(' and PinholePhoto.id in (%s)', $item_list);
        }
        $wrapper_class = SwatDBClassMap::get('PinholePhotoWrapper');
        return SwatDB::query($this->app->db, $sql, $wrapper_class);
    }
Пример #27
0
    protected function getPhotographers()
    {
        if ($this->id === null || $this->comment->photographer !== null) {
            $photographer_id = $this->comment->photographer === null ? 0 : $this->comment->photographer->id;
            $instance_id = $this->app->getInstanceId();
            $sql = sprintf('select * from PinholePhotographer
				where instance %s %s and (status = %s or id = %s)
				order by fullname', SwatDB::equalityOperator($instance_id), $this->app->db->quote($instance_id, 'integer'), $this->app->db->quote(PinholePhotographer::STATUS_ENABLED, 'integer'), $this->app->db->quote($photographer_id, 'integer'));
            $rs = SwatDB::query($this->app->db, $sql);
            $photographers = array();
            foreach ($rs as $photographer) {
                $photographers[$photographer->id] = $photographer->fullname;
            }
        } else {
            return array();
        }
    }
    protected function getInterests()
    {
        if ($this->interests === null) {
            $this->interests = array();
            if ($this->app->hasModule('SiteDatabaseModule')) {
                $sql = 'select id, title, shortname
					from MailingListInterest
					where visible = %s and instance %s %s
					order by displayorder';
                $sql = sprintf($sql, $this->app->db->quote(true, 'boolean'), SwatDB::equalityOperator($this->app->getInstanceId()), $this->app->db->quote($this->app->getInstanceId(), 'integer'));
                $rs = SwatDB::query($this->app->db, $sql, null, array('integer', 'text'));
                while ($row = $rs->fetchRow(MDB2_FETCHMODE_OBJECT)) {
                    $this->interests[$row->shortname] = $row->title;
                }
            }
        }
        return $this->interests;
    }
Пример #29
0
    /**
     * Gets information about image files attached to a post
     *
     * @param integer $post_id the id of the post.
     * @param string $form_unique_id the id of form for use when the post has
     *                                not yet been saved.
     *
     * @return array a structure containing file info.
     */
    protected function getImages($post_id, $form_unique_id)
    {
        $instance_id = $this->app->getInstanceId();
        if ($this->app->getInstance() === null) {
            $path = '../../files';
        } else {
            $path = '../../files/' . $this->app->getInstance()->shortname;
        }
        $file_sql = sprintf('select * from BlorgFile
			where post %s %s and form_unique_id %s %s
			order by id', SwatDB::equalityOperator($post_id), $this->app->db->quote($post_id, 'integer'), SwatDB::equalityOperator($form_unique_id), $this->app->db->quote($form_unique_id, 'text'));
        $files = SwatDB::query($this->app->db, $file_sql, SwatDBClassMap::get('BlorgFileWrapper'));
        if (count($files) > 0) {
            // efficiently load images
            $image_sql = 'select * from Image where id in (%s)';
            $images = $files->loadAllSubDataObjects('image', $this->app->db, $image_sql, SwatDBClassMap::get('SiteImageWrapper'));
            if (count($images) > 0) {
                // efficiently load image sets
                $image_set_sql = 'select * from ImageSet where id in (%s)';
                $image_sets = $images->loadAllSubDataObjects('image_set', $this->app->db, $image_set_sql, SwatDBClassMap::get('SiteImageSetWrapper'));
            }
        }
        // build response struct
        $response = array();
        foreach ($files as $file) {
            if ($file->image instanceof SiteImage) {
                $utc = clone $file->createdate;
                $utc->toUTC();
                $local = clone $utc;
                $local->convertTZ($this->app->default_time_zone);
                $local = $local->formatLikeIntl('yyyy-MM-dd\'T\'hh:mm:ss');
                $utc = $utc->formatLikeIntl('yyyy-MM-dd\'T\'hh:mm:ss');
                $info = array('id' => $file->id, 'filename' => $file->filename, 'filepath' => $path . $file->filename, 'filesize' => $file->filesize, 'uri' => $file->getRelativeUri(), 'mime_type' => $file->mime_type, 'visible' => $file->visible, 'createdate_utc' => $utc, 'createdate_local' => $local, 'description' => $file->getDescription(), 'images' => array());
                $image = $file->image;
                $images = array();
                foreach ($image->image_set->dimensions as $dimension) {
                    $images[$dimension->shortname] = array('title' => $dimension->title, 'uri' => $image->getUri($dimension->shortname), 'width' => $image->getWidth($dimension->shortname), 'height' => $image->getHeight($dimension->shortname));
                }
                $info['images'] = $images;
                $response[] = $info;
            }
        }
        return $response;
    }
Пример #30
0
    /**
     * Loads a meta-data data-object by its shortname
     *
     * An instance is required to load this object by shortname since meta-data
     * shortnames are not required to be unique across site instances.
     *
     * @param string $shortname the shortname of the meta-data data-object to
     *                           load.
     * @param SiteInstance $instance the site instance of the meta-data
     *                                   data-object to load.
     *
     * @return boolean true if this meta-data data-object was loaded and false
     *                  if it could not be loaded.
     */
    public function loadByShortname($shortname, SiteInstance $instance = null)
    {
        $this->instance = $instance;
        $instance_id = $this->instance === null ? null : $this->instance->id;
        $row = null;
        $loaded = false;
        if ($this->table !== null) {
            $sql = sprintf('select * from %s where shortname = %s
				and instance %s %s', $this->table, $this->db->quote($shortname, 'text'), SwatDB::equalityOperator($instance_id), $this->db->quote($instance_id, 'integer'));
            $rs = SwatDB::query($this->db, $sql, null);
            $row = $rs->fetchRow(MDB2_FETCHMODE_ASSOC);
        }
        if ($row !== null) {
            $this->initFromRow($row);
            $this->generatePropertyHashes();
            $loaded = true;
        }
        return $loaded;
    }