get('cvid'); } /** * Function to get the Module to which the record belongs * @return Vtiger_Module_Model */ public function getModule() { return $this->module; } /** * Function to set the Module to which the record belongs * @param $moduleName * @return Vtiger_Record_Model or Module Specific Record Model instance */ public function setModule($moduleName) { $this->module = Vtiger_Module_Model::getInstance($moduleName); return $this; } public static function getInstanceById($cvId) { $db = PearDatabase::getInstance(); $sql = 'SELECT * FROM vtiger_customview WHERE cvid = ?'; $params = array($cvId); $result = $db->pquery($sql, $params); if ($db->num_rows($result) > 0) { $row = $db->query_result_rowdata($result, 0); $customView = new self(); return $customView->setData($row)->setModule($row['entitytype']); } return null; } /** * @param $skipRecords * @param $module * @return array * @throws Exception */ public function getRecordIds($skipRecords = false, $module = false) { $db = PearDatabase::getInstance(); $cvId = $this->getId(); $moduleModel = $this->getModule(); $moduleName = $moduleModel->get('name'); $baseTableName = $moduleModel->get('basetable'); $baseTableId = $moduleModel->get('basetableid'); $listViewModel = ITS4YouMobileApp_ListView_Model::getInstance($moduleName, $cvId); $queryGenerator = $listViewModel->get('query_generator'); $searchKey = $this->get('search_key'); $searchValue = $this->get('search_value'); $operator = $this->get('operator'); if (!empty($searchValue)) { $queryGenerator->addUserSearchConditions(array('search_field' => $searchKey, 'search_text' => $searchValue, 'operator' => $operator)); } if ($moduleName == 'Documents') { $folderValue = $this->get('folder_value'); if (!empty($folderValue)) { $queryGenerator->addCondition($this->get('folder_id'), $folderValue, 'e'); } } $searchParams = $this->get('search_params'); if (empty($searchParams)) { $searchParams = array(); } $transformedSearchParams = Vtiger_Util_Helper::transferListSearchParamsToFilterCondition($searchParams, $moduleModel); $glue = ""; if ($this->php7_count($queryGenerator->getWhereFields()) > 0 && ($this->php7_count($transformedSearchParams)) > 0) { $glue = QueryGenerator::$AND; } $queryGenerator->parseAdvFilterList($transformedSearchParams, $glue); $listQuery = $queryGenerator->getQuery(); if ($module == 'RecycleBin') { $listQuery = preg_replace("/vtiger_crmentity.deleted\s*=\s*0/i", 'vtiger_crmentity.deleted = 1', $listQuery); } if ($skipRecords && !empty($skipRecords) && is_array($skipRecords) && $this->php7_count($skipRecords) > 0) { $listQuery .= ' AND ' . $baseTableName . '.' . $baseTableId . ' NOT IN (' . generateQuestionMarks($skipRecords) . ')'; $params = array($skipRecords); } $result = $db->pquery($listQuery, $params); $noOfRecords = $db->num_rows($result); $recordIds = array(); for ($i = 0; $i < $noOfRecords; ++$i) { $recordIds[] = $db->query_result($result, $i, $baseTableId); } return $recordIds; } protected function php7_count($value) { // PHP 8.x does not allow count(null) or count(string) if (is_null($value)) return 0; if (!is_array($value)) return 1; return count($value); } }