[ 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 * Vtiger Widget Model Class 12 */ 13 class Vtiger_Widget_Model extends Vtiger_Base_Model { 14 15 public function getWidth() { 16 $largerSizedWidgets = array('GroupedBySalesPerson', 'PipelinedAmountPerSalesPerson', 'GroupedBySalesStage', 'Funnel Amount'); 17 $title = $this->getName(); 18 if(in_array($title, $largerSizedWidgets)) { 19 $this->set('width', '6'); 20 } 21 22 $width = $this->get('width'); 23 if(empty($width)) { 24 $this->set('width', '4'); 25 } 26 return $this->get('width'); 27 } 28 29 public function getHeight() { 30 //Special case for History widget 31 $title = $this->getTitle(); 32 if($title == 'History') { 33 $this->set('height', '2'); 34 } 35 $height = $this->get('height'); 36 if(empty($height)) { 37 $this->set('height', '1'); 38 } 39 return $this->get('height'); 40 } 41 42 public function getPositionCol($default=0) { 43 $position = $this->get('position'); 44 if ($position) { 45 $position = Zend_Json::decode(decode_html($position)); 46 return intval($position['col']); 47 } 48 return $default; 49 } 50 51 public function getPositionRow($default=0) { 52 $position = $this->get('position'); 53 if ($position) { 54 $position = Zend_Json::decode(decode_html($position)); 55 return intval($position['row']); 56 } 57 return $default; 58 } 59 60 /** 61 * Function to get the url of the widget 62 * @return <String> 63 */ 64 public function getUrl() { 65 $url = decode_html($this->get('linkurl')).'&linkid='.$this->get('linkid'); 66 $widgetid = $this->has('widgetid')? $this->get('widgetid') : $this->get('id'); 67 if ($widgetid) $url .= '&widgetid=' . $widgetid; 68 return $url; 69 } 70 71 /** 72 * Function to get the Title of the widget 73 */ 74 public function getTitle() { 75 $title = $this->get('title'); 76 if(!isset($title)) { 77 $title = $this->get('linklabel'); 78 } 79 return $title; 80 } 81 82 public function getName() { 83 $widgetName = $this->get('name'); 84 if(empty($widgetName)){ 85 //since the html entitites will be encoded 86 //TODO : See if you need to push decode_html to base model 87 $linkUrl = decode_html($this->getUrl()); 88 preg_match('/name=[a-zA-Z]+/', $linkUrl, $matches); 89 $matches = explode('=', $matches[0]); 90 $widgetName = $matches[1]; 91 $this->set('name', $widgetName); 92 } 93 return $widgetName; 94 } 95 /** 96 * Function to get the instance of Vtiger Widget Model from the given array of key-value mapping 97 * @param <Array> $valueMap 98 * @return Vtiger_Widget_Model instance 99 */ 100 public static function getInstanceFromValues($valueMap) { 101 $self = new self(); 102 $self->setData($valueMap); 103 return $self; 104 } 105 106 public static function getInstance($linkId, $userId) { 107 $db = PearDatabase::getInstance(); 108 $result = $db->pquery('SELECT * FROM vtiger_module_dashboard_widgets 109 INNER JOIN vtiger_links ON vtiger_links.linkid = vtiger_module_dashboard_widgets.linkid 110 WHERE linktype = ? AND vtiger_links.linkid = ? AND userid = ?', array('DASHBOARDWIDGET', $linkId, $userId)); 111 112 $self = new self(); 113 if($db->num_rows($result)) { 114 $row = $db->query_result_rowdata($result, 0); 115 $self->setData($row); 116 } 117 return $self; 118 } 119 120 public static function updateWidgetPosition($position, $linkId, $widgetId, $userId) { 121 if (!$linkId && !$widgetId) return; 122 123 $db = PearDatabase::getInstance(); 124 $sql = 'UPDATE vtiger_module_dashboard_widgets SET position=? WHERE userid=?'; 125 $params = array($position, $userId); 126 if ($linkId) { 127 $sql .= ' AND linkid = ?'; 128 $params[] = $linkId; 129 } else if ($widgetId) { 130 $sql .= ' AND id = ?'; 131 $params[] = $widgetId; 132 } 133 $db->pquery($sql, $params); 134 } 135 136 public static function getInstanceWithWidgetId($widgetId, $userId) { 137 $db = PearDatabase::getInstance(); 138 $result = $db->pquery('SELECT * FROM vtiger_module_dashboard_widgets 139 INNER JOIN vtiger_links ON vtiger_links.linkid = vtiger_module_dashboard_widgets.linkid 140 WHERE linktype = ? AND vtiger_module_dashboard_widgets.id = ? AND userid = ?', array('DASHBOARDWIDGET', $widgetId, $userId)); 141 142 $self = new self(); 143 if($db->num_rows($result)) { 144 $row = $db->query_result_rowdata($result, 0); 145 $self->setData($row); 146 } 147 return $self; 148 } 149 150 /** 151 * Function to add a widget from the Users Dashboard 152 */ 153 public function add() { 154 $db = PearDatabase::getInstance(); 155 156 $sql = 'SELECT id FROM vtiger_module_dashboard_widgets WHERE linkid = ? AND userid = ?'; 157 $params = array($this->get('linkid'), $this->get('userid')); 158 159 $filterid = $this->get('filterid'); 160 if (!empty($filterid)) { 161 $sql .= ' AND filterid = ?'; 162 $params[] = $this->get('filterid'); 163 } 164 165 $result = $db->pquery($sql, $params); 166 if(!$db->num_rows($result)) { 167 $db->pquery('INSERT INTO vtiger_module_dashboard_widgets(linkid, userid, filterid, title, data) VALUES(?,?,?,?,?)', 168 array($this->get('linkid'), $this->get('userid'), $this->get('filterid'), $this->get('title'), Zend_Json::encode($this->get('data')))); 169 $this->set('id', $db->getLastInsertID()); 170 } else if($this->has('data')){ 171 $db->pquery('INSERT INTO vtiger_module_dashboard_widgets(linkid, userid, filterid, title, data) VALUES(?,?,?,?,?)', 172 array($this->get('linkid'), $this->get('userid'), $this->get('filterid'), $this->get('title'), Zend_Json::encode($this->get('data')))); 173 $this->set('id', $db->getLastInsertID()); 174 } 175 else { 176 $this->set('id', $db->query_result($result, 0, 'id')); 177 } 178 } 179 180 /** 181 * Function to remove the widget from the Users Dashboard 182 */ 183 public function remove() { 184 $db = PearDatabase::getInstance(); 185 $db->pquery('DELETE FROM vtiger_module_dashboard_widgets WHERE id = ? AND userid = ?', 186 array($this->get('id'), $this->get('userid'))); 187 } 188 189 /** 190 * Function returns URL that will remove a widget for a User 191 * @return <String> 192 */ 193 public function getDeleteUrl() { 194 $url = 'index.php?module=Vtiger&action=RemoveWidget&linkid='. $this->get('linkid'); 195 $widgetid = $this->has('widgetid')? $this->get('widgetid') : $this->get('id'); 196 if ($widgetid) $url .= '&widgetid=' . $widgetid; 197 return $url; 198 } 199 200 /** 201 * Function to check the Widget is Default widget or not 202 * @return <boolean> true/false 203 */ 204 public function isDefault() { 205 $defaultWidgets = $this->getDefaultWidgets(); 206 $widgetName = $this->getName(); 207 208 if (in_array($widgetName, $defaultWidgets)) { 209 return true; 210 } 211 return false; 212 } 213 214 /** 215 * Function to get Default widget Names 216 * @return <type> 217 */ 218 public function getDefaultWidgets() { 219 return array(); 220 } 221 }
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 |