Beispiel #1
0
 function queryToSelectFilteredRecords($module, $fieldnames, $filterOrAlertInstance, $pagingModel)
 {
     if ($filterOrAlertInstance instanceof Mobile_WS_SearchFilterModel) {
         return $filterOrAlertInstance->execute($fieldnames, $pagingModel);
     }
     global $adb;
     $moduleWSId = Mobile_WS_Utils::getEntityModuleWSId($module);
     $columnByFieldNames = Mobile_WS_Utils::getModuleColumnTableByFieldNames($module, $fieldnames);
     // Build select clause similar to Webservice query
     $selectColumnClause = "CONCAT('{$moduleWSId}','x',vtiger_crmentity.crmid) as id,";
     foreach ($columnByFieldNames as $fieldname => $fieldinfo) {
         $selectColumnClause .= sprintf("%s.%s as %s,", $fieldinfo['table'], $fieldinfo['column'], $fieldname);
     }
     $selectColumnClause = rtrim($selectColumnClause, ',');
     $query = $filterOrAlertInstance->query();
     $query = preg_replace("/SELECT.*FROM(.*)/i", "SELECT {$selectColumnClause} FROM \$1", $query);
     if ($pagingModel !== false) {
         $query .= sprintf(" LIMIT %s, %s", $pagingModel->currentCount(), $pagingModel->limit());
     }
     $prequeryResult = $adb->pquery($query, $filterOrAlertInstance->queryParameters());
     return new SqlResultIterator($adb, $prequeryResult);
 }