示例#1
0
 /**
  * Check if ListViewData query is UTF-8 encoded
  *
  * @dataProvider dataProvider
  * @group 62763
  * @return void
  */
 public function testQueryEncoding($searchValue, $expected)
 {
     $_REQUEST = array('module' => 'Contacts', 'action' => 'index', 'searchFormTab' => 'basic_search', 'query' => 'true', 'name_basic' => $searchValue);
     $bean = BeanFactory::getBean('Accounts');
     $listViewData = new ListViewData();
     $result = $listViewData->getListViewData($bean, '');
     $this->assertEquals($expected, $result['query']);
 }
示例#2
0
 /**
  * Test asserts order by value
  *
  * @group 58890
  * @return void
  */
 public function testOrderBy()
 {
     $bean = new SugarBean58890();
     $listViewData = new ListViewData();
     $listViewData->listviewName = $bean->module_name;
     $listViewData->setVariableName($bean->object_name, '', $listViewData->listviewName);
     if (!empty($listViewData->var_order_by) && !empty($_SESSION[$listViewData->var_order_by])) {
         unset($_SESSION[$listViewData->var_order_by]);
     }
     $listViewData->getListViewData($bean, '', -1, -1, array('name' => array()));
     $this->assertEquals('date_entered DESC', $bean->orderByString58890, 'Order by date_entered DESC should be used');
     $GLOBALS['current_user']->setPreference('listviewOrder', array('orderBy' => 'name', 'sortOrder' => 'ASC'), 0, $listViewData->var_name);
     $listViewData->getListViewData($bean, '', -1, -1, array('name' => array()));
     $this->assertEquals('name ASC', $bean->orderByString58890, 'User\'s preference should be used');
 }
 public function getListViewData($seed, $where, $offset = -1, $limit = -1, $filter_fields = array(), $params = array(), $id_field = 'id')
 {
     // add is_archived and warn_in_months field manually to list of fields that should be retrieved ($filter_fields). so we can be sure that we can access them in the $result array. this is needed for proper highlightning per contract
     $addedFilterFields = array_merge($filter_fields, array('is_archived' => true, 'warn_in_months' => true));
     $isIndexView = !array_key_exists('searchFormTab', $_REQUEST);
     // user has opened the index view of the module but not used the search yet.
     $isBasicSearch = array_key_exists('searchFormTab', $_REQUEST) && 'basic_search' === $_REQUEST['searchFormTab'];
     // executing a basic search query
     $isQueryCleared = array_key_exists('clear_query', $_REQUEST) && $_REQUEST['clear_query'];
     // advanced/basic search. clicked on "Clear"
     if ($isIndexView || $isBasicSearch || $isQueryCleared) {
         $where = empty($where) ? 'is_archived = 0' : $where . ' and is_archived = 0';
     }
     $result = parent::getListViewData($seed, $where, $offset, $limit, $addedFilterFields, $params, $id_field);
     /* calculate the maximum finalcosts value if you want to use the HsvHighlighter
      * $contract = oqc_ExternalContractQuery::getBiggestExternalContract();
      * $maxFinalcosts = $contract->finalcosts;
      */
     // create Highlighter instance used for color calculation
     $highlighter = new RedYellowDateHighlighter();
     foreach ($result['data'] as &$externalContract) {
         // only highlight if
         // not archived and
         // some end date is set and
         // end date not in past (?) TODO how can we determine that..
         $isHighlighted = !$externalContract['IS_ARCHIVED'] && !empty($externalContract['ENDDATE']);
         if ($isHighlighted) {
             $externalContract['customRowColor'] = $highlighter->getHighlightningColor($externalContract['ENDDATE'], $externalContract['WARN_IN_MONTHS']);
         }
     }
     return $result;
 }
 public function getListViewData($seed, $where, $offset = -1, $limit = -1, $filter_fields = array(), $params = array(), $id_field = 'id')
 {
     // add packaged_product_ids field manually to list of fields that should be retrieved ($filter_fields). so we can be sure that we can access the PACKAGED_PRODUCT_IDS fields in the $result array. this is needed for proper highlightning per product bean depending whether it contains other products or not.
     $addedFilterFields = array_merge($filter_fields, array('packaged_product_ids' => true, 'is_option' => true));
     $result = parent::getListViewData($seed, $where, $offset, $limit, $addedFilterFields, $params, $id_field);
     $highlighter = new PackageHighlighter();
     foreach ($result['data'] as &$productArray) {
         $productArray['customRowColor'] = $highlighter->getHighlightningColor($productArray);
     }
     //   $GLOBALS['log']->error('Product ListViewData '. var_export($result, true));
     return $result;
 }
示例#5
0
 /**
  * Performs the search
  *
  * @param  $query   string what we are searching for
  * @param  $modules array  modules we are searching in
  * @param  $offset  int    search result offset
  * @return array
  */
 protected function _performSearch($query, $modules, $offset = -1)
 {
     $primary_module = '';
     $results = array();
     require_once 'include/SearchForm/SearchForm2.php';
     $where = '';
     $searchEmail = preg_match("/^([^\\%]|\\%)*@([^\\%]|\\%)*\$/", $query);
     foreach ($modules as $moduleName) {
         if (empty($primary_module)) {
             $primary_module = $moduleName;
         }
         $searchFields = SugarSpot::getSearchFields($moduleName);
         $class = $GLOBALS['beanList'][$moduleName];
         $return_fields = array();
         $seed = new $class();
         if (empty($searchFields[$moduleName])) {
             continue;
         }
         if ($class == 'aCase') {
             $class = 'Case';
         }
         foreach ($searchFields[$moduleName] as $k => $v) {
             $keep = false;
             $searchFields[$moduleName][$k]['value'] = $query;
             if (!empty($GLOBALS['dictionary'][$class]['unified_search'])) {
                 if (empty($GLOBALS['dictionary'][$class]['fields'][$k]['unified_search'])) {
                     if (isset($searchFields[$moduleName][$k]['db_field'])) {
                         foreach ($searchFields[$moduleName][$k]['db_field'] as $field) {
                             if (!empty($GLOBALS['dictionary'][$class]['fields'][$field]['unified_search'])) {
                                 $return_fields[] = $field;
                                 $keep = true;
                             }
                         }
                     }
                     if (!$keep) {
                         if (strpos($k, 'email') === false || !$searchEmail) {
                             unset($searchFields[$moduleName][$k]);
                         }
                     }
                 } else {
                     $return_fields[] = $k;
                 }
             } else {
                 if (empty($GLOBALS['dictionary'][$class]['fields'][$k])) {
                     unset($searchFields[$moduleName][$k]);
                 } else {
                     switch ($GLOBALS['dictionary'][$class]['fields'][$k]['type']) {
                         case 'id':
                         case 'date':
                         case 'datetime':
                         case 'bool':
                             unset($searchFields[$moduleName][$k]);
                         default:
                             $return_fields[] = $k;
                     }
                 }
             }
         }
         $searchForm = new SearchForm($seed, $moduleName);
         $searchForm->setup(array($moduleName => array()), $searchFields, '', 'saved_views');
         $where_clauses = $searchForm->generateSearchWhere();
         $where = "";
         if (count($where_clauses) > 0) {
             $where = '((' . implode(' ) OR ( ', $where_clauses) . '))';
         }
         $lvd = new ListViewData();
         $lvd->additionalDetails = false;
         $max = !empty($sugar_config['max_spotresults_initial']) ? $sugar_config['max_spotresults_initial'] : 5;
         if ($offset !== -1) {
             $max = !empty($sugar_config['max_spotresults_more']) ? $sugar_config['max_spotresults_more'] : 20;
         }
         $params = array();
         if ($moduleName == 'Reports') {
             $params['overrideOrder'] = true;
             $params['orderBy'] = 'name';
         }
         $results[$moduleName] = $lvd->getListViewData($seed, $where, $offset, $max, $return_fields, $params, 'id');
     }
     return $results;
 }