[ Index ] |
PHP Cross Reference of vtigercrm-6.1.0 |
[Summary view] [Print] [Text view]
1 <?php 2 3 /* +*********************************************************************************** 4 * The contents of this file are subject to the vtiger CRM Public License Version 1.0 5 * ("License"); You may not use this file except in compliance with the License 6 * The Original Code is: vtiger CRM Open Source 7 * The Initial Developer of the Original Code is vtiger. 8 * Portions created by vtiger are Copyright (C) vtiger. 9 * All Rights Reserved. 10 * *********************************************************************************** */ 11 12 class EmailTemplates_Module_Model extends Vtiger_Module_Model { 13 14 /** 15 * Function to get Alphabet Search Field 16 */ 17 public function getAlphabetSearchField() { 18 return 'templatename'; 19 } 20 21 /** 22 * Function to get the url for the Create Record view of the module 23 * @return <String> - url 24 */ 25 public function getCreateRecordUrl() { 26 return 'index.php?module=' . $this->get('name') . '&view=' . $this->getEditViewName(); 27 } 28 29 /** 30 * Function to save a given record model of the current module 31 * @param EmailtTemplates_Record_Model $recordModel 32 * @return <integer> template id 33 */ 34 public function saveRecord($recordModel) { 35 $db = PearDatabase::getInstance(); 36 $templateid = $recordModel->getId(); 37 if(empty($templateid)){ 38 $templateid = $db->getUniqueID('vtiger_emailtemplates'); 39 $sql = "INSERT INTO vtiger_emailtemplates(templatename, subject, description, body, deleted, templateid) VALUES (?,?,?,?,?,?)"; 40 }else{ 41 $sql = "UPDATE vtiger_emailtemplates SET templatename=?, subject=?, description=?, body=?, deleted=? WHERE templateid = ?"; 42 } 43 $params = array(decode_html($recordModel->get('templatename')), decode_html($recordModel->get('subject')), 44 decode_html($recordModel->get('description')), $recordModel->get('body'), 0, $templateid); 45 $db->pquery($sql, $params); 46 return $recordModel->setId($templateid); 47 } 48 49 /** 50 * Function to delete the email template 51 * @param type $recordIds 52 */ 53 public function deleteRecord($recordModel) { 54 $recordId = $recordModel->getId(); 55 $db = PearDatabase::getInstance(); 56 $db->pquery('DELETE FROM vtiger_emailtemplates WHERE templateid = ? ', array($recordId)); 57 } 58 59 /** 60 * Function to delete all the email templates 61 * @param type $recordIds 62 */ 63 public function deleteAllRecords() { 64 $db = PearDatabase::getInstance(); 65 $db->pquery('DELETE FROM vtiger_emailtemplates', array()); 66 } 67 68 /** 69 * Function to get Email template fields from modules 70 * @return <array> template fields 71 */ 72 public function getAllModuleEmailTemplateFields() { 73 $currentUserModel = Users_Record_Model::getCurrentUserModel(); 74 $allModuleList = $this->getAllModuleList(); 75 $allRelFields = array(); 76 foreach ($allModuleList as $index => $module) { 77 if($module == 'Users'){ 78 $fieldList = $this->getRelatedModuleFieldList($module, $currentUserModel); 79 }else{ 80 $fieldList = $this->getRelatedFields($module, $currentUserModel); 81 } 82 foreach ($fieldList as $key => $field) { 83 $option = array(vtranslate($field['module'], $field['module']) . ':' . vtranslate($field['fieldlabel'], $field['module']), "$" . strtolower($field['module']) . "-" . $field['columnname'] . "$"); 84 $allFields[] = $option; 85 if (!empty($field['referencelist'])) { 86 foreach ($field['referencelist'] as $key => $relField) { 87 $relOption = array(vtranslate($field['fieldlabel'], $field['module']) . ':' . '(' . vtranslate($relField['module'], $relField['module']) . ')' . vtranslate($relField['fieldlabel'],$relField['module']), "$" . strtolower($field['module']) . "-" . $field['columnname'] . ":" . $relField['columnname'] . "$"); 88 $allRelFields[] = $relOption; 89 } 90 } 91 } 92 if(is_array($allFields) && is_array($allRelFields)){ 93 $allFields = array_merge($allFields, $allRelFields); 94 $allRelFields=""; 95 } 96 $allOptions[vtranslate($module, $module)] = $allFields; 97 $allFields = ""; 98 } 99 100 $option = array('Current Date', '$custom-currentdate$'); 101 $allFields[] = $option; 102 $option = array('Current Time', '$custom-currenttime$'); 103 $allFields[] = $option; 104 $allOptions['generalFields'] = $allFields; 105 return $allOptions; 106 } 107 108 /** 109 * Function to get module fields 110 * @param type $module 111 * @param type $currentUserModel 112 * @return <arrau> 113 */ 114 function getRelatedFields($module, $currentUserModel) { 115 $handler = vtws_getModuleHandlerFromName($module, $currentUserModel); 116 $meta = $handler->getMeta(); 117 $moduleFields = $meta->getModuleFields(); 118 119 $returnData = array(); 120 foreach ($moduleFields as $key => $field) { 121 $referencelist = array(); 122 $relatedField = $field->getReferenceList(); 123 if ($field->getFieldName() == 'assigned_user_id') { 124 $relModule = 'Users'; 125 $referencelist = $this->getRelatedModuleFieldList($relModule, $currentUserModel); 126 } 127 if (!empty($relatedField)) { 128 foreach ($relatedField as $ind => $relModule) { 129 $referencelist = $this->getRelatedModuleFieldList($relModule, $currentUserModel); 130 } 131 } 132 $returnData[] = array('module' => $module, 'fieldname' => $field->getFieldName(), 'columnname' => $field->getColumnName(), 'fieldlabel' => $field->getFieldLabelKey(), 'referencelist' => $referencelist); 133 134 } 135 return $returnData; 136 } 137 138 /** 139 * Function to get related module fields 140 * @param type $relModule 141 * @param type $user 142 * @return null 143 */ 144 145 function getRelatedModuleFieldList($relModule, $user) { 146 $handler = vtws_getModuleHandlerFromName($relModule, $user); 147 $relMeta = $handler->getMeta(); 148 if (!$relMeta->isModuleEntity()) { 149 return null; 150 } 151 $relModuleFields = $relMeta->getModuleFields(); 152 $relModuleFieldList = array(); 153 foreach ($relModuleFields as $relind => $relModuleField) { 154 if($relModule == 'Users') { 155 if($relModuleField->getFieldDataType() == 'string' || $relModuleField->getFieldDataType() == 'email' || $relModuleField->getFieldDataType() == 'phone') { 156 $skipFields = array(98,115,116,31,32); 157 if(!in_array($relModuleField->getUIType(), $skipFields) && $relModuleField->getFieldName() != 'asterisk_extension'){ 158 $relModuleFieldList[] = array('module' => $relModule, 'fieldname' => $relModuleField->getFieldName(), 'columnname' => $relModuleField->getColumnName(), 'fieldlabel' => $relModuleField->getFieldLabelKey()); 159 } 160 } 161 } else { 162 $relModuleFieldList[] = array('module' => $relModule, 'fieldname' => $relModuleField->getFieldName(), 'columnname' => $relModuleField->getColumnName(), 'fieldlabel' => $relModuleField->getFieldLabelKey()); 163 } 164 } 165 return $relModuleFieldList; 166 } 167 168 /** 169 * Function to get module list which has the email field. 170 * @return type 171 */ 172 public function getAllModuleList(){ 173 $db = PearDatabase::getInstance(); 174 175 $query = 'SELECT DISTINCT(name) AS modulename FROM vtiger_tab 176 LEFT JOIN vtiger_field ON vtiger_field.tabid = vtiger_tab.tabid 177 WHERE vtiger_field.uitype = ?'; 178 $result = $db->pquery($query, array(13)); 179 $num_rows = $db->num_rows($result); 180 $moduleList = array(); 181 for($i=0; $i<$num_rows; $i++){ 182 $moduleList[] = $db->query_result($result, $i, 'modulename'); 183 } 184 return $moduleList; 185 } 186 187 /** 188 * Function to get the Quick Links for the module 189 * @param <Array> $linkParams 190 * @return <Array> List of Vtiger_Link_Model instances 191 */ 192 public function getSideBarLinks($linkParams) { 193 $linkTypes = array('SIDEBARLINK', 'SIDEBARWIDGET'); 194 $links = Vtiger_Link_Model::getAllByType($this->getId(), $linkTypes, $linkParams); 195 196 $quickLinks = array( 197 array( 198 'linktype' => 'SIDEBARLINK', 199 'linklabel' => 'LBL_RECORDS_LIST', 200 'linkurl' => $this->getDefaultUrl(), 201 'linkicon' => '', 202 ), 203 ); 204 foreach($quickLinks as $quickLink) { 205 $links['SIDEBARLINK'][] = Vtiger_Link_Model::getInstanceFromValues($quickLink); 206 } 207 return $links; 208 } 209 210 public function getRecordIds($skipRecords){ 211 $db = PearDatabase::getInstance(); 212 213 $query = 'SELECT templateid FROM vtiger_emailtemplates WHERE templateid NOT IN ('.generateQuestionMarks($skipRecords).')'; 214 $result = $db->pquery($query, $skipRecords); 215 $num_rows = $db->num_rows($result); 216 $recordIds = array(); 217 for($i; $i<$num_rows; $i++){ 218 $recordIds[] = $db->query_result($result, $i, 'templateid'); 219 } 220 return $recordIds; 221 } 222 223 /** 224 * Funxtion to identify if the module supports quick search or not 225 */ 226 public function isQuickSearchEnabled() { 227 return false; 228 } 229 }
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 |