当前位置: 首页>>代码示例>>PHP>>正文


PHP SwatDB::query方法代码示例

本文整理汇总了PHP中SwatDB::query方法的典型用法代码示例。如果您正苦于以下问题:PHP SwatDB::query方法的具体用法?PHP SwatDB::query怎么用?PHP SwatDB::query使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在SwatDB的用法示例。


在下文中一共展示了SwatDB::query方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: insertTag

    /**
     * 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;
    }
开发者ID:gauthierm,项目名称:pinhole,代码行数:35,代码来源:PinholePhotoTagEntry.php

示例2: getComments

    protected function getComments($limit = null, $offset = null)
    {
        $sql = sprintf('select BlorgComment.* from BlorgComment
			left outer join BlorgAuthor on BlorgComment.author = BlorgAuthor.id
			where %s
			order by createdate desc', $this->getWhereClause());
        $this->app->db->setLimit($limit, $offset);
        $wrapper = SwatDBClassMap::get('BlorgCommentWrapper');
        $comments = SwatDB::query($this->app->db, $sql, $wrapper);
        // efficiently load posts for all comments
        $instance_id = $this->app->getInstanceId();
        $post_sql = sprintf('select id, title, bodytext
			from BlorgPost
			where instance %s %s and id in (%%s)', SwatDB::equalityOperator($instance_id), $this->app->db->quote($instance_id, 'integer'));
        $post_wrapper = SwatDBClassMap::get('BlorgPostWrapper');
        $comments->loadAllSubDataObjects('post', $this->app->db, $post_sql, $post_wrapper);
        // efficiently load authors for all comments
        $instance_id = $this->app->getInstanceId();
        $author_sql = sprintf('select id, name
			from BlorgAuthor
			where instance %s %s and id in (%%s)', SwatDB::equalityOperator($instance_id), $this->app->db->quote($instance_id, 'integer'));
        $author_wrapper = SwatDBClassMap::get('BlorgAuthorWrapper');
        $comments->loadAllSubDataObjects('author', $this->app->db, $author_sql, $author_wrapper);
        return $comments;
    }
开发者ID:nburka,项目名称:blorg,代码行数:25,代码来源:Index.php

示例3: getComments

    protected function getComments($limit = null, $offset = null)
    {
        $sql = sprintf('select PinholeComment.* from PinholeComment
			left outer join PinholePhotographer on PinholeComment.photographer = PinholePhotographer.id
			where %s
			order by createdate desc', $this->getWhereClause());
        $this->app->db->setLimit($limit, $offset);
        $wrapper = SwatDBClassMap::get('PinholeCommentWrapper');
        $comments = SwatDB::query($this->app->db, $sql, $wrapper);
        // efficiently load photos for all comments
        $instance_id = $this->app->getInstanceId();
        $photo_sql = sprintf('select PinholePhoto.*	from PinholePhoto
			inner join ImageSet on ImageSet.id = PinholePhoto.image_set
			where ImageSet.instance %s %s and PinholePhoto.id in (%%s)', SwatDB::equalityOperator($instance_id), $this->app->db->quote($instance_id, 'integer'));
        $photo_wrapper = SwatDBClassMap::get('PinholePhotoWrapper');
        $comments->loadAllSubDataObjects('photo', $this->app->db, $photo_sql, $photo_wrapper);
        // efficiently load photographers for all comments
        $instance_id = $this->app->getInstanceId();
        $photographer_sql = sprintf('select id, fullname
			from PinholePhotographer
			where instance %s %s and id in (%%s)', SwatDB::equalityOperator($instance_id), $this->app->db->quote($instance_id, 'integer'));
        $photographer_wrapper = SwatDBClassMap::get('PinholePhotographerWrapper');
        $comments->loadAllSubDataObjects('photographer', $this->app->db, $photographer_sql, $photographer_wrapper);
        return $comments;
    }
开发者ID:gauthierm,项目名称:pinhole,代码行数:25,代码来源:Index.php

示例4: loadProviders

    public function loadProviders($read_only = true)
    {
        $providers_wrapper_class = SwatDBClassMap::get('CMEProviderWrapper');
        $providers_wrapper = new $providers_wrapper_class();
        $providers_wrapper->setOptions('read_only', $read_only);
        $providers = SwatDB::query($this->db, 'select * from CMEProvider', $providers_wrapper);
        $sql = sprintf('select CMEFrontMatterProviderBinding.front_matter,
				CMEFrontMatterProviderBinding.provider
			from CMEFrontMatterProviderBinding
			inner join CMEProvider on
				CMEProvider.id = CMEFrontMatterProviderBinding.provider
			where CMEFrontMatterProviderBinding.front_matter in (%s)
			order by CMEFrontMatterProviderBinding.front_matter,
				CMEProvider.displayorder, CMEProvider.id', $this->db->implodeArray($this->getIndexes(), 'integer'));
        $rows = SwatDB::query($this->db, $sql);
        $front_matter_id = null;
        foreach ($rows as $row) {
            if ($row->front_matter !== $front_matter_id) {
                $front_matter_id = $row->front_matter;
                $front_matter = $this->getByIndex($row->front_matter);
                $front_matter->providers = new $providers_wrapper_class();
                $front_matter->providers->setOptions('read_only', $read_only);
            }
            $provider = $providers->getByIndex($row->provider);
            $front_matter->providers->add($provider);
        }
        return $providers;
    }
开发者ID:nrfredrickson,项目名称:Cme,代码行数:28,代码来源:CMEFrontMatterWrapper.php

示例5: getSegments

    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'));
    }
开发者ID:GervaisdeM,项目名称:deliverance,代码行数:7,代码来源:DeliveranceListCampaignSegmentCacheUpdater.php

示例6: buildInternal

    protected function buildInternal()
    {
        parent::buildInternal();
        $locale = SwatI18NLocale::get();
        $item_list = $this->getItemList('integer');
        $dep = new AdminListDependency();
        $dep->setTitle(CME::_('CME front matter'), CME::_('CME front matters'));
        $sql = sprintf('select CMEFrontMatter.id, sum(CMECredit.hours) as hours
			from CMEFrontMatter
			left outer join CMECredit
				on CMECredit.front_matter = CMEFrontMatter.id
			where CMEFrontMatter.id in (%s)
			group by CMEFrontMatter.id', $item_list);
        $rs = SwatDB::query($this->app->db, $sql);
        $class_name = SwatDBClassMap::get('CMEFrontMatter');
        foreach ($rs as $row) {
            $front_matter = new $class_name($row);
            $front_matter->setDatabase($this->app->db);
            $row->status_level = AdminDependency::DELETE;
            $row->parent = null;
            // not using ngettext because hours is a float
            $row->title = sprintf($row->hours == 1 ? CME::_('%s (1 hour)') : CME::_('%s (%s hours)'), $front_matter->getProviderTitleList(), $locale->formatNumber($row->hours));
            $dep->entries[] = new AdminDependencyEntry($row);
        }
        $message = $this->ui->getWidget('confirmation_message');
        $message->content = $dep->getMessage();
        $message->content_type = 'text/xml';
        if ($dep->getStatusLevelCount(AdminDependency::DELETE) === 0) {
            $this->switchToCancelButton();
        }
    }
开发者ID:nrfredrickson,项目名称:Cme,代码行数:31,代码来源:Delete.php

示例7: insertTag

    /**
     * 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;
    }
开发者ID:GervaisdeM,项目名称:blorg,代码行数:35,代码来源:BlorgTagEntry.php

示例8: getEarnedCredits

    /**
     * Gets earned CME credits to include in the quarterly report
     *
     * Credits are included if and only if:
     *
     * - the credit is earned
     * - the provider is the specified provider
     * - the earned date is within the quarter
     * - the account is not deleted
     *
     * @return array
     */
    protected function getEarnedCredits()
    {
        $sql = sprintf('select AccountEarnedCMECredit.* from AccountEarnedCMECredit
				inner join Account
					on AccountEarnedCMECredit.account = Account.id
				inner join CMECredit
					on AccountEarnedCMECredit.credit = CMECredit.id
				inner join CMEFrontMatter
					on CMECredit.front_matter = CMEFrontMatter.id
			where CMEFrontMatter.id 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->app->db->quote($this->provider->id, 'integer'), $this->app->db->quote($this->app->config->date->time_zone, 'text'), $this->app->db->quote($this->start_date->getDate(), 'date'), $this->app->db->quote($this->app->config->date->time_zone, 'text'), $this->app->db->quote($this->end_date->getDate(), 'date'));
        $earned_credits = SwatDB::query($this->app->db, $sql, SwatDBClassMap::get('CMEAccountEarnedCMECreditWrapper'));
        // efficiently load accounts
        $accounts = $this->loadAccounts($earned_credits);
        // load addresses
        $addresses = $this->loadAccountAddresses($accounts);
        // efficiently load credits
        $credits = $this->loadCredits($earned_credits);
        // sort earned credits (sorting is application specific)
        $earned_credits_array = $earned_credits->getArray();
        usort($earned_credits_array, array($this, 'compareEarnedCredit'));
        return $earned_credits_array;
    }
开发者ID:nrfredrickson,项目名称:Cme,代码行数:41,代码来源:CMEQuizReportGenerator.php

示例9: initSideBar

    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();
    }
开发者ID:nburka,项目名称:blorgy,代码行数:25,代码来源:BlorgyLayout.php

示例10: buildInternal

    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();
        }
    }
开发者ID:nburka,项目名称:blorg,代码行数:28,代码来源:Delete.php

示例11: getPhoto

    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;
    }
开发者ID:gauthierm,项目名称:pinhole,代码行数:25,代码来源:PinholePhotoLoaderPage.php

示例12: getTableModel

    /**
     * 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;
    }
开发者ID:gauthierm,项目名称:pinhole,代码行数:30,代码来源:Index.php

示例13: initReport

    protected function initReport()
    {
        $quarter = SiteApplication::initVar('quarter', null, SiteApplication::VAR_GET);
        if ($quarter === null || preg_match('/^2[0-9]{3}-0[1-4]$/', $quarter) === 0) {
            throw new AdminNotFoundException('Invalid quarter.');
        }
        list($year, $quarter) = explode('-', $quarter, 2);
        $start_month = (intval($quarter) - 1) * 3 + 1;
        $quarter = new SwatDate();
        $quarter->setTime(0, 0, 0);
        $quarter->setDate($year, $start_month, 1);
        $quarter->setTZ($this->app->default_time_zone);
        $quarter->toUTC();
        $type = SiteApplication::initVar('type', null, SiteApplication::VAR_GET);
        $provider = new CMEProvider();
        $provider->setDatabase($this->app->db);
        if (!$provider->loadByShortname($type)) {
            throw new AdminNotFoundException('Invalid CME provider.');
        }
        $sql = sprintf('select * from QuizReport
			where quarter = %s and provider = %s', $this->app->db->quote($quarter->getDate(), 'date'), $this->app->db->quote($provider->id, 'integer'));
        $this->report = SwatDB::query($this->app->db, $sql, SwatDBClassMap::get('CMEQuizReportWrapper'))->getFirst();
        if (!$this->report instanceof CMEQuizReport) {
            throw new AdminNotFoundException(sprintf('Report not found for quarter %s.', $quarter->getDate()));
        }
        $this->report->setFileBase('../../system/quiz-report-updater');
        if (!file_exists($this->report->getFilePath())) {
            throw new AdminNotFoundException(sprintf('Report file ‘%s’ not found', $this->report->getFilePath()));
        }
    }
开发者ID:nrfredrickson,项目名称:Cme,代码行数:30,代码来源:Download.php

示例14: load

    /**
     * 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;
    }
开发者ID:gauthierm,项目名称:pinhole,代码行数:36,代码来源:PinholeComment.php

示例15: initComments

    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);
            }
        }
    }
开发者ID:GervaisdeM,项目名称:blorg,代码行数:59,代码来源:BlorgCommentsAtomPage.php


注:本文中的SwatDB::query方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。