public function searchRecord($searchValue, $searchModule, $potentialId) { $db = PearDatabase::getInstance(); $potentialId = intval($potentialId); if ($searchModule == 'Products') { $sql = "SELECT\n\t\t\t\t\t\tcrm.*,\n\t\t\t\t\t\tprod.*\n\t\t\t\t\tFROM\n\t\t\t\t\t\t`vtiger_products` prod\n\t\t\t\t\t\tINNER JOIN `vtiger_crmentity` crm\n\t\t\t\t\t\t\tON crm.`crmid` = prod.`productid`\n\t\t\t\t\t\tINNER JOIN `vtiger_seproductsrel` prodrel\n\t\t\t\t\t\t\tON prod.`productid` = prodrel.`productid`\n\t\t\t\t\t\t\tAND prodrel.`setype` = 'Potentials'\n\t\t\t\t\tWHERE prod.`productname` LIKE '%{$searchValue}%'\n\t\t\t\t\t\tAND crm.`setype` = 'Products'\n\t\t\t\t\t\tAND crm.`deleted` = 0\n\t\t\t\t\t\tAND prodrel.`crmid` = '{$potentialId}';"; } else { $sql = "SELECT\n\t\t\t\t\t\tcrm.*,\n\t\t\t\t\t\tserv.*\n\t\t\t\t\tFROM\n\t\t\t\t\t\t`vtiger_service` serv\n\t\t\t\t\t\tINNER JOIN `vtiger_crmentity` crm\n\t\t\t\t\t\t\tON crm.`crmid` = serv.`serviceid`\n\t\t\t\t\t\tINNER JOIN `vtiger_crmentityrel` crmrel\n\t\t\t\t\t\t\tON serv.`serviceid` = crmrel.`relcrmid`\n\t\t\t\t\t\t\tAND crmrel.`module` = 'Potentials'\n\t\t\t\t\tWHERE serv.`servicename` LIKE '%{$searchValue}%'\n\t\t\t\t\t\tAND crm.`setype` = 'Services'\n\t\t\t\t\t\tAND crm.`deleted` = 0\n\t\t\t\t\t\tAND crmrel.`crmid` = '{$potentialId}';"; } $result = $db->pquery($sql, array()); $noOfRows = $db->num_rows($result); $moduleModels = array(); $matchingRecords = array(); for ($i = 0; $i < $noOfRows; ++$i) { $row = $db->query_result_rowdata($result, $i); if (Users_Privileges_Model::isPermitted($row['setype'], 'DetailView', $row['crmid'])) { $row['id'] = $row['crmid']; $moduleName = $row['setype']; if (!array_key_exists($moduleName, $moduleModels)) { $moduleModels[$moduleName] = Vtiger_Module_Model::getInstance($moduleName); } $moduleModel = $moduleModels[$moduleName]; $modelClassName = Vtiger_Loader::getComponentClassName('Model', 'Record', $moduleName); $recordInstance = new $modelClassName(); $matchingRecords[$moduleName][$row['id']] = $recordInstance->setData($row)->setModuleFromInstance($moduleModel); } } return $matchingRecords; }
function process(Vtiger_Request $request) { $log = vglobal('log'); $log->debug('Entering ' . __CLASS__ . '::' . __METHOD__ . '() method ...'); $moduleName = $request->getModule(); $recordId = $request->get('record'); $view = $request->get('fromview'); $viewer = $this->getViewer($request); $handlerClass = Vtiger_Loader::getComponentClassName('Model', 'MappedFields', $moduleName); $mfModel = new $handlerClass(); if ($view == 'List') { $allRecords = Vtiger_Mass_Action::getRecordsListFromRequest($request); $templates = $mfModel->getActiveTemplatesForModule($moduleName, $view); $viewer->assign('ALL_RECORDS', $allRecords); } else { $templates = $mfModel->getActiveTemplatesForRecord($recordId, $view, $moduleName); $viewer->assign('RECORD', $recordId); } $viewer->assign('TEMPLATES', $templates); $viewer->assign('VIEW', $view); $viewer->assign('MODULE_NAME', $moduleName); $viewer->assign('BASE_MODULE_NAME', 'Vtiger'); $this->preProcess($request); $viewer->view('GenerateModal.tpl', $qualifiedModule); $this->postProcess($request); $log->debug('Exiting ' . __CLASS__ . '::' . __METHOD__ . ' method ...'); }
function process(Vtiger_Request $request) { $currentUser = Users_Record_Model::getCurrentUserModel(); $moduleName = $request->getModule(); $componentName = $request->get('name'); $linkId = $request->get('linkid'); if (!empty($componentName)) { $className = Vtiger_Loader::getComponentClassName('Dashboard', $componentName, $moduleName); if (!empty($className)) { $widget = NULL; if (!empty($linkId)) { $widget = new Vtiger_Widget_Model(); $widget->set('linkid', $linkId); $widget->set('userid', $currentUser->getId()); $widget->set('filterid', $request->get('filterid', NULL)); if ($request->has('data')) { $widget->set('data', $request->get('data')); } $widget->add(); } $classInstance = new $className(); $classInstance->process($request, $widget); return; } } $response = new Vtiger_Response(); $response->setResult(array('success' => false, 'message' => vtranslate('NO_DATA'))); $response->emit(); }
/** * Static Function to get the list of records matching the search key * @param <String> $searchKey * @return <Array> - List of Vtiger_Record_Model or Module Specific Record Model instances */ public static function getSearchResult($searchKey, $module = false) { $db = PearDatabase::getInstance(); $deletedCondition = $this->getModule()->getDeletedRecordCondition(); $query = 'SELECT * FROM vtiger_crmentity INNER JOIN vtiger_leaddetails ON vtiger_leaddetails.leadid = vtiger_crmentity.crmid WHERE label LIKE ? AND ' . $deletedCondition; $params = array("%{$searchKey}%"); $result = $db->pquery($query, $params); $noOfRows = $db->num_rows($result); $moduleModels = array(); $matchingRecords = array(); for ($i = 0; $i < $noOfRows; ++$i) { $row = $db->query_result_rowdata($result, $i); $row['id'] = $row['crmid']; $moduleName = $row['setype']; if (!array_key_exists($moduleName, $moduleModels)) { $moduleModels[$moduleName] = Vtiger_Module_Model::getInstance($moduleName); } $moduleModel = $moduleModels[$moduleName]; $modelClassName = Vtiger_Loader::getComponentClassName('Model', 'Record', $moduleName); $recordInstance = new $modelClassName(); $matchingRecords[$moduleName][$row['id']] = $recordInstance->setData($row)->setModuleFromInstance($moduleModel); } return $matchingRecords; }
public static function getInstanceFromServerType($type,$componentName) { // SalesPlatform.ru begin require_once 'includes/SalesPlatform/NetIDNA/idna_convert.class.php'; // SalesPlatform.ru end $db = PearDatabase::getInstance(); $query = 'SELECT * FROM '.self::tableName.' WHERE server_type=?'; $params = array($type); $result = $db->pquery($query,$params); try{ $modelClassName = Vtiger_Loader::getComponentClassName('Model', $componentName, 'Settings:Vtiger'); }catch(Exception $e) { $modelClassName = self; } $instance = new $modelClassName(); if($db->num_rows($result) > 0 ){ $rowData = $db->query_result_rowdata($result,0); $instance->setData($rowData); } // SalesPlatform.ru begin $idn = new idna_convert(); $mail_server_username = $idn->decode($instance->get('server_username')); $from_email_field = $idn->decode($instance->get('from_email_field')); $instance->set('server_username', $mail_server_username); $instance->set('from_email_field', $from_email_field); // SalesPlatform.ru end return $instance; }
/** * Function to get the instance * @param <String> $moduleName - module name * @param <String> $recordId - record id * @return <Vtiger_DetailView_Model> */ public static function getInstance($moduleName, $recordId) { $modelClassName = Vtiger_Loader::getComponentClassName('Model', 'DetailView', $moduleName); $instance = new $modelClassName(); $moduleModel = Vtiger_Module_Model::getInstance($moduleName); $recordModel = Reports_Record_Model::getCleanInstance($recordId, $moduleName); return $instance->setModule($moduleModel)->setRecord($recordModel); }
/** * 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, $viewId = 0) { $db = PearDatabase::getInstance(); $modelClassName = Vtiger_Loader::getComponentClassName('Model', 'ListView', $moduleName); $instance = new $modelClassName(); $moduleModel = Vtiger_Module_Model::getInstance($moduleName); return $instance->set('module', $moduleModel); }
/** * 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; }
/** * Function to get instance of provider model * @param <String> $providerName * @return <SMSNotifier_Provider_Model> provider object */ public static function getInstance($providerName) { if (!empty($providerName)) { $providerName = trim($providerName); $className = Vtiger_Loader::getComponentClassName('Provider', $providerName, 'SMSNotifier'); return new $className(); } return false; }
/** * Function to get the instance * @param <String> $moduleName - module name * @param <String> $recordId - record id * @return <Vtiger_DetailView_Model> */ public static function getInstance($moduleName, $recordId) { $modelClassName = Vtiger_Loader::getComponentClassName('Model', 'DetailView', $moduleName); $instance = new $modelClassName(); $moduleModel = EmailTemplates_Module_Model::getInstance($moduleName); $recordModel = EmailTemplates_Record_Model::getInstanceById($recordId, $moduleName); $recordModel->trackView(); return $instance->setModule($moduleModel)->setRecord($recordModel); }
public static function getInstance($record, $moduleName, $relatedRecord, $relatedModuleName) { $modelClassName = Vtiger_Loader::getComponentClassName('Model', 'RelatedCommentModal', $moduleName); $instance = new $modelClassName(); $recordModel = Vtiger_Record_Model::getInstanceById($record, $moduleName); $relationListView = Vtiger_RelationListView_Model::getInstance($recordModel, $relatedModuleName); $instance->set('relationListView', $relationListView)->set('record', $record)->set('moduleName', $moduleName)->set('relatedRecord', $relatedRecord)->set('relatedModuleName', $relatedModuleName); return $instance; }
/** * 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; }
/** * 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; }
/** * Get invnetory instance * @param string $moduleName Module name * @return Vtiger_Inventory_Model instance */ public static function getInstance($moduleName) { $instance = Vtiger_Cache::get('Inventory', $moduleName); if (!$instance) { $modelClassName = Vtiger_Loader::getComponentClassName('Model', 'Inventory', $moduleName); $instance = new $modelClassName(); $instance->initialize($moduleName); Vtiger_Cache::set('Inventory', $moduleName, $instance); } return $instance; }
/** * Static Function to get the instance of Vtiger TreeView Model for the given Vtiger Module Model * @param string name of the module * @return Vtiger_TreeView_Model instance */ public static function getInstance($moduleModel) { $moduleName = $moduleModel->get('name'); if (isset(self::$_cached_instance[$moduleName])) { return self::$_cached_instance[$moduleName]; } $modelClassName = Vtiger_Loader::getComponentClassName('Model', 'TreeView', $moduleName); $instance = new $modelClassName(); self::$_cached_instance[$moduleName] = $instance->set('module', $moduleModel); return self::$_cached_instance[$moduleName]; }
public static function getInstance($module) { $instance = Vtiger_Cache::get('transferOwnership', $module); if (!$instance) { $modelClassName = Vtiger_Loader::getComponentClassName('Model', 'TransferOwnership', $module); $instance = new $modelClassName(); $instance->set('module', $module); Vtiger_Cache::set('transferOwnership', $module, $instance); } return $instance; }
/** * 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); }
public static function getCleanInstance($moduleName = 'Vtiger') { $handlerClass = Vtiger_Loader::getComponentClassName('Model', 'PDF', $moduleName); $pdf = new $handlerClass(); $data = []; $fields = Settings_PDF_Module_Model::getFieldsByStep(); foreach ($fields as $field) { $data[$field] = ''; } $pdf->setData($data); return $pdf; }
public static function getInstanceFromServerType($type,$componentName) { $db = PearDatabase::getInstance(); $query = 'SELECT * FROM '.self::tableName.' WHERE server_type=?'; $params = array($type); $result = $db->pquery($query,$params); try{ $modelClassName = Vtiger_Loader::getComponentClassName('Model', $componentName, 'Settings:Vtiger'); }catch(Exception $e) { $modelClassName = self; } $instance = new $modelClassName(); if($db->num_rows($result) > 0 ){ $rowData = $db->query_result_rowdata($result,0); $instance->setData($rowData); } return $instance; }
/** * Function searches the records in the module, if parentId & parentModule * is given then searches only those records related to them. * @param <String> $searchValue - Search value * @param <Integer> $parentId - parent recordId * @param <String> $parentModule - parent module name * @return <Array of Users_Record_Model> */ public function searchRecord($searchValue, $parentId = false, $parentModule = false, $relatedModule = false) { if (!empty($searchValue)) { $db = PearDatabase::getInstance(); $query = 'SELECT * FROM vtiger_users WHERE (first_name LIKE ? OR last_name LIKE ?) AND status = ?'; $params = array("%{$searchValue}%", "%{$searchValue}%", 'Active'); $result = $db->pquery($query, $params); $noOfRows = $db->num_rows($result); $matchingRecords = array(); for ($i = 0; $i < $noOfRows; ++$i) { $row = $db->query_result_rowdata($result, $i); $modelClassName = Vtiger_Loader::getComponentClassName('Model', 'Record', 'Users'); $recordInstance = new $modelClassName(); $matchingRecords['Users'][$row['id']] = $recordInstance->setData($row)->setModuleFromInstance($this); } return $matchingRecords; } }
/** * 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; }
public function getType($module = false) { $moduleName = Vtiger_Functions::getModuleName($module); $dir = 'modules/Vtiger/widgets/'; $ffs = scandir($dir); foreach ($ffs as $ff) { $action = str_replace('.php', "", $ff); if ($ff != '.' && $ff != '..' && !is_dir($dir . '/' . $ff) && $action != 'Basic') { $folderFiles[$action] = $action; vimport('~~' . $dir . $ff); $modelClassName = Vtiger_Loader::getComponentClassName('Widget', $action, 'Vtiger'); $instance = new $modelClassName(); if ($instance->allowedModules && !in_array($moduleName, $instance->allowedModules)) { unset($folderFiles[$action]); } } } return $folderFiles; }
public function process(Vtiger_Request $request) { $module = $request->getModule(); $transferOwnerId = $request->get('transferOwnerId'); $record = $request->get('record'); $modelClassName = Vtiger_Loader::getComponentClassName('Model', 'TransferOwnership', $module); $transferModel = new $modelClassName(); if (empty($record)) { $recordIds = $this->getBaseModuleRecordIds($request); } else { $recordIds[] = $record; } $relatedModuleRecordIds = $transferModel->getRelatedModuleRecordIds($request, $recordIds); $transferRecordIds = array_merge($relatedModuleRecordIds, $recordIds); $transferModel->transferRecordsOwnership($module, $transferOwnerId, $transferRecordIds); $response = new Vtiger_Response(); $response->setResult(true); $response->emit(); }
function getUnLinkedRecord() { $targetId = $this->get('targetid'); $targetModule = $this->get('targetmodule'); $db = PearDatabase::getInstance(); $query = 'SELECT * FROM vtiger_crmentity WHERE crmid = ?'; $params = array($targetId); $result = $db->pquery($query, $params); $noOfRows = $db->num_rows($result); $moduleModels = array(); if ($noOfRows) { if (!array_key_exists($targetModule, $moduleModels)) { $moduleModel = Vtiger_Module_Model::getInstance($targetModule); } $row = $db->query_result_rowdata($result, 0); $modelClassName = Vtiger_Loader::getComponentClassName('Model', 'Record', $targetModule); $recordInstance = new $modelClassName(); $recordInstance->setData($row)->setModuleFromInstance($moduleModel); return $recordInstance; } return false; }
/** * Function returns related records * @param Vtiger_Request $request * @return <type> */ function showRelatedList(Vtiger_Request $request) { $moduleName = $request->getModule(); $relatedModuleName = $request->get('relatedModule'); $targetControllerClass = null; // Added to support related list view from the related module, rather than the base module. try { $targetControllerClass = Vtiger_Loader::getComponentClassName('View', 'In' . $moduleName . 'Relation', $relatedModuleName); } catch (AppException $e) { try { // If any module wants to have same view for all the relation, then invoke this. $targetControllerClass = Vtiger_Loader::getComponentClassName('View', 'InRelation', $relatedModuleName); } catch (AppException $e) { // Default related list $targetControllerClass = Vtiger_Loader::getComponentClassName('View', 'RelatedList', $moduleName); } } if ($targetControllerClass) { $targetController = new $targetControllerClass(); return $targetController->process($request); } }
function process(Vtiger_Request $request) { $this->preProcess($request); $moduleName = $request->getModule(); $allRecords = []; $recordId = $request->get('record'); $view = $request->get('fromview'); $allRecords = Vtiger_Mass_Action::getRecordsListFromRequest($request); $handlerClass = Vtiger_Loader::getComponentClassName('Model', 'PDF', $moduleName); $pdfModel = new $handlerClass(); $viewer = $this->getViewer($request); if ($view === 'Detail') { $viewer->assign('TEMPLATES', $pdfModel->getActiveTemplatesForRecord($recordId, $view, $moduleName)); } elseif ($view === 'List') { $viewer->assign('TEMPLATES', $pdfModel->getActiveTemplatesForModule($moduleName, $view)); } $exportValues = '&record=' . $recordId . '&fromview=' . $view; $viewer->assign('ALL_RECORDS', $allRecords); $viewer->assign('EXPORT_VARS', $exportValues); $viewer->assign('MODULE_NAME', $moduleName); $viewer->view('ExportPDF.tpl', $moduleName); $this->postProcess($request); }
/** * Static Function to get the list of records matching the search key * @param <String> $searchKey * @return <Array> - List of Vtiger_Record_Model or Module Specific Record Model instances */ public static function getSearchResult($searchKey, $module = false) { $db = PearDatabase::getInstance(); global $log; $query = 'SELECT label, crmid, setype, createdtime FROM vtiger_crmentity WHERE label LIKE ? AND vtiger_crmentity.deleted = 0'; $params = array("%{$searchKey}%"); if ($module !== false) { $query .= ' AND setype = ?'; $params[] = $module; } //$log->debug("busqueda global getSearchResult... ".$query); //Modified by jmangarret 19/05/2015 if ($module == "RegistroDeVentas" || $module == "Boletos" || $module == "VentaDeProductos") { $query = $query . " UNION ALL " . 'select CONCAT(cf_1618, " ",registrodeventasname) as label, R2.registrodeventasid as crmid, "RegistroDeVentas" as setype, E.createdtime as createdtime '; $query = $query . 'from vtiger_registrodeventas as R1, vtiger_registrodeventascf as R2, vtiger_crmentity as E '; $query = $query . 'where R1.registrodeventasid=R2.registrodeventasid AND R2.registrodeventasid = E.crmid AND E.deleted = 0 '; $query = $query . 'AND (R2.cf_1618 like ? OR R2.cf_854 like ? OR R1.registrodeventasname like ?) '; $params = array_merge($params, array("%{$searchKey}%", "%{$searchKey}%", "%{$searchKey}%")); $query = $query . " UNION ALL " . 'select localizador as label, B.boletosid as crmid, "Boletos" as setype, E.createdtime as createdtime '; $query = $query . 'from vtiger_boletos AS B, vtiger_crmentity AS E '; $query = $query . 'where B.boletosid = E.crmid AND E.deleted = 0 AND (B.localizador like ? or B.boleto1 like ?)'; $params = array_merge($params, array("%{$searchKey}%", "%{$searchKey}%")); } //$params = array_merge($params ,array("%$searchKey%","%$searchKey%")); //Remove the ordering for now to improve the speed //$query .= ' ORDER BY createdtime DESC'; $result = $db->pquery($query, $params); $noOfRows = $db->num_rows($result); //die($query); $moduleModels = $matchingRecords = $leadIdsList = array(); for ($i = 0; $i < $noOfRows; ++$i) { $row = $db->query_result_rowdata($result, $i); if ($row['setype'] === 'Leads') { $leadIdsList[] = $row['crmid']; } } $convertedInfo = Leads_Module_Model::getConvertedInfo($leadIdsList); for ($i = 0, $recordsCount = 0; $i < $noOfRows && $recordsCount < 100; ++$i) { $row = $db->query_result_rowdata($result, $i); if ($row['setype'] === 'Leads' && $convertedInfo[$row['crmid']]) { continue; } if (Users_Privileges_Model::isPermitted($row['setype'], 'DetailView', $row['crmid'])) { $row['id'] = $row['crmid']; $moduleName = $row['setype']; if (!array_key_exists($moduleName, $moduleModels)) { $moduleModels[$moduleName] = Vtiger_Module_Model::getInstance($moduleName); } $moduleModel = $moduleModels[$moduleName]; $modelClassName = Vtiger_Loader::getComponentClassName('Model', 'Record', $moduleName); $recordInstance = new $modelClassName(); $matchingRecords[$moduleName][$row['id']] = $recordInstance->setData($row)->setModuleFromInstance($moduleModel); $recordsCount++; } } return $matchingRecords; }
/** * Function to get the instance * @param <String> $moduleName - module name * @return <Vtiger_DashBoard_Model> */ public static function getInstance($moduleName) { global $log; $log->debug("Entering ./models/DashBoard.php::staticgetInstance"); $modelClassName = Vtiger_Loader::getComponentClassName('Model', 'DashBoard', $moduleName); $instance = new $modelClassName(); $moduleModel = Vtiger_Module_Model::getInstance($moduleName); return $instance->setModule($moduleModel); }
/** * Static Function to get the list of records matching the search key * @param <String> $searchKey * @return <Array> - List of Vtiger_Record_Model or Module Specific Record Model instances */ public static function getSearchResult($searchKey, $module = false) { global $max_number_search_result; $db = PearDatabase::getInstance(); $query = 'SELECT label, searchlabel, crmid, setype, createdtime FROM vtiger_crmentity crm INNER JOIN vtiger_entityname e ON crm.setype = e.modulename WHERE searchlabel LIKE ? AND turn_off = ? AND crm.deleted = 0'; $params = array("%{$searchKey}%", 1); if ($module !== false) { $query .= ' AND setype = ?'; $params[] = $module; } $query .= ' ORDER BY sequence ASC, createdtime DESC'; $result = $db->pquery($query, $params); $noOfRows = $db->num_rows($result); $moduleModels = $matchingRecords = $leadIdsList = array(); for ($i = 0; $i < $noOfRows; ++$i) { $row = $db->query_result_rowdata($result, $i); if ($row['setype'] === 'Leads') { $leadIdsList[] = $row['crmid']; } } $convertedInfo = Leads_Module_Model::getConvertedInfo($leadIdsList); for ($i = 0, $recordsCount = 0; $i < $noOfRows && $recordsCount < $max_number_search_result; ++$i) { $row = $db->query_result_rowdata($result, $i); if ($row['setype'] === 'Leads' && $convertedInfo[$row['crmid']]) { continue; } if (Users_Privileges_Model::isPermitted($row['setype'], 'DetailView', $row['crmid'])) { $row['id'] = $row['crmid']; $moduleName = $row['setype']; if (!array_key_exists($moduleName, $moduleModels)) { $moduleModels[$moduleName] = Vtiger_Module_Model::getInstance($moduleName); } $moduleModel = $moduleModels[$moduleName]; $modelClassName = Vtiger_Loader::getComponentClassName('Model', 'Record', $moduleName); $recordInstance = new $modelClassName(); $matchingRecords[$moduleName][$row['id']] = $recordInstance->setData($row)->setModuleFromInstance($moduleModel); $recordsCount++; } } return $matchingRecords; }
/** * Function searches the records in the module, if parentId & parentModule * is given then searches only those records related to them. * @param <String> $searchValue - Search value * @param <Integer> $parentId - parent recordId * @param <String> $parentModule - parent module name * @return <Array of Vtiger_Record_Model> */ public function searchRecord($searchValue, $parentId = false, $parentModule = false, $relatedModule = false) { if (!empty($searchValue) && empty($parentId) && empty($parentModule)) { $matchingRecords = Vtiger_Record_Model::getSearchResult($searchValue, $this->getName()); } else { if ($parentId && $parentModule) { $db = PearDatabase::getInstance(); $result = $db->pquery($this->getSearchRecordsQuery($searchValue, $parentId, $parentModule), array()); $noOfRows = $db->num_rows($result); $moduleModels = array(); $matchingRecords = array(); for ($i = 0; $i < $noOfRows; ++$i) { $row = $db->query_result_rowdata($result, $i); if (Users_Privileges_Model::isPermitted($row['setype'], 'DetailView', $row['crmid'])) { $row['id'] = $row['crmid']; $moduleName = $row['setype']; if (!array_key_exists($moduleName, $moduleModels)) { $moduleModels[$moduleName] = Vtiger_Module_Model::getInstance($moduleName); } $moduleModel = $moduleModels[$moduleName]; $modelClassName = Vtiger_Loader::getComponentClassName('Model', 'Record', $moduleName); $recordInstance = new $modelClassName(); $matchingRecords[$moduleName][$row['id']] = $recordInstance->setData($row)->setModuleFromInstance($moduleModel); } } } } return $matchingRecords; }