Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save betobaz/60a00befea04e74631e3 to your computer and use it in GitHub Desktop.
Save betobaz/60a00befea04e74631e3 to your computer and use it in GitHub Desktop.
SugarCRM: Visibility: Modify SQL
<?php
if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
class YourVisibilityClass extends SugarVisibility{
protected $bean;
public function __construct($bean)
{
$this->bean = $bean;
$this->module_dir = $this->bean->module_dir;
}
public function addVisibilityWhereQuery(SugarQuery $sugarQuery, $options = array())
{
global $current_user, $timedate;
$aclRole = new ACLRole();
$rolesNames = $aclRole->getUserRoleNames($current_user->id); //
$where = null;
//$GLOBALS['log']->fatal('Tasks_By_Day_Mobile::addVisibilityWhere:: llamando al where personalizado'.print_r($sugarQuery,true));
if( count($rolesNames) && in_array('Salesman', $rolesNames) ){
$meeting_dateStart = new SugarDateTime();
$meeting_dateEnd = new SugarDateTime();
$dateStart = $timedate->tzUser($meeting_dateStart, $current_user)->setTime('00','00','00')->asDb();
$dateEnd = $timedate->tzUser($meeting_dateEnd, $current_user)->setTime('23','59','59')->asDb();
$sugarQuery->where()->between('date_start', $dateStart, $dateEnd);
}
//$GLOBALS['log']->fatal("query ".$sugarQuery->compileSql());
return $sugarQuery;
}
}
<?php
$dictionary['Task']['visibility'] = array(
"YourVisibilityClass" => true,
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment