Esempio n. 1
0
 /**
  * Function to get the list view entries
  * @param Vtiger_Paging_Model $pagingModel
  * @return <Array> - Associative array of record id mapped to Vtiger_Record_Model instance.
  */
 public function getListViewEntries($pagingModel)
 {
     $db = PearDatabase::getInstance();
     $moduleName = $this->getModule()->get('name');
     $moduleFocus = CRMEntity::getInstance($moduleName);
     $moduleModel = Vtiger_Module_Model::getInstance($moduleName);
     $queryGenerator = $this->get('query_generator');
     $listViewContoller = $this->get('listview_controller');
     $listQuery = $queryGenerator->getQuery();
     $startIndex = $pagingModel->getStartIndex();
     $pageLimit = $pagingModel->getPageLimit();
     $importedRecordIds = $this->getLastImportedRecord();
     $listViewRecordModels = array();
     if (count($importedRecordIds) != 0) {
         $moduleModel = $this->get('module');
         $listQuery .= ' AND ' . $moduleModel->basetable . '.' . $moduleModel->basetableid . ' IN (' . implode(',', $importedRecordIds) . ')';
         $listQuery .= " LIMIT {$startIndex}, {$pageLimit}";
         $listResult = $db->pquery($listQuery, array());
         $listViewEntries = $listViewContoller->getListViewRecords($moduleFocus, $moduleName, $listResult);
         $pagingModel->calculatePageRange($listViewEntries);
         foreach ($listViewEntries as $recordId => $record) {
             $record['id'] = $recordId;
             $listViewRecordModels[$recordId] = $moduleModel->getRecordFromArray($record);
         }
     }
     return $listViewRecordModels;
 }
Esempio n. 2
0
 /**
  * Function to get the list view entries
  * @param Vtiger_Paging_Model $pagingModel
  * @return <Array> - Associative array of record id mapped to Vtiger_Record_Model instance.
  */
 public function getListViewEntries($pagingModel)
 {
     $db = PearDatabase::getInstance();
     $module = $this->getModule();
     $moduleName = $module->getName();
     $parentModuleName = $module->getParentName();
     $qualifiedModuleName = $moduleName;
     if (!empty($parentModuleName)) {
         $qualifiedModuleName = $parentModuleName . ':' . $qualifiedModuleName;
     }
     $recordModelClass = Vtiger_Loader::getComponentClassName('Model', 'Record', $qualifiedModuleName);
     $listQuery = $this->getBasicListQuery();
     $startIndex = $pagingModel->getStartIndex();
     $pageLimit = $pagingModel->getPageLimit();
     $orderBy = $this->getForSql('orderby');
     if (!empty($orderBy) && $orderBy === 'smownerid') {
         $fieldModel = Vtiger_Field_Model::getInstance('assigned_user_id', $moduleModel);
         if ($fieldModel->getFieldDataType() == 'owner') {
             $orderBy = 'COALESCE(CONCAT(vtiger_users.first_name,vtiger_users.last_name),vtiger_groups.groupname)';
         }
     }
     if (!empty($orderBy)) {
         $listQuery .= ' ORDER BY ' . $orderBy . ' ' . $this->getForSql('sortorder');
     }
     $sourceModule = $this->get('sourceModule');
     if (!empty($sourceModule)) {
         $tabId = Vtiger_Functions::getModuleId($sourceModule);
         $listQuery .= " WHERE `module` = '{$tabId}' ";
     }
     if ($module->isPagingSupported()) {
         $nextListQuery = $listQuery . ' LIMIT ' . ($startIndex + $pageLimit) . ',1';
         $listQuery .= " LIMIT {$startIndex}, {$pageLimit}";
     }
     $listResult = $db->pquery($listQuery, array());
     $noOfRecords = $db->num_rows($listResult);
     $listViewRecordModels = array();
     for ($i = 0; $i < $noOfRecords; ++$i) {
         $row = $db->query_result_rowdata($listResult, $i);
         $record = new $recordModelClass();
         $record->setData($row);
         $recordModule = Vtiger_Functions::getModuleName($row['module']);
         $record->set('module', vtranslate($recordModule, $recordModule));
         if (method_exists($record, 'getModule') && method_exists($record, 'setModule')) {
             $moduleModel = Settings_Vtiger_Module_Model::getInstance($qualifiedModuleName);
             $record->setModule($moduleModel);
         }
         $listViewRecordModels[$record->getId()] = $record;
     }
     if ($module->isPagingSupported()) {
         $pagingModel->calculatePageRange($listViewRecordModels);
         $nextPageResult = $db->pquery($nextListQuery, array());
         $nextPageNumRows = $db->num_rows($nextPageResult);
         if ($nextPageNumRows <= 0) {
             $pagingModel->set('nextPageExists', false);
         }
     }
     return $listViewRecordModels;
 }
Esempio n. 3
0
 /**
  * Function to get the list view entries
  * @param Vtiger_Paging_Model $pagingModel
  * @return <Array> - Associative array of record id mapped to Vtiger_Record_Model instance.
  */
 public function getListViewEntries($pagingModel)
 {
     $db = PearDatabase::getInstance();
     $module = $this->getModule();
     $moduleName = $module->getName();
     $parentModuleName = $module->getParentName();
     $qualifiedModuleName = $moduleName;
     if (!empty($parentModuleName)) {
         $qualifiedModuleName = $parentModuleName . ':' . $qualifiedModuleName;
     }
     $recordModelClass = Vtiger_Loader::getComponentClassName('Model', 'Record', $qualifiedModuleName);
     $listFields = $module->listFields;
     $listQuery = "SELECT ";
     foreach ($listFields as $fieldName => $fieldLabel) {
         $listQuery .= "{$fieldName}, ";
     }
     $listQuery .= $module->baseIndex . " FROM " . $module->baseTable;
     $params = array();
     $sourceModule = $this->get('sourceModule');
     if (!empty($sourceModule)) {
         $listQuery .= ' WHERE module_name = ?';
         $params[] = $sourceModule;
     }
     $startIndex = $pagingModel->getStartIndex();
     $pageLimit = $pagingModel->getPageLimit();
     $orderBy = $this->getForSql('orderby');
     if (!empty($orderBy)) {
         $listQuery .= ' ORDER BY ' . $orderBy . ' ' . $this->getForSql('sortorder');
     }
     $nextListQuery = $listQuery . ' LIMIT ' . ($startIndex + $pageLimit) . ',1';
     $listQuery .= " LIMIT {$startIndex}," . ($pageLimit + 1);
     $listResult = $db->pquery($listQuery, $params);
     $noOfRecords = $db->num_rows($listResult);
     $listViewRecordModels = array();
     for ($i = 0; $i < $noOfRecords; ++$i) {
         $row = $db->query_result_rowdata($listResult, $i);
         $record = new $recordModelClass();
         $row['module_name'] = vtranslate($row['module_name'], $row['module_name']);
         $row['execution_condition'] = vtranslate($record->executionConditionAsLabel($row['execution_condition']), 'Settings:Workflows');
         $record->setData($row);
         $listViewRecordModels[$record->getId()] = $record;
     }
     $pagingModel->calculatePageRange($listViewRecordModels);
     if ($db->num_rows($listResult) > $pageLimit) {
         array_pop($listViewRecordModels);
         $pagingModel->set('nextPageExists', true);
     } else {
         $pagingModel->set('nextPageExists', false);
     }
     $nextPageResult = $db->pquery($nextListQuery, $params);
     $nextPageNumRows = $db->num_rows($nextPageResult);
     if ($nextPageNumRows <= 0) {
         $pagingModel->set('nextPageExists', false);
     }
     return $listViewRecordModels;
 }
Esempio n. 4
0
 /**
  * Function to get the list view entries
  * @param Vtiger_Paging_Model $pagingModel
  * @return <Array> - Associative array of record id mapped to Vtiger_Record_Model instance.
  */
 public function getListViewEntries($pagingModel)
 {
     $db = PearDatabase::getInstance();
     $module = $this->getModule();
     $parentModuleName = $module->getParentName();
     if (!empty($parentModuleName)) {
         $qualifiedModuleName = $parentModuleName . ':' . $module->getName();
     }
     $recordModelClass = Vtiger_Loader::getComponentClassName('Model', 'Record', $qualifiedModuleName);
     $listFields = $module->listFields;
     $listQuery = 'SELECT ';
     foreach ($listFields as $fieldName => $fieldLabel) {
         $listQuery .= '`' . $fieldName . '`, ';
     }
     $listQuery .= '`' . $module->baseIndex . '` FROM `' . $module->baseTable . '`';
     $params = [];
     $sourceModule = $this->get('sourceModule');
     if (!empty($sourceModule)) {
         $sourceModule = Vtiger_Functions::getModuleName($sourceModule);
         $listQuery .= ' WHERE `tabid` = ?';
         $params[] = $sourceModule;
     }
     $startIndex = $pagingModel->getStartIndex();
     $pageLimit = $pagingModel->getPageLimit();
     $orderBy = $this->getForSql('orderby');
     if (!empty($orderBy)) {
         $listQuery .= ' ORDER BY ' . $orderBy . ' ' . $this->getForSql('sortorder');
     }
     $nextListQuery = $listQuery . ' LIMIT ' . ($startIndex + $pageLimit) . ',1';
     $listQuery .= " LIMIT {$startIndex}," . ($pageLimit + 1);
     $listResult = $db->pquery($listQuery, $params);
     $listViewRecordModels = [];
     while ($row = $db->getRow($listResult)) {
         $recordModel = new $recordModelClass();
         $moduleName = Vtiger_Functions::getModuleName($row['tabid']);
         $relModuleName = Vtiger_Functions::getModuleName($row['reltabid']);
         $row['tabid'] = vtranslate($moduleName, $moduleName);
         $row['reltabid'] = vtranslate($relModuleName, $relModuleName);
         $recordModel->setData($row);
         $listViewRecordModels[$recordModel->getId()] = $recordModel;
     }
     $pagingModel->calculatePageRange($listViewRecordModels);
     if ($listResult->rowCount() > $pageLimit) {
         array_pop($listViewRecordModels);
         $pagingModel->set('nextPageExists', true);
     } else {
         $pagingModel->set('nextPageExists', false);
     }
     $nextPageResult = $db->pquery($nextListQuery, $params);
     if ($nextPageResult->rowCount() <= 0) {
         $pagingModel->set('nextPageExists', false);
     }
     return $listViewRecordModels;
 }
Esempio n. 5
0
 /**
  * Function to get the list view entries
  * @param Vtiger_Paging_Model $pagingModel
  * @return <Array> - Associative array of record id mapped to Vtiger_Record_Model instance.
  */
 public function getListViewEntries($pagingModel)
 {
     $forModule = $this->get('formodule');
     $dependentPicklists = Vtiger_DependencyPicklist::getDependentPicklistFields($forModule);
     $noOfRecords = count($dependentPicklists);
     $recordModelClass = Vtiger_Loader::getComponentClassName('Model', 'Record', 'Settings:PickListDependency');
     $listViewRecordModels = array();
     for ($i = 0; $i < $noOfRecords; $i++) {
         $record = new $recordModelClass();
         $module = $dependentPicklists[$i]['module'];
         unset($dependentPicklists[$i]['module']);
         $record->setData($dependentPicklists[$i]);
         $record->set('sourceModule', $module);
         $record->set('sourceLabel', vtranslate($module, $module));
         $listViewRecordModels[] = $record;
     }
     $pagingModel->calculatePageRange($listViewRecordModels);
     return $listViewRecordModels;
 }
Esempio n. 6
0
 /**
  * Function to get the list view entries
  * @param Vtiger_Paging_Model $pagingModel
  * @return <Array> - Associative array of record id mapped to Vtiger_Record_Model instance.
  */
 public function getListViewEntries($pagingModel)
 {
     $db = PearDatabase::getInstance();
     $moduleName = $this->getModule()->get('name');
     $moduleFocus = CRMEntity::getInstance($moduleName);
     $moduleModel = Vtiger_Module_Model::getInstance($moduleName);
     $queryGenerator = $this->get('query_generator');
     $listViewContoller = $this->get('listview_controller');
     $listQuery = $this->getQuery();
     $listQuery = preg_replace("/vtiger_crmentity.deleted\\s*=\\s*0/i", 'vtiger_crmentity.deleted = 1', $listQuery);
     $startIndex = $pagingModel->getStartIndex();
     $pageLimit = $pagingModel->getPageLimit();
     $orderBy = $this->getForSql('orderby');
     $sortOrder = $this->getForSql('sortorder');
     if (!empty($orderBy)) {
         $listQuery .= ' ORDER BY ' . $orderBy . ' ' . $sortOrder;
     }
     $listQuery .= " LIMIT {$startIndex}," . ($pageLimit + 1);
     $listResult = $db->pquery($listQuery, array());
     $listViewRecordModels = array();
     $listViewEntries = $listViewContoller->getListViewRecords($moduleFocus, $moduleName, $listResult);
     $pagingModel->calculatePageRange($listViewEntries);
     if ($db->num_rows($listResult) > $pageLimit) {
         array_pop($listViewEntries);
         $pagingModel->set('nextPageExists', true);
     } else {
         $pagingModel->set('nextPageExists', false);
     }
     $index = 0;
     foreach ($listViewEntries as $recordId => $record) {
         $rawData = $db->query_result_rowdata($listResult, $index++);
         $record['id'] = $recordId;
         $listViewRecordModels[$recordId] = $moduleModel->getRecordFromArray($record, $rawData);
     }
     return $listViewRecordModels;
 }
Esempio n. 7
0
 /**
  * Function to get the list view entries
  * @param Vtiger_Paging_Model $pagingModel
  * @return <Array> - Associative array of record id mapped to Vtiger_Record_Model instance.
  */
 public function getListViewEntries($pagingModel)
 {
     $db = PearDatabase::getInstance();
     $startIndex = $pagingModel->getStartIndex();
     $pageLimit = $pagingModel->getPageLimit();
     $orderBy = $this->getForSql('orderby');
     $sortOrder = $this->getForSql('sortorder');
     $listQuery = $this->getQuery();
     $searchKey = $this->get('search_key');
     $searchValue = $this->get('search_value');
     if (!empty($searchKey) && !empty($searchValue)) {
         $listQuery .= " WHERE {$searchKey} LIKE '{$searchValue}%'";
     }
     if (!empty($orderBy) && $orderBy === 'smownerid') {
         $fieldModel = Vtiger_Field_Model::getInstance('assigned_user_id', $moduleModel);
         if ($fieldModel->getFieldDataType() == 'owner') {
             $orderBy = 'COALESCE(CONCAT(vtiger_users.first_name,vtiger_users.last_name),vtiger_groups.groupname)';
         }
     }
     if ($orderBy) {
         $listQuery .= " ORDER BY {$orderBy} {$sortOrder}";
     }
     $listQuery .= " LIMIT {$startIndex}," . ($pageLimit + 1);
     $result = $db->pquery($listQuery, array());
     $num_rows = $db->num_rows($result);
     $listViewRecordModels = array();
     for ($i = 0; $i < $num_rows; $i++) {
         $recordModel = new EmailTemplates_Record_Model();
         $recordModel->setModule('EmailTemplates');
         $row = $db->query_result_rowdata($result, $i);
         $listViewRecordModels[$row['templateid']] = $recordModel->setData($row);
     }
     $pagingModel->calculatePageRange($listViewRecordModels);
     if ($num_rows > $pageLimit) {
         array_pop($listViewRecordModels);
         $pagingModel->set('nextPageExists', true);
     } else {
         $pagingModel->set('nextPageExists', false);
     }
     return $listViewRecordModels;
 }
Esempio n. 8
0
 /**
  * Function to get the list view entries
  * @param Vtiger_Paging_Model $pagingModel
  * @return <Array> - Associative array of record id mapped to Vtiger_Record_Model instance.
  */
 public function getListViewEntries($pagingModel)
 {
     $db = PearDatabase::getInstance();
     $moduleName = $this->getModule()->get('name');
     $moduleFocus = CRMEntity::getInstance($moduleName);
     $moduleModel = Vtiger_Module_Model::getInstance($moduleName);
     $queryGenerator = $this->get('query_generator');
     $listViewContoller = $this->get('listview_controller');
     $searchParams = $this->get('search_params');
     if (empty($searchParams)) {
         $searchParams = array();
     }
     $glue = "";
     if (count($queryGenerator->getWhereFields()) > 0 && count($searchParams) > 0) {
         $glue = QueryGenerator::$AND;
     }
     $queryGenerator->parseAdvFilterList($searchParams, $glue);
     $searchKey = $this->get('search_key');
     $searchValue = $this->get('search_value');
     $operator = $this->get('operator');
     if (!empty($searchKey)) {
         $queryGenerator->addUserSearchConditions(array('search_field' => $searchKey, 'search_text' => $searchValue, 'operator' => $operator));
     }
     $orderBy = $this->getForSql('orderby');
     $sortOrder = $this->getForSql('sortorder');
     //List view will be displayed on recently created/modified records
     if (empty($orderBy) && empty($sortOrder) && $moduleName != "Users") {
         $orderBy = 'modifiedtime';
         $sortOrder = 'DESC';
     }
     if (!empty($orderBy)) {
         $columnFieldMapping = $moduleModel->getColumnFieldMapping();
         $orderByFieldName = $columnFieldMapping[$orderBy];
         $orderByFieldModel = $moduleModel->getField($orderByFieldName);
         if ($orderByFieldModel && $orderByFieldModel->getFieldDataType() == Vtiger_Field_Model::REFERENCE_TYPE) {
             //IF it is reference add it in the where fields so that from clause will be having join of the table
             $queryGenerator = $this->get('query_generator');
             $queryGenerator->addWhereField($orderByFieldName);
         }
     }
     if (!empty($orderBy) && $orderBy === 'smownerid') {
         $fieldModel = Vtiger_Field_Model::getInstance('assigned_user_id', $moduleModel);
         if ($fieldModel->getFieldDataType() == 'owner') {
             $orderBy = 'COALESCE(CONCAT(vtiger_users.first_name,vtiger_users.last_name),vtiger_groups.groupname)';
         }
     }
     $listQuery = $this->getQuery();
     $request = new Vtiger_Request($_REQUEST, $_REQUEST);
     $potential_id = $this->get('potential_id');
     if (Settings_SalesProcesses_Module_Model::checkRelatedToPotentialsLimit() && Settings_SalesProcesses_Module_Model::isLimitForModule($request->get('module'))) {
         if (empty($potential_id)) {
             $potential_id = $this->get('potentialid');
             if ($potential_id == '') {
                 $potential_id = -1;
             }
         }
         $newListQuery = '';
         $explodedListQuery = explode('INNER JOIN', $listQuery);
         foreach ($explodedListQuery as $key => $value) {
             $newListQuery .= 'INNER JOIN' . $value;
             if ($key == 0 && $moduleName == 'Products') {
                 $newListQuery .= ' INNER JOIN vtiger_seproductsrel AS seproductsrel ON vtiger_products.productid = seproductsrel.productid ';
             } elseif ($key == 0 && $moduleName == 'Services') {
                 $newListQuery .= ' INNER JOIN vtiger_crmentityrel ON (vtiger_crmentityrel.relcrmid = vtiger_service.serviceid OR vtiger_crmentityrel.crmid = vtiger_service.serviceid) ';
             }
         }
         $newListQuery = trim($newListQuery, 'INNER JOIN');
         if ($moduleName == 'Products') {
             $newListQuery .= " AND seproductsrel.crmid = '{$potential_id}' ";
         } elseif ($moduleName == 'Services') {
             $newListQuery .= " AND ( (vtiger_crmentityrel.crmid = '{$potential_id}' AND module = 'Potentials') OR (vtiger_crmentityrel.relcrmid = '{$potential_id}' AND relmodule = 'Potentials')) ";
         }
         $listQuery = $newListQuery;
     }
     if ($this->get('subProductsPopup')) {
         $listQuery = $this->addSubProductsQuery($listQuery);
     }
     $sourceModule = $this->get('src_module');
     $sourceField = $this->get('src_field');
     if (!empty($sourceModule)) {
         if (method_exists($moduleModel, 'getQueryByModuleField')) {
             $overrideQuery = $moduleModel->getQueryByModuleField($sourceModule, $sourceField, $this->get('src_record'), $listQuery);
             if (!empty($overrideQuery)) {
                 $listQuery = $overrideQuery;
             }
         }
     }
     $startIndex = $pagingModel->getStartIndex();
     $pageLimit = $pagingModel->getPageLimit();
     if (!empty($orderBy)) {
         if ($orderByFieldModel && $orderByFieldModel->getFieldDataType() == Vtiger_Field_Model::REFERENCE_TYPE) {
             $referenceModules = $orderByFieldModel->getReferenceList();
             $referenceNameFieldOrderBy = array();
             foreach ($referenceModules as $referenceModuleName) {
                 $referenceModuleModel = Vtiger_Module_Model::getInstance($referenceModuleName);
                 $referenceNameFields = $referenceModuleModel->getNameFields();
                 $columnList = array();
                 foreach ($referenceNameFields as $nameField) {
                     $fieldModel = $referenceModuleModel->getField($nameField);
                     $columnList[] = $fieldModel->get('table') . $orderByFieldModel->getName() . '.' . $fieldModel->get('column');
                 }
                 if (count($columnList) > 1) {
                     $referenceNameFieldOrderBy[] = getSqlForNameInDisplayFormat(array('first_name' => $columnList[0], 'last_name' => $columnList[1]), 'Users') . ' ' . $sortOrder;
                 } else {
                     $referenceNameFieldOrderBy[] = implode('', $columnList) . ' ' . $sortOrder;
                 }
             }
             $listQuery .= ' ORDER BY ' . implode(',', $referenceNameFieldOrderBy);
         } else {
             $listQuery .= ' ORDER BY ' . $orderBy . ' ' . $sortOrder;
         }
     }
     $viewid = ListViewSession::getCurrentView($moduleName);
     if (empty($viewid)) {
         $viewid = $pagingModel->get('viewid');
     }
     $_SESSION['lvs'][$moduleName][$viewid]['start'] = $pagingModel->get('page');
     ListViewSession::setSessionQuery($moduleName, $listQuery, $viewid);
     //For Products popup in Price Book Related list
     if ($sourceModule !== 'PriceBooks' && $sourceField !== 'priceBookRelatedList') {
         $listQuery .= " LIMIT {$startIndex}," . ($pageLimit + 1);
     }
     $listResult = $db->pquery($listQuery, array());
     $listViewRecordModels = array();
     $listViewEntries = $listViewContoller->getListViewRecords($moduleFocus, $moduleName, $listResult);
     $pagingModel->calculatePageRange($listViewEntries);
     if ($db->num_rows($listResult) > $pageLimit && $sourceModule !== 'PriceBooks' && $sourceField !== 'priceBookRelatedList') {
         array_pop($listViewEntries);
         $pagingModel->set('nextPageExists', true);
     } else {
         $pagingModel->set('nextPageExists', false);
     }
     $index = 0;
     foreach ($listViewEntries as $recordId => $record) {
         $rawData = $db->query_result_rowdata($listResult, $index++);
         $record['id'] = $recordId;
         $listViewRecordModels[$recordId] = $moduleModel->getRecordFromArray($record, $rawData);
         $listViewRecordModels[$recordId]->lockEditView = Users_Privileges_Model::checkLockEdit($moduleName, $recordId);
         $listViewRecordModels[$recordId]->isPermittedToEditView = Users_Privileges_Model::isPermitted($moduleName, 'EditView', $recordId);
         $listViewRecordModels[$recordId]->colorList = Settings_DataAccess_Module_Model::executeColorListHandlers($moduleName, $recordId, $listViewRecordModels[$recordId]);
     }
     return $listViewRecordModels;
 }
Esempio n. 9
0
	/**
	 * Function to get the list view entries
	 * @param Vtiger_Paging_Model $pagingModel
	 * @return <Array> - Associative array of record id mapped to Vtiger_Record_Model instance.
	 */
	public function getListViewEntries($pagingModel) {
		$db = PearDatabase::getInstance();
		$moduleName = $this->getModule()->get('name');
		$moduleFocus = CRMEntity::getInstance($moduleName);
		$moduleModel = Vtiger_Module_Model::getInstance($moduleName);

		$queryGenerator = $this->get('query_generator');
		$listViewContoller = $this->get('listview_controller');

        $orderBy = $this->getForSql('orderby');
		$sortOrder = $this->getForSql('sortorder');

		if(!empty($orderBy)){
            $columnFieldMapping = $moduleModel->getColumnFieldMapping();
            $orderByFieldName = $columnFieldMapping[$orderBy];
            $orderByFieldModel = $moduleModel->getField($orderByFieldName);
            if($orderByFieldModel && $orderByFieldModel->getFieldDataType() == Vtiger_Field_Model::REFERENCE_TYPE){
                //IF it is reference add it in the where fields so that from clause will be having join of the table
                $queryGenerator = $this->get('query_generator');
                $queryGenerator->addWhereField($orderByFieldName);
            }
        }
		if (!empty($orderBy) && $orderBy === 'smownerid') {
			$fieldModel = Vtiger_Field_Model::getInstance('assigned_user_id', $moduleModel);
			if ($fieldModel->getFieldDataType() == 'owner') {
				$orderBy = 'COALESCE(' . getSqlForNameInDisplayFormat(['first_name' => 'vtiger_users.first_name', 'last_name' => 'vtiger_users.last_name'], 'Users') . ',vtiger_groups.groupname)';
			}
		}

		$listQuery = $this->getQuery();
		$listQuery = preg_replace("/vtiger_crmentity.deleted\s*=\s*0/i", 'vtiger_crmentity.deleted = 1', $listQuery);

		$startIndex = $pagingModel->getStartIndex();
		$pageLimit = $pagingModel->getPageLimit();

		if(!empty($orderBy)) {
            if($orderByFieldModel && $orderByFieldModel->isReferenceField()){
                $referenceModules = $orderByFieldModel->getReferenceList();
                $referenceNameFieldOrderBy = array();
                foreach($referenceModules as $referenceModuleName) {
                    $referenceModuleModel = Vtiger_Module_Model::getInstance($referenceModuleName);
                    $referenceNameFields = $referenceModuleModel->getNameFields();

                    $columnList = array();
                    foreach($referenceNameFields as $nameField) {
                        $fieldModel = $referenceModuleModel->getField($nameField);
                        $columnList[] = $fieldModel->get('table').'.'.$fieldModel->get('column');
                    }
                    if(count($columnList) > 1) {
                        $referenceNameFieldOrderBy[] = getSqlForNameInDisplayFormat(array('first_name'=>$columnList[0],'last_name'=>$columnList[1]),'Users').' '.$sortOrder;
                    } else {
                        $referenceNameFieldOrderBy[] = implode('', $columnList).' '.$sortOrder ;
                    }
                }
                $listQuery .= ' ORDER BY '. implode(',',$referenceNameFieldOrderBy);
            }else{
                $listQuery .= ' ORDER BY '. $orderBy . ' ' .$sortOrder;
            }
		}
		$listQuery .= " LIMIT $startIndex,".($pageLimit+1);

		$listResult = $db->pquery($listQuery, array());
		$listViewRecordModels = array();
		$listViewEntries =  $listViewContoller->getListViewRecords($moduleFocus,$moduleName, $listResult);
		$pagingModel->calculatePageRange($listViewEntries);

		if($db->num_rows($listResult) > $pageLimit){
			array_pop($listViewEntries);
			$pagingModel->set('nextPageExists', true);
		}else{
			$pagingModel->set('nextPageExists', false);
		}

		$index = 0;
		foreach($listViewEntries as $recordId => $record) {
			$rawData = $db->query_result_rowdata($listResult, $index++);
			$record['id'] = $recordId;
			$listViewRecordModels[$recordId] = $moduleModel->getRecordFromArray($record, $rawData);
			$listViewRecordModels[$recordId]->lockEditView = Users_Privileges_Model::checkLockEdit($moduleName, $recordId);
			$listViewRecordModels[$recordId]->isPermittedToEditView = Users_Privileges_Model::isPermitted($moduleName, 'EditView', $recordId);
			$listViewRecordModels[$recordId]->colorList = Settings_DataAccess_Module_Model::executeColorListHandlers( $moduleName, $recordId, $listViewRecordModels[$recordId] );
		}
		return $listViewRecordModels;
	}
Esempio n. 10
0
 /**
  * Function to get the list view entries
  * @param Vtiger_Paging_Model $pagingModel
  * @return <Array> - Associative array of record id mapped to Vtiger_Record_Model instance.
  */
 public function getListViewEntries($pagingModel, $searchResult = false)
 {
     $db = PearDatabase::getInstance();
     $moduleName = $this->getModule()->get('name');
     $moduleFocus = CRMEntity::getInstance($moduleName);
     $moduleModel = Vtiger_Module_Model::getInstance($moduleName);
     $currentUser = Users_Record_Model::getCurrentUserModel();
     $queryGenerator = $this->get('query_generator');
     $listViewContoller = $this->get('listview_controller');
     $listViewFields = array('visibility', 'assigned_user_id', 'activitystatus');
     $queryGenerator->setFields(array_unique(array_merge($queryGenerator->getFields(), $listViewFields)));
     $searchParams = $this->get('search_params');
     if (empty($searchParams)) {
         $searchParams = array();
     }
     $glue = "";
     if (count($queryGenerator->getWhereFields()) > 0 && count($searchParams) > 0) {
         $glue = QueryGenerator::$AND;
     }
     $queryGenerator->parseAdvFilterList($searchParams, $glue);
     $searchKey = $this->get('search_key');
     $searchValue = $this->get('search_value');
     $operator = $this->get('operator');
     if (!empty($searchKey)) {
         $queryGenerator->addUserSearchConditions(array('search_field' => $searchKey, 'search_text' => $searchValue, 'operator' => $operator));
     }
     $orderBy = $this->getForSql('orderby');
     $sortOrder = $this->getForSql('sortorder');
     //List view will be displayed on recently created/modified records
     if (empty($orderBy) && empty($sortOrder) && $moduleName != "Users") {
         $orderBy = 'modifiedtime';
         $sortOrder = 'DESC';
     }
     if (!empty($orderBy)) {
         $columnFieldMapping = $moduleModel->getColumnFieldMapping();
         $orderByFieldName = $columnFieldMapping[$orderBy];
         $orderByFieldModel = $moduleModel->getField($orderByFieldName);
         if ($orderByFieldModel && $orderByFieldModel->isReferenceField()) {
             //IF it is reference add it in the where fields so that from clause will be having join of the table
             $queryGenerator = $this->get('query_generator');
             $queryGenerator->setConditionField($orderByFieldName);
             //$queryGenerator->whereFields[] = $orderByFieldName;
         }
     }
     if (!empty($orderBy) && $orderBy === 'smownerid') {
         $fieldModel = Vtiger_Field_Model::getInstance('assigned_user_id', $moduleModel);
         if ($fieldModel->getFieldDataType() == 'owner') {
             $orderBy = 'COALESCE(' . getSqlForNameInDisplayFormat(['first_name' => 'vtiger_users.first_name', 'last_name' => 'vtiger_users.last_name'], 'Users', '') . ', vtiger_groups.groupname)';
         }
     }
     //To combine date and time fields for sorting
     if ($orderBy == 'date_start') {
         $orderBy = "str_to_date(concat(date_start,time_start),'%Y-%m-%d %H:%i:%s')";
     } else {
         if ($orderBy == 'due_date') {
             $orderBy = "str_to_date(concat(due_date,time_end),'%Y-%m-%d %H:%i:%s')";
         }
     }
     $listQuery = $this->getQuery();
     if ($searchResult && $searchResult != '' && is_array($searchResult)) {
         $listQuery .= " AND vtiger_crmentity.crmid IN (" . implode(', ', $searchResult) . ") ";
     }
     unset($searchResult);
     $sourceModule = $this->get('src_module');
     if (!empty($sourceModule)) {
         if (method_exists($moduleModel, 'getQueryByModuleField')) {
             $overrideQuery = $moduleModel->getQueryByModuleField($sourceModule, $this->get('src_field'), $this->get('src_record'), $listQuery);
             if (!empty($overrideQuery)) {
                 $listQuery = $overrideQuery;
             }
         }
     }
     $startIndex = $pagingModel->getStartIndex();
     $pageLimit = $pagingModel->getPageLimit();
     if (!empty($orderBy)) {
         if ($orderByFieldModel && $orderByFieldModel->isReferenceField()) {
             $referenceModules = $orderByFieldModel->getReferenceList();
             $referenceNameFieldOrderBy = array();
             foreach ($referenceModules as $referenceModuleName) {
                 $referenceModuleModel = Vtiger_Module_Model::getInstance($referenceModuleName);
                 $referenceNameFields = $referenceModuleModel->getNameFields();
                 $columnList = array();
                 foreach ($referenceNameFields as $nameField) {
                     $fieldModel = $referenceModuleModel->getField($nameField);
                     $columnList[] = $fieldModel->get('table') . $orderByFieldModel->getName() . '.' . $fieldModel->get('column');
                 }
                 if (count($columnList) > 1) {
                     $referenceNameFieldOrderBy[] = getSqlForNameInDisplayFormat(array('first_name' => $columnList[0], 'last_name' => $columnList[1]), 'Users') . ' ' . $sortOrder;
                 } else {
                     $referenceNameFieldOrderBy[] = implode('', $columnList) . ' ' . $sortOrder;
                 }
             }
             $listQuery .= ' ORDER BY ' . implode(', ', $referenceNameFieldOrderBy);
         } else {
             $listQuery .= ' ORDER BY ' . $orderBy . ' ' . $sortOrder;
         }
     }
     $viewid = ListViewSession::getCurrentView($moduleName);
     if (empty($viewid)) {
         $viewid = $pagingModel->get('viewid');
     }
     $_SESSION['lvs'][$moduleName][$viewid]['start'] = $pagingModel->get('page');
     ListViewSession::setSessionQuery($moduleName, $listQuery, $viewid);
     $listQueryWithNoLimit = $listQuery;
     $listQuery .= " LIMIT {$startIndex}," . ($pageLimit + 1);
     $listResult = $db->pquery($listQuery, array());
     $listViewRecordModels = array();
     $listViewEntries = $listViewContoller->getListViewRecords($moduleFocus, $moduleName, $listResult);
     $pagingModel->calculatePageRange($listViewEntries);
     if ($db->num_rows($listResult) > $pageLimit) {
         array_pop($listViewEntries);
         $pagingModel->set('nextPageExists', true);
     } else {
         $pagingModel->set('nextPageExists', false);
     }
     $groupsIds = Vtiger_Util_Helper::getGroupsIdsForUsers($currentUser->getId());
     $index = 0;
     foreach ($listViewEntries as $recordId => $record) {
         $rawData = $db->query_result_rowdata($listResult, $index++);
         $visibleFields = array('activitytype', 'date_start', 'due_date', 'assigned_user_id', 'visibility', 'smownerid');
         $ownerId = $rawData['smownerid'];
         $visibility = true;
         if (in_array($ownerId, $groupsIds)) {
             $visibility = false;
         } else {
             if ($ownerId == $currentUser->getId()) {
                 $visibility = false;
             }
         }
         if (!$currentUser->isAdminUser() && $rawData['activitytype'] != 'Task' && $rawData['visibility'] == 'Private' && $ownerId && $visibility) {
             foreach ($record as $data => $value) {
                 if (in_array($data, $visibleFields) != -1) {
                     unset($rawData[$data]);
                     unset($record[$data]);
                 }
             }
             $record['subject'] = vtranslate('Busy', 'Events') . '*';
         }
         if ($record['activitytype'] == 'Task') {
             unset($record['visibility']);
             unset($rawData['visibility']);
         }
         $record['id'] = $recordId;
         $listViewRecordModels[$recordId] = $moduleModel->getRecordFromArray($record, $rawData);
         $listViewRecordModels[$recordId]->lockEditView = Users_Privileges_Model::checkLockEdit($moduleName, $recordId);
         $listViewRecordModels[$recordId]->isPermittedToEditView = Users_Privileges_Model::isPermitted($moduleName, 'EditView  ', $recordId);
         $listViewRecordModels[$recordId]->colorList = Settings_DataAccess_Module_Model::executeColorListHandlers($moduleName, $recordId, $listViewRecordModels[$recordId]);
     }
     return $listViewRecordModels;
 }
Esempio n. 11
0
 /**
  * Function to get the list view entries
  * @param Vtiger_Paging_Model $pagingModel
  * @return <Array> - Associative array of record id mapped to Vtiger_Record_Model instance.
  */
 public function getListViewEntries($pagingModel)
 {
     $db = PearDatabase::getInstance();
     $module = $this->getModule();
     $moduleName = $module->getName();
     $parentModuleName = $module->getParentName();
     $qualifiedModuleName = $moduleName;
     if (!empty($parentModuleName)) {
         $qualifiedModuleName = $parentModuleName . ':' . $qualifiedModuleName;
     }
     $recordModelClass = Vtiger_Loader::getComponentClassName('Model', 'Record', $qualifiedModuleName);
     $listQuery = $this->getBasicListQuery();
     $startIndex = $pagingModel->getStartIndex();
     $pageLimit = $pagingModel->getPageLimit();
     $orderBy = $this->getForSql('orderby');
     if (!empty($orderBy)) {
         $listQuery .= ' ORDER BY ' . $orderBy . ' ' . $this->getForSql('sortorder');
     }
     if ($module->isPagingSupported()) {
         $nextListQuery = $listQuery . ' LIMIT ' . ($startIndex + $pageLimit) . ',1';
         $listQuery .= " LIMIT {$startIndex}, {$pageLimit}";
     }
     $listResult = $db->pquery($listQuery, array());
     $noOfRecords = $db->num_rows($listResult);
     $listViewRecordModels = array();
     for ($i = 0; $i < $noOfRecords; ++$i) {
         $row = $db->query_result_rowdata($listResult, $i);
         $record = new $recordModelClass();
         $record->setData($row);
         if (method_exists($record, 'getModule') && method_exists($record, 'setModule')) {
             $moduleModel = Settings_Vtiger_Module_Model::getInstance($qualifiedModuleName);
             $record->setModule($moduleModel);
         }
         $listViewRecordModels[$record->getId()] = $record;
     }
     if ($module->isPagingSupported()) {
         $pagingModel->calculatePageRange($listViewRecordModels);
         $nextPageResult = $db->pquery($nextListQuery, array());
         $nextPageNumRows = $db->num_rows($nextPageResult);
         if ($nextPageNumRows <= 0) {
             $pagingModel->set('nextPageExists', false);
         }
     }
     return $listViewRecordModels;
 }
Esempio n. 12
0
 /**
  * Function to get the list view entries
  * @param Vtiger_Paging_Model $pagingModel
  * @return <Array> - Associative array of record id mapped to Vtiger_Record_Model instance.
  */
 public function getListViewEntries($pagingModel)
 {
     $db = PearDatabase::getInstance();
     $module = $this->getModule();
     $moduleName = $module->getName();
     $parentModuleName = $module->getParentName();
     $qualifiedModuleName = $moduleName;
     if (!empty($parentModuleName)) {
         $qualifiedModuleName = $parentModuleName . ':' . $qualifiedModuleName;
     }
     $recordModelClass = Vtiger_Loader::getComponentClassName('Model', 'Record', $qualifiedModuleName);
     $listFields = $module->listFields;
     unset($listFields['all_tasks']);
     unset($listFields['active_tasks']);
     $listQuery = "SELECT ";
     foreach ($listFields as $fieldName => $fieldLabel) {
         $listQuery .= "{$fieldName}, ";
     }
     $listQuery .= $module->baseIndex . " FROM " . $module->baseTable;
     $params = array();
     $sourceModule = $this->get('sourceModule');
     if (!empty($sourceModule)) {
         $listQuery .= ' WHERE module_name = ?';
         $params[] = $sourceModule;
     }
     $startIndex = $pagingModel->getStartIndex();
     $pageLimit = $pagingModel->getPageLimit();
     $orderBy = $this->getForSql('orderby');
     if (!empty($orderBy) && $orderBy === 'smownerid') {
         $fieldModel = Vtiger_Field_Model::getInstance('assigned_user_id', $moduleModel);
         if ($fieldModel->getFieldDataType() == 'owner') {
             $orderBy = 'COALESCE(CONCAT(vtiger_users.first_name,vtiger_users.last_name),vtiger_groups.groupname)';
         }
     }
     if (!empty($orderBy)) {
         $listQuery .= ' ORDER BY ' . $orderBy . ' ' . $this->getForSql('sortorder');
     }
     $nextListQuery = $listQuery . ' LIMIT ' . ($startIndex + $pageLimit) . ',1';
     $listQuery .= " LIMIT {$startIndex}," . ($pageLimit + 1);
     $listResult = $db->pquery($listQuery, $params);
     $noOfRecords = $db->num_rows($listResult);
     $listViewRecordModels = array();
     for ($i = 0; $i < $noOfRecords; ++$i) {
         $row = $db->query_result_rowdata($listResult, $i);
         $record = new $recordModelClass();
         $module_name = $row['module_name'];
         //To handle translation of calendar to To Do
         if ($module_name == 'Calendar') {
             $module_name = vtranslate('LBL_TASK', $module_name);
         } else {
             $module_name = vtranslate($module_name, $module_name);
         }
         $workflowModel = $record->getInstance($row['workflow_id']);
         $taskList = $workflowModel->getTasks();
         $row['module_name'] = $module_name;
         $row['execution_condition'] = vtranslate($record->executionConditionAsLabel($row['execution_condition']), 'Settings:Workflows');
         $row['summary'] = vtranslate($row['summary'], 'Settings:Workflows');
         $row['all_tasks'] = count($taskList);
         $row['active_tasks'] = $workflowModel->getActiveCountFromRecord($taskList);
         $record->setData($row);
         $listViewRecordModels[$record->getId()] = $record;
     }
     $pagingModel->calculatePageRange($listViewRecordModels);
     if ($db->num_rows($listResult) > $pageLimit) {
         array_pop($listViewRecordModels);
         $pagingModel->set('nextPageExists', true);
     } else {
         $pagingModel->set('nextPageExists', false);
     }
     $nextPageResult = $db->pquery($nextListQuery, $params);
     $nextPageNumRows = $db->num_rows($nextPageResult);
     if ($nextPageNumRows <= 0) {
         $pagingModel->set('nextPageExists', false);
     }
     return $listViewRecordModels;
 }
Esempio n. 13
0
	/**
	 * Function to get the list view entries
	 * @param Vtiger_Paging_Model $pagingModel
	 * @return <Array> - Associative array of record id mapped to Vtiger_Record_Model instance.
	 */
	public function getListViewEntries($pagingModel) {
		$db = PearDatabase::getInstance();

		$module = $this->getModule();
		$moduleName = $module->getName();
		$parentModuleName = $module->getParentName();
		$qualifiedModuleName = $moduleName;
		if(!empty($parentModuleName)) {
			$qualifiedModuleName = $parentModuleName.':'.$qualifiedModuleName;
		}
		$recordModelClass = Vtiger_Loader::getComponentClassName('Model', 'Record', $qualifiedModuleName);

		$listFields = $module->listFields;
		$listQuery = "SELECT ";
		foreach ($listFields as $fieldName => $fieldLabel) {
			if($fieldName == 'processname') {		// Получить название процесса, к которому привязан обработчик
				$listQuery .= "processid, (SELECT name FROM vtiger_process WHERE processid=com_vtiger_workflows.processid) AS processname, ";
				continue;
			}
			$listQuery .= "$fieldName, ";
		}
		$listQuery .= "details, ";
		$listQuery .= $module->baseIndex . " FROM ". $module->baseTable;

		$filterActive = $this->get('filterActive');
		$sourceProcess = $this->get('sourceProcess');
		$sourceModule = $this->get('sourceModule');
		$qWhereItems = array();
		$params = array();
		if($filterActive > -1) {
			$qWhereItems[] = 'active=?';
			$params[] = $filterActive;
		}
		if($sourceProcess > -1) {
			$qWhereItems[] = 'processid=?';
			$params[] = $sourceProcess;
		}
		if(!empty($sourceModule)) {
			$qWhereItems[] = 'module_name=?';
			$params[] = $sourceModule;
		}
		$qWhereCount = count($qWhereItems);
		if($qWhereCount>0) {
			$listQuery .= ' WHERE ' . $qWhereItems[0];
			for($i=1; $i<$qWhereCount;  $i++) {
				$listQuery .= ' AND ' . $qWhereItems[$i];
			}
		}

		$startIndex = $pagingModel->getStartIndex();
		$pageLimit = $pagingModel->getPageLimit();

		$orderBy = $this->getForSql('orderby');
		if (!empty($orderBy) && $orderBy === 'smownerid') { 
			$fieldModel = Vtiger_Field_Model::getInstance('assigned_user_id', $moduleModel); 
			if ($fieldModel->getFieldDataType() == 'owner') { 
				$orderBy = 'COALESCE(CONCAT(vtiger_users.first_name,vtiger_users.last_name),vtiger_groups.groupname)'; 
			} 
		}
		if(!empty($orderBy)) {
			$listQuery .= ' ORDER BY '. $orderBy . ' ' .$this->getForSql('sortorder');
		}
        $nextListQuery = $listQuery.' LIMIT '.($startIndex+$pageLimit).',1';
		$listQuery .= " LIMIT $startIndex,".($pageLimit+1);

		$listResult = $db->pquery($listQuery, $params);
		$noOfRecords = $db->num_rows($listResult);

		$listViewRecordModels = array();
		for($i=0; $i<$noOfRecords; ++$i) {
			$row = $db->query_result_rowdata($listResult, $i);
			$record = new $recordModelClass();
			
			$row['active'] = '<input type="checkbox" class="wf_active" ' . ($row['active'] ? 'checked' : '') . '>';
			
			$row['summary'] = '<a href="index.php?module=Workflows&parent=Settings&view=Edit&record='.$row['workflow_id'].'" title="'.$row['details'].'">' . string_contraction($row['summary'], 60, 5) . '</a>';
			
			$module_name = $row['module_name'];
			if($module_name == 'Calendar') $module_name = vtranslate('LBL_TASK', $module_name);
			else $module_name = vtranslate($module_name, $module_name);
			$row['module_name'] = '<a href="index.php?module='.$row['module_name'].'&view=List">' . $module_name . '</a>';
			
			$row['processname'] = $row['processid']>100 ? '<a href="index.php?module=Process&view=Detail&record='.$row['processid'].'">' . string_contraction($row['processname'], 30) . '</a>' : '--';
			
			$row['execution_condition'] = vtranslate($record->executionConditionAsLabel($row['execution_condition']), 'Settings:Workflows');

			$record->setData($row);
			$listViewRecordModels[$record->getId()] = $record;
		}
		$pagingModel->calculatePageRange($listViewRecordModels);
		
		if($db->num_rows($listResult) > $pageLimit){
			array_pop($listViewRecordModels);
			$pagingModel->set('nextPageExists', true);
		}else{
			$pagingModel->set('nextPageExists', false);
		}
		
        $nextPageResult = $db->pquery($nextListQuery, $params);
        $nextPageNumRows = $db->num_rows($nextPageResult);
        if($nextPageNumRows <= 0) {
            $pagingModel->set('nextPageExists', false);
        }
		return $listViewRecordModels;
	}
Esempio n. 14
0
 /**
  * Function to get the list view entries
  * @param Vtiger_Paging_Model $pagingModel
  * @return <Array> - Associative array of record id mapped to Vtiger_Record_Model instance.
  */
 public function getListViewEntries($pagingModel)
 {
     $db = PearDatabase::getInstance();
     $module = $this->getModule();
     $parentModuleName = $module->getParentName();
     $qualifiedModuleName = 'PDF';
     //$moduleName;
     if (!empty($parentModuleName)) {
         $qualifiedModuleName = $parentModuleName . ':' . $qualifiedModuleName;
     }
     $recordModelClass = Vtiger_Loader::getComponentClassName('Model', 'Record', $qualifiedModuleName);
     $listFields = $module->listFields;
     $listQuery = 'SELECT ';
     foreach ($listFields as $fieldName => $fieldLabel) {
         $listQuery .= '`' . $fieldName . '`, ';
     }
     $listQuery .= '`' . $module->baseIndex . '` FROM `' . $module->baseTable . '`';
     $params = [];
     $sourceModule = $this->get('sourceModule');
     if (!empty($sourceModule)) {
         $listQuery .= ' WHERE `module_name` = ?';
         $params[] = $sourceModule;
     }
     $startIndex = $pagingModel->getStartIndex();
     $pageLimit = $pagingModel->getPageLimit();
     $orderBy = $this->getForSql('orderby');
     if (!empty($orderBy) && $orderBy === 'smownerid') {
         $fieldModel = Vtiger_Field_Model::getInstance('assigned_user_id', $moduleModel);
         if ($fieldModel->getFieldDataType() == 'owner') {
             $orderBy = 'COALESCE(CONCAT(`vtiger_users`.`first_name`, `vtiger_users`.`last_name`), `vtiger_groups`.`groupname`)';
         }
     }
     if (!empty($orderBy)) {
         $listQuery .= ' ORDER BY ' . $orderBy . ' ' . $this->getForSql('sortorder');
     }
     $nextListQuery = $listQuery . ' LIMIT ' . ($startIndex + $pageLimit) . ',1';
     $listQuery .= " LIMIT {$startIndex}," . ($pageLimit + 1);
     $listResult = $db->pquery($listQuery, $params);
     $listViewRecordModels = [];
     while ($row = $db->fetchByAssoc($listResult)) {
         $record = new $recordModelClass();
         $module_name = $row['module_name'];
         //To handle translation of calendar to To Do
         if ($module_name == 'Calendar') {
             $module_name = vtranslate('LBL_TASK', $module_name);
         } else {
             $module_name = vtranslate($module_name, $module_name);
         }
         $row['module_name'] = $module_name;
         $row['summary'] = vtranslate($row['summary'], $qualifiedModuleName);
         $record->setData($row);
         $listViewRecordModels[$record->getId()] = $record;
     }
     $pagingModel->calculatePageRange($listViewRecordModels);
     if ($db->num_rows($listResult) > $pageLimit) {
         array_pop($listViewRecordModels);
         $pagingModel->set('nextPageExists', true);
     } else {
         $pagingModel->set('nextPageExists', false);
     }
     $nextPageResult = $db->pquery($nextListQuery, $params);
     $nextPageNumRows = $db->num_rows($nextPageResult);
     if ($nextPageNumRows <= 0) {
         $pagingModel->set('nextPageExists', false);
     }
     return $listViewRecordModels;
 }
Esempio n. 15
0
 /**
  * Function to get the list view entries
  * @param Vtiger_Paging_Model $pagingModel
  * @return <Array> - Associative array of record id mapped to Vtiger_Record_Model instance.
  */
 public function getListViewEntries($pagingModel)
 {
     $db = PearDatabase::getInstance();
     $moduleName = $this->getModule()->get('name');
     $moduleFocus = CRMEntity::getInstance($moduleName);
     $moduleModel = Vtiger_Module_Model::getInstance($moduleName);
     $queryGenerator = $this->get('query_generator');
     $listViewContoller = $this->get('listview_controller');
     $folderKey = $this->get('folder_id');
     $folderValue = $this->get('folder_value');
     if (!empty($folderValue)) {
         $queryGenerator->addCondition($folderKey, $folderValue, 'e');
     }
     $searchParams = $this->get('search_params');
     if (empty($searchParams)) {
         $searchParams = array();
     }
     $glue = "";
     if (count($queryGenerator->getWhereFields()) > 0 && count($searchParams) > 0) {
         $glue = QueryGenerator::$AND;
     }
     $queryGenerator->parseAdvFilterList($searchParams, $glue);
     $searchKey = $this->get('search_key');
     $searchValue = $this->get('search_value');
     $operator = $this->get('operator');
     if (!empty($searchKey)) {
         $queryGenerator->addUserSearchConditions(array('search_field' => $searchKey, 'search_text' => $searchValue, 'operator' => $operator));
     }
     $orderBy = $this->getForSql('orderby');
     $sortOrder = $this->getForSql('sortorder');
     //List view will be displayed on recently created/modified records
     if (empty($orderBy) && empty($sortOrder) && $moduleName != "Users") {
         $orderBy = 'modifiedtime';
         $sortOrder = 'DESC';
     }
     if (!empty($orderBy)) {
         $columnFieldMapping = $moduleModel->getColumnFieldMapping();
         $orderByFieldName = $columnFieldMapping[$orderBy];
         $orderByFieldModel = $moduleModel->getField($orderByFieldName);
         if ($orderByFieldModel && $orderByFieldModel->getFieldDataType() == Vtiger_Field_Model::REFERENCE_TYPE) {
             //IF it is reference add it in the where fields so that from clause will be having join of the table
             $queryGenerator = $this->get('query_generator');
             $queryGenerator->addWhereField($orderByFieldName);
             //$queryGenerator->whereFields[] = $orderByFieldName;
         }
     }
     if (!empty($orderBy) && $orderBy === 'smownerid') {
         $fieldModel = Vtiger_Field_Model::getInstance('assigned_user_id', $moduleModel);
         if ($fieldModel->getFieldDataType() == 'owner') {
             $orderBy = 'COALESCE(CONCAT(vtiger_users.first_name,vtiger_users.last_name),vtiger_groups.groupname)';
         }
     }
     $listQuery = $this->getQuery();
     $sourceModule = $this->get('src_module');
     if (!empty($sourceModule)) {
         if (method_exists($moduleModel, 'getQueryByModuleField')) {
             $overrideQuery = $moduleModel->getQueryByModuleField($sourceModule, $this->get('src_field'), $this->get('src_record'), $listQuery);
             if (!empty($overrideQuery)) {
                 $listQuery = $overrideQuery;
             }
         }
     }
     $startIndex = $pagingModel->getStartIndex();
     $pageLimit = $pagingModel->getPageLimit();
     if (!empty($orderBy)) {
         if ($orderByFieldModel && $orderByFieldModel->isReferenceField()) {
             $referenceModules = $orderByFieldModel->getReferenceList();
             $referenceNameFieldOrderBy = array();
             foreach ($referenceModules as $referenceModuleName) {
                 $referenceModuleModel = Vtiger_Module_Model::getInstance($referenceModuleName);
                 $referenceNameFields = $referenceModuleModel->getNameFields();
                 $columnList = array();
                 foreach ($referenceNameFields as $nameField) {
                     $fieldModel = $referenceModuleModel->getField($nameField);
                     $columnList[] = $fieldModel->get('table') . $orderByFieldModel->getName() . '.' . $fieldModel->get('column');
                 }
                 if (count($columnList) > 1) {
                     $referenceNameFieldOrderBy[] = getSqlForNameInDisplayFormat(array('first_name' => $columnList[0], 'last_name' => $columnList[1]), 'Users') . ' ' . $sortOrder;
                 } else {
                     $referenceNameFieldOrderBy[] = implode('', $columnList) . ' ' . $sortOrder;
                 }
             }
             $listQuery .= ' ORDER BY ' . implode(',', $referenceNameFieldOrderBy);
         } else {
             $listQuery .= ' ORDER BY ' . $orderBy . ' ' . $sortOrder;
         }
     }
     $viewid = ListViewSession::getCurrentView($moduleName);
     if (empty($viewid)) {
         $viewid = $pagingModel->get('viewid');
     }
     $_SESSION['lvs'][$moduleName][$viewid]['start'] = $pagingModel->get('page');
     ListViewSession::setSessionQuery($moduleName, $listQuery, $viewid);
     $listQuery .= " LIMIT {$startIndex}," . ($pageLimit + 1);
     $listResult = $db->pquery($listQuery, array());
     $listViewRecordModels = array();
     $listViewEntries = $listViewContoller->getListViewRecords($moduleFocus, $moduleName, $listResult);
     $pagingModel->calculatePageRange($listViewEntries);
     if ($db->num_rows($listResult) > $pageLimit) {
         array_pop($listViewEntries);
         $pagingModel->set('nextPageExists', true);
     } else {
         $pagingModel->set('nextPageExists', false);
     }
     $index = 0;
     foreach ($listViewEntries as $recordId => $record) {
         $rawData = $db->query_result_rowdata($listResult, $index++);
         $record['id'] = $recordId;
         $listViewRecordModels[$recordId] = $moduleModel->getRecordFromArray($record, $rawData);
     }
     return $listViewRecordModels;
 }
Esempio n. 16
0
 function getListViewEntries(Vtiger_Paging_Model $paging)
 {
     $db = PearDatabase::getInstance();
     $moduleModel = $this->getModule();
     $module = $moduleModel->getName();
     $fields = $this->get('fields');
     $fieldModels = $moduleModel->getFields();
     if (is_array($fields)) {
         foreach ($fields as $fieldName) {
             $fieldModel = $fieldModels[$fieldName];
             $tableColumns[] = $fieldModel->get('table') . '.' . $fieldModel->get('column');
         }
     }
     $startIndex = $paging->getStartIndex();
     $pageLimit = $paging->getPageLimit();
     $ignoreEmpty = $this->get('ignoreEmpty');
     $focus = CRMEntity::getInstance($module);
     $query = $focus->getQueryForDuplicates($module, $tableColumns, '', $ignoreEmpty);
     $query .= " LIMIT {$startIndex}, " . ($pageLimit + 1);
     $result = $db->pquery($query, array());
     $rows = $db->num_rows($result);
     $this->result = $result;
     $group = 'group0';
     $temp = $fieldValues = array();
     $groupCount = 0;
     $groupRecordCount = 0;
     $entries = array();
     for ($i = 0; $i < $rows; $i++) {
         $entries[] = $db->query_result_rowdata($result, $i);
     }
     $paging->calculatePageRange($entries);
     if ($rows > $pageLimit) {
         array_pop($entries);
         $paging->set('nextPageExists', true);
     } else {
         $paging->set('nextPageExists', false);
     }
     $rows = count($entries);
     for ($i = 0; $i < $rows; $i++) {
         $row = $entries[$i];
         if ($i != 0) {
             $slicedArray = array_slice($row, 1);
             array_walk($temp, 'lower_array');
             array_walk($slicedArray, 'lower_array');
             $arrDiff = array_diff($temp, $slicedArray);
             if (count($arrDiff) > 0) {
                 $groupCount++;
                 $temp = $slicedArray;
                 $groupRecordCount = 0;
             }
             $group = "group" . $groupCount;
         }
         $fieldValues[$group][$groupRecordCount]['recordid'] = $row['recordid'];
         foreach ($row as $field => $value) {
             if ($i == 0 && $field != 'recordid') {
                 $temp[$field] = $value;
             }
             $fieldModel = $fieldModels[$field];
             $resultRow[$field] = $value;
         }
         $fieldValues[$group][$groupRecordCount++] = $resultRow;
     }
     return $fieldValues;
 }
Esempio n. 17
0
 /**
  * Function to get the list view entries
  * @param Vtiger_Paging_Model $pagingModel
  * @return <Array> - Associative array of record id mapped to Vtiger_Record_Model instance.
  */
 public function getListViewEntries($pagingModel)
 {
     $db = PearDatabase::getInstance();
     $startIndex = $pagingModel->getStartIndex();
     $pageLimit = $pagingModel->getPageLimit();
     $orderBy = $this->getForSql('orderby');
     $sortOrder = $this->getForSql('sortorder');
     $listQuery = $this->getQuery();
     $searchKey = $this->get('search_key');
     $searchValue = $this->get('search_value');
     if (!empty($searchKey) && !empty($searchValue)) {
         $listQuery .= " WHERE {$searchKey} LIKE '{$searchValue}%'";
     }
     if ($orderBy) {
         $listQuery .= " ORDER BY {$orderBy} {$sortOrder}";
     }
     $listQuery .= " LIMIT {$startIndex}," . ($pageLimit + 1);
     $result = $db->pquery($listQuery, array());
     $num_rows = $db->num_rows($result);
     $listViewRecordModels = array();
     for ($i = 0; $i < $num_rows; $i++) {
         $recordModel = new EmailTemplates_Record_Model();
         $recordModel->setModule('EmailTemplates');
         $row = $db->query_result_rowdata($result, $i);
         $listViewRecordModels[$row['templateid']] = $recordModel->setData($row);
     }
     $pagingModel->calculatePageRange($listViewRecordModels);
     if ($num_rows > $pageLimit) {
         array_pop($listViewRecordModels);
         $pagingModel->set('nextPageExists', true);
     } else {
         $pagingModel->set('nextPageExists', false);
     }
     return $listViewRecordModels;
 }
Esempio n. 18
0
 /**
  * Function to get the list view entries
  * @param Vtiger_Paging_Model $pagingModel
  * @return <Array> - Associative array of record id mapped to Vtiger_Record_Model instance.
  */
 public function getListViewEntries($pagingModel)
 {
     $db = PearDatabase::getInstance();
     $moduleName = $this->getModule()->get('name');
     $moduleFocus = CRMEntity::getInstance($moduleName);
     $moduleModel = Vtiger_Module_Model::getInstance($moduleName);
     $queryGenerator = $this->get('query_generator');
     $listViewContoller = $this->get('listview_controller');
     $searchKey = $this->get('search_key');
     $searchValue = $this->get('search_value');
     $operator = $this->get('operator');
     if (!empty($searchKey)) {
         $queryGenerator->addUserSearchConditions(array('search_field' => $searchKey, 'search_text' => $searchValue, 'operator' => $operator));
     }
     $orderBy = $this->getForSql('orderby');
     $sortOrder = $this->getForSql('sortorder');
     //List view will be displayed on recently created/modified records
     if (empty($orderBy) && empty($sortOrder) && $moduleName != "Users") {
         $orderBy = 'modifiedtime';
         $sortOrder = 'DESC';
     }
     if (!empty($orderBy)) {
         $columnFieldMapping = $moduleModel->getColumnFieldMapping();
         $orderByFieldName = $columnFieldMapping[$orderBy];
         $orderByFieldModel = $moduleModel->getField($orderByFieldName);
         if ($orderByFieldModel && $orderByFieldModel->getFieldDataType() == Vtiger_Field_Model::REFERENCE_TYPE) {
             //IF it is reference add it in the where fields so that from clause will be having join of the table
             $queryGenerator = $this->get('query_generator');
             $queryGenerator->addWhereField($orderByFieldName);
             //$queryGenerator->whereFields[] = $orderByFieldName;
         }
     }
     //To combine date and time fields for sorting
     if ($orderBy == 'date_start') {
         $orderBy = "str_to_date(concat(date_start,time_start),'%Y-%m-%d %H:%i:%s')";
     } else {
         if ($orderBy == 'due_date') {
             $orderBy = "str_to_date(concat(due_date,time_end),'%Y-%m-%d %H:%i:%s')";
         }
     }
     $listQuery = $this->getQuery();
     $sourceModule = $this->get('src_module');
     if (!empty($sourceModule)) {
         if (method_exists($moduleModel, 'getQueryByModuleField')) {
             $overrideQuery = $moduleModel->getQueryByModuleField($sourceModule, $this->get('src_field'), $this->get('src_record'), $listQuery);
             if (!empty($overrideQuery)) {
                 $listQuery = $overrideQuery;
             }
         }
     }
     $startIndex = $pagingModel->getStartIndex();
     $pageLimit = $pagingModel->getPageLimit();
     if (!empty($orderBy)) {
         if ($orderByFieldModel && $orderByFieldModel->isReferenceField()) {
             $referenceModules = $orderByFieldModel->getReferenceList();
             $referenceNameFieldOrderBy = array();
             foreach ($referenceModules as $referenceModuleName) {
                 $referenceModuleModel = Vtiger_Module_Model::getInstance($referenceModuleName);
                 $referenceNameFields = $referenceModuleModel->getNameFields();
                 $columnList = array();
                 foreach ($referenceNameFields as $nameField) {
                     $fieldModel = $referenceModuleModel->getField($nameField);
                     $columnList[] = $fieldModel->get('table') . $orderByFieldModel->getName() . '.' . $fieldModel->get('column');
                 }
                 if (count($columnList) > 1) {
                     $referenceNameFieldOrderBy[] = getSqlForNameInDisplayFormat(array('first_name' => $columnList[0], 'last_name' => $columnList[1]), 'Users') . ' ' . $sortOrder;
                 } else {
                     $referenceNameFieldOrderBy[] = implode('', $columnList) . ' ' . $sortOrder;
                 }
             }
             $listQuery .= ' ORDER BY ' . implode(',', $referenceNameFieldOrderBy);
         } else {
             $listQuery .= ' ORDER BY ' . $orderBy . ' ' . $sortOrder;
         }
     }
     $viewid = ListViewSession::getCurrentView($moduleName);
     ListViewSession::setSessionQuery($moduleName, $listQuery, $viewid);
     $listQueryWithNoLimit = $listQuery;
     $listQuery .= " LIMIT {$startIndex}," . ($pageLimit + 1);
     $listResult = $db->pquery($listQuery, array());
     $listViewRecordModels = array();
     $listViewEntries = $listViewContoller->getListViewRecords($moduleFocus, $moduleName, $listResult);
     $pagingModel->calculatePageRange($listViewEntries);
     if ($db->num_rows($listResult) > $pageLimit) {
         array_pop($listViewEntries);
         $pagingModel->set('nextPageExists', true);
     } else {
         $pagingModel->set('nextPageExists', false);
     }
     $index = 0;
     foreach ($listViewEntries as $recordId => $record) {
         $rawData = $db->query_result_rowdata($listResult, $index++);
         $record['id'] = $recordId;
         $listViewRecordModels[$recordId] = $moduleModel->getRecordFromArray($record, $rawData);
     }
     return $listViewRecordModels;
 }
Esempio n. 19
0
	/**
	 * Function to get the list view entries
	 * @param Vtiger_Paging_Model $pagingModel
	 * @return <Array> - Associative array of record id mapped to Vtiger_Record_Model instance.
	 */
	public function getListViewEntries($pagingModel)
	{
		$db = PearDatabase::getInstance();

		$moduleName = $this->getModule()->get('name');
		$moduleFocus = CRMEntity::getInstance($moduleName);
		$moduleModel = Vtiger_Module_Model::getInstance($moduleName);

		$queryGenerator = $this->get('query_generator');
		$listViewContoller = $this->get('listview_controller');

		$searchParams = $this->get('search_params');
		if (empty($searchParams)) {
			$searchParams = array();
		}

		$glue = "";
		if (count($queryGenerator->getWhereFields()) > 0 && (count($searchParams)) > 0) {
			$glue = QueryGenerator::$AND;
		}
		$queryGenerator->parseAdvFilterList($searchParams, $glue);

		$searchKey = $this->get('search_key');
		$searchValue = $this->get('search_value');
		$operator = $this->get('operator');
		if (!empty($searchKey)) {
			$queryGenerator->addUserSearchConditions(array('search_field' => $searchKey, 'search_text' => $searchValue, 'operator' => $operator));
		}



		$orderBy = $this->getForSql('orderby');
		$sortOrder = $this->getForSql('sortorder');

		//List view will be displayed on recently created/modified records
		if (empty($orderBy) && empty($sortOrder) && $moduleName != "Users") {
			$orderBy = 'modifiedtime';
			$sortOrder = 'DESC';
		}

		if (!empty($orderBy)) {
			$columnFieldMapping = $moduleModel->getColumnFieldMapping();
			$orderByFieldName = $columnFieldMapping[$orderBy];
			$orderByFieldModel = $moduleModel->getField($orderByFieldName);
			if ($orderByFieldModel && ($orderByFieldModel->isReferenceField() || $orderByFieldModel->getFieldDataType() == Vtiger_Field_Model::CURRENCY_LIST)) {
				//IF it is reference add it in the where fields so that from clause will be having join of the table
				$queryGenerator = $this->get('query_generator');
				$queryGenerator->addWhereField($orderByFieldName);
				//$queryGenerator->whereFields[] = $orderByFieldName;
			}
		}

		if (!empty($orderBy) && $orderBy === 'smownerid') {
			$fieldModel = Vtiger_Field_Model::getInstance('assigned_user_id', $moduleModel);
			if ($fieldModel->getFieldDataType() == 'owner') {
				$orderBy = 'COALESCE(' . getSqlForNameInDisplayFormat(['first_name' => 'vtiger_users.first_name', 'last_name' => 'vtiger_users.last_name'], 'Users') . ',vtiger_groups.groupname)';
			}
		}

		$listQuery = $this->getQuery();

		$sourceModule = $this->get('src_module');
		$sourceField = $this->get('src_field');
		if (!empty($sourceModule)) {
			if (method_exists($moduleModel, 'getQueryByModuleField')) {
				$overrideQuery = $moduleModel->getQueryByModuleField($sourceModule, $this->get('src_field'), $this->get('src_record'), $listQuery, $this->get('currency_id'));
				if (!empty($overrideQuery)) {
					$listQuery = $overrideQuery;
				}
			}
		}

		$startIndex = $pagingModel->getStartIndex();
		$pageLimit = $pagingModel->getPageLimit();

		if (!empty($orderBy)) {
			if ($orderByFieldModel && $orderByFieldModel->isReferenceField()) {
				$referenceModules = $orderByFieldModel->getReferenceList();
				$referenceNameFieldOrderBy = array();
				foreach ($referenceModules as $referenceModuleName) {
					$referenceModuleModel = Vtiger_Module_Model::getInstance($referenceModuleName);
					$referenceNameFields = $referenceModuleModel->getNameFields();

					$columnList = array();
					foreach ($referenceNameFields as $nameField) {
						$fieldModel = $referenceModuleModel->getField($nameField);
						$columnList[] = $fieldModel->get('table') . $orderByFieldModel->getName() . '.' . $fieldModel->get('column');
					}
					if (count($columnList) > 1) {
						$referenceNameFieldOrderBy[] = getSqlForNameInDisplayFormat(array('first_name' => $columnList[0], 'last_name' => $columnList[1]), 'Users') . ' ' . $sortOrder;
					} else {
						$referenceNameFieldOrderBy[] = implode('', $columnList) . ' ' . $sortOrder;
					}
				}
				$listQuery .= ' ORDER BY ' . implode(',', $referenceNameFieldOrderBy);
			} else if ($orderByFieldModel && $orderByFieldModel->getFieldDataType() == Vtiger_Field_Model::CURRENCY_LIST) {
				$listQuery .= ' ORDER BY ' . $orderByFieldModel->getUITypeModel()->getCurrenyListReferenceFieldName() . ' ' . $sortOrder;
			} else {
				$listQuery .= ' ORDER BY ' . $orderBy . ' ' . $sortOrder;
			}
		}

		$viewid = ListViewSession::getCurrentView($moduleName);
		if (empty($viewid)) {
			$viewid = $pagingModel->get('viewid');
		}
		$_SESSION['lvs'][$moduleName][$viewid]['start'] = $pagingModel->get('page');
		ListViewSession::setSessionQuery($moduleName, $listQuery, $viewid);

		//For Pricebooks popup in Products and Services Related list
		if ($sourceField !== 'productsRelatedList') {
			$listQuery .= " LIMIT $startIndex," . ($pageLimit + 1);
		}

		$listResult = $db->pquery($listQuery, array());

		$listViewRecordModels = array();
		$listViewEntries = $listViewContoller->getListViewRecords($moduleFocus, $moduleName, $listResult);

		$pagingModel->calculatePageRange($listViewEntries);

		//To check if next page
		if ($db->num_rows($listResult) > $pageLimit && $sourceField !== 'productsRelatedList') {
			array_pop($listViewEntries);
			$pagingModel->set('nextPageExists', true);
		} else {
			$pagingModel->set('nextPageExists', false);
		}

		$index = 0;
		foreach ($listViewEntries as $recordId => $record) {
			$rawData = $db->query_result_rowdata($listResult, $index++);
			$record['id'] = $recordId;

			// Pass through the src_record state to dependent model
			if ($this->has('src_record')) {
				$rawData['src_record'] = $this->get('src_record');
			}

			$listViewRecordModels[$recordId] = $moduleModel->getRecordFromArray($record, $rawData);
			$listViewRecordModels[$recordId]->lockEditView = Users_Privileges_Model::checkLockEdit($moduleName, $recordId);
			$listViewRecordModels[$recordId]->isPermittedToEditView = Users_Privileges_Model::isPermitted($moduleName, 'EditView', $recordId);
			$listViewRecordModels[$recordId]->colorList = Settings_DataAccess_Module_Model::executeColorListHandlers($moduleName, $recordId, $listViewRecordModels[$recordId]);
		}

		return $listViewRecordModels;
	}
Esempio n. 20
0
 /**
  * Function to get the list view entries
  * @param Vtiger_Paging_Model $pagingModel
  * @return <Array> - Associative array of record id mapped to Vtiger_Record_Model instance.
  */
 public function getListViewEntries($pagingModel)
 {
     global $current_user;
     $db = PearDatabase::getInstance();
     $moduleName = $this->getModule()->get('name');
     $moduleFocus = CRMEntity::getInstance($moduleName);
     $moduleModel = Vtiger_Module_Model::getInstance($moduleName);
     $queryGenerator = $this->get('query_generator');
     $listViewContoller = $this->get('listview_controller');
     $searchKey = $this->get('search_key');
     $searchValue = $this->get('search_value');
     $operator = $this->get('operator');
     if (!empty($searchKey)) {
         $queryGenerator->addUserSearchConditions(array('search_field' => $searchKey, 'search_text' => $searchValue, 'operator' => $operator));
     }
     $orderBy = $this->getForSql('orderby');
     $sortOrder = $this->getForSql('sortorder');
     //List view will be displayed on recently created/modified records
     if (empty($orderBy) && empty($sortOrder) && $moduleName != "Users") {
         $orderBy = 'modifiedtime';
         $orderBy = 'createdtime';
         $sortOrder = 'DESC';
     }
     if (!empty($orderBy)) {
         $columnFieldMapping = $moduleModel->getColumnFieldMapping();
         $orderByFieldName = $columnFieldMapping[$orderBy];
         $orderByFieldModel = $moduleModel->getField($orderByFieldName);
         if ($orderByFieldModel && $orderByFieldModel->getFieldDataType() == Vtiger_Field_Model::REFERENCE_TYPE) {
             //IF it is reference add it in the where fields so that from clause will be having join of the table
             $queryGenerator = $this->get('query_generator');
             $queryGenerator->addWhereField($orderByFieldName);
             //$queryGenerator->whereFields[] = $orderByFieldName;
         }
     }
     $listQuery = $this->getQuery();
     $sourceModule = $this->get('src_module');
     if (!empty($sourceModule)) {
         if (method_exists($moduleModel, 'getQueryByModuleField')) {
             $overrideQuery = $moduleModel->getQueryByModuleField($sourceModule, $this->get('src_field'), $this->get('src_record'), $listQuery);
             if (!empty($overrideQuery)) {
                 $listQuery = $overrideQuery;
             }
         }
     }
     $startIndex = $pagingModel->getStartIndex();
     $pageLimit = $pagingModel->getPageLimit();
     //Modified by jmangarret 16jun2015
     if ($current_user->roleid == "H9") {
         $listQuery .= ' AND smownerid=' . $current_user->id;
     }
     //Modified by jmangarret 13ene2016 popUP seleccionar localizadores desde Registro de Ventas
     if ($moduleName == "Localizadores" && $sourceModule == "RegistroDeVentas") {
         $listQuery .= ' AND vtiger_localizadores.procesado=0';
     }
     //Modified by jmangarret 03feb2016 popUP seleccionar cuentas desde Comsiones Satelites
     if ($moduleName == "Accounts" && $sourceModule == "ComisionSatelites") {
         $listQuery .= ' AND vtiger_account.account_type="Satelite"';
     }
     if (!empty($orderBy)) {
         if ($orderByFieldModel && $orderByFieldModel->isReferenceField()) {
             $referenceModules = $orderByFieldModel->getReferenceList();
             $referenceNameFieldOrderBy = array();
             foreach ($referenceModules as $referenceModuleName) {
                 $referenceModuleModel = Vtiger_Module_Model::getInstance($referenceModuleName);
                 $referenceNameFields = $referenceModuleModel->getNameFields();
                 $columnList = array();
                 foreach ($referenceNameFields as $nameField) {
                     $fieldModel = $referenceModuleModel->getField($nameField);
                     $columnList[] = $fieldModel->get('table') . $orderByFieldModel->getName() . '.' . $fieldModel->get('column');
                 }
                 if (count($columnList) > 1) {
                     $referenceNameFieldOrderBy[] = getSqlForNameInDisplayFormat(array('first_name' => $columnList[0], 'last_name' => $columnList[1]), 'Users') . ' ' . $sortOrder;
                 } else {
                     $referenceNameFieldOrderBy[] = implode('', $columnList) . ' ' . $sortOrder;
                 }
             }
             $listQuery .= ' ORDER BY ' . implode(',', $referenceNameFieldOrderBy);
         } else {
             $listQuery .= ' ORDER BY ' . $orderBy . ' ' . $sortOrder;
         }
     }
     $viewid = ListViewSession::getCurrentView($moduleName);
     ListViewSession::setSessionQuery($moduleName, $listQuery, $viewid);
     $listQuery .= " LIMIT {$startIndex}," . ($pageLimit + 1);
     $listResult = $db->pquery($listQuery, array());
     $listViewRecordModels = array();
     $listViewEntries = $listViewContoller->getListViewRecords($moduleFocus, $moduleName, $listResult);
     $pagingModel->calculatePageRange($listViewEntries);
     if ($db->num_rows($listResult) > $pageLimit) {
         array_pop($listViewEntries);
         $pagingModel->set('nextPageExists', true);
     } else {
         $pagingModel->set('nextPageExists', false);
     }
     $index = 0;
     foreach ($listViewEntries as $recordId => $record) {
         $rawData = $db->query_result_rowdata($listResult, $index++);
         $record['id'] = $recordId;
         $listViewRecordModels[$recordId] = $moduleModel->getRecordFromArray($record, $rawData);
     }
     return $listViewRecordModels;
 }