[ Index ] |
PHP Cross Reference of vtigercrm-6.1.0 |
[Summary view] [Print] [Text view]
1 <?php 2 /*+*********************************************************************************** 3 * The contents of this file are subject to the vtiger CRM Public License Version 1.0 4 * ("License"); You may not use this file except in compliance with the License 5 * The Original Code is: vtiger CRM Open Source 6 * The Initial Developer of the Original Code is vtiger. 7 * Portions created by vtiger are Copyright (C) vtiger. 8 * All Rights Reserved. 9 *************************************************************************************/ 10 11 class EmailTemplates_ListView_Model extends Vtiger_ListView_Model { 12 13 14 /** 15 * Function to get the list of Mass actions for the module 16 * @param <Array> $linkParams 17 * @return <Array> - Associative array of Link type to List of Vtiger_Link_Model instances for Mass Actions 18 */ 19 public function getListViewMassActions($linkParams) { 20 $moduleModel = $this->getModule(); 21 $linkTypes = array('LISTVIEWMASSACTION'); 22 $links = array(); 23 24 $massActionLinks[] = array( 25 'linktype' => 'LISTVIEWMASSACTION', 26 'linklabel' => 'LBL_DELETE', 27 'linkurl' => 'javascript:Vtiger_List_Js.massDeleteRecords("index.php?module='.$moduleModel->get('name').'&action=MassDelete");', 28 'linkicon' => '' 29 ); 30 31 foreach($massActionLinks as $massActionLink) { 32 $links['LISTVIEWMASSACTION'][] = Vtiger_Link_Model::getInstanceFromValues($massActionLink); 33 } 34 35 return $links; 36 } 37 38 /** 39 * Static Function to get the Instance of Vtiger ListView model for a given module and custom view 40 * @param <String> $moduleName - Module Name 41 * @param <Number> $viewId - Custom View Id 42 * @return Vtiger_ListView_Model instance 43 */ 44 public static function getInstance($moduleName, $viewId = 0) { 45 $db = PearDatabase::getInstance(); 46 $modelClassName = Vtiger_Loader::getComponentClassName('Model', 'ListView', $moduleName); 47 $instance = new $modelClassName(); 48 49 $moduleModel = Vtiger_Module_Model::getInstance($moduleName); 50 return $instance->set('module', $moduleModel); 51 } 52 53 /** 54 * Function to get the list view header 55 * @return <Array> - List of Vtiger_Field_Model instances 56 */ 57 public function getListViewHeaders() { 58 $fieldObjects = array(); 59 $listViewHeaders = array('Template Name' => 'templatename', 'Subject' => 'subject'); 60 foreach ($listViewHeaders as $key => $fieldName) { 61 $fieldModel = new EmailTemplates_Field_Model(); 62 $fieldModel->set('name', $fieldName); 63 $fieldModel->set('label', $key); 64 $fieldModel->set('column', $fieldName); 65 $fieldObjects[] = $fieldModel; 66 } 67 return $fieldObjects; 68 } 69 70 /** 71 * Function to get the list view entries 72 * @param Vtiger_Paging_Model $pagingModel 73 * @return <Array> - Associative array of record id mapped to Vtiger_Record_Model instance. 74 */ 75 76 public function getListViewEntries($pagingModel) { 77 $db = PearDatabase::getInstance(); 78 $startIndex = $pagingModel->getStartIndex(); 79 $pageLimit = $pagingModel->getPageLimit(); 80 $orderBy = $this->getForSql('orderby'); 81 $sortOrder = $this->getForSql('sortorder'); 82 83 $listQuery = $this->getQuery(); 84 $searchKey = $this->get('search_key'); 85 $searchValue = $this->get('search_value'); 86 87 if(!empty($searchKey) && !empty($searchValue)) { 88 $listQuery .= " WHERE $searchKey LIKE '$searchValue%'"; 89 } 90 if (!empty($orderBy) && $orderBy === 'smownerid') { 91 $fieldModel = Vtiger_Field_Model::getInstance('assigned_user_id', $moduleModel); 92 if ($fieldModel->getFieldDataType() == 'owner') { 93 $orderBy = 'COALESCE(CONCAT(vtiger_users.first_name,vtiger_users.last_name),vtiger_groups.groupname)'; 94 } 95 } 96 if ($orderBy) { 97 $listQuery .= " ORDER BY $orderBy $sortOrder"; 98 } 99 $listQuery .= " LIMIT $startIndex,".($pageLimit+1); 100 101 $result = $db->pquery($listQuery, array()); 102 $num_rows = $db->num_rows($result); 103 104 $listViewRecordModels = array(); 105 for ($i = 0; $i < $num_rows; $i++) { 106 $recordModel = new EmailTemplates_Record_Model(); 107 $recordModel->setModule('EmailTemplates'); 108 $row = $db->query_result_rowdata($result, $i); 109 $listViewRecordModels[$row['templateid']] = $recordModel->setData($row); 110 } 111 112 $pagingModel->calculatePageRange($listViewRecordModels); 113 114 if($num_rows > $pageLimit){ 115 array_pop($listViewRecordModels); 116 $pagingModel->set('nextPageExists', true); 117 }else{ 118 $pagingModel->set('nextPageExists', false); 119 } 120 121 return $listViewRecordModels; 122 } 123 124 /** 125 * Function to get the list of listview links for the module 126 * @param <Array> $linkParams 127 * @return <Array> - Associate array of Link Type to List of Vtiger_Link_Model instances 128 */ 129 public function getListViewLinks($linkParams) { 130 $moduleModel = $this->getModule(); 131 132 $linkTypes = array('LISTVIEWBASIC', 'LISTVIEW', 'LISTVIEWSETTING'); 133 $links = Vtiger_Link_Model::getAllByType($moduleModel->getId(), $linkTypes, $linkParams); 134 135 $basicLinks = array( 136 array( 137 'linktype' => 'LISTVIEWBASIC', 138 'linklabel' => 'LBL_ADD_RECORD', 139 'linkurl' => $moduleModel->getCreateRecordUrl(), 140 'linkicon' => '' 141 ) 142 ); 143 foreach($basicLinks as $basicLink) { 144 $links['LISTVIEWBASIC'][] = Vtiger_Link_Model::getInstanceFromValues($basicLink); 145 } 146 147 return $links; 148 } 149 150 function getQuery() { 151 $listQuery = 'SELECT templateid, templatename, foldername, subject FROM vtiger_emailtemplates'; 152 return $listQuery; 153 } 154 155 /** 156 * Function to get the list view entries 157 * @param Vtiger_Paging_Model $pagingModel 158 * @return <Array> - Associative array of record id mapped to Vtiger_Record_Model instance. 159 */ 160 public function getListViewCount() { 161 $db = PearDatabase::getInstance(); 162 163 $listQuery = $this->getQuery(); 164 165 $position = stripos($listQuery, 'from'); 166 if ($position) { 167 $split = spliti('from', $listQuery); 168 $splitCount = count($split); 169 $listQuery = 'SELECT count(*) AS count '; 170 for ($i=1; $i<$splitCount; $i++) { 171 $listQuery = $listQuery. ' FROM ' .$split[$i]; 172 } 173 } 174 $searchKey = $this->get('search_key'); 175 $searchValue = $this->get('search_value'); 176 177 if(!empty($searchKey) && !empty($searchValue)) { 178 $listQuery .= " WHERE $searchKey LIKE '$searchValue%'"; 179 } 180 181 $listResult = $db->pquery($listQuery, array()); 182 return $db->query_result($listResult, 0, 'count'); 183 } 184 185 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Fri Nov 28 20:08:37 2014 | Cross-referenced by PHPXref 0.7.1 |