本文整理汇总了PHP中CriteriaCompo::setGroupBy方法的典型用法代码示例。如果您正苦于以下问题:PHP CriteriaCompo::setGroupBy方法的具体用法?PHP CriteriaCompo::setGroupBy怎么用?PHP CriteriaCompo::setGroupBy使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CriteriaCompo
的用法示例。
在下文中一共展示了CriteriaCompo::setGroupBy方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getRSSItems
function getRSSItems(&$items)
{
// check module_read permission
$module_handler =& xoops_gethandler('module');
$module =& $module_handler->getByDirname('xoonips');
$gperm_handler =& xoops_gethandler('groupperm');
$can_read = $gperm_handler->checkRight('module_read', $module->getVar('mid'), XOOPS_GROUP_ANONYMOUS);
if (!$can_read) {
return;
}
// get all published items
$limit = 10;
$category = $module->getVar('name');
$ib_handler =& xoonips_getormhandler('xoonips', 'item_basic');
$criteria = new CriteriaCompo();
$criteria->add(new Criteria('event_type_id', ETID_CERTIFY_ITEM));
$criteria->setGroupBy('ev.item_id');
$criteria->setSort('ev.timestamp');
$criteria->setOrder('DESC');
$criteria->setLimit($limit);
$fields = '*,MAX(ev.timestamp) AS pubdate';
$join = new XooNIpsJoinCriteria('xoonips_event_log', 'item_id', 'item_id', 'INNER', 'ev');
$criteria->add(new Criteria('iil.certify_state', CERTIFIED));
$join->cascade(new XooNIpsJoinCriteria('xoonips_index_item_link', 'item_id', 'item_id', 'INNER', 'iil'));
$criteria->add(new Criteria('idx.open_level', OL_PUBLIC));
$join->cascade(new XooNIpsJoinCriteria('xoonips_index', 'index_id', 'index_id', 'INNER', 'idx'), 'iil', true);
$res =& $ib_handler->open($criteria, $fields, false, $join);
while ($obj =& $ib_handler->getNext($res)) {
$item_id = intval($obj->get('item_id'));
$doi = $obj->get('doi');
$title = $this->_getItemTitle($item_id, 's');
$url = $this->_getItemUrl($item_id, $doi, 's');
$description = $obj->get('description');
$items[] = array('pubdate' => $obj->getExtraVar('pubdate'), 'title' => $title, 'link' => $url, 'guid' => $url, 'description' => $description, 'category' => $category);
}
$ib_handler->close($res);
}
示例2: empty
function _b_wp_contents_show($options, $wp_num = "")
{
$no_posts = empty($options[0]) ? 10 : $options[0];
$GLOBALS['dateformat'] = stripslashes(get_settings('date_format'));
$GLOBALS['timeformat'] = stripslashes(get_settings('time_format'));
$_criteria = new CriteriaCompo(new Criteria('post_status', 'publish'));
$_criteria->add(new Criteria('post_date', current_time('mysql'), '<='));
$_criteria->setGroupBy(wp_table('posts') . '.ID');
$_criteria->setSort('post_date');
$_criteria->setOrder('DESC');
$_criteria->setLimit($no_posts);
$_criteria->setStart(0);
$postHandler =& wp_handler('Post');
$postObjects =& $postHandler->getObjects($_criteria, false, '', 'DISTINCT');
$lposts = array();
foreach ($postObjects as $postObject) {
$lposts[] =& $postObject->exportWpObject();
}
if ($lposts) {
// Get the categories for all the posts
$_post_id_list = array();
foreach ($lposts as $post) {
$_post_id_list[] = $post->ID;
$GLOBALS['category_cache'][wp_id()][$post->ID] = array();
}
$_post_id_list = implode(',', $_post_id_list);
$_post_id_criteria =& new Criteria('post_id', '(' . $_post_id_list . ')', 'IN');
$_joinCriteria =& new XoopsJoinCriteria(wp_table('post2cat'), 'ID', 'post_id');
$_joinCriteria->cascade(new XoopsJoinCriteria(wp_table('categories'), 'category_id', 'cat_ID'));
$postObjects =& $postHandler->getObjects($_post_id_criteria, false, 'ID, category_id, cat_name, category_nicename, category_description, category_parent', true, $_joinCriteria);
foreach ($postObjects as $postObject) {
$_cat->ID = $postObject->getVar('ID');
$_cat->category_id = $postObject->getExtraVar('category_id');
$_cat->cat_name = $postObject->getExtraVar('cat_name');
$_cat->category_nicename = $postObject->getExtraVar('category_nicename');
$_cat->category_description = $postObject->getExtraVar('category_description');
$_cat->category_parent = $postObject->getExtraVar('category_parent');
$GLOBALS['category_cache'][wp_id()][$postObject->getVar('ID')][] =& $_cat;
unset($_cat);
}
// Do the same for comment numbers
$_criteria =& new CriteriaCompo(new Criteria('post_status', 'publish'));
$_criteria->add(new Criteria('comment_approved', '1 '));
$_criteria->add($_post_id_criteria);
$_criteria->setGroupBy('ID');
$_joinCriteria =& new XoopsJoinCriteria(wp_table('comments'), 'ID', 'comment_post_ID');
$postObjects =& $postHandler->getObjects($_criteria, false, 'ID, COUNT( comment_ID ) AS ccount', false, $_joinCriteria);
foreach ($postObjects as $postObject) {
$GLOBALS['comment_count_cache'][wp_id()]['' . $postObject->getVar('ID')] = $postObject->getExtraVar('ccount');
}
}
$blog = 1;
$block = array();
$block['use_theme_template'] = get_xoops_option(wp_mod(), 'use_theme_template');
$block['style'] = block_style_get(false);
$block['divid'] = 'wpBlockContent' . $wp_num;
$block['template_content'] = "";
$i = 0;
$GLOBALS['previousday'] = 0;
foreach ($lposts as $post) {
$GLOBALS['post'] = $post;
if ($block['use_theme_template'] == 0) {
$content = array();
start_wp();
$content['date'] = the_date($GLOBALS['dateformat'], '', '', false);
$content['time'] = the_time('', false);
$content['title'] = the_title('', '', false);
$content['permlink'] = get_permalink();
$content['author'] = the_author_posts_link('', false);
$content['category'] = the_category('', '', false);
$content['body'] = the_content(_WP_TPL_MORE, 0, '', false);
$content['linkpage'] = link_pages('<br />Pages: ', '<br />', 'number', 'next page', 'previous page', '%', '', false);
if (get_xoops_option(wp_mod(), 'wp_use_xoops_comments') == 0) {
$content['comments'] = comments_popup_link(_WP_TPL_COMMENT0, _WP_TPL_COMMENT1, _WP_TPL_COMMENTS, '', 'Comments Off', false);
} else {
$content['comments'] = xcomments_popup_link(_WP_TPL_COMMENT0, _WP_TPL_COMMENT1, _WP_TPL_COMMENTS, '', 'Comments Off', false);
$content['comments'] .= " | ";
$content['comments'] .= comments_popup_link(_WP_TPL_COMMENT0, _WP_TPL_COMMENT1, _WP_TPL_COMMENTS, '', 'Comments Off', false);
}
$content['trackback'] = trackback_rdf(0, false);
$block['contents'][] = $content;
} else {
ob_start();
include get_custom_path('content_block-template.php');
$block['template_content'] .= ob_get_contents();
ob_end_clean();
}
}
$GLOBALS['previousday'] = 0;
$GLOBALS['day'] = 0;
$GLOBALS['comment_count_cache'][wp_id()] = array();
return $block;
}
示例3: empty
function _b_wp_contents_show($options, $wp_num = "")
{
$no_posts = empty($options[0]) ? 10 : $options[0];
$tpl_file = empty($options[1]) ? 'wp_contents.html' : $options[1];
$category = empty($options[2]) ? "all" : intval($options[2]);
$GLOBALS['dateformat'] = get_settings('date_format');
$GLOBALS['timeformat'] = get_settings('time_format');
$_criteria = new CriteriaCompo(new Criteria('post_status', 'publish'));
$_criteria->add(new Criteria('post_date', current_time('mysql'), '<='));
if (empty($category) || $category == 'all' || $category == '0') {
$_joinCriteria = null;
} else {
$_joinCriteria =& new XoopsJoinCriteria(wp_table('post2cat'), 'ID', 'post_id');
$_wCriteria =& new CriteriaCompo();
$_wCriteria->add(new Criteria('category_id', intCriteriaVal($category)), 'OR');
$_catc = trim(get_category_children($category, '', ' '));
if ($_catc !== "") {
$_catc_array = explode(' ', $_catc);
for ($_j = 0; $_j < count($_catc_array); $_j++) {
$_wCriteria->add(new Criteria('category_id', intCriteriaVal($_catc_array[$_j])), 'OR');
}
}
$_criteria->add($_wCriteria);
}
$_criteria->setGroupBy(wp_table('posts') . '.ID');
$_criteria->setSort('post_date');
$_criteria->setOrder('DESC');
$_criteria->setLimit($no_posts);
$_criteria->setStart(0);
$postHandler =& wp_handler('Post');
$postObjects =& $postHandler->getObjects($_criteria, false, '', 'DISTINCT', $_joinCriteria);
// echo $postHandler->getLastSQL();
$lposts = array();
foreach ($postObjects as $postObject) {
$lposts[] =& $postObject->exportWpObject();
}
if ($lposts) {
// Get the categories for all the posts
$_post_id_list = array();
foreach ($lposts as $post) {
$_post_id_list[] = $post->ID;
$GLOBALS['category_cache'][wp_id()][$post->ID] = array();
}
$_post_id_list = implode(',', $_post_id_list);
$_post_id_criteria =& new Criteria('post_id', '(' . $_post_id_list . ')', 'IN');
$_joinCriteria =& new XoopsJoinCriteria(wp_table('post2cat'), 'ID', 'post_id');
$_joinCriteria->cascade(new XoopsJoinCriteria(wp_table('categories'), 'category_id', 'cat_ID'));
$postObjects =& $postHandler->getObjects($_post_id_criteria, false, 'ID, category_id, cat_name, category_nicename, category_description, category_parent', true, $_joinCriteria);
foreach ($postObjects as $postObject) {
$_cat->ID = $postObject->getVar('ID');
$_cat->category_id = $postObject->getExtraVar('category_id');
$_cat->cat_name = $postObject->getExtraVar('cat_name');
$_cat->category_nicename = $postObject->getExtraVar('category_nicename');
$_cat->category_description = $postObject->getExtraVar('category_description');
$_cat->category_parent = $postObject->getExtraVar('category_parent');
$GLOBALS['category_cache'][wp_id()][$postObject->getVar('ID')][] =& $_cat;
unset($_cat);
}
// Do the same for comment numbers
$_post_id_criteria =& new Criteria('comment_post_ID', '(' . $_post_id_list . ')', 'IN');
$_criteria =& new CriteriaCompo(new Criteria('post_status', 'publish'));
$_criteria->add(new Criteria('comment_approved', '1 '));
$_criteria->add($_post_id_criteria);
$_criteria->setGroupBy('ID');
$_joinCriteria =& new XoopsJoinCriteria(wp_table('comments'), 'ID', 'comment_post_ID');
$postObjects =& $postHandler->getObjects($_criteria, false, 'ID, COUNT( comment_ID ) AS ccount', false, $_joinCriteria);
foreach ($postObjects as $postObject) {
$GLOBALS['comment_count_cache'][wp_id()]['' . $postObject->getVar('ID')] = $postObject->getExtraVar('ccount');
}
// Get post-meta info
if ($meta_list = $GLOBALS['wpdb']->get_results('SELECT post_id, meta_key, meta_value FROM ' . wp_table('postmeta') . ' WHERE post_id IN(' . $_post_id_list . ') ORDER BY post_id, meta_key', ARRAY_A)) {
// Change from flat structure to hierarchical:
$GLOBALS['post_meta_cache'][wp_id()] = array();
foreach ($meta_list as $metarow) {
$mpid = $metarow['post_id'];
$mkey = $metarow['meta_key'];
$mval = $metarow['meta_value'];
// Force subkeys to be array type:
if (!isset($GLOBALS['post_meta_cache'][wp_id()][$mpid]) || !is_array($GLOBALS['post_meta_cache'][wp_id()][$mpid])) {
$GLOBALS['post_meta_cache'][wp_id()][$mpid] = array();
}
if (!isset($GLOBALS['post_meta_cache'][wp_id()][$mpid]["{$mkey}"]) || !is_array($GLOBALS['post_meta_cache'][wp_id()][$mpid]["{$mkey}"])) {
$GLOBALS['post_meta_cache'][wp_id()][$mpid]["{$mkey}"] = array();
}
// Add a value to the current pid/key:
$GLOBALS['post_meta_cache'][wp_id()][$mpid]["{$mkey}"][] = $mval;
}
}
}
$blog = 1;
$block = array();
$block['use_theme_template'] = get_xoops_option(wp_mod(), 'use_theme_template');
$block['style'] = block_style_get(false);
$block['divid'] = 'wpBlockContent' . $wp_num;
$block['template_content'] = "";
$i = 0;
$GLOBALS['previousday'] = 0;
foreach ($lposts as $post) {
$GLOBALS['post'] = $post;
if ($block['use_theme_template'] == 0) {
//.........这里部分代码省略.........
示例4: _set_feed_items
function _set_feed_items(&$feed, $output, $limit, $start)
{
global $event_handler;
global $item_handler;
global $xgroup_handler;
// get events
$criteria = new CriteriaCompo();
$fields = 'event_id,event_type_id,item_id,gid,MAX(timestamp)';
$groupby = '';
if ($output['certify_item']) {
$criteria->add(new Criteria('event_type_id', ETID_CERTIFY_ITEM));
$groupby .= 'item_id';
}
if ($output['insert_group']) {
if ($output['certify_item']) {
$criteria->add(new Criteria('event_type_id', ETID_INSERT_GROUP), 'OR');
$groupby .= ',gid';
} else {
$criteria->add(new Criteria('event_type_id', ETID_INSERT_GROUP));
$groupby .= 'gid';
}
}
$criteria->setSort('timestamp');
$criteria->setOrder('DESC');
$criteria->setLimit($limit);
$criteria->setGroupBy($groupby);
$criteria->setStart($start);
// query
$event_objs =& $event_handler->getObjects($criteria, false, $fields);
// get records
$num = 0;
foreach ($event_objs as $event_obj) {
$event_type_id = $event_obj->getVar('event_type_id', 'n');
$timestamp = $event_obj->getExtraVar('MAX(timestamp)');
$is_error = false;
switch ($event_type_id) {
case ETID_CERTIFY_ITEM:
$item_id = $event_obj->getVar('item_id', 'n');
$item_obj =& $item_handler->get($item_id);
if (is_object($item_obj)) {
$item = $item_obj->getVarArray('n');
$category = 'Incoming Public Item';
$title = _create_item_title($item['item_id']);
$description = _create_item_description($item['item_id']);
$link = _create_item_link($item['item_id'], $item['doi']);
if ($description === false) {
$is_error = true;
}
} else {
$is_error = true;
// item was already deleted
}
break;
case ETID_INSERT_GROUP:
$gid = $event_obj->getVar('gid', 'n');
$xgroup_obj =& $xgroup_handler->getGroupObject($gid);
if (is_object($xgroup_obj)) {
$group = $xgroup_obj->getVarArray('n');
$category = 'Incoming Group';
$title = _MD_XOONIPS_EVENT_NEW_GROUP . ' : ' . $group['gname'];
$description = $group['gdesc'] === '' ? '(empty)' : $group['gdesc'];
$link = XOOPS_URL . '/modules/xoonips/groups.php';
// TODO: detail page
} else {
$is_error = true;
// group was already deleted
}
break;
default:
$is_error = true;
break;
}
if ($is_error == false) {
$feed->addItem($category, $title, $description, $link, $timestamp);
$num++;
}
}
return $num;
}