本文整理汇总了PHP中QueryGenerator类的典型用法代码示例。如果您正苦于以下问题:PHP QueryGenerator类的具体用法?PHP QueryGenerator怎么用?PHP QueryGenerator使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了QueryGenerator类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: populateTo
public function populateTo($request)
{
$viewer = $this->getViewer($request);
$inventoryRecordId = $request->get('record');
$recordModel = Vtiger_Record_Model::getInstanceById($inventoryRecordId, $request->getModule());
$inventoryModule = $recordModel->getModule();
$inventotyfields = $inventoryModule->getFields();
$toEmailConsiderableFields = array('contact_id', 'account_id', 'vendor_id');
$db = PearDatabase::getInstance();
$to = array();
$to_info = array();
$toMailNamesList = array();
foreach ($toEmailConsiderableFields as $fieldName) {
if (!array_key_exists($fieldName, $inventotyfields)) {
continue;
}
$fieldModel = $inventotyfields[$fieldName];
if (!$fieldModel->isViewable()) {
continue;
}
$fieldValue = $recordModel->get($fieldName);
if (empty($fieldValue)) {
continue;
}
$referenceList = $fieldModel->getReferenceList();
$referenceModule = $referenceList[0];
$fieldLabel = Vtiger_Util_Helper::getLabel($fieldValue);
$referenceModuleModel = Vtiger_Module_Model::getInstance($referenceModule);
$emailFields = $referenceModuleModel->getFieldsByType('email');
if (count($emailFields) <= 0) {
continue;
}
$current_user = Users_Record_Model::getCurrentUserModel();
$queryGenerator = new QueryGenerator($referenceModule, $current_user);
$queryGenerator->setFields(array_keys($emailFields));
$query = $queryGenerator->getQuery();
$query .= ' AND crmid = ' . $fieldValue;
$result = $db->pquery($query, array());
$num_rows = $db->num_rows($result);
if ($num_rows <= 0) {
continue;
}
foreach ($emailFields as $fieldName => $emailFieldModel) {
$emailValue = $db->query_result($result, 0, $fieldName);
if (!empty($emailValue)) {
$to[] = $emailValue;
$to_info[$fieldValue][] = $emailValue;
$toMailNamesList[$fieldValue][] = array('label' => $fieldLabel, 'value' => $emailValue);
break;
}
}
if (!empty($to)) {
break;
}
}
$viewer->assign('TO', $to);
$viewer->assign('TOMAIL_NAMES_LIST', $toMailNamesList);
$viewer->assign('TOMAIL_INFO', $to_info);
}
示例2: getWorkflowQuery
public function getWorkflowQuery($workflow)
{
$conditions = Zend_Json::decode(decode_html($workflow->test));
$moduleName = $workflow->moduleName;
$queryGenerator = new QueryGenerator($moduleName, $this->user);
$queryGenerator->setFields(array('id'));
$this->addWorkflowConditionsToQueryGenerator($queryGenerator, $conditions);
if ($moduleName == 'Calendar' || $moduleName == 'Events') {
if ($conditions) {
$queryGenerator->addConditionGlue('AND');
}
// We should only get the records related to proper activity type
if ($moduleName == 'Calendar') {
$queryGenerator->addCondition('activitytype', 'Emails', 'n');
$queryGenerator->addCondition('activitytype', 'Task', 'e', 'AND');
} else {
if ($moduleName == "Events") {
$queryGenerator->addCondition('activitytype', 'Emails', 'n');
$queryGenerator->addCondition('activitytype', 'Task', 'n', 'AND');
}
}
}
$query = $queryGenerator->getQuery();
return $query;
}
示例3: process
function process(Vtiger_Request $request)
{
global $log;
$log->debug("Entering ./views/MiniListWizard.php::process");
$currentUser = Users_Record_Model::getCurrentUserModel();
$viewer = $this->getViewer($request);
$moduleName = $request->getModule();
$viewer->assign('MODULE_NAME', $moduleName);
$viewer->assign('WIZARD_STEP', $request->get('step'));
switch ($request->get('step')) {
case 'step1':
$modules = Vtiger_Module_Model::getSearchableModules();
//Since comments is not treated as seperate module
unset($modules['ModComments']);
$viewer->assign('MODULES', $modules);
break;
case 'step2':
$selectedModule = $request->get('selectedModule');
$filters = CustomView_Record_Model::getAllByGroup($selectedModule);
$viewer->assign('ALLFILTERS', $filters);
break;
case 'step3':
$selectedModule = $request->get('selectedModule');
$filterid = $request->get('filterid');
$db = PearDatabase::getInstance();
$generator = new QueryGenerator($selectedModule, $currentUser);
$generator->initForCustomViewById($filterid);
$listviewController = new ListViewController($db, $currentUser, $generator);
$listviewController->getListViewHeaderFields();
$viewer->assign('LIST_VIEW_CONTROLLER', $listviewController);
$viewer->assign('SELECTED_MODULE', $selectedModule);
break;
}
$viewer->view('dashboards/MiniListWizard.tpl', $moduleName);
}
示例4: getExportQuery
/**
* Function that generates Export Query based on the mode
* @param Vtiger_Request $request
* @return <String> export query
*/
function getExportQuery(Vtiger_Request $request)
{
$currentUser = Users_Record_Model::getCurrentUserModel();
$mode = $request->getMode();
$cvId = $request->get('viewname');
$moduleName = $request->get('source_module');
$queryGenerator = new QueryGenerator($moduleName, $currentUser);
$queryGenerator->initForCustomViewById($cvId);
$fieldInstances = $this->moduleFieldInstances;
$accessiblePresenceValue = array(0, 2);
foreach ($fieldInstances as $field) {
// Check added as querygenerator is not checking this for admin users
$presence = $field->get('presence');
if (in_array($presence, $accessiblePresenceValue)) {
$fields[] = $field->getName();
}
}
$queryGenerator->setFields($fields);
$query = $queryGenerator->getQuery();
if (in_array($moduleName, getInventoryModules())) {
$query = $this->moduleInstance->getExportQuery($this->focus, $query);
}
$this->accessibleFields = $queryGenerator->getFields();
switch ($mode) {
case 'ExportAllData':
return $query;
break;
case 'ExportCurrentPage':
$pagingModel = new Vtiger_Paging_Model();
$limit = $pagingModel->getPageLimit();
$currentPage = $request->get('page');
if (empty($currentPage)) {
$currentPage = 1;
}
$currentPageStart = ($currentPage - 1) * $limit;
if ($currentPageStart < 0) {
$currentPageStart = 0;
}
$query .= ' LIMIT ' . $currentPageStart . ',' . $limit;
return $query;
break;
case 'ExportSelectedRecords':
$idList = $this->getRecordsListFromRequest($request);
$baseTable = $this->moduleInstance->get('basetable');
$baseTableColumnId = $this->moduleInstance->get('basetableid');
if (!empty($idList)) {
if (!empty($baseTable) && !empty($baseTableColumnId)) {
$idList = implode(',', $idList);
$query .= ' AND ' . $baseTable . '.' . $baseTableColumnId . ' IN (' . $idList . ')';
}
} else {
$query .= ' AND ' . $baseTable . '.' . $baseTableColumnId . ' NOT IN (' . implode(',', $request->get('excluded_ids')) . ')';
}
return $query;
break;
default:
return $query;
break;
}
}
示例5: render
public static function render($userInputObject, $user)
{
global $list_max_entries_per_page;
$adb = PearDatabase::getInstance();
$viewer = new Import_UI_Viewer();
$ownerId = $userInputObject->get('foruser');
$owner = new Users();
$owner->id = $ownerId;
$owner->retrieve_entity_info($ownerId, 'Users');
if (!is_admin($user) && $user->id != $owner->id) {
$viewer->display('OperationNotPermitted.tpl', 'Vtiger');
exit;
}
$userDBTableName = Import_Utils::getDbTableName($owner);
$moduleName = $userInputObject->get('module');
$moduleMeta = self::getModuleMeta($moduleName, $user);
$result = $adb->query('SELECT recordid FROM ' . $userDBTableName . ' WHERE status is NOT NULL AND recordid IS NOT NULL');
$noOfRecords = $adb->num_rows($result);
$importedRecordIds = array();
for ($i = 0; $i < $noOfRecords; ++$i) {
$importedRecordIds[] = $adb->query_result($result, $i, 'recordid');
}
if (count($importedRecordIds) == 0) {
$importedRecordIds[] = 0;
}
$focus = CRMEntity::getInstance($moduleName);
$queryGenerator = new QueryGenerator($moduleName, $user);
$customView = new CustomView($moduleName);
$viewId = $customView->getViewIdByName('All', $moduleName);
$queryGenerator->initForCustomViewById($viewId);
$list_query = $queryGenerator->getQuery();
// Fetch only last imported records
$list_query .= ' AND ' . $focus->table_name . '.' . $focus->table_index . ' IN (' . implode(',', $importedRecordIds) . ')';
if (PerformancePrefs::getBoolean('LISTVIEW_COMPUTE_PAGE_COUNT', false) === true) {
$count_result = $adb->query(mkCountQuery($list_query));
$noofrows = $adb->query_result($count_result, 0, "count");
} else {
$noofrows = null;
}
$start = ListViewSession::getRequestCurrentPage($moduleName, $list_query, $viewId, false);
$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($list_query . " LIMIT {$limit_start_rec}, {$list_max_entries_per_page}", array());
$recordListRangeMsg = getRecordRangeMessage($list_result, $limit_start_rec, $noofrows);
$viewer->assign('recordListRange', $recordListRangeMsg);
$controller = new ListViewController($adb, $user, $queryGenerator);
$listview_header = $controller->getListViewHeader($focus, $moduleName, $url_string, $sorder, $order_by, true);
$listview_entries = $controller->getListViewEntries($focus, $moduleName, $list_result, $navigation_array, true);
$viewer->assign('CURRENT_PAGE', $start);
$viewer->assign('LISTHEADER', $listview_header);
$viewer->assign('LISTENTITY', $listview_entries);
$viewer->assign('FOR_MODULE', $moduleName);
$viewer->assign('FOR_USER', $ownerId);
$isAjax = $userInputObject->get('ajax');
if (!empty($isAjax)) {
echo $viewer->fetch('ListViewEntries.tpl');
} else {
$viewer->display('ImportListView.tpl');
}
}
示例6: addRelationsFromRelatedModuleViewId
/**
* Function to add relations using related module viewid
* @param Vtiger_Request $request
*/
public function addRelationsFromRelatedModuleViewId(Vtiger_Request $request)
{
$sourceRecordId = $request->get('sourceRecord');
$relatedModuleName = $request->get('relatedModule');
$viewId = $request->get('viewId');
if ($viewId) {
$sourceModuleModel = Vtiger_Module_Model::getInstance($request->getModule());
$relatedModuleModel = Vtiger_Module_Model::getInstance($relatedModuleName);
$relationModel = Vtiger_Relation_Model::getInstance($sourceModuleModel, $relatedModuleModel);
$emailEnabledModulesInfo = $relationModel->getEmailEnabledModulesInfoForDetailView();
if (array_key_exists($relatedModuleName, $emailEnabledModulesInfo)) {
$fieldName = $emailEnabledModulesInfo[$relatedModuleName]['fieldName'];
$db = PearDatabase::getInstance();
$currentUserModel = Users_Record_Model::getCurrentUserModel();
$queryGenerator = new QueryGenerator($relatedModuleName, $currentUserModel);
$queryGenerator->initForCustomViewById($viewId);
$query = $queryGenerator->getQuery();
$result = $db->pquery($query, array());
$numOfRows = $db->num_rows($result);
for ($i = 0; $i < $numOfRows; $i++) {
$relatedRecordIdsList[] = $db->query_result($result, $i, $fieldName);
}
if (empty($relatedRecordIdsList)) {
$response = new Vtiger_Response();
$response->setResult(array(false));
$response->emit();
} else {
foreach ($relatedRecordIdsList as $relatedRecordId) {
$relationModel->addRelation($sourceRecordId, $relatedRecordId);
}
}
}
}
}
示例7: getKeyMetricsWithCount
protected function getKeyMetricsWithCount()
{
global $current_user, $adb;
$current_user = Users_Record_Model::getCurrentUserModel();
require_once 'modules/CustomView/ListViewTop.php';
$metriclists = getMetricList();
foreach ($metriclists as $key => $metriclist) {
$metricresult = NULL;
if ($metriclist['module'] == "Calendar") {
$listquery = getListQuery($metriclist['module']);
$oCustomView = new CustomView($metriclist['module']);
$metricsql = $oCustomView->getModifiedCvListQuery($metriclist['id'], $listquery, $metriclist['module']);
$metricresult = $adb->query(Vtiger_Functions::mkCountQuery($metricsql));
} else {
$queryGenerator = new QueryGenerator($metriclist['module'], $current_user);
$queryGenerator->initForCustomViewById($metriclist['id']);
$metricsql = $queryGenerator->getQuery();
$metricresult = $adb->query(Vtiger_Functions::mkCountQuery($metricsql));
}
if ($metricresult) {
$rowcount = $adb->fetch_array($metricresult);
$metriclists[$key]['count'] = $rowcount['count'];
}
}
return $metriclists;
}
示例8: getKeyMetricsWithCount
protected function getKeyMetricsWithCount()
{
global $log;
$log->debug("Entering ./dashboards/KeyMetrics.php::getKeyMetricsWithCount");
global $current_user, $adb;
$current_user = Users_Record_Model::getCurrentUserModel();
require_once 'modules/CustomView/ListViewTop.php';
$metriclists = getMetricList();
foreach ($metriclists as $key => $metriclist) {
$metricresult = NULL;
$queryGenerator = new QueryGenerator($metriclist['module'], $current_user);
$queryGenerator->initForCustomViewById($metriclist['id']);
if ($metriclist['module'] == "Calendar") {
// For calendar we need to eliminate emails or else it will break in status empty condition
$queryGenerator->addCondition('activitytype', "Emails", 'n', QueryGenerator::$AND);
}
$metricsql = $queryGenerator->getQuery();
$metricresult = $adb->query(Vtiger_Functions::mkCountQuery($metricsql));
if ($metricresult) {
$rowcount = $adb->fetch_array($metricresult);
$metriclists[$key]['count'] = $rowcount['count'];
}
}
return $metriclists;
}
示例9: getQuery
/**
* Function returns the Query for the relationhips
* @param <Vtiger_Record_Model> $recordModel
* @param type $actions
* @return <String>
*/
public function getQuery($recordModel, $actions = false)
{
$parentModuleModel = $this->getParentModuleModel();
$relatedModuleModel = $this->getRelationModuleModel();
$relatedModuleName = $relatedModuleModel->get('name');
$parentModuleName = $parentModuleModel->get('name');
$functionName = $this->get('name');
$focus = CRMEntity::getInstance($parentModuleName);
$focus->id = $recordModel->getId();
if (method_exists($parentModuleModel, $functionName)) {
$query = $parentModuleModel->{$functionName}($recordModel, $relatedModuleModel);
} else {
$result = $focus->{$functionName}($recordModel->getId(), $parentModuleModel->getId(), $relatedModuleModel->getId(), $actions);
$query = $result['query'];
}
//modify query if any module has summary fields, those fields we are displayed in related list of that module
$relatedListFields = $relatedModuleModel->getConfigureRelatedListFields();
if (count($relatedListFields) > 0) {
$currentUser = Users_Record_Model::getCurrentUserModel();
$queryGenerator = new QueryGenerator($relatedModuleName, $currentUser);
$queryGenerator->setFields($relatedListFields);
$selectColumnSql = $queryGenerator->getSelectClauseColumnSQL();
$newQuery = spliti('FROM', $query);
$selectColumnSql = 'SELECT DISTINCT vtiger_crmentity.crmid,' . $selectColumnSql;
}
if ($functionName == ('get_pricebook_products' || 'get_pricebook_services')) {
$selectColumnSql = $selectColumnSql . ', vtiger_pricebookproductrel.listprice';
}
$query = $selectColumnSql . ' FROM ' . $newQuery[1];
return $query;
}
示例10: getContent
function getContent(Mobile_API_Request $request)
{
global $current_user, $adb;
$current_user = $this->getActiveUser();
$module = $request->get('module');
$limit = $request->get('number');
$offset = $request->get('offset');
$search = isset($_REQUEST['src_str']) ? $request->get('src_str') : '';
$customView = new CustomView($module);
if (!empty($_REQUEST['view'])) {
$viewid = $_REQUEST['view'];
} else {
$viewid = $customView->getViewId($module);
}
$queryGenerator = new QueryGenerator($module, $current_user);
if ($viewid != "0") {
$queryGenerator->initForCustomViewById($viewid);
} else {
$queryGenerator->initForDefaultCustomView();
}
$list_query = $queryGenerator->getQuery();
//get entity fields for each module
$entity_sql = "select fieldname,tablename,entityidfield from vtiger_entityname where modulename =?";
$ws_entity = $adb->pquery($entity_sql, array($module));
$fieldname = $adb->query_result($ws_entity, 0, 'fieldname');
$tablename = $adb->query_result($ws_entity, 0, 'tablename');
//set the list and content order
if ($module == 'Contacts' || $module == 'Leads') {
$list_query .= " AND (lastname LIKE '%{$search}%' OR firstname LIKE '%{$search}%') ORDER BY lastname";
} elseif ($module != 'Calendar' and $module != 'Events') {
$list_query .= " AND " . $tablename . "." . $fieldname . " LIKE '%{$search}%' ORDER BY " . $tablename . "." . $fieldname;
} elseif ($module == 'Calendar' || $module == 'Events') {
$calendarview_selected = $request->get('viewName');
$list_query .= " AND vtiger_activity.activitytype!='Emails'";
if ($calendarview_selected == 'week') {
$list_query .= " AND week(date_start) = week(NOW()) AND year(date_start) = year(NOW())";
} elseif ($calendarview_selected == 'month') {
$list_query .= " AND month(date_start) = month(NOW()) AND year(date_start) = year(NOW())";
} elseif ($calendarview_selected == 'year') {
$list_query .= " AND year(date_start) = year(NOW())";
} elseif ($calendarview_selected == 'today') {
$list_query .= " AND DATE(date_start) = DATE(NOW())";
}
$list_query .= " AND subject LIKE '%{$search}%' ORDER BY date_start DESC";
} else {
$list_query .= " AND " . $tablename . "." . $fieldname . " LIKE '%{$search}%' ORDER BY " . $tablename . "." . $fieldname;
}
$list_query .= " LIMIT {$offset}, {$limit};";
$listview_entries = $adb->pquery($list_query, array());
$response = new Mobile_API_Response();
$response->setResult(array('records' => $listview_entries, 'module' => $module));
return $response;
}
示例11: getInstance
/**
* Static Function to get the Instance of Vtiger ListView model for a given module and custom view
* @param <String> $moduleName - Module Name
* @param <Number> $viewId - Custom View Id
* @return Vtiger_ListView_Model instance
*/
public static function getInstance($moduleName, $sourceModule)
{
$db = PearDatabase::getInstance();
$currentUser = vglobal('current_user');
$modelClassName = Vtiger_Loader::getComponentClassName('Model', 'ListView', $moduleName);
$instance = new $modelClassName();
$sourceModuleModel = Vtiger_Module_Model::getInstance($sourceModule);
$queryGenerator = new QueryGenerator($sourceModuleModel->get('name'), $currentUser);
$queryGenerator->initForDefaultCustomView();
$controller = new ListViewController($db, $currentUser, $queryGenerator);
return $instance->set('module', $sourceModuleModel)->set('query_generator', $queryGenerator)->set('listview_controller', $controller);
}
示例12: getCalculations
function getCalculations(Vtiger_Request $request)
{
$fromModule = $request->get('fromModule');
$record = $request->get('record');
$showtype = $request->get('showtype');
$rqLimit = $request->get('limit');
$db = PearDatabase::getInstance();
$fields = ['id', 'name', 'calculationsstatus'];
$limit = 10;
$params = [];
if (!empty($rqLimit)) {
$limit = $rqLimit;
}
if ($fromModule == 'Accounts') {
$fields[] = 'potentialid';
} elseif ($fromModule == 'Potentials') {
$fields[] = 'assigned_user_id';
}
$calculationConfig = Settings_SalesProcesses_Module_Model::getConfig('calculation');
$calculationsStatus = $calculationConfig['calculationsstatus'];
$currentUser = Users_Record_Model::getCurrentUserModel();
$module = 'Calculations';
$instance = CRMEntity::getInstance($module);
$securityParameter = $instance->getUserAccessConditionsQuerySR($module, $currentUser);
$queryGenerator = new QueryGenerator($module, $currentUser);
$queryGenerator->setFields($fields);
$sql = $queryGenerator->getQuery();
if ($securityParameter != '') {
$sql .= $securityParameter;
}
$calculationsStatusSearch = implode("','", $calculationsStatus);
$showtype = $request->get('showtype');
if ($showtype == 'archive') {
$sql .= " AND vtiger_calculations.calculationsstatus IN ('{$calculationsStatusSearch}')";
} else {
$sql .= " AND vtiger_calculations.calculationsstatus NOT IN ('{$calculationsStatusSearch}')";
}
if ($fromModule == 'Accounts') {
$sql .= ' AND vtiger_calculations.relatedid = ?';
$params[] = $record;
} elseif ($fromModule == 'Potentials') {
$sql .= ' AND vtiger_calculations.potentialid = ?';
$params[] = $record;
}
$sql .= ' LIMIT ' . $limit;
$result = $db->pquery($sql, $params);
$returnData = array();
for ($i = 0; $i < $db->num_rows($result); $i++) {
$returnData[] = $db->query_result_rowdata($result, $i);
}
return $returnData;
}
示例13: getExportQuery
/**
* Function that generates Export Query based on the mode
* @param Vtiger_Request $request
* @return <String> export query
*/
function getExportQuery(Vtiger_Request $request)
{
$currentUser = Users_Record_Model::getCurrentUserModel();
$cvId = $request->get('viewname');
$moduleName = $request->get('source_module');
$queryGenerator = new QueryGenerator($moduleName, $currentUser);
if (!empty($cvId)) {
$queryGenerator->initForCustomViewById($cvId);
}
$acceptedFields = array('user_name', 'title', 'first_name', 'last_name', 'email1', 'email2', 'secondaryemail', 'phone_work', 'phone_mobile', 'phone_fax', 'address_street', 'address_city', 'address_state', 'address_country', 'address_postalcode');
$queryGenerator->setFields($acceptedFields);
$query = $queryGenerator->getQuery();
return $query;
}
示例14: convertMap2Array
private function convertMap2Array()
{
global $adb, $current_user;
$xml = $this->getXMLContent();
if (isset($xml->records)) {
foreach ($xml->records->record as $k => $v) {
if (isset($v->action)) {
$action = strtolower((string) $v->action);
if (!in_array($action, $this->actions)) {
$action = $this->default_action;
}
} else {
$action = $this->default_action;
}
if (isset($v->id)) {
$rs = $adb->pquery('select setype from vtiger_crmentity where crmid=? and deleted=0', array((int) $v->id));
if ($adb->num_rows($rs) == 1) {
$recinfo = $adb->fetch_array($rs);
$this->mapping[$action]['ids'][] = (int) $v->id;
$this->mapping[$action][$recinfo['setype']][] = (int) $v->id;
if (!in_array($recinfo['setype'], $this->mapping['modules'])) {
$this->mapping['modules'][] = $recinfo['setype'];
}
}
} else {
$tabid = getTabid((string) $v->module);
$ui4rs = $adb->pquery('select fieldname from vtiger_field where uitype=4 and tabid=?', array($tabid));
$ui4 = $adb->query_result($ui4rs, 0, 0);
$queryGenerator = new QueryGenerator((string) $v->module, $current_user);
$queryGenerator->setFields(array('id'));
$queryGenerator->addCondition($ui4, (string) $v->value, 'e');
$query = $queryGenerator->getQuery();
$idrs = $adb->pquery($query, array());
if ($idrs and $adb->num_rows($idrs) > 0) {
$id = $adb->query_result($idrs, 0, 0);
$this->mapping[$action]['ids'][] = (int) $id;
$this->mapping[$action][(string) $v->module][] = (int) $id;
if (!in_array($recinfo['setype'], $this->mapping['modules'])) {
$this->mapping['modules'][] = $recinfo['setype'];
}
}
}
}
}
}
示例15: getQuery
/**
* Function returns the Query for the relationhips
* @param <Vtiger_Record_Model> $recordModel
* @param type $actions
* @return <String>
*/
public function getQuery($recordModel, $actions = false, $relationListView_Model = false)
{
$parentModuleModel = $this->getParentModuleModel();
$relatedModuleModel = $this->getRelationModuleModel();
$relatedModuleName = $relatedModuleModel->get('name');
$parentModuleName = $parentModuleModel->get('name');
$functionName = $this->get('name');
$focus = CRMEntity::getInstance($parentModuleName);
$focus->id = $recordModel->getId();
if (method_exists($parentModuleModel, $functionName)) {
$query = $parentModuleModel->{$functionName}($recordModel, $relatedModuleModel);
} else {
$result = $focus->{$functionName}($recordModel->getId(), $parentModuleModel->getId(), $relatedModuleModel->getId(), $actions);
$query = $result['query'];
}
//modify query if any module has summary fields, those fields we are displayed in related list of that module
$relatedListFields = $this->getRelationFields(true, true);
if (count($relatedListFields) == 0) {
$relatedListFields = $relatedModuleModel->getConfigureRelatedListFields();
}
if (count($relatedListFields) > 0) {
$currentUser = Users_Record_Model::getCurrentUserModel();
$queryGenerator = new QueryGenerator($relatedModuleName, $currentUser);
$queryGenerator->setFields($relatedListFields);
$selectColumnSql = $queryGenerator->getSelectClauseColumnSQL();
$newQuery = explode('FROM', $query);
$selectColumnSql = 'SELECT DISTINCT vtiger_crmentity.crmid, ' . $selectColumnSql;
}
if ($functionName == 'get_product_pricebooks') {
$selectColumnSql = $selectColumnSql . ' ,vtiger_pricebookproductrel.listprice, vtiger_pricebook.currency_id, vtiger_products.unit_price';
}
if ($functionName == 'get_service_pricebooks') {
$selectColumnSql = $selectColumnSql . ' ,vtiger_pricebookproductrel.listprice, vtiger_pricebook.currency_id, vtiger_service.unit_price';
}
if ($selectColumnSql && $newQuery[1]) {
$query = $selectColumnSql . ' FROM ' . $newQuery[1];
}
if ($relationListView_Model) {
$searchParams = $relationListView_Model->get('search_params');
$this->addSearchConditions($query, $searchParams, $relatedModuleName);
}
return $query;
}