function _classified_page_user_ads in Classified Ads 7.3
Same name and namespace in other branches
- 6.3 classified.module \_classified_page_user_ads()
Page callback for user/<uid>/classified.
Cannot use a traditional query because body is now a field, which can be missing or renamed, and cannot use an EntityFieldQuery because we need to sort on the secondary table of the node type, whereas propertyOrderBy only works on the base table, in this case {node}.
So we do a poor man's EFQ to get the node_ids, and leave it to the list function to load nodes as needed.
Parameters
object $account: A user account for which to list authored ads.
Return value
array Render array for the ads list.
1 string reference to '_classified_page_user_ads'
- classified_menu in ./
classified.module - Implements hook_menu().
File
- ./
classified.module, line 636 - A pure D7 classified ads module inspired by the ed_classified module.
Code
function _classified_page_user_ads($account) {
global $user;
$min_status = $account->uid == $user->uid || user_access('administer nodes') ? 0 : 1;
/** @var SelectQuery $q */
$q = db_select('node', 'n');
$q
->comment(__FUNCTION__);
/** @var PagerDefault $q */
$q = $q
->extend('PagerDefault');
$q
->limit(10);
$cn = $q
->innerJoin('classified_node', 'cn', 'n.vid = cn.vid');
$q
->addField('n', 'nid', 'id');
$q
->condition('n.type', 'classified')
->condition('n.uid', $account->uid)
->condition('n.status', $min_status, '>=')
->orderBy("{$cn}.expires")
->orderBy("n.changed")
->orderBy('n.created')
->addTag('node_access');
$results = $q
->execute();
unset($cn, $min_status, $q);
$ret['list'] = _classified_list_nodes($results);
$ret['pager'] = array(
'#theme' => 'pager',
);
return $ret;
}