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


PHP DB::get_value方法代码示例

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


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

示例1: get_dashboard

 /**
  * Handles get requests for the dashboard
  * @todo update check should probably be cron'd and cached, not re-checked every load
  */
 public function get_dashboard()
 {
     // Not sure how best to determine this yet, maybe set an option on install, maybe do this:
     $firstpostdate = DB::get_value('SELECT min(pubdate) FROM {posts} WHERE status = ?', array(Post::status('published')));
     $this->theme->active_time = HabariDateTime::date_create($firstpostdate);
     // get the active theme, so we can check it
     // @todo this should be worked into the main Update::check() code for registering beacons
     $active_theme = Themes::get_active();
     $active_theme = $active_theme->name . ':' . $active_theme->version;
     // check to see if we have updates to display
     $this->theme->updates = Options::get('updates_available', array());
     // collect all the stats we display on the dashboard
     $this->theme->stats = array('author_count' => Users::get(array('count' => 1)), 'page_count' => Posts::get(array('count' => 1, 'content_type' => Post::type('page'), 'status' => Post::status('published'))), 'entry_count' => Posts::get(array('count' => 1, 'content_type' => Post::type('entry'), 'status' => Post::status('published'))), 'comment_count' => Comments::count_total(Comment::STATUS_APPROVED, false), 'tag_count' => Tags::vocabulary()->count_total(), 'page_draft_count' => Posts::get(array('count' => 1, 'content_type' => Post::type('page'), 'status' => Post::status('draft'), 'user_id' => User::identify()->id)), 'entry_draft_count' => Posts::get(array('count' => 1, 'content_type' => Post::type('entry'), 'status' => Post::status('draft'), 'user_id' => User::identify()->id)), 'unapproved_comment_count' => User::identify()->can('manage_all_comments') ? Comments::count_total(Comment::STATUS_UNAPPROVED, false) : Comments::count_by_author(User::identify()->id, Comment::STATUS_UNAPPROVED), 'spam_comment_count' => User::identify()->can('manage_all_comments') ? Comments::count_total(Comment::STATUS_SPAM, false) : Comments::count_by_author(User::identify()->id, Comment::STATUS_SPAM), 'user_entry_scheduled_count' => Posts::get(array('count' => 1, 'content_type' => Post::type('any'), 'status' => Post::status('scheduled'), 'user_id' => User::identify()->id)));
     $this->fetch_dashboard_modules();
     // check for first run
     $u = User::identify();
     if (!isset($u->info->experience_level)) {
         $this->theme->first_run = true;
         $u->info->experience_level = 'user';
         $u->info->commit();
     } else {
         $this->theme->first_run = false;
     }
     $this->display('dashboard');
 }
开发者ID:ringmaster,项目名称:system,代码行数:29,代码来源:admindashboardhandler.php

示例2: test_delete_block

 public function test_delete_block()
 {
     $params = array('title' => $this->title, 'type' => $this->type);
     $block = new Block($params);
     $block->insert();
     $count = DB::get_value('SELECT count(*) FROM {blocks}');
     $block->delete();
     $this->assert_equal($count - 1, DB::get_value('SELECT count(*) FROM {blocks}'), 'Count of blocks should decrease by one');
 }
开发者ID:habari,项目名称:tests,代码行数:9,代码来源:test_block.php

示例3: unregister_type

 /**
  * Removes a logging type from the lookup table
  *
  * @param string $type The type of the error
  * @param string $module The module of the error
  */
 public static function unregister_type($type = 'default', $module = null)
 {
     $id = DB::get_value("SELECT id FROM {log_types} WHERE module = ? and type = ?", array(self::get_module($module), $type));
     if ($id) {
         if (!DB::exists('{log}', array('type_id' => $id))) {
             DB::delete('{log_types}', array('id' => $id));
         }
     }
 }
开发者ID:wwxgitcat,项目名称:habari,代码行数:15,代码来源:eventlog.php

示例4: test_createduplicategroup

 function test_createduplicategroup()
 {
     // Can I create two groups with the same name?
     $group = UserGroup::create('name=new dupe group');
     $group2 = UserGroup::create('name=new dupe group');
     assert($group2 instanceof UserGroup);
     $this->assert_true(DB::get_value('SELECT count(*) FROM {groups} WHERE name = ?', array('new dupe group')) == 1, 'Was able to create two groups with the same name.');
     $group->delete();
     $group2->delete();
 }
开发者ID:psaintlaurent,项目名称:Habari,代码行数:10,代码来源:test_usergroup.php

示例5: test_delete

 public function test_delete()
 {
     $group = UserGroup::get("new test group");
     Plugins::register(array($this, 'filter_usergroup_delete_allow'), 'filter', 'usergroup_delete_allow');
     $this->assert_true($group instanceof UserGroup, 'Could not retrieve group named "new test group".');
     $this->allow_filter = false;
     $group->delete();
     $this->assert_false(DB::get_value('SELECT count(*) FROM {groups} WHERE name = ?', array('new test group')) == 0, 'Was able to delete a group despite not being allowed to do so.');
     $this->allow_filter = true;
     $group->delete();
     $this->assert_true(DB::get_value('SELECT count(*) FROM {groups} WHERE name = ?', array('new test group')) == 0, 'Was not able to delete a created group.');
     $group = UserGroup::get("new test group");
     $this->assert_false($group instanceof UserGroup, 'Was able to retrieve (deleted) group named "new test group".');
 }
开发者ID:habari,项目名称:tests,代码行数:14,代码来源:test_usergroup.php

示例6: add_cron

 /**
  * Add a new cron job to the DB.
  *
  * @see CronJob
  * @param array $paramarray A paramarray of cron job feilds.
  * @return \Habari\CronJob
  */
 static function add_cron($paramarray)
 {
     // Delete any existing job with this same name
     if ($job = CronTab::get_cronjob($paramarray['name'])) {
         $job->delete();
     }
     $cron = new CronJob($paramarray);
     $result = $cron->insert();
     //If the new cron should run earlier than the others, rest next_cron to its strat time.
     $next_cron = DB::get_value('SELECT next_run FROM {crontab} ORDER BY next_run ASC LIMIT 1', array());
     if (intval(Options::get('next_cron')) > intval($next_cron)) {
         Options::set('next_cron', $next_cron);
     }
     return $result ? $cron : false;
 }
开发者ID:habari,项目名称:system,代码行数:22,代码来源:crontab.php

示例7: add_to_area

 /**
  * Add this block to a particular area in the theme
  * 
  * @param string $area The name of the area to add to
  * @param integer $order The position of the block within the area
  * @param string $scope The scope id into which to add this block
  */
 public function add_to_area($area, $order = null, $scope = null)
 {
     if (is_null($scope)) {
         $scope = 0;
     }
     if (is_null($order) || !is_int($order)) {
         $order = DB::get_value('SELECT max(display_order) + 1 FROM {blocks_areas} WHERE area = :area AND scope_id = :scope', array('area' => $area, 'scope' => $scope));
         if (is_null($order)) {
             $order = 1;
         }
     } else {
         DB::query('UPDATE {blocks_areas} SET display_order = display_order + 1 WHERE area = :area AND scope_id = :scope AND display_order >= :order', array('area' => $area, 'scope' => $scope, 'order' => $order));
     }
     // If the block isn't saved in the database, insert it.
     if (!$this->id) {
         $this->insert();
     }
     $result = DB::query('INSERT INTO {blocks_areas} (block_id, area, scope_id, display_order) VALUES (:block_id, :area, :scope_id, :display_order)', array('block_id' => $this->id, 'area' => $area, 'scope_id' => $scope, 'display_order' => $order));
 }
开发者ID:ringmaster,项目名称:system,代码行数:26,代码来源:block.php

示例8: get_dashboard

 /**
  * Handles get requests for the dashboard
  * @todo update check should probably be cron'd and cached, not re-checked every load
  */
 public function get_dashboard()
 {
     // Not sure how best to determine this yet, maybe set an option on install, maybe do this:
     $firstpostdate = DB::get_value('SELECT min(pubdate) FROM {posts} WHERE status = ?', array(Post::status('published')));
     if (intval($firstpostdate) !== 0) {
         $firstpostdate = time() - $firstpostdate;
     }
     $this->theme->active_time = array('years' => floor($firstpostdate / 31556736), 'months' => floor($firstpostdate % 31556736 / 2629728), 'days' => round($firstpostdate % 2629728 / 86400));
     // get the active theme, so we can check it
     $active_theme = Themes::get_active();
     $active_theme = $active_theme->name . ':' . $active_theme->version;
     // if the active plugin list has changed, expire the updates cache
     if (Cache::has('dashboard_updates') && Cache::get('dashboard_updates_plugins') != Options::get('active_plugins')) {
         Cache::expire('dashboard_updates');
     }
     // if the theme version has changed, expire the updates cache
     if (Cache::has('dashboard_updates') && Cache::get('dashboard_updates_theme') != $active_theme) {
         Cache::expire('dashboard_updates');
     }
     /*
      * Check for updates to core and any hooked plugins
      * cache the output so we don't make a request every load but can still display updates
      */
     if (Cache::has('dashboard_updates')) {
         $this->theme->updates = Cache::get('dashboard_updates');
     } else {
         $updates = Update::check();
         if (!Error::is_error($updates)) {
             Cache::set('dashboard_updates', $updates);
             $this->theme->updates = $updates;
             // cache the set of plugins we just used to check for
             Cache::set('dashboard_updates_plugins', Options::get('active_plugins'));
             // cache the active theme we just used to check for
             Cache::set('dashboard_updates_theme', $active_theme);
         } else {
             $this->theme->updates = array();
         }
     }
     $this->theme->stats = array('author_count' => Users::get(array('count' => 1)), 'page_count' => Posts::get(array('count' => 1, 'content_type' => Post::type('page'), 'status' => Post::status('published'))), 'entry_count' => Posts::get(array('count' => 1, 'content_type' => Post::type('entry'), 'status' => Post::status('published'))), 'comment_count' => Comments::count_total(Comment::STATUS_APPROVED, FALSE), 'tag_count' => Tags::count_total(), 'page_draft_count' => Posts::get(array('count' => 1, 'content_type' => Post::type('page'), 'status' => Post::status('draft'), 'user_id' => User::identify()->id)), 'entry_draft_count' => Posts::get(array('count' => 1, 'content_type' => Post::type('entry'), 'status' => Post::status('draft'), 'user_id' => User::identify()->id)), 'unapproved_comment_count' => User::identify()->can('manage_all_comments') ? Comments::count_total(Comment::STATUS_UNAPPROVED, FALSE) : Comments::count_by_author(User::identify()->id, Comment::STATUS_UNAPPROVED), 'spam_comment_count' => User::identify()->can('manage_all_comments') ? Comments::count_total(Comment::STATUS_SPAM, FALSE) : Comments::count_by_author(User::identify()->id, Comment::STATUS_SPAM), 'user_entry_scheduled_count' => Posts::get(array('count' => 1, 'content_type' => Post::type('any'), 'status' => Post::status('scheduled'), 'user_id' => User::identify()->id)));
     $this->fetch_dashboard_modules();
     // check for first run
     $u = User::identify();
     if (!isset($u->info->experience_level)) {
         $this->theme->first_run = true;
         $u->info->experience_level = 'user';
         $u->info->commit();
     } else {
         $this->theme->first_run = false;
     }
     $this->display('dashboard');
 }
开发者ID:psaintlaurent,项目名称:Habari,代码行数:55,代码来源:adminhandler.php

示例9: theme_area

 /**
  * Displays blocks associated to the specified area and current scope.
  *
  * @param Theme $theme The theme with which this area will be output
  * @param string $area The area to which blocks will be output
  * @param string $context The area of context within the theme that could adjust the template used
  * @param string $scope Used to force a specific scope
  * @return string the output of all the blocks
  */
 public function theme_area($theme, $area, $context = null, $scope = null)
 {
     // This array would normally come from the database via:
     $scopes = $this->get_scopes($area);
     $active_scope = 0;
     foreach ($scopes as $scope_id => $scope_object) {
         if (is_null($scope) && $this->check_scope_criteria($scope_object->criteria) || $scope == $scope_object->name) {
             $scope_block_count = DB::get_value('SELECT count( *) FROM {blocks_areas} ba WHERE ba.scope_id = ?', array($scope_object->id));
             if ($scope_block_count > 0) {
                 $active_scope = $scope_object->id;
             }
             break;
         }
     }
     $area_blocks = $this->get_blocks($area, $active_scope, $theme);
     $this->area = $area;
     if (isset($context)) {
         $this->context[] = $context;
     }
     // This is the block wrapper fallback template list
     $fallback = array($area . '.blockwrapper', 'blockwrapper', 'content');
     if (!is_null($context)) {
         array_unshift($fallback, $context . '.blockwrapper');
         array_unshift($fallback, $context . '.' . $area . '.blockwrapper');
     }
     $output = '';
     $i = 0;
     foreach ($area_blocks as $block_instance_id => $block) {
         // Temporarily set some values into the block
         $block->_area = $area;
         $block->_instance_id = $block_instance_id;
         $block->_area_index = $i++;
         $block->_fallback = $fallback;
         $hook = 'block_content_' . $block->type;
         Plugins::act($hook, $block, $this);
         Plugins::act('block_content', $block, $this);
         $block->_content = implode('', $this->content_return($block, $context));
         if (trim($block->_content) == '') {
             unset($area_blocks[$block_instance_id]);
         }
     }
     // Potentially render each block inside of a wrapper.
     reset($area_blocks);
     $firstkey = key($area_blocks);
     end($area_blocks);
     $lastkey = key($area_blocks);
     foreach ($area_blocks as $block_instance_id => $block) {
         $block->_first = $block_instance_id == $firstkey;
         $block->_last = $block_instance_id == $lastkey;
         // Set up the theme for the wrapper
         $this->block = $block;
         $this->content = $block->_content;
         // This pattern renders the block inside the wrapper template only if a matching template exists
         $newoutput = $this->display_fallback($fallback, 'fetch');
         if ($newoutput === false) {
             $output .= $block->_content;
         } else {
             $output .= $newoutput;
         }
         // Remove temporary values from the block so they're not saved to the database
         unset($block->_area);
         unset($block->_instance_id);
         unset($block->_area_index);
         unset($block->_first);
         unset($block->_last);
     }
     if (trim($output) != '') {
         // This is the area fallback template list
         $fallback = array($context . '.area.' . $area, $context . '.area', 'area.' . $area, 'area');
         $this->content = $output;
         $newoutput = $this->display_fallback($fallback, 'fetch');
         if ($newoutput !== false) {
             $output = $newoutput;
         }
     }
     $this->area = '';
     if (isset($context)) {
         array_pop($this->context);
     }
     return $output;
 }
开发者ID:habari,项目名称:system,代码行数:90,代码来源:theme.php

示例10: add_cron

 /**
  * Add a new cron job to the DB.
  *
  * @see CronJob
  * @param array $paramarray A paramarray of cron job feilds.
  */
 static function add_cron($paramarray)
 {
     $cron = new CronJob($paramarray);
     $result = $cron->insert();
     //If the new cron should run earlier than the others, rest next_cron to its strat time.
     $next_cron = DB::get_value('SELECT next_run FROM {crontab} ORDER BY next_run ASC LIMIT 1', array());
     if (intval(Options::get('next_cron')) > intval($next_cron)) {
         Options::set('next_cron', $next_cron);
     }
     return $result;
 }
开发者ID:ringmaster,项目名称:system,代码行数:17,代码来源:crontab.php

示例11: test_object_type

	public function test_object_type()
	{
		 $name = 'unit_test';
		 Vocabulary::add_object_type( $name );
		 $sql_id = DB::get_value( "SELECT id FROM {object_types} WHERE name = :vocab_name", array( 'vocab_name' => $name ) );
		 $id = Vocabulary::object_type_id( $name );
		 $this->assert_equal( $sql_id, $id, 'The sql id should equal the id returned.' );
		 DB::delete( '{object_types}', array( 'name' => $name ) );
	}
开发者ID:rynodivino,项目名称:tests,代码行数:9,代码来源:test_taxonomy.php

示例12: array

     $collect = array('threadBuy' => array());
     $callbacks = array('pw_bbs_posts' => '_callbackPosts', 'pw_bbs_threads_buy' => '_callbackThreadsBuy');
     list($_srcTable, $_subT) = getSubTable('pw_posts', $db_plist);
     $nextId = transferDataByPk($_srcTable, $associateFields, 'pid', $lastId, $limit, $callbacks);
     if ($collect['threadBuy']) {
         $sql = 'INSERT INTO pw_bbs_threads_buy (`tid`, `pid`, `created_userid`, `created_time`, `ctype`, `cost`) VALUES %s';
         $targetDb->query(sprintf($sql, implode(',', $collect['threadBuy'])));
     }
     //分表
     calculatePercent("SELECT COUNT(*) FROM {$_srcTable}", "SELECT COUNT(*) FROM {$_srcTable} WHERE pid <= {$nextId}");
     $db_plist && ($_subTMessage = $_srcTable);
     //分表跳转
     refreshSubTableTo('truncateGThreadsTmp', $db_plist, $_subT);
 } elseif ('truncateGThreadsTmp' == $action) {
     //转移群组数据到版块 "群组升级"" 分类 "群组话题" 版块
     $data = $targetDb->get_value("SELECT count(*) FROM tmp_group_to_thread");
     if ($data == 0) {
         refreshTo('favors');
     }
     $sql = "INSERT INTO pw_bbs_forum (`parentid`, `type`, `name`, `hassub`, `isshow`, `created_time`) VALUES (0, 'category', '群组升级', 1, 1, {$timestamp})";
     $targetDb->query($sql);
     $categoryid = $targetDb->insert_id();
     $sql = "INSERT INTO pw_bbs_forum (`parentid`, `type`, `name`, `isshow`, `newtime`, `created_time`) VALUES ({$categoryid}, 'forum', '群组话题', 1, 3, {$timestamp})";
     $targetDb->query($sql);
     $fid = $targetDb->insert_id();
     $targetDb->query(sprintf("REPLACE INTO tmp_group_to_thread SET tid = 0, cid = %d, fid = %d", $categoryid, $fid));
     refreshTo('truncateGThreadsTmpDo');
 } elseif ('truncateGThreadsTmpDo' == $action) {
     $data = $targetDb->get_one("SELECT * FROM tmp_group_to_thread WHERE tid=0");
     if (!$data) {
         refreshTo('favors');
开发者ID:sanzhumu,项目名称:nextwind,代码行数:31,代码来源:up87to90.php

示例13: action_comment_insert_before


//.........这里部分代码省略.........
		if ( preg_match( "/^\d+$/", $comment->name ) ) {
			$comment->status = Comment::STATUS_SPAM;
			$spamcheck[] = _t('Commenters with numeric names are spammy.');
		}

		// now look at the comment text
		// if it's digits only, discard it
		$textonly = strip_tags( $comment->content );

		if ( preg_match( "/^\d+$/", $textonly ) ) {
			$comment->status = Comment::STATUS_SPAM;
			$spamcheck[] = _t('Comments that are only numeric are spammy.');
		}

		// is the content whitespaces only?
		if ( preg_match( "/\A\s+\z/", $textonly ) ) {
			$comment->status = Comment::STATUS_SPAM;
			$spamcheck[] = _t('Comments that are only whitespace characters are spammy.');
		}

		// is the content the single word "array"?
		if ( 'array' == strtolower( $textonly ) ) {
			$comment->status = Comment::STATUS_SPAM;
			$spamcheck[] = _t('Comments that are only "array" are spammy.');
		}

		// is the content the same as the name?
		if ( strtolower( $textonly ) == strtolower( $comment->name ) ) {
			$comment->status = Comment::STATUS_SPAM;
			$spamcheck[] = _t('Comments that consist of only the commenters name are spammy.');
		}

		// a lot of spam starts with "<strong>some text...</strong>"
		if ( preg_match( "#^<strong>[^.]+\.\.\.</strong>#", $comment->content ) )
		{
			$comment->status = Comment::STATUS_SPAM;
			$spamcheck[] = _t('Comments that start with strong text are spammy.');
		}

		// are there more than 3 URLs posted?  If so, it's almost certainly spam
		if ( preg_match_all( "#https?://#", strtolower( $comment->content ), $matches, PREG_SET_ORDER ) > 3 ) {
			$comment->status = Comment::STATUS_SPAM;
			$spamcheck[] = _t('There is a 3 URL limit in comments.');
		}

		// are there more than 3 URLencoded characters in the content?
		if ( preg_match_all( "/%[0-9a-f]{2}/", strtolower( $comment->content ), $matches, PREG_SET_ORDER ) > 3 ) {
			$comment->status = Comment::STATUS_SPAM;
			$spamcheck[] = _t('There is a 3 URL-encoded character limit in comments.');
		}

		// Was the tcount high enough?
		/* // This only works with special javascript running on comment form
		if ( empty($handlervars['tcount']) || $handlervars['tcount'] < 10 ) {
			$comment->status = Comment::STATUS_SPAM;
			$spamcheck[] = _t('Commenter did not actually type content.');
		}
		*/

		// We don't allow bbcode here, silly
		if ( stripos($comment->content, '[url=') !== false ) {
			$comment->status = Comment::STATUS_SPAM;
			$spamcheck[] = _t('We do not accept BBCode here.');
		}

		// Must have less than half link content
		$nonacontent = strip_tags(preg_replace('/<a.*?<\/a/i', '', $comment->content));
		$text_length = strlen( $textonly );
		if ( strlen($nonacontent) / ( $text_length == 0 ? 1 : $text_length) < 0.5 ) {
			$comment->status = Comment::STATUS_SPAM;
			$spamcheck[] = _t('Too much text that is a link compared to that which is not.');
		}

		// Only do db checks if it's not already spam
		if ($comment->status != Comment::STATUS_SPAM) {
			$spams = DB::get_value('SELECT count(*) FROM ' . DB::table('comments') . ' WHERE status = ? AND ip = ?', array(Comment::STATUS_SPAM, $comment->ip));
			// If you've already got two spams on your IP address, all you ever do is spam
			if ($spams > 1) {
				$comment->status = Comment::STATUS_SPAM;
				$spamcheck[] = sprintf(_t('Too many existing spams from this IP: %s'), $comment->ip);
			}
		}

		// Any commenter that takes longer than the session timeout is automatically moderated
		if (!isset($_SESSION['comments_allowed']) || ! in_array(Controller::get_var('ccode'), $_SESSION['comments_allowed'])) {
			$comment->status = Comment::STATUS_UNAPPROVED;
			$spamcheck[] = _t("The commenter's session timed out.");
		}

		if ( isset($comment->info->spamcheck) && is_array($comment->info->spamcheck)) {
			$comment->info->spamcheck = array_unique(array_merge($comment->info->spamcheck, $spamcheck));
		}
		else {
			$comment->info->spamcheck = $spamcheck;
		}

		// otherwise everything looks good
		// so continue processing the comment
		return;
	}
开发者ID:rynodivino,项目名称:system,代码行数:101,代码来源:spamchecker.plugin.php

示例14: move_term

    /**
     * Moves a term within the vocabulary. Returns a Term object. null parameters append the term to the end of any hierarchies.
     * @return Term The Term object moved
     **/
    public function move_term($term, $target_term = null, $before = FALSE)
    {
        // We assume that the arguments passed are valid terms. Check them before calling this.
        // If there are terms in the vocabulary, work out the reference point
        if (!$this->is_empty()) {
            $source_left = $term->mptt_left;
            $source_right = $term->mptt_right;
            $range = $source_right - $source_left + 1;
            $nodes_moving = $range / 2;
            // parent and descendants
            DB::begin_transaction();
            // Move the source nodes out of the way by making mptt_left and mptt_right negative
            $source_to_temp = $source_right + 1;
            // move the terms so that the rightmost one's mptt_right is -1
            $params = array('displacement' => $source_to_temp, 'vocab_id' => $this->id, 'range_left' => $source_left, 'range_right' => $source_right);
            $res = DB::query('
				UPDATE {terms} 
				SET 
					mptt_left = mptt_left - :displacement, 
					mptt_right = mptt_right - :displacement 
				WHERE 
					vocabulary_id = :vocab_id
					AND mptt_left BETWEEN :range_left AND :range_right
				', $params);
            if (!$res) {
                DB::rollback();
                return FALSE;
            }
            // Close the gap in the tree created by moving those nodes out
            $params = array('range' => $range, 'vocab_id' => $this->id, 'source_left' => $source_left);
            $res = DB::query('UPDATE {terms} SET mptt_left=mptt_left-:range WHERE vocabulary_id=:vocab_id AND mptt_left > :source_left', $params);
            if (!$res) {
                DB::rollback();
                return FALSE;
            }
            $res = DB::query('UPDATE {terms} SET mptt_right=mptt_right-:range WHERE vocabulary_id=:vocab_id AND mptt_right > :source_left', $params);
            if (!$res) {
                DB::rollback();
                return FALSE;
            }
            // Determine the insertion point mptt_target
            if ($this->hierarchical) {
                if (null == $target_term) {
                    // If no target is specified, put the new term after the last term
                    $mptt_target = DB::get_value('SELECT MAX(mptt_right) FROM {terms} WHERE vocabulary_id=?', array($this->id)) + 1;
                } else {
                    if (FALSE == $before) {
                        $mptt_target = DB::get_value('SELECT mptt_right FROM {terms} WHERE vocabulary_id=? AND id = ?', array($this->id, $target_term->id));
                    } else {
                        $mptt_target = DB::get_value('SELECT mptt_left FROM {terms} WHERE vocabulary_id=? AND id = ?', array($this->id, $target_term->id));
                    }
                }
            } else {
                // vocabulary is not hierarchical
                if (FALSE != $before) {
                    $mptt_target = DB::get_value('SELECT mptt_left FROM {terms} WHERE vocabulary_id=? AND id = ?', array($this->id, $target_term->id));
                } else {
                    $mptt_target = DB::get_value('SELECT MAX(mptt_right) FROM {terms} WHERE vocabulary_id=?', array($this->id)) + 1;
                }
            }
            $temp_left = $source_left - $source_to_temp;
            $temp_to_target = $mptt_target - $temp_left;
            // Create space in the tree for the insertion
            $params = array('vocab_id' => $this->id, 'range' => $range, 'mptt_target' => $mptt_target);
            $res = DB::query('UPDATE {terms} SET mptt_left=mptt_left+:range WHERE vocabulary_id=:vocab_id AND mptt_left >= :mptt_target', $params);
            if (!$res) {
                DB::rollback();
                return FALSE;
            }
            $res = DB::query('UPDATE {terms} SET mptt_right=mptt_right+:range WHERE vocabulary_id=:vocab_id AND mptt_right >= :mptt_target', $params);
            if (!$res) {
                DB::rollback();
                return FALSE;
            }
            // Move the temp nodes into the space created for them
            $params = array('vocab_id' => $this->id, 'temp_to_target' => $temp_to_target);
            $res = DB::query('UPDATE {terms} SET mptt_left=mptt_left+:temp_to_target WHERE vocabulary_id=:vocab_id AND mptt_left < 0', $params);
            if (!$res) {
                DB::rollback();
                return FALSE;
            }
            $res = DB::query('UPDATE {terms} SET mptt_right=mptt_right+:temp_to_target WHERE vocabulary_id=:vocab_id AND mptt_right < 0', $params);
            if (!$res) {
                DB::rollback();
                return FALSE;
            }
            // Success!
            DB::commit();
            // @todo: need to return the updated term
            return $term;
        }
        return FALSE;
    }
开发者ID:psaintlaurent,项目名称:Habari,代码行数:97,代码来源:vocabulary.php

示例15: max_count

 /**
  * Returns the number of times the most used tag is used.
  *
  * @return int The number of times the most used tag is used.
  **/
 public static function max_count()
 {
     return DB::get_value('SELECT count( t2.object_id ) AS max FROM {terms} t, {object_terms} t2 WHERE t2.term_id = t.id AND t.vocabulary_id = ? GROUP BY t.id ORDER BY max DESC LIMIT 1', array(Tags::vocabulary()->id));
 }
开发者ID:psaintlaurent,项目名称:Habari,代码行数:9,代码来源:tags.php


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