Posted by gobinathm.php on September 9, 2010 at 6:34am
Hi,
Im using custom module to handle this view.I did many try(find inside the code) but nothing works and also sorting too. Only arguments code works charm. Guide me to right way / help me with solutions.
and here is the exported view link http://pastebin.com/YzzzLEbW
function custom_module(){
views_include("view");
$view = new view();
$display = 'default';
$display_id = 'page_1';
$view = views_get_view('master');
// ensure view exists
if (!$view)
print("Not real");
// set display_id
$view->set_display('page');
$view->set_use_ajax(true);
$view->set_use_pager('mini');
$view->pager['items_per_page'] = 5;
$handler->override_option('path', 'ajaxlisting');
$view->is_cacheable = FALSE;
//Try 1 for filtering
$view->init_handlers();
$handler = $view->new_display('default', 'Defaults', 'default');
$handler->override_option('use_pager', '1');
$new_view_filters = $view->display_handler->get_option('filters');
if (empty($new_view_filters)) {
$new_view_filters = array();
}
$new_view_filters['field_internationalcode_value'] = array(
'id' => 'field_internationalcode_value',
'table' => 'node_data_field_internationalcode',
'field' => 'field_internationalcode_value',
'operator' => 'or',
'value' => 'US',
'group' => '0',
'exposed' => FALSE,
'relationship' => 'none',
);
$view_overrides = array();
$view_overrides['filters'] = $new_view_filters;
foreach ($view_overrides as $option => $definition) {
$view->display_handler->override_option($option, $definition);
}
//Try 1 filter ends & Try 2 filter starts
$view->display_handler->options['handlers']['filters']['field_internationalcode_value']->value = 'US';
//Try 2 filter ends & Try 1 sorting starts
$view->display['default']->handler- >options['sorts']['field_internationalcode_value']['order'] = 'DESC';
//Try 1 sorting ends & try 2 sorting starts
$sort['field_volatility_value']['order'] = 'ASC';
$view->display_handler->set_option('sorts', $sort);
// Try 2 sorting ends & Arguments Works good below
if (is_object($view)) {
if (is_array($args)) {
//$view->set_arguments($args);
$view->set_arguments(array($filt[0],$filt[1]));
$view->build($display_id);
}
// try 3 for filtering starts here
if (is_string($display_id)) {
$view->set_display($display_id);
$filter = $view->get_item($display_id, 'filter', 'field_internationalcode_value');
$filter['value'] = 'US';
$view->set_item($display_id, 'filter', 'field_internationalcode_value', $filter);
} else {
$view->init_display();
}
// try 3 ends here
$view->pre_execute();
$final = $view->execute($display_id);
$output = $view->render();
// Clean up after processing
$output = $view->post_execute();
}
return $view->result;
}
Im pulling everything but yet no solution
help me with this,
Thanxs,
Gobi.
Comments
one more try but also not working
i tried pre-view method and i placed this inside custom module(themespage) also not working
function themespage_views_pre_view(&$view) {
if ($view->name == 'master') {
$view->display['default']->handler->options['sorts']['field_internationalcode_value']['order'] = 'DESC';
}
}
am i doing anything worng
Hey.. did u code this view
Hey.. did u code this view urself?
or did u use the views ui?
rajarju
Hey Arjun
Yep,
im doing this own coding arjun for 3 days almost finally stucks with the problem :(
you have any idea what im doing wrong...
i think you are naughty in drupal coding huh ...
U could have used the views
U could have used the views UI to build ur view and then export it
To see what is going wrong .. u can import ur view code to the views ui and see if it is working there
i didnt get time to do the same..
lemme know if it helps..
Cheers!
rajarju
import ma code thro' views import
Arjun,
You mean importing this code to backend views module to check ?
Is it good idea since i did exported the views code[link in post] i verified with ma code but no solution are you in gtalk if u like to catch up there ?
One thing that i am still not
One thing that i am still not able to understand is
Why would you want to write a custom view from scratch
you could create a view using the admin ui
then do a query alter using hook if required.
If you want to give custom arguments then u could call view using get view
See if this code helps
http://groups.drupal.org/node/91374#comment-293774
rajarju