grthtrhthjhtyjytjytkergtrhtrjytjerhrfh4:24 29/09/2026query = $query; $this->results = $results; } public function display() { $headers = $this->getListViewHeaders(); $total = $this->results->getTotal(); if ($total > 1) { $size = $this->query->getSize(); if ($size) { $from = $this->query->getFrom(); $string = $this->query->getSearchString(); $page = (int)($from / $size) + 1; $prev = $page > 1; $next = $total - $from > $size; $last = (int)($total / $size) + ($total%$size === 0 ? 0 : 1); $this->view->getTemplate()->assign('pagination', [ 'prev' => $prev, 'next' => $next, 'page' => $page, 'last' => $last, 'size' => $size, 'from' => $from, 'total' => $total, 'string' => $string, ]); } else { throw new SearchException('Search Size can not be Zero.', SearchException::ZERO_SIZE); } } $this->view->getTemplate()->assign('total', $total); $this->view->getTemplate()->assign('headers', $headers); $this->view->getTemplate()->assign('results', $this->results); $this->view->getTemplate()->assign('resultsAsBean', $this->results->getHitsAsBeans()); parent::display(); } /** * * @return array of header info * @throws Exception */ protected function getListViewHeaders() { $headers = []; $listViewDefs = $this->getListViewDefs(); foreach ($listViewDefs as $module => $listViewDef) { $bean = BeanFactory::getBean($module); if (!$bean) { throw new Exception('Module bean not found for search results: ' . $module); } foreach ($listViewDef as $fieldKey => $fieldValue) { if (isset($fieldValue['default']) && $fieldValue['default']) { $header = $this->getListViewHeader($bean, $fieldKey, $fieldValue); $headers[$module][$fieldKey] = array_merge($fieldValue, $header); } } } return $headers; } /** * * @return array of list view definitions */ protected function getListViewDefs() { $listViewDefs = []; if ($this->results->isGroupedByModule()) { $modules = array_keys($this->results->getHits()); foreach ($modules as $module) { $viewList = new ViewList(); $viewList->type = 'list'; $viewList->module = $module; $metaDataFile = $viewList->getMetaDataFile(); require($metaDataFile); } } return $listViewDefs; } /** * * @param SugarBean $bean * @param string $fieldKey * @param string $fieldValue * @return array of header */ protected function getListViewHeader(SugarBean $bean, $fieldKey, $fieldValue) { $fieldDef = $bean->getFieldDefinition(strtolower($fieldKey)); $header = [ 'label' => $this->getListViewHeaderLabel($bean, $fieldValue, $fieldDef), 'comment' => isset($fieldDef['comment']) ? $fieldDef['comment'] : null, 'field' => $fieldDef['name'], ]; return $header; } /** * * @param SugarBean $bean * @param array $fieldValue * @param array $fieldDef * @return array of label */ protected function getListViewHeaderLabel(SugarBean $bean, $fieldValue, $fieldDef) { $label = isset($fieldValue['label']) ? LangText::get( $fieldValue['label'], null, LangText::USING_ALL_STRINGS, true, true, $bean->module_name ) : null; if (!$label) { $label = isset($fieldDef['vname']) ? LangText::get($fieldDef['vname'], null, LangText::USING_ALL_STRINGS, true, false, $bean->module_name) : null; } return $label; } }