Esempio n. 1
0
 function getReportCharts($category)
 {
     global $current_user;
     $chartsList = array();
     require_once 'modules/Reports/SavedReport.php';
     $sq = new SugarQuery();
     $savedReportBean = BeanFactory::getBean('Reports');
     $sq->from($savedReportBean);
     // Make sure the user isn't seeing reports they don't have access to
     $modules = array_keys(getACLDisAllowedModules());
     if (count($modules)) {
         $sq->where()->notIn('module', $modules);
     }
     //create the $where statement(s)
     $sq->where()->notEquals('chart_type', 'none');
     switch ($category) {
         case 'global':
             // build global where string
             $sq->where()->equals('saved_reports.team_set_id', '1');
             break;
         case 'myTeams':
             // build myTeams where string
             $myTeams = $current_user->get_my_teams();
             $teamWhere = '';
             foreach ($myTeams as $team_id => $team_name) {
                 if ($team_id != '1' && $team_id != $current_user->getPrivateTeamID()) {
                     if ($teamWhere == '') {
                         $teamWhere .= ' ';
                     } else {
                         $teamWhere .= 'OR ';
                     }
                     $teamWhere .= "saved_reports.team_set_id='" . $team_id . "' ";
                 }
             }
             $sq->whereRaw($teamWhere);
             break;
         case 'mySaved':
             // build mySaved where string
             $sq->where()->equals('saved_reports.team_set_id', $current_user->getPrivateTeamID());
             break;
         case 'myFavorites':
             global $current_user;
             $sugaFav = BeanFactory::getBean('SugarFavorites');
             $current_favorites_beans = $sugaFav->getUserFavoritesByModule('Reports', $current_user);
             $current_favorites = array();
             foreach ((array) $current_favorites_beans as $key => $val) {
                 array_push($current_favorites, $val->record_id);
             }
             if (is_array($current_favorites) && !empty($current_favorites)) {
                 $sq->where()->in('saved_reports.id', array_values($current_favorites));
             } else {
                 $sq->where()->in('saved_reports.id', array('-1'));
             }
             break;
         default:
             break;
     }
     //retrieve array of reports
     $savedReports = $savedReportBean->fetchFromQuery($sq);
     $chartsList = array();
     if (!empty($savedReports)) {
         foreach ($savedReports as $savedReport) {
             // clint - fixes bug #20398
             // only display dashlets that are from visibile modules and that the user has permission to list
             require_once 'include/MySugar/MySugar.php';
             $myDashlet = new MySugar($savedReport->module);
             $displayDashlet = $myDashlet->checkDashletDisplay();
             if ($displayDashlet) {
                 $title = getReportNameTranslation($savedReport->name);
                 $report_def = array('title' => $title, 'onclick' => 'return SUGAR.mySugar.addDashlet(\'' . $savedReport->id . '\', \'chart\', \'' . $savedReport->module . '\');');
                 array_push($chartsList, $report_def);
             }
         }
     }
     asort($chartsList);
     $this->dashlets[$category] = $chartsList;
 }
 /**
  * Add Visibility to a SugarQuery Object
  * @param SugarQuery $sugarQuery
  * @param array $options
  * @return object|SugarQuery
  */
 public function addVisibilityWhereQuery(SugarQuery $sugarQuery, $options = array())
 {
     $where = $this->addVisibilityPortal('', 'where');
     if (!empty($where)) {
         $sugarQuery->whereRaw($where);
     }
     return $sugarQuery;
 }
Esempio n. 3
0
 /**
  * {@inheritdoc}
  */
 public function addVisibilityWhereQuery(SugarQuery $sugarQuery, array $options = array())
 {
     if (!$this->getOption('where_condition')) {
         return $sugarQuery;
     }
     $cond = '';
     $this->addVisibility($cond);
     if (!empty($cond)) {
         $sugarQuery->whereRaw($cond);
     }
     return $sugarQuery;
 }
Esempio n. 4
0
 /**
  * For Floats we need to round down to the precision of the passed in value, since the db's could be showing
  * something different
  *
  * @param Number $value                         The value for which we are trying to filter
  * @param String $fieldName                     What field we are trying to modify
  * @param SugarBean $bean                       The associated SugarBean
  * @param SugarQuery $q                         The full query object
  * @param SugarQuery_Builder_Where $where       The where object for the filter
  * @param String $op                            The filter operation we are trying to do
  * @return bool
  * @throws SugarApiExceptionInvalidParameter
  */
 public function fixForFilter(&$value, $fieldName, SugarBean $bean, SugarQuery $q, SugarQuery_Builder_Where $where, $op)
 {
     // if we have an array, pull the first value
     if (is_array($value)) {
         $v = $value[1];
     } else {
         $v = $value;
     }
     $decimal_separator_location = substr(strrchr($v, '.'), 1);
     // if we don't have a decimal, just use the normal methods back up the chain
     // since it's a whole number that is being searched on
     if ($decimal_separator_location === false) {
         return true;
     }
     // ROUND(<value>, <precision>) is the standard across all DB's we support
     $field = "ROUND({$fieldName}, " . strlen($decimal_separator_location) . ")";
     switch ($op) {
         case '$equals':
             $q->whereRaw("{$field} = {$value}");
             return false;
         case '$not_equals':
             $q->whereRaw("{$field} != {$value}");
             return false;
         case '$between':
             if (!is_array($value) || count($value) != 2) {
                 throw new SugarApiExceptionInvalidParameter('$between requires an array with two values.');
             }
             $q->whereRaw("{$field} BETWEEN {$value['0']} AND {$value['1']}");
             return false;
         case '$lt':
             $q->whereRaw("{$field} < {$value}");
             return false;
         case '$lte':
             $q->whereRaw("{$field} <= {$value}");
             return false;
         case '$gt':
             $q->whereRaw("{$field} > {$value}");
             return false;
         case '$gte':
             $q->whereRaw("{$field} >= {$value}");
             return false;
     }
     return true;
 }