Default setting of sorting
function blog_list_view($form, &$form_state) {
global $base_url;
if (isset($form_state['values']['option'])) {
$option = $form_state['values']['option'];
}
$html = '<div class="row-fluid"><div class="span12">'
. '<a style="color:#0088CC;text-decoration:none;" href="' . $base_url . '/node/add/blog">Create New Blog</a>'
. '<a style="color:#0088CC;text-decoration:none; padding-left:20px;" href="' . $base_url . '/admin/content/comment">Manage Comments</a>' .
'</div></div>';
$form['option'] = array(
'#type' => 'markup',
'#default_value' => $option,
'#prefix' => $html,
// '#suffix' => '</div>',
'#attributes' => array('class' => array('input-medium')),
);
$header = array(
array(
'data' => 'Title',
'field' => 'title'
),
array(
'data' => 'Author',
'field' => 'uid'
),
array(
'data' => 'Updated',
'field' => 'created'
),
array(
'data' => 'operations',
),
);
if (isset($_GET ['sort']) && isset($_GET ['order'])) {
if ($_GET ['sort'] == 'asc')
$sort = 'ASC';
else
$sort = 'DESC';
switch ($_GET ['order']) {
case 'Id' :
$order = 'nid';
break;
case 'Title' :
$order = 'title';
break;
case 'Author' :
$order = 'uid';
break;
case 'Updated' :
$order = 'changed';
break;
}
} else {
$sort = 'ASC';
$order = 'nid';
}
$query = db_select('node', 'n');
$query->join('users', 'u', 'u.uid=n.uid');
$query->fields('n', array('title', 'nid', 'uid', 'changed'));
$query->fields('u', array('name'));
$query->condition('n.status', 1);
$query->condition('n.type', array(blog), 'IN');
if(!isset($_GET ['order'])){
$query->orderBy('n.created', 'DESC');
}else{
// $query->range(0, 10);
$query->orderBy($order, $sort);
}
function blog_list_view($form, &$form_state) {
global $base_url;
if (isset($form_state['values']['option'])) {
$option = $form_state['values']['option'];
}
$html = '<div class="row-fluid"><div class="span12">'
. '<a style="color:#0088CC;text-decoration:none;" href="' . $base_url . '/node/add/blog">Create New Blog</a>'
. '<a style="color:#0088CC;text-decoration:none; padding-left:20px;" href="' . $base_url . '/admin/content/comment">Manage Comments</a>' .
'</div></div>';
$form['option'] = array(
'#type' => 'markup',
'#default_value' => $option,
'#prefix' => $html,
// '#suffix' => '</div>',
'#attributes' => array('class' => array('input-medium')),
);
$header = array(
array(
'data' => 'Title',
'field' => 'title'
),
array(
'data' => 'Author',
'field' => 'uid'
),
array(
'data' => 'Updated',
'field' => 'created'
),
array(
'data' => 'operations',
),
);
if (isset($_GET ['sort']) && isset($_GET ['order'])) {
if ($_GET ['sort'] == 'asc')
$sort = 'ASC';
else
$sort = 'DESC';
switch ($_GET ['order']) {
case 'Id' :
$order = 'nid';
break;
case 'Title' :
$order = 'title';
break;
case 'Author' :
$order = 'uid';
break;
case 'Updated' :
$order = 'changed';
break;
}
} else {
$sort = 'ASC';
$order = 'nid';
}
$query = db_select('node', 'n');
$query->join('users', 'u', 'u.uid=n.uid');
$query->fields('n', array('title', 'nid', 'uid', 'changed'));
$query->fields('u', array('name'));
$query->condition('n.status', 1);
$query->condition('n.type', array(blog), 'IN');
if(!isset($_GET ['order'])){
$query->orderBy('n.created', 'DESC');
}else{
// $query->range(0, 10);
$query->orderBy($order, $sort);
}
No comments:
Post a Comment