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


PHP MDB2_Driver_Common::implodeArray方法代码示例

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


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

示例1: loadPhotoTags

    /**
     * Efficiently loads tags for a set of photos
     *
     * @param PinholePhotoWrapper $photos the photos for which to efficiently load
     *                                 tags.
     */
    protected function loadPhotoTags(PinholePhotoWrapper $photos)
    {
        $instance_id = $this->app->getInstance() === null ? null : $this->app->getInstanceId();
        $wrapper = SwatDBClassMap::get('PinholeTagDataObjectWrapper');
        // get photo ids
        $photo_ids = array();
        foreach ($photos as $photo) {
            $photo_ids[] = $photo->id;
        }
        $photo_ids = $this->db->implodeArray($photo_ids, 'integer');
        // build SQL to select all tags
        $sql = sprintf('select PinholeTag.*, PinholePhotoTagBinding.photo
			from PinholeTag
				inner join PinholePhotoTagBinding on
					PinholeTag.id = PinholePhotoTagBinding.tag
			where photo in (%s) and PinholeTag.instance %s %s
			order by photo, createdate desc', $photo_ids, SwatDB::equalityOperator($instance_id), $this->db->quote($instance_id, 'integer'));
        // get all tags
        $tags = SwatDB::query($this->db, $sql, $wrapper);
        // assign tags to correct photos
        $current_photo_id = null;
        $current_recordset = null;
        foreach ($tags as $tag) {
            $photo_id = $tag->getInternalValue('photo');
            if ($photo_id !== $current_photo_id) {
                $current_photo_id = $photo_id;
                $current_recordset = new $wrapper();
                $photos[$photo_id]->tags = new $wrapper();
            }
            $photos[$photo_id]->tags->add($tag);
        }
    }
开发者ID:gauthierm,项目名称:pinhole,代码行数:38,代码来源:PinholeTagList.php

示例2: loadPostTags

    /**
     * Efficiently loads tags for a set of posts
     *
     * @param BlorgPostWrapper $posts the posts for which to efficiently load
     *                                 tags.
     */
    protected function loadPostTags(BlorgPostWrapper $posts)
    {
        $instance_id = $this->instance === null ? null : $this->instance->id;
        $wrapper = SwatDBClassMap::get('BlorgTagWrapper');
        // get post ids
        $post_ids = array();
        foreach ($posts as $post) {
            $post_ids[] = $post->id;
        }
        $post_ids = $this->db->implodeArray($post_ids, 'integer');
        // build SQL to select all tags
        $sql = sprintf('select BlorgTag.*, BlorgPostTagBinding.post
			from BlorgTag
				inner join BlorgPostTagBinding on
					BlorgTag.id = BlorgPostTagBinding.tag
			where post in (%s) and BlorgTag.instance %s %s
			order by post, createdate desc', $post_ids, SwatDB::equalityOperator($instance_id), $this->db->quote($instance_id, 'integer'));
        // get all tags
        $tags = SwatDB::query($this->db, $sql, $wrapper);
        // assign empty recordsets for all posts
        foreach ($posts as $post) {
            $recordset = new $wrapper();
            $post->setTags($recordset);
        }
        // assign tags to correct posts
        $current_post_id = null;
        $current_recordset = null;
        foreach ($tags as $tag) {
            $post_id = $tag->getInternalValue('post');
            if ($post_id !== $current_post_id) {
                $current_post_id = $post_id;
                $current_recordset = $posts[$post_id]->getTags();
            }
            $current_recordset->add($tag);
        }
    }
开发者ID:GervaisdeM,项目名称:blorg,代码行数:42,代码来源:BlorgPostLoader.php

示例3: commit

    /**
     * Commits keywords indexed by this indexer to the database index table
     *
     * If this indexer was created with the <code>$new</code> parameter then
     * the index is cleared for this indexer's document type before new
     * keywords are inserted. Otherwise, the new keywords are simply appended
     * to the existing index.
     */
    public function commit()
    {
        try {
            $this->db->beginTransaction();
            if ($this->new) {
                $this->clear();
                $this->new = false;
            }
            $indexed_ids = $this->db->implodeArray($this->clear_document_ids, 'integer');
            $delete_sql = sprintf('delete from NateGoSearchIndex
				where document_id in (%s) and document_type = %s', $indexed_ids, $this->db->quote($this->document_type, 'integer'));
            $result = $this->db->exec($delete_sql);
            if (MDB2::isError($result)) {
                throw new NateGoSearchDBException($result);
            }
            $keyword = array_pop($this->keywords);
            while ($keyword !== null) {
                $sql = sprintf('insert into NateGoSearchIndex (
						document_id,
						document_type,
						field_id,
						word,
						weight,
						location
					) values (%s, %s, %s, %s, %s, %s)', $this->db->quote($keyword->getDocumentId(), 'integer'), $this->db->quote($keyword->getDocumentType(), 'integer'), $this->db->quote($keyword->getTermId(), 'integer'), $this->db->quote($keyword->getWord(), 'text'), $this->db->quote($keyword->getWeight(), 'integer'), $this->db->quote($keyword->getLocation(), 'integer'));
                $result = $this->db->exec($sql);
                if (MDB2::isError($result)) {
                    throw new NateGoSearchDBException($result);
                }
                unset($keyword);
                $keyword = array_pop($this->keywords);
            }
            $popular_keyword = array_pop($this->popular_keywords);
            while ($popular_keyword !== null) {
                // TODO: there must be a better way to handle dupe words...
                $sql = sprintf('select count(keyword) from NateGoSearchPopularKeywords
					where keyword = %s', $this->db->quote($popular_keyword, 'text'));
                $exists = $this->db->queryOne($sql);
                if (MDB2::isError($result)) {
                    throw new NateGoSearchDBException($result);
                }
                if (!$exists) {
                    $sql = sprintf('insert into NateGoSearchPopularKeywords
						(keyword) values (%s)', $this->db->quote($popular_keyword, 'text'));
                    $result = $this->db->exec($sql);
                    if (MDB2::isError($result)) {
                        throw new NateGoSearchDBException($result);
                    }
                }
                unset($popular_keyword);
                $popular_keyword = array_pop($this->popular_keywords);
            }
            $this->clear_document_ids = array();
            $this->db->commit();
        } catch (NateGoSearchDBException $e) {
            $this->db->rollback();
            throw $e;
        }
    }
开发者ID:GervaisdeM,项目名称:nate-go-search,代码行数:67,代码来源:NateGoSearchIndexer.php


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