[ 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 Vtiger_MiniList_Model extends Vtiger_Widget_Model { 12 13 protected $widgetModel; 14 protected $extraData; 15 16 protected $listviewController; 17 protected $queryGenerator; 18 protected $listviewHeaders; 19 protected $listviewRecords; 20 protected $targetModuleModel; 21 22 public function setWidgetModel($widgetModel) { 23 $this->widgetModel = $widgetModel; 24 $this->extraData = $this->widgetModel->get('data'); 25 26 // Decode data if not done already. 27 if (is_string($this->extraData)) { 28 $this->extraData = Zend_Json::decode(decode_html($this->extraData)); 29 } 30 if ($this->extraData == NULL) { 31 throw new Exception("Invalid data"); 32 } 33 } 34 35 public function getTargetModule() { 36 return $this->extraData['module']; 37 } 38 39 public function getTargetFields() { 40 $fields = $this->extraData['fields']; 41 if (!in_array("id", $fields)) $fields[] = "id"; 42 return $fields; 43 } 44 45 public function getTargetModuleModel() { 46 if (!$this->targetModuleModel) { 47 $this->targetModuleModel = Vtiger_Module_Model::getInstance($this->getTargetModule()); 48 } 49 return $this->targetModuleModel; 50 } 51 52 protected function initListViewController() { 53 if (!$this->listviewController) { 54 $currentUserModel = Users_Record_Model::getCurrentUserModel(); 55 $db = PearDatabase::getInstance(); 56 57 $filterid = $this->widgetModel->get('filterid'); 58 $this->queryGenerator = new QueryGenerator($this->getTargetModule(), $currentUserModel); 59 $this->queryGenerator->initForCustomViewById($filterid); 60 $this->queryGenerator->setFields( $this->getTargetFields() ); 61 62 if (!$this->listviewController) { 63 $this->listviewController = new ListViewController($db, $currentUserModel, $this->queryGenerator); 64 } 65 66 $this->listviewHeaders = $this->listviewRecords = NULL; 67 } 68 } 69 70 public function getTitle($prefix='') { 71 $this->initListViewController(); 72 73 $db = PearDatabase::getInstance(); 74 75 $suffix = ''; 76 $customviewrs = $db->pquery('SELECT viewname FROM vtiger_customview WHERE cvid=?', array($this->widgetModel->get('filterid'))); 77 if ($db->num_rows($customviewrs)) { 78 $customview = $db->fetch_array($customviewrs); 79 $suffix = ' - ' . $customview['viewname']; 80 } 81 return $prefix . vtranslate($this->getTargetModuleModel()->label, $this->getTargetModule()). $suffix; 82 } 83 84 public function getHeaders() { 85 $this->initListViewController(); 86 87 if (!$this->listviewHeaders) { 88 $headerFieldModels = array(); 89 foreach ($this->listviewController->getListViewHeaderFields() as $fieldName => $webserviceField) { 90 $fieldObj = Vtiger_Field::getInstance($webserviceField->getFieldId()); 91 $headerFieldModels[$fieldName] = Vtiger_Field_Model::getInstanceFromFieldObject($fieldObj); 92 } 93 $this->listviewHeaders = $headerFieldModels; 94 } 95 96 return $this->listviewHeaders; 97 } 98 99 public function getHeaderCount() { 100 return count($this->getHeaders()); 101 } 102 103 public function getRecordLimit() { 104 return 10; 105 } 106 107 public function getRecords() { 108 109 $this->initListViewController(); 110 111 if (!$this->listviewRecords) { 112 $db = PearDatabase::getInstance(); 113 114 $query = $this->queryGenerator->getQuery(); 115 $query .= ' ORDER BY vtiger_crmentity.modifiedtime DESC '; 116 $query .= ' LIMIT 0,' . $this->getRecordLimit(); 117 $query = str_replace(" FROM ", ",vtiger_crmentity.crmid as id FROM ", $query); 118 119 $result = $db->pquery($query, array()); 120 121 $targetModuleName = $this->getTargetModule(); 122 $targetModuleFocus= CRMEntity::getInstance($targetModuleName); 123 124 $entries = $this->listviewController->getListViewRecords($targetModuleFocus,$targetModuleName,$result); 125 126 $this->listviewRecords = array(); 127 $index = 0; 128 foreach ($entries as $id => $record) { 129 $rawData = $db->query_result_rowdata($result, $index++); 130 $record['id'] = $id; 131 $this->listviewRecords[$id] = $this->getTargetModuleModel()->getRecordFromArray($record, $rawData); 132 } 133 } 134 135 return $this->listviewRecords; 136 } 137 }
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 |