/** * 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; }
/** * 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; }
$smarty->assign("LISTENTITY", $listview_entries); $smarty->assign("SELECT_SCRIPT", $view_script); $smarty->assign("AVALABLE_FIELDS", getMergeFields($currentModule, "available_fields")); $smarty->assign("FIELDS_TO_MERGE", getMergeFields($currentModule, "fileds_to_merge")); //Added to select Multiple records in multiple pages $smarty->assign("SELECTEDIDS", vtlib_purify($_REQUEST['selobjs'])); $smarty->assign("ALLSELECTEDIDS", vtlib_purify($_REQUEST['allselobjs'])); $smarty->assign("CURRENT_PAGE_BOXES", implode(array_keys($listview_entries), ";")); $navigationOutput = getTableHeaderSimpleNavigation($navigation_array, $url_string, "Contacts", "index", $viewid); $alphabetical = AlphabeticalSearch($currentModule, 'index', 'lastname', 'true', 'basic', "", "", "", "", $viewid); $fieldnames = $controller->getAdvancedSearchOptionString(); $criteria = getcriteria_options(); $smarty->assign("CRITERIA", $criteria); $smarty->assign("FIELDNAMES", $fieldnames); $smarty->assign("NAVIGATION", $navigationOutput); $smarty->assign("ALPHABETICAL", $alphabetical); $smarty->assign("MODULE", $currentModule); $smarty->assign("SINGLE_MOD", 'Contact'); $check_button = Button_Check($currentModule); $smarty->assign("CHECK", $check_button); ListViewSession::setSessionQuery($currentModule, $list_query, $viewid); // Gather the custom link information to display include_once 'vtlib/Vtiger/Link.php'; $customlink_params = array('MODULE' => $currentModule, 'ACTION' => vtlib_purify($_REQUEST['action']), 'CATEGORY' => $category); $smarty->assign('CUSTOM_LINKS', Vtiger_Link::getAllByType(getTabid($currentModule), array('LISTVIEWBASIC', 'LISTVIEW'), $customlink_params)); // END if (isset($_REQUEST['ajax']) && $_REQUEST['ajax'] != '') { $smarty->display("ListViewEntries.tpl"); } else { $smarty->display("ListView.tpl"); }
/** * Overrided to add HTML content for callstatus irrespective of the filters */ public function getListViewEntries($pagingModel) { $db = PearDatabase::getInstance(); $moduleName = $this->getModule()->get('name'); $moduleFocus = CRMEntity::getInstance($moduleName); $moduleModel = Vtiger_Module_Model::getInstance($moduleName); //Add the direction field to the query irrespective of filter $queryGenerator = $this->get('query_generator'); $fields = $queryGenerator->getFields(); array_push($fields, 'direction'); $queryGenerator->setFields($fields); $this->set('query_generator', $queryGenerator); //END $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->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(); if (!empty($orderBy)) { if ($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); } //Adding the HTML content based on the callstatus and direction to the records foreach ($listViewEntries as $recordId => $record) { //To Replace RecordingUrl by Icon $recordingUrl = explode('>', $listViewEntries[$recordId]['recordingurl']); $url = explode('<', $recordingUrl[1]); if ($url[0] != '' && $listViewEntries[$recordId]['callstatus'] == 'completed') { $listViewEntries[$recordId]['recordingurl'] = $recordingUrl[0] . '>' . '<i class="icon-volume-up"></i>' . '</a>'; } else { $listViewEntries[$recordId]['recordingurl'] = ''; } if ($listViewEntries[$recordId]['direction'] == 'outbound') { if ($listViewEntries[$recordId]['callstatus'] == 'ringing' || $listViewEntries[$recordId]['callstatus'] == 'in-progress') { $listViewEntries[$recordId]['callstatus'] = '<span class="label label-info"><i class="icon-arrow-up icon-white"> </i> ' . $listViewEntries[$recordId]["callstatus"] . '</span>'; } else { if ($listViewEntries[$recordId]['callstatus'] == 'completed') { $listViewEntries[$recordId]['callstatus'] = '<span class="label label-success"><i class="icon-arrow-up icon-white"> </i> ' . $listViewEntries[$recordId]["callstatus"] . '</span>'; } else { if ($listViewEntries[$recordId]['callstatus'] == 'no-answer') { $listViewEntries[$recordId]['callstatus'] = '<span class="label label-important"><i class="icon-arrow-up icon-white"> </i> ' . $listViewEntries[$recordId]["callstatus"] . '</span>'; } else { $listViewEntries[$recordId]['callstatus'] = '<span class="label label-warning"><i class="icon-arrow-up icon-white"> </i> ' . $listViewEntries[$recordId]["callstatus"] . '</span>'; } } } } else { if ($listViewEntries[$recordId]['direction'] == 'inbound') { if ($listViewEntries[$recordId]['callstatus'] == 'ringing' || $listViewEntries[$recordId]['callstatus'] == 'in-progress') { $listViewEntries[$recordId]['callstatus'] = '<span class="label label-info"><i class="icon-arrow-down icon-white"> </i> ' . $listViewEntries[$recordId]["callstatus"] . '</span>'; } else { if ($listViewEntries[$recordId]['callstatus'] == 'completed') { $listViewEntries[$recordId]['callstatus'] = '<span class="label label-success"><i class="icon-arrow-down icon-white"> </i> ' . $listViewEntries[$recordId]["callstatus"] . '</span>'; } else { if ($listViewEntries[$recordId]['callstatus'] == 'no-answer') { $listViewEntries[$recordId]['callstatus'] = '<span class="label label-important"><i class="icon-arrow-down icon-white"> </i> ' . $listViewEntries[$recordId]["callstatus"] . '</span>'; } else { $listViewEntries[$recordId]['callstatus'] = '<span class="label label-warning"><i class="icon-arrow-down icon-white"> </i> ' . $listViewEntries[$recordId]["callstatus"] . '</span>'; } } } } } } //END $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; }
/** Function to get related list entries in detailed array format * @param $module -- modulename:: Type string * @param $relatedmodule -- relatedmodule:: Type string * @param $focus -- focus:: Type object * @param $query -- query:: Type string * @param $button -- buttons:: Type string * @param $returnset -- returnset:: Type string * @param $id -- id:: Type string * @param $edit_val -- edit value:: Type string * @param $del_val -- delete value:: Type string * @returns $related_entries -- related entires:: Type string array */ function GetRelatedListBase($module, $relatedmodule, $focus, $query, $button, $returnset, $id = '', $edit_val = '', $del_val = '', $skipActions = false) { $log = LoggerManager::getLogger('account_list'); $log->debug("Entering GetRelatedList(" . $module . "," . $relatedmodule . "," . get_class($focus) . "," . $query . "," . $button . "," . $returnset . "," . $edit_val . "," . $del_val . ") method ..."); require_once 'Smarty_setup.php'; require_once "data/Tracker.php"; require_once 'include/database/PearDatabase.php'; global $adb, $app_strings, $current_language; $current_module_strings = return_module_language($current_language, $module); global $list_max_entries_per_page, $urlPrefix, $currentModule, $theme, $theme_path, $theme_path, $mod_strings; $smarty = new vtigerCRM_Smarty(); if (!isset($where)) { $where = ""; } $button = '<table cellspacing=0 cellpadding=2><tr><td>' . $button . '</td></tr></table>'; // Added to have Purchase Order as form Title $theme_path = "themes/" . $theme . "/"; $image_path = $theme_path . "images/"; $smarty->assign("MOD", $mod_strings); $smarty->assign("APP", $app_strings); $smarty->assign("THEME", $theme); $smarty->assign("IMAGE_PATH", $image_path); $smarty->assign("MODULE", $relatedmodule); // We do not have RelatedListView in Detail View mode of Calendar module. So need to skip it. if ($module != 'Calendar') { $focus->initSortByField($relatedmodule); } //Retreive the list from Database //Appending the security parameter Security fix by Don if ($relatedmodule != 'Faq' && $relatedmodule != 'PriceBook' && $relatedmodule != 'Vendors' && $relatedmodule != 'Users') { global $current_user; $secQuery = getNonAdminAccessControlQuery($relatedmodule, $current_user); if (strlen($secQuery) > 1) { $query = appendFromClauseToQuery($query, $secQuery); } } if ($relatedmodule == 'Leads') { $query .= " AND vtiger_leaddetails.converted = 0"; } if (isset($where) && $where != '') { $query .= ' and ' . $where; } if (!$_SESSION['rlvs'][$module][$relatedmodule]) { $modObj = new ListViewSession(); $modObj->sortby = $focus->default_order_by; $modObj->sorder = $focus->default_sort_order; $_SESSION['rlvs'][$module][$relatedmodule] = get_object_vars($modObj); } if (!empty($_REQUEST['order_by'])) { if (method_exists($focus, getSortOrder)) { $sorder = $focus->getSortOrder(); } if (method_exists($focus, getOrderBy)) { $order_by = $focus->getOrderBy(); } if (isset($order_by) && $order_by != '') { $_SESSION['rlvs'][$module][$relatedmodule]['sorder'] = $sorder; $_SESSION['rlvs'][$module][$relatedmodule]['sortby'] = $order_by; } } elseif ($_SESSION['rlvs'][$module][$relatedmodule]) { $sorder = $_SESSION['rlvs'][$module][$relatedmodule]['sorder']; $order_by = $_SESSION['rlvs'][$module][$relatedmodule]['sortby']; } else { $order_by = $focus->default_order_by; $sorder = $focus->default_sort_order; } //Added by Don for AssignedTo ordering issue in Related Lists $query_order_by = $order_by; if ($order_by == 'smownerid') { $userNameSql = getSqlForNameInDisplayFormat(array('first_name' => 'vtiger_users.first_name', 'last_name' => 'vtiger_users.last_name'), 'Users'); $query_order_by = "case when (vtiger_users.user_name not like '') then {$userNameSql} else vtiger_groups.groupname end "; } elseif ($order_by != 'crmid' && !empty($order_by)) { $tabname = getTableNameForField($relatedmodule, $order_by); if ($tabname !== '' and $tabname != NULL) { $query_order_by = $tabname . "." . $query_order_by; } } if (!empty($query_order_by)) { $query .= ' ORDER BY ' . $query_order_by . ' ' . $sorder; } if ($relatedmodule == 'Calendar') { $mod_listquery = "activity_listquery"; } else { $mod_listquery = strtolower($relatedmodule) . "_listquery"; } $_SESSION[$mod_listquery] = $query; $url_qry = "&order_by=" . $order_by . "&sorder=" . $sorder; $computeCount = isset($_REQUEST['withCount']) ? $_REQUEST['withCount'] : ''; if (PerformancePrefs::getBoolean('LISTVIEW_COMPUTE_PAGE_COUNT', false) === true || (bool) $computeCount == true) { //Retreiving the no of rows if ($relatedmodule == "Calendar") { //for calendar related list, count will increase when we have multiple contacts //relationship for single activity $count_query = mkCountQuery($query); $count_result = $adb->query($count_query); $noofrows = $adb->query_result($count_result, 0, "count"); } else { $count_query = mkCountQuery($query); $count_result = $adb->query($count_query); if ($adb->num_rows($count_result) > 0) { $noofrows = $adb->query_result($count_result, 0, "count"); } else { $noofrows = $adb->num_rows($count_result); } } } else { $noofrows = null; } //Setting Listview session object while sorting/pagination if (isset($_REQUEST['relmodule']) && $_REQUEST['relmodule'] != '' && $_REQUEST['relmodule'] == $relatedmodule) { $relmodule = vtlib_purify($_REQUEST['relmodule']); if ($_SESSION['rlvs'][$module][$relmodule]) { setSessionVar($_SESSION['rlvs'][$module][$relmodule], $noofrows, $list_max_entries_per_page, $module, $relmodule); } } global $relationId; $start = RelatedListViewSession::getRequestCurrentPage($relationId, $query); $navigation_array = VT_getSimpleNavigationValues($start, $list_max_entries_per_page, $noofrows); $limit_start_rec = ($start - 1) * $list_max_entries_per_page; $list_result = $adb->pquery($query . " LIMIT {$limit_start_rec}, {$list_max_entries_per_page}", array()); /* Save the related list in session for when we click in a register * from this list we will can navigate with the arrows left and right, to move only in this related list */ $relcv = new CustomView(); $relviewId = $relcv->getViewId($relatedmodule); ListViewSession::setSessionQuery($relatedmodule, $query, $relviewId); $_SESSION['lvs'][$relatedmodule][$relviewId]['start'] = $start; //Retreive the List View Table Header $id = vtlib_purify($_REQUEST['record']); $listview_header = getListViewHeader($focus, $relatedmodule, '', $sorder, $order_by, $id, '', $module, $skipActions); //"Accounts"); if ($noofrows > 15) { $smarty->assign('SCROLLSTART', '<div style="overflow:auto;height:315px;width:100%;">'); $smarty->assign('SCROLLSTOP', '</div>'); } $smarty->assign("LISTHEADER", $listview_header); if ($module == 'PriceBook' && $relatedmodule == 'Products') { $listview_entries = getListViewEntries($focus, $relatedmodule, $list_result, $navigation_array, 'relatedlist', $returnset, $edit_val, $del_val, '', '', '', '', $skipActions); } if ($module == 'Products' && $relatedmodule == 'PriceBooks') { $listview_entries = getListViewEntries($focus, $relatedmodule, $list_result, $navigation_array, 'relatedlist', $returnset, 'EditListPrice', 'DeletePriceBookProductRel', '', '', '', '', $skipActions); } elseif ($relatedmodule == 'SalesOrder') { $listview_entries = getListViewEntries($focus, $relatedmodule, $list_result, $navigation_array, 'relatedlist', $returnset, 'SalesOrderEditView', 'DeleteSalesOrder', '', '', '', '', $skipActions); } else { $listview_entries = getListViewEntries($focus, $relatedmodule, $list_result, $navigation_array, 'relatedlist', $returnset, $edit_val, $del_val, '', '', '', '', $skipActions); } $navigationOutput = array(); $navigationOutput[] = getRecordRangeMessage($list_result, $limit_start_rec, $noofrows); if (empty($id) && !empty($_REQUEST['record'])) { $id = vtlib_purify($_REQUEST['record']); } $navigationOutput[] = getRelatedTableHeaderNavigation($navigation_array, $url_qry, $module, $relatedmodule, $id); $related_entries = array('header' => $listview_header, 'entries' => $listview_entries, 'navigation' => $navigationOutput); $log->debug("Exiting GetRelatedList method ..."); return $related_entries; }
/** * 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; }
$smarty->assign("NO_FOLDERS", "yes"); } $smarty->assign("NO_OF_FOLDERS", $foldercount); $smarty->assign("FOLDERS", $folders); $smarty->assign("EMPTY_FOLDERS", $emptyfolders); $smarty->assign("ALL_FOLDERS", array_merge($folders, $emptyfolders)); //Added to select Multiple records in multiple pages $smarty->assign("SELECTEDIDS", vtlib_purify($_REQUEST['selobjs'])); $smarty->assign("ALLSELECTEDIDS", vtlib_purify($_REQUEST['allselobjs'])); $alphabetical = AlphabeticalSearch($currentModule, 'index', 'notes_title', 'true', 'basic', "", "", "", "", $viewid); $fieldnames = $controller->getAdvancedSearchOptionString(); $criteria = getcriteria_options(); $smarty->assign("CRITERIA", $criteria); $smarty->assign("FIELDNAMES", $fieldnames); $smarty->assign("ALPHABETICAL", $alphabetical); $smarty->assign("NAVIGATION", $navigationOutput); $smarty->assign("RECORD_COUNTS", $record_string); $smarty->assign("IS_ADMIN", $current_user->is_admin); $check_button = Button_Check($module); $smarty->assign("CHECK", $check_button); ListViewSession::setSessionQuery($currentModule, $focus->query, $viewid); // Gather the custom link information to display include_once 'vtlib/Vtiger/Link.php'; $customlink_params = array('MODULE' => $currentModule, 'ACTION' => vtlib_purify($_REQUEST['action']), 'CATEGORY' => $category); $smarty->assign('CUSTOM_LINKS', Vtiger_Link::getAllByType(getTabid($currentModule), array('LISTVIEWBASIC', 'LISTVIEW'), $customlink_params)); // END if (isset($_REQUEST['ajax']) && $_REQUEST['ajax'] != '' || $_REQUEST['mode'] == 'ajax') { $smarty->display("DocumentsListViewEntries.tpl"); } else { $smarty->display("DocumentsListView.tpl"); }
/** * 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; }
/** * 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; }
/** * 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; }