
Originally Posted by
mathewp
Thanks for your help... Putting the fields in place isn't the problem. I need to find a way to get date from start_date and end_date fields and get all the records that fall in that range.
I want mysql to run the following query:
SELECT * from sugarcrm.leads
where date_entered
BETWEEN start_date AND end_date;
Hi Mathew
You need to create a custom controller for your module (custom/<ModuleName>/controller.php) containing the method action_listview.
Inside this method you need to override the $this->bean as an instance of a new class which extends the default module class.
Inside that module class you need to implement the method create_new_list_query.
This method is defined in the data/SugarBean.php.
Take a look at this two piece of code:
controller:
PHP Code:
<?PHP
require_once('include/MVC/Controller/SugarController.php');
require_once('modules/Opportunities/OpportunityInListView.php');
class OpportunitiesController extends SugarController {
function action_listview() {
$this->view_object_map['bean'] = $this->bean;
$this->view = 'list';
$GLOBALS['view'] = $this->view;
$this->bean = new OpportunityInListView();
}
}
?>
new class:
PHP Code:
<?php
if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
class OpportunityInListView extends Opportunity {
function Opportunity() {
parent::Opportunity();
}
function create_new_list_query($order_by, $where,$filter=array(),$params=array(), $show_deleted = 0,$join_type='', $return_array = false,$parentbean, $singleSelect = false){
$ret_array = parent::create_new_list_query($order_by, $where,$filter,$params, $show_deleted,$join_type, $return_array,$parentbean, $singleSelect);
$ret_array['select'] .= ", accounts.name account_name, jtl0.account_id account_id, jtl1.name agency_name, jtl2.name advertiser_name ";
$ret_array['from'] .= "
LEFT JOIN accounts_opportunities jtl0 ON opportunities.id=jtl0.opportunity_id AND jtl0.deleted=0
LEFT JOIN accounts accounts ON accounts.id=jtl0.account_id AND accounts.deleted=0 AND accounts.deleted=0
LEFT JOIN accounts jtl1 ON opportunities.agency_id=jtl1.id AND jtl1.deleted=0
LEFT JOIN accounts jtl2 ON opportunities.advertiser_id=jtl2.id AND jtl2.deleted=0";
$ret_array['where'] = str_replace("opportunities.agency_name", "jtl1.name", $ret_array['where']);
$ret_array['where'] = str_replace("opportunities.advertiser_name", "jtl2.name", $ret_array['where']);
return $ret_array;
}
}
?>
Kind regards
Bookmarks