示例#1
0
文件: Index.php 项目: nburka/blorg
    protected function getCommentCount()
    {
        $sql = 'select count(1) from BlorgComment
			left outer join BlorgAuthor on BlorgComment.author = BlorgAuthor.id
			where ' . $this->getWhereClause();
        return SwatDB::queryOne($this->app->db, $sql);
    }
示例#2
0
    protected function getCommentCount()
    {
        $sql = 'select count(1) from PinholeComment
			left outer join PinholePhotographer on PinholeComment.photographer = PinholePhotographer.id
			where ' . $this->getWhereClause();
        return SwatDB::queryOne($this->app->db, $sql);
    }
示例#3
0
 protected function processInternal()
 {
     parent::processInternal();
     $pager = $this->ui->getWidget('pager');
     $pager->total_records = SwatDB::queryOne($this->app->db, sprintf('select count(id) from Newsletter where %s', $this->getWhereClause()));
     $pager->process();
 }
示例#4
0
    public function hasAttested(CMEFrontMatter $front_matter)
    {
        $this->checkDB();
        $sql = sprintf('select count(1) from AccountAttestedCMEFrontMatter
			where account = %s and front_matter = %s', $this->db->quote($this->id, 'integer'), $this->db->quote($front_matter->id, 'integer'));
        return SwatDB::queryOne($this->db, $sql) > 0;
    }
示例#5
0
文件: BlorgTag.php 项目: nburka/blorg
    /**
     * Gets the number of visible posts this tag applies to
     *
     * This is more efficient than getting the set of posts and counting the
     * set. Use this method if you don't need the actual post objects.
     *
     * @return integer the number of posts this tag applies to.
     */
    public function getVisiblePostCount()
    {
        $sql = 'select count(id) from BlorgPost
			inner join BlorgPostTagBinding on id = post
			where tag = %s and BlorgPost.enabled = %s';
        return SwatDB::queryOne($this->db, sprintf($sql, $this->db->quote($this->id, 'integer'), $this->db->quote(true, 'boolean')));
    }
示例#6
0
    protected function initStartDate()
    {
        $oldest_date_string = SwatDB::queryOne($this->app->db, 'select min(complete_date) from InquisitionResponse
			where complete_date is not null
				and inquisition in (select evaluation from AccountCMEProgress)');
        $this->start_date = new SwatDate($oldest_date_string);
        $this->start_date->setTimezone($this->app->default_time_zone);
    }
示例#7
0
文件: Edit.php 项目: nburka/blorgy
    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;
    }
示例#8
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';
 }
示例#9
0
    protected function initInquisition()
    {
        parent::initInquisition();
        if (!$this->inquisition instanceof InquisitionInquisition) {
            // if we got here from the question index, load the inquisition
            // from the binding as we only have one inquisition per question
            $sql = sprintf('select inquisition from InquisitionInquisitionQuestionBinding
				where question = %s', $this->app->db->quote($this->question->id));
            $inquisition_id = SwatDB::queryOne($this->app->db, $sql);
            $this->inquisition = $this->loadInquisition($inquisition_id);
        }
    }
示例#10
0
文件: Delete.php 项目: nburka/blorgy
    protected function processDBData()
    {
        AdminDBDelete::processDBData();
        $instance_id = $this->app->getInstanceId();
        $sql = sprintf('select parent from Article
			where id = %s and instance %s %s', $this->app->db->quote($this->getFirstItem(), 'integer'), SwatDB::equalityOperator($instance_id), $this->app->db->quote($instance_id, 'integer'));
        $this->parent_id = SwatDB::queryOne($this->app->db, $sql);
        $item_list = $this->getItemList('integer');
        $sql = sprintf('delete from Article
			where id in (%s) and instance %s %s', $item_list, SwatDB::equalityOperator($instance_id), $this->app->db->quote($instance_id, 'integer'));
        $num = SwatDB::exec($this->app->db, $sql);
        $message = new SwatMessage(sprintf(Site::ngettext('One article has been deleted.', '%s articles have been deleted.', $num), SwatString::numberFormat($num)));
        $this->app->messages->add($message);
    }
    public static function getDefaultList(SiteApplication $app, SiteInstance $instance = null)
    {
        $default_list = $app->config->mail_chimp->default_list;
        if ($app->hasModule('SiteMultipleInstanceModule') && $app->getInstance() === null) {
            if ($instance === null) {
                throw new DeliveranceException('Instance must be set.');
            }
            $sql = 'select value from InstanceConfigSetting
				where name = %s and instance = %s';
            $sql = sprintf($sql, $app->db->quote('mail_chimp.default_list', 'text'), $app->db->quote($instance->id, 'integer'));
            $default_list = SwatDB::queryOne($app->db, $sql);
        }
        return $default_list;
    }
示例#12
0
文件: Index.php 项目: nburka/blorg
    protected function getTableModel(SwatView $view)
    {
        $sql = sprintf('select count(id) from BlorgTag where %s', $this->getWhereClause());
        $pager = $this->ui->getWidget('pager');
        $pager->total_records = SwatDB::queryOne($this->app->db, $sql);
        $sql = sprintf('select id, title, shortname
			from BlorgTag
			where %s
			order by %s', $this->getWhereClause(), $this->getOrderByClause($view, 'title'));
        $tags = SwatDB::query($this->app->db, $sql, 'BlorgTagWrapper');
        if (count($tags) > 0) {
            $this->ui->getWidget('results_frame')->visible = true;
            $this->ui->getWidget('results_message')->content = $pager->getResultsMessage(Blorg::_('result'), Blorg::_('results'));
        }
        return $tags;
    }
示例#13
0
    protected function loadData()
    {
        $instance_id = $this->app->getInstanceId();
        if ($instance_id === null) {
            $where_clause = '1 = 1';
        } else {
            $where_clause = sprintf('instance %s %s', SwatDB::equalityOperator($instance_id), $this->app->db->quote($instance_id, 'integer'));
        }
        $order_widget = $this->ui->getWidget('order');
        $sql = sprintf('select * from BlorgAuthor where %s
			order by displayorder, name', $where_clause);
        $authors = SwatDB::query($this->app->db, $sql, SwatDBClassMap::get('BlorgAuthorWrapper'));
        foreach ($authors as $author) {
            $order_widget->addOption($author->id, $author->name);
        }
        $sql = 'select sum(displayorder) from BlorgAuthor where ' . $where_clause;
        $sum = SwatDB::queryOne($this->app->db, $sql, 'integer');
        $options_list = $this->ui->getWidget('options');
        $options_list->value = $sum == 0 ? 'auto' : 'custom';
    }
示例#14
0
    /**
     * Logs the current session into a {@link SiteAccount}
     *
     * @param string $email the email address of the account to login.
     * @param string $password the password of the account to login.
     *
     * @return boolean true if the session was successfully logged in and false
     *                       if the passphrase is incorrect.
     */
    public function login($passphrase)
    {
        // TODO: should passphrase be salted?
        $passphrase = md5($passphrase);
        $instance = $this->getInstanceId();
        $sql = sprintf('select instance from InstanceConfigSetting
			where instance %s %s and name = %s and value = %s', SwatDB::equalityOperator($instance), $this->app->db->quote($instance, 'integer'), $this->app->db->quote('pinhole.passphrase', 'text'), $this->app->db->quote($passphrase, 'text'));
        $id = SwatDB::queryOne($this->app->db, $sql);
        if ($id !== null) {
            $this->activate();
            if (!isset($this->authenticated_instances) || !$this->authenticated_instances instanceof ArrayObject) {
                $this->authenticated_instances = new ArrayObject();
            }
            $this->authenticated_instances[$this->getInstanceId()] = true;
            $logged_in = true;
        } else {
            $this->logout();
            $logged_in = false;
        }
        return $logged_in;
    }
    protected function initLastSegments()
    {
        for ($rating = 1; $rating <= 5; $rating++) {
            $use_random_start = true;
            if ($this->incremental === true) {
                $sql = sprintf('select value
					from MailingListMemberUpdaterCache
					where rating = %s and field = %s
					order by id desc
					limit 1', $this->db->quote($rating, 'integer'), $this->db->quote($this->field, 'text'));
                $segment = SwatDB::queryOne($this->db, $sql);
                if ($segment !== null) {
                    $use_random_start = false;
                    $this->last_segment[$rating] = $this->getNumericSegment($segment);
                }
            }
            // random the starting last segment, so as to not bias when running
            // incremental updates. is rand() good enough for this?
            if ($use_random_start === true) {
                $this->last_segment[$rating] = rand(0, $this->number_of_segments);
            }
        }
    }
示例#16
0
 public function getPostCount()
 {
     $count = false;
     if ($this->memcache !== null) {
         $key = $this->getPostCountCacheKey();
         $count = $this->memcache->getNs('posts', $key);
     }
     if ($count === false) {
         $sql = 'select count(1) from BlorgPost';
         $sql .= $this->getWhereClause();
         $count = SwatDB::queryOne($this->db, $sql);
         if ($this->memcache !== null) {
             $this->memcache->setNs('posts', $key, $count);
         }
     }
     return $count;
 }
示例#17
0
 /**
  * Gets the number of photos this tag applies to
  *
  * This is more efficient than getting the set of photos and counting the
  * set. Use this method if you don't need the actual photo objects.
  *
  * @return integer the number of photos this tag applies to.
  *
  * @see PinholeAbstractTag::getPhotos()
  */
 public function getPhotoCount()
 {
     $sql = 'select count(id) from PinholePhoto';
     $join_clauses = implode(' ', $this->getJoinClauses());
     if ($join_clauses != '') {
         $sql .= ' ' . $join_clauses . ' ';
     }
     $where_clause = $this->getWhereClause();
     if ($where_clause != '') {
         $sql .= ' where ' . $where_clause;
     }
     return SwatDB::queryOne($this->db, $sql);
 }
示例#18
0
文件: Index.php 项目: nburka/blorg
    protected function getVisibleAuthorCount()
    {
        $instance_id = $this->app->getInstanceId();
        $sql = sprintf('select count(1) 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'));
        return SwatDB::queryOne($this->app->db, $sql);
    }
    protected function initComments($page)
    {
        // get comments for this page
        $this->comments = false;
        $key = $this->getCommentsCacheKey();
        $this->comments = $this->app->getCacheRecordset('photos', SwatDBClassMap::get('PinholeCommentWrapper'), $key);
        if ($this->comments === false) {
            $sql = sprintf('select PinholeComment.* from
				PinholeComment %s where %s
				order by PinholeComment.createdate desc', $this->getJoinClause(), $this->getWhereClause());
            $offset = ($page - 1) * $this->getPageSize();
            $this->app->db->setLimit($this->getPageSize(), $offset);
            $wrapper = SwatDBClassMap::get('PinholeCommentWrapper');
            $this->comments = SwatDB::query($this->app->db, $sql, $wrapper);
            // efficiently load photos
            $photo_wrapper = SwatDBClassMap::get('PinholePhotoWrapper');
            $photo_sql = 'select * from PinholePhoto where id in (%s)';
            $this->comments->loadAllSubDataObjects('photo', $this->app->db, $photo_sql, $photo_wrapper);
            // efficiently load photographers
            $photographer_wrapper = SwatDBClassMap::get('PinholePhotographerWrapper');
            $photographer_sql = 'select id, fullname, shortname, email, visible
				from PinholePhotographer
				where id in (%s)';
            $this->comments->loadAllSubDataObjects('photographer', $this->app->db, $photographer_sql, $photographer_wrapper);
            $this->app->addCacheRecordset($this->comments, $key, 'photos');
        } else {
            $this->comments->setDatabase($this->app->db);
        }
        // if we're not on the first page and there are no comments, 404
        if ($page > 1 && count($this->comments) === 0) {
            throw new SiteNotFoundException('Page not found.');
        }
        // get total number of comments
        $this->total_count = false;
        $total_key = $this->getTotalCountCacheKey();
        $this->total_count = $this->app->getCacheValue('photos', $total_key);
        if ($this->total_count === false) {
            $sql = sprintf('select count(1) from PinholeComment %s where %s', $this->getJoinClause(), $this->getWhereClause());
            $this->total_count = SwatDB::queryOne($this->app->db, $sql);
            $this->app->addCacheValue($this->total_count, 'photos', $total_key);
        }
    }
    protected function saveEarnedCredits(CMEAccount $account, CMEFrontMatter $front_matter)
    {
        $wrapper = SwatDBClassMap::get('CMEAccountEarnedCMECreditWrapper');
        $class_name = SwatDBClassMap::get('CMEAccountEarnedCMECredit');
        $earned_credits = new $wrapper();
        $earned_date = new SwatDate();
        $earned_date->toUTC();
        foreach ($front_matter->credits as $credit) {
            if ($credit->isEarned($account)) {
                // check for existing earned credit before saving
                $sql = sprintf('select count(1)
					from AccountEarnedCMECredit
					where credit = %s and account = %s', $this->app->db->quote($credit->id, 'integer'), $this->app->db->quote($account->id, 'integer'));
                if (SwatDB::queryOne($this->app->db, $sql) == 0) {
                    $earned_credit = new $class_name();
                    $earned_credit->account = $account->id;
                    $earned_credit->credit = $credit->id;
                    $earned_credit->earned_date = $now;
                    $earned_credits->add($earned_credit);
                }
            }
        }
        $earned_credits->setDatabase($this->app->db);
        $earned_credits->save();
    }
示例#21
0
    protected function getCommentsTableModel(SwatTableView $view)
    {
        $sql = sprintf('select count(id) from BlorgComment
			where post = %s and spam = %s', $this->app->db->quote($this->post->id, 'integer'), $this->app->db->quote(false, 'boolean'));
        $pager = $this->ui->getWidget('pager');
        $pager->total_records = SwatDB::queryOne($this->app->db, $sql);
        $sql = sprintf('select id, fullname, author, bodytext, createdate, status
			from BlorgComment
			where post = %s and spam = %s
			order by %s', $this->app->db->quote($this->post->id, 'integer'), $this->app->db->quote(false, 'boolean'), $this->getOrderByClause($view, 'createdate'));
        $this->app->db->setLimit($pager->page_size, $pager->current_record);
        $comments = SwatDB::query($this->app->db, $sql, SwatDBClassMap::get('BlorgCommentWrapper'));
        $store = new SwatTableStore();
        foreach ($comments as $comment) {
            $ds = new SwatDetailsStore($comment);
            //TODO: distinguish authors somehow
            if ($comment->author !== null) {
                $ds->fullname = $comment->author->name;
            }
            $ds->bodytext = SwatString::condense(SwatString::ellipsizeRight($comment->bodytext, 500));
            $ds->post_id = $this->post->id;
            $store->add($ds);
        }
        return $store;
    }
示例#22
0
    protected function getTableModel(SwatView $view)
    {
        $sql = sprintf('select count(PinholePhoto.id) from PinholePhoto
			inner join ImageSet on PinholePhoto.image_set = ImageSet.id
			where %s', $this->getWhereClause());
        $pager = $this->ui->getWidget('pager');
        $pager->total_records = SwatDB::queryOne($this->app->db, $sql);
        $sql = sprintf('select PinholePhoto.* from PinholePhoto
			inner join ImageSet on PinholePhoto.image_set = ImageSet.id
			where %s
			order by PinholePhoto.upload_date desc, PinholePhoto.id', $this->getWhereClause());
        $this->app->db->setLimit($pager->page_size, $pager->current_record);
        $wrapper_class = SwatDBClassMap::get('PinholePhotoWrapper');
        $photos = SwatDB::query($this->app->db, $sql, $wrapper_class);
        $tile_view = $this->ui->getWidget('index_view');
        $tile_view->check_all_unit = Pinhole::_('Pending Photos');
        $store = new SwatTableStore();
        if (count($photos) > 0) {
            $tile_view->check_all_extended_count = $pager->total_records;
            $tile_view->check_all_visible_count = count($photos);
            foreach ($photos as $photo) {
                $ds = new SwatDetailsStore();
                $ds->photo = $photo;
                $ds->class_name = $this->getTileClasses($photo);
                $store->add($ds);
            }
        }
        return $store;
    }
    protected function getTagStats()
    {
        if (isset($this->app->memcache)) {
            $cache_key = 'PinholeStatisticsGadget.tag_stats';
            $value = $this->app->memcache->getNs('photos', $cache_key);
            if ($value !== false) {
                return $value;
            }
        }
        $sql = "select count(distinct PinholePhotoTagBinding.tag) as tag_count\n\t\t\tfrom PinholePhotoTagBinding\n\t\t\tinner join PinholePhoto on\n\t\t\t\tPinholePhoto.id = PinholePhotoTagBinding.photo\n\t\t\tinner join ImageSet on PinholePhoto.image_set = ImageSet.id\n\t\t\twhere ImageSet.instance %s %s and PinholePhoto.status = %s";
        $sql = sprintf($sql, SwatDB::equalityOperator($this->app->getInstanceId()), $this->app->db->quote($this->app->getInstanceId(), 'integer'), $this->app->db->quote(PinholePhoto::STATUS_PUBLISHED, 'integer'));
        $tag_count = SwatDB::queryOne($this->app->db, $sql);
        $sql = "select count(PinholePhotoTagBinding.photo) as tag_count,\n\t\t\t\tPinholeTag.id\n\t\t\tfrom PinholePhotoTagBinding\n\t\t\tinner join PinholeTag on PinholePhotoTagBinding.tag = PinholeTag.id\n\t\t\tinner join PinholePhoto on\n\t\t\t\tPinholePhoto.id = PinholePhotoTagBinding.photo\n\t\t\tinner join ImageSet on PinholePhoto.image_set = ImageSet.id\n\t\t\twhere ImageSet.instance %s %s and PinholePhoto.status = %s\n\t\t\t%s\n\t\t\tgroup by PinholeTag.id\n\t\t\torder by tag_count desc";
        if (!$this->app->session->isLoggedIn()) {
            $private_where_clause = sprintf('and PinholePhoto.private = %s', $this->app->db->quote(false, 'boolean'));
        } else {
            $private_where_clause = '';
        }
        $sql = sprintf($sql, SwatDB::equalityOperator($this->app->getInstanceId()), $this->app->db->quote($this->app->getInstanceId(), 'integer'), $this->app->db->quote(PinholePhoto::STATUS_PUBLISHED, 'integer'), $private_where_clause);
        $popular_tag_info = SwatDB::queryRow($this->app->db, $sql);
        if ($popular_tag_info === null) {
            $stats = new StdClass();
            $stats->tag_count = 0;
            return $stats;
        } else {
            $sql = sprintf('select title, name from PinholeTag
				where PinholeTag.id = %s', $this->app->db->quote($popular_tag_info->id, 'integer'));
            $popular_tag = SwatDB::queryRow($this->app->db, $sql);
            $stats = new StdClass();
            $stats->tag_count = $tag_count;
            $stats->popular_tag_title = $popular_tag->title;
            $stats->popular_tag_name = $popular_tag->name;
            $stats->popular_tag_count = $popular_tag_info->tag_count;
            if (isset($this->app->memcache)) {
                $this->app->memcache->setNs('photos', $cache_key, $stats);
            }
        }
        return $stats;
    }
示例#24
0
    protected function getAllPendingPhotosCount()
    {
        $instance_id = $this->app->getInstanceId();
        $sql = sprintf('select count(PinholePhoto.id) from PinholePhoto
			inner join ImageSet on PinholePhoto.image_set = ImageSet.id
			where PinholePhoto.status = %s and ImageSet.instance %s %s', $this->app->db->quote(PinholePhoto::STATUS_PENDING, 'integer'), SwatDB::equalityOperator($instance_id), $this->app->db->quote($instance_id, 'integer'));
        return SwatDB::queryOne($this->app->db, $sql);
    }
示例#25
0
    protected function getTableModel(SwatView $view)
    {
        $this->searchPhotos();
        $sql = sprintf('select count(PinholePhoto.id)
			from PinholePhoto
			inner join ImageSet on PinholePhoto.image_set = ImageSet.id
			%s where %s', $this->join_clause, $this->getWhereClause());
        $pager = $this->ui->getWidget('pager');
        $pager->total_records = SwatDB::queryOne($this->app->db, $sql);
        $sql = sprintf('select PinholePhoto.* from PinholePhoto
			inner join ImageSet on PinholePhoto.image_set = ImageSet.id
			%s where %s order by %s', $this->join_clause, $this->getWhereClause(), $this->order_by_clause);
        $this->app->db->setLimit($pager->page_size, $pager->current_record);
        $wrapper_class = SwatDBClassMap::get('PinholePhotoWrapper');
        $photos = SwatDB::query($this->app->db, $sql, $wrapper_class);
        $store = new SwatTableStore();
        if (count($photos) != 0) {
            $this->ui->getWidget('results_message')->content = $pager->getResultsMessage(Pinhole::_('result'), Pinhole::_('results'));
            foreach ($photos as $photo) {
                $ds = new SwatDetailsStore();
                $ds->photo = $photo;
                $ds->class_name = $this->getTileClasses($photo);
                $store->add($ds);
            }
        }
        return $store;
    }
示例#26
0
    protected function getQuarterEarnedCredits(CMEProvider $provider, $year, $quarter)
    {
        $start_month = ($quarter - 1) * 3 + 1;
        $start_date = new SwatDate();
        $start_date->setTime(0, 0, 0);
        $start_date->setDate($year, $start_month, 1);
        $start_date->setTZ($this->default_time_zone);
        $end_date = clone $start_date;
        $end_date->addMonths(3);
        $sql = sprintf('select count(1)
			from AccountCMEProgressCreditBinding
			inner join AccountCMEProgress on
				AccountCMEProgressCreditBinding.progress = AccountCMEProgress.id
			inner join AccountEarnedCMECredit on
				AccountEarnedCMECredit.account = AccountCMEProgress.account
				and AccountCMEProgressCreditBinding.credit =
					AccountEarnedCMECredit.credit
			inner join CMECredit on
				CMECredit.id = AccountEarnedCMECredit.credit
			inner join Account on AccountCMEProgress.account = Account.id
			where CMECredit.front_matter in (
					select CMEFrontMatterProviderBinding.front_matter
					from CMEFrontMatterProviderBinding
					where CMEFrontMatterProviderBinding.provider = %s
				)
			and convertTZ(earned_date, %s) >= %s
			and convertTZ(earned_date, %s) < %s
			and Account.delete_date is null', $this->db->quote($provider->id, 'integer'), $this->db->quote($this->config->date->time_zone, 'text'), $this->db->quote($start_date->getDate(), 'date'), $this->db->quote($this->config->date->time_zone, 'text'), $this->db->quote($end_date->getDate(), 'date'));
        return SwatDB::queryOne($this->db, $sql);
    }
示例#27
0
    /**
     * Gets a count of tags not in this list that also apply to the photos
     * of this list
     *
     * @return integer Number of sub tags
     *
     * @see PinholePhoto::getSubTags()
     */
    public function getSubTagCount()
    {
        $args = func_get_args();
        $cache_key = $this->getCacheKey(__FUNCTION__, $args);
        $count = $this->app->getCacheValue($cache_key, 'photos');
        if ($count === false) {
            $sql = sprintf('select count(PinholeTag.id)
				from PinholeTag where %s', $this->getSubTagWhereClause());
            $count = SwatDB::queryOne($this->db, $sql);
            $this->app->addCacheValue($count, $cache_key, 'photos');
        }
        return $count - count($this);
    }
示例#28
0
    public function getVisibleCommentCount()
    {
        if ($this->hasInternalValue('visible_comment_count') && $this->getInternalValue('visible_comment_count') !== null) {
            $comment_count = $this->getInternalValue('visible_comment_count');
        } else {
            $this->checkDB();
            $sql = sprintf('select visible_comment_count
				from BlorgPostVisibleCommentCountView
				where post = %s', $this->db->quote($this->id, 'integer'));
            $comment_count = SwatDB::queryOne($this->db, $sql);
        }
        return $comment_count;
    }
示例#29
0
    protected function initComments($page)
    {
        // get comments for this page
        $this->comments = false;
        if (isset($this->app->memcache)) {
            $key = $this->getCommentsCacheKey();
            $this->comments = $this->app->memcache->getNs('posts', $key);
            /*
             * Note: The limit of comments per page is somewhat important here.
             * In extreme cases, we could run over the 1M size limit for cached
             * values. This would occur when every comment is close to the
             * maximum size in bodytext (8K) and the associated posts also have
             * a very large bodytext (about 8K each). In these rare cases,
             * caching will fail.
             */
        }
        if ($this->comments === false) {
            $sql = sprintf('select BlorgComment.* from BlorgComment %s where %s
				order by BlorgComment.createdate desc', $this->getJoinClause(), $this->getWhereClause());
            $offset = ($page - 1) * $this->getPageSize();
            $this->app->db->setLimit($this->getPageSize(), $offset);
            $wrapper = SwatDBClassMap::get('BlorgCommentWrapper');
            $this->comments = SwatDB::query($this->app->db, $sql, $wrapper);
            // efficiently load posts
            $post_wrapper = SwatDBClassMap::get('BlorgPostWrapper');
            $post_sql = 'select id, title, shortname, bodytext, publish_date
				from BlorgPost
				where id in (%s)';
            $this->comments->loadAllSubDataObjects('post', $this->app->db, $post_sql, $post_wrapper);
            // efficiently load authors
            $author_wrapper = SwatDBClassMap::get('BlorgAuthorWrapper');
            $author_sql = 'select id, name, shortname, email, visible
				from BlorgAuthor
				where id in (%s)';
            $this->comments->loadAllSubDataObjects('author', $this->app->db, $author_sql, $author_wrapper);
            if (isset($this->app->memcache)) {
                $this->app->memcache->setNs('posts', $key, $this->comments);
            }
        } else {
            $this->comments->setDatabase($this->app->db);
        }
        // if we're not on the first page and there are no comments, 404
        if ($page > 1 && count($this->comments) === 0) {
            throw new SiteNotFoundException('Page not found.');
        }
        // get total number of comments
        $this->total_count = false;
        if (isset($this->app->memcache)) {
            $total_key = $this->getTotalCountCacheKey();
            $this->total_count = $this->app->memcache->getNs('posts', $total_key);
        }
        if ($this->total_count === false) {
            $sql = sprintf('select count(1) from BlorgComment %s where %s', $this->getJoinClause(), $this->getWhereClause());
            $this->total_count = SwatDB::queryOne($this->app->db, $sql);
            if (isset($this->app->memcache)) {
                $this->app->memcache->setNs('posts', $total_key, $this->total_count);
            }
        }
    }
 protected function displayQueue()
 {
     $sql = 'select count(id) from MailingListSubscribeQueue';
     $queued_updates = SwatDB::queryOne($this->db, $sql);
     if ($queued_updates > 0) {
         $this->debug(sprintf("\n%s Member Updates Queued. Remember to run the updater.\n", SwatString::numberFormat($queued_updates)), true);
     }
 }