Created
August 20, 2015 21:01
-
-
Save eggsurplus/8a0ff95fff061b889077 to your computer and use it in GitHub Desktop.
Adding SecuritySuite support to a chart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//......... | |
protected function constuctQuery() | |
{ | |
$query = "SELECT lead_source,sales_stage,sum(amount_usdollar/1000) as total, ". | |
"count(*) as opp_count FROM opportunities "; | |
$query .= " WHERE opportunities.deleted=0 "; | |
if ( count($this->lsbo_ids) > 0 ) | |
$query .= "AND opportunities.assigned_user_id IN ('".implode("','",$this->lsbo_ids)."') "; | |
if ( count($this->lsbo_lead_sources) > 0 ) | |
$query .= "AND opportunities.lead_source IN ('".implode("','",$this->lsbo_lead_sources)."') "; | |
else | |
$query .= "AND opportunities.lead_source IN ('".implode("','",array_keys($GLOBALS['app_list_strings']['lead_source_dom']))."') "; | |
/* BEGIN - SECURITY GROUPS */ | |
//this dashlet lives in the Home module so we will need to load a placeholder bean to look up permissions | |
//this logic mimics SugarBean->create_new_list_query() | |
$report_bean = BeanFactory::getBean('Opportunities'); | |
global $current_user, $sugar_config; | |
if($report_bean->bean_implements('ACL') && ACLController::requireSecurityGroup($report_bean->module_dir, 'list') ) | |
{ | |
require_once('modules/SecurityGroups/SecurityGroup.php'); | |
global $current_user; | |
$owner_where = $report_bean->getOwnerWhere($current_user->id); | |
$group_where = SecurityGroup::getGroupWhere($report_bean->table_name,$report_bean->report_bean,$current_user->id); | |
if(!empty($owner_where)){ | |
$query .= " AND (". $owner_where." or ".$group_where.") "; | |
} else { | |
$query .= ' AND '. $group_where; | |
} | |
} | |
/* END - SECURITY GROUPS */ | |
$query .= " GROUP BY sales_stage,lead_source ORDER BY lead_source,sales_stage"; | |
return $query; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment