示例#1
0
 function buildWhere()
 {
     global $current_user;
     $returnArray = array();
     if (!is_array($this->filters)) {
         // use defaults
         $this->filters = array();
         foreach ($this->searchFields as $name => $params) {
             if (!empty($params['default'])) {
                 $this->filters[$name] = $params['default'];
             }
         }
     }
     foreach ($this->filters as $name => $params) {
         if (!empty($params)) {
             if ($name == 'assigned_user_id' && $this->myItemsOnly) {
                 continue;
             }
             // don't handle assigned user filter if filtering my items only
             $widgetDef = $this->seedBean->field_defs[$name];
             $widgetClass = $this->layoutManager->getClassFromWidgetDef($widgetDef, true);
             $widgetDef['table'] = $this->seedBean->table_name;
             $widgetDef['table_alias'] = $this->seedBean->table_name;
             if (!empty($widgetDef['source']) && $widgetDef['source'] == 'custom_fields') {
                 $widgetDef['table'] = $this->seedBean->table_name . "_cstm";
                 $widgetDef['table_alias'] = $widgetDef['table'];
             }
             switch ($widgetDef['type']) {
                 // handle different types
                 case 'date':
                 case 'datetime':
                 case 'datetimecombo':
                     if (is_array($params) && !empty($params)) {
                         if (!empty($params['date'])) {
                             $widgetDef['input_name0'] = $params['date'];
                         }
                         $filter = 'queryFilter' . $params['type'];
                     } else {
                         $filter = 'queryFilter' . $params;
                     }
                     array_push($returnArray, $widgetClass->{$filter}($widgetDef, true));
                     break;
                 case 'assigned_user_name':
                     // This type runs through the SugarWidgetFieldname class, and needs a little extra help to make it through
                     if (!isset($widgetDef['column_key'])) {
                         $widgetDef['column_key'] = $name;
                     }
                     // No break here, we want to run through the default handler
                 // No break here, we want to run through the default handler
                 case 'relate':
                     if (isset($widgetDef['link']) && $this->seedBean->load_relationship($widgetDef['link'])) {
                         $widgetLink = $widgetDef['link'];
                         $widgetDef['module'] = $this->seedBean->{$widgetLink}->focus->module_name;
                         $widgetDef['link'] = $this->seedBean->{$widgetLink}->getRelationshipObject()->name;
                     }
                     // No break - run through the default handler
                 // No break - run through the default handler
                 default:
                     $widgetDef['input_name0'] = $params;
                     if (is_array($params) && !empty($params)) {
                         // handle array query
                         array_push($returnArray, $widgetClass->queryFilterone_of($widgetDef, false));
                     } else {
                         array_push($returnArray, $widgetClass->queryFilterStarts_With($widgetDef, true));
                     }
                     $widgetDef['input_name0'] = $params;
                     break;
             }
         }
     }
     if ($this->myItemsOnly) {
         array_push($returnArray, $this->seedBean->table_name . '.' . "assigned_user_id = '" . $current_user->id . "'");
     }
     return $returnArray;
 }