[ Index ]

PHP Cross Reference of vtigercrm-6.1.0

title

Body

[close]

/modules/Vtiger/models/ -> DashBoard.php (source)

   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_DashBoard_Model extends Vtiger_Base_Model {
  12  
  13      /**
  14       * Function to get Module instance
  15       * @return <Vtiger_Module_Model>
  16       */
  17  	public function getModule() {
  18          return $this->module;
  19      }
  20  
  21      /**
  22       * Function to set the module instance
  23       * @param <Vtiger_Module_Model> $moduleInstance - module model
  24       * @return Vtiger_DetailView_Model>
  25       */
  26  	public function setModule($moduleInstance) {
  27          $this->module = $moduleInstance;
  28          return $this;
  29      }
  30  
  31      /**
  32       *  Function to get the module name
  33       *  @return <String> - name of the module
  34       */
  35  	public function getModuleName(){
  36          return $this->getModule()->get('name');
  37      }
  38  
  39      /**
  40       * Function returns the list of Widgets
  41       * @return <Array of Vtiger_Widget_Model>
  42       */
  43  	public function getSelectableDashboard() {
  44          $db = PearDatabase::getInstance();
  45          $currentUser = Users_Record_Model::getCurrentUserModel();
  46          $moduleModel = $this->getModule();
  47  
  48          $sql = 'SELECT * FROM vtiger_links WHERE linktype = ?
  49                      AND tabid = ? AND linkid NOT IN (SELECT linkid FROM vtiger_module_dashboard_widgets
  50                      WHERE userid = ?)';
  51          $params = array('DASHBOARDWIDGET', $moduleModel->getId(), $currentUser->getId());
  52  
  53          $sql .= ' UNION SELECT * FROM vtiger_links WHERE linklabel in (?,?)';
  54          $params[] = 'Mini List';
  55          $params[] = 'Notebook';
  56          $result = $db->pquery($sql, $params);
  57  
  58          $widgets = array();
  59          for($i=0; $i<$db->num_rows($result); $i++) {
  60              $row = $db->query_result_rowdata($result, $i);
  61  
  62              if($row['linklabel'] == 'Tag Cloud') {
  63                  $isTagCloudExists = getTagCloudView($currentUser->getId());
  64                  if($isTagCloudExists == 'false') {
  65                      continue;
  66                  }
  67              }
  68              $widgets[] = Vtiger_Widget_Model::getInstanceFromValues($row);
  69          }
  70  
  71          return $widgets;
  72      }
  73  
  74      /**
  75       * Function returns List of User's selected Dashboard Widgets
  76       * @return <Array of Vtiger_Widget_Model>
  77       */
  78  	public function getDashboards() {
  79          $db = PearDatabase::getInstance();
  80          $currentUser = Users_Record_Model::getCurrentUserModel();
  81          $moduleModel = $this->getModule();
  82  
  83          $sql = " SELECT vtiger_links.*, vtiger_module_dashboard_widgets.userid, vtiger_module_dashboard_widgets.id as widgetid, vtiger_module_dashboard_widgets.position as position, vtiger_links.linkid as id FROM vtiger_links ".
  84                  " INNER JOIN vtiger_module_dashboard_widgets ON vtiger_links.linkid=vtiger_module_dashboard_widgets.linkid".
  85                  " WHERE (vtiger_module_dashboard_widgets.userid = ? AND linktype = ? AND tabid = ?)";
  86          $params = array($currentUser->getId(), 'DASHBOARDWIDGET', $moduleModel->getId());
  87          $result = $db->pquery($sql, $params);
  88  
  89          $widgets = array();
  90  
  91          for($i=0, $len=$db->num_rows($result); $i<$len; $i++) {
  92              $row = $db->query_result_rowdata($result, $i);
  93              $row['linkid'] = $row['id'];
  94              $widgets[] = Vtiger_Widget_Model::getInstanceFromValues($row);
  95          }
  96  
  97          foreach ($widgets as $index => $widget) {
  98              $label = $widget->get('linklabel');
  99              if($label == 'Tag Cloud') {
 100                  $isTagCloudExists = getTagCloudView($currentUser->getId());
 101                  if($isTagCloudExists === 'false')  unset($widgets[$index]);
 102              }
 103          }
 104  
 105          return $widgets;
 106      }
 107  
 108      /**
 109       * Function to get the default widgets(Deprecated)
 110       * @return <Array of Vtiger_Widget_Model>
 111       */
 112  	public function getDefaultWidgets() {
 113          //TODO: Need to review this API is needed?
 114          $moduleModel = $this->getModule();
 115          $widgets = array();
 116  
 117          return $widgets;
 118      }
 119  
 120  
 121      /**
 122       * Function to get the instance
 123       * @param <String> $moduleName - module name
 124       * @return <Vtiger_DashBoard_Model>
 125       */
 126  	public static function getInstance($moduleName) {
 127          $modelClassName = Vtiger_Loader::getComponentClassName('Model', 'DashBoard', $moduleName);
 128          $instance = new $modelClassName();
 129  
 130          $moduleModel = Vtiger_Module_Model::getInstance($moduleName);
 131  
 132          return $instance->setModule($moduleModel);
 133      }
 134  
 135  
 136  }


Generated: Fri Nov 28 20:08:37 2014 Cross-referenced by PHPXref 0.7.1