[ Index ]

PHP Cross Reference of vtigercrm-6.1.0

title

Body

[close]

/pkg/vtiger/modules/CustomerPortal/settings/models/ -> Module.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 Settings_CustomerPortal_Module_Model extends Settings_Vtiger_Module_Model {
  12  
  13      var $name = 'CustomerPortal';
  14  
  15      /**
  16       * Function to get Current portal user
  17       * @return <Interger> userId
  18       */
  19  	public function getCurrentPortalUser() {
  20          $db = PearDatabase::getInstance();
  21  
  22          $result = $db->pquery("SELECT prefvalue FROM vtiger_customerportal_prefs WHERE prefkey = 'userid' AND tabid = 0", array());
  23          if ($db->num_rows($result)) {
  24              return $db->query_result($result, 0, 'prefvalue');
  25          }
  26          return false;
  27      }
  28  
  29      /**
  30       * Function to get current default assignee from portal
  31       * @return <Integer> userId
  32       */
  33  	public function getCurrentDefaultAssignee() {
  34          $db = PearDatabase::getInstance();
  35  
  36          $result = $db->pquery("SELECT prefvalue FROM vtiger_customerportal_prefs WHERE prefkey = 'defaultassignee' AND tabid = 0", array());
  37          if ($db->num_rows($result)) {
  38              return $db->query_result($result, 0, 'prefvalue');
  39          }
  40          return false;
  41      }
  42  
  43      /**
  44       * Function to get list of portal modules
  45       * @return <Array> list of portal modules <Vtiger_Module_Model>
  46       */
  47  	public function getModulesList() {
  48          if (!$this->portalModules) {
  49              $db = PearDatabase::getInstance();
  50  
  51              $query = "SELECT vtiger_customerportal_tabs.*, vtiger_customerportal_prefs.prefvalue, vtiger_tab.name FROM vtiger_customerportal_tabs
  52                      INNER JOIN vtiger_customerportal_prefs ON vtiger_customerportal_prefs.tabid = vtiger_customerportal_tabs.tabid AND vtiger_customerportal_prefs.prefkey='showrelatedinfo'
  53                      INNER JOIN vtiger_tab ON vtiger_customerportal_tabs.tabid = vtiger_tab.tabid AND vtiger_tab.presence = 0 ORDER BY vtiger_customerportal_tabs.sequence";
  54  
  55              $result = $db->pquery($query, array());
  56              $rows = $db->num_rows($result);
  57  
  58              for($i=0; $i<$rows; $i++) {
  59                  $rowData = $db->query_result_rowdata($result, $i);
  60                  $tabId = $rowData['tabid'];
  61                  $moduleModel = Vtiger_Module_Model::getInstance($tabId);
  62                  foreach ($rowData as $key => $value) {
  63                      $moduleModel->set($key, $value);
  64                  }
  65                  $portalModules[$tabId] = $moduleModel;
  66              }
  67              $this->portalModules = $portalModules;
  68          }
  69          return $this->portalModules;
  70      }
  71  
  72      /**
  73       * Function to save the details of Portal modules
  74       */
  75  	public function save() {
  76          $db = PearDatabase::getInstance();
  77          $privileges = $this->get('privileges');
  78          $defaultAssignee = $this->get('defaultAssignee');
  79          $portalModulesInfo = $this->get('portalModulesInfo');
  80          
  81          //Update details of view all record option for every module from Customer portal
  82          $updateQuery = "UPDATE vtiger_customerportal_prefs SET prefvalue = CASE ";
  83          foreach ($portalModulesInfo as $tabId => $moduleDetails) {
  84              $prefValue = $moduleDetails['prefValue'];
  85              $updateQuery .= " WHEN tabid = $tabId THEN $prefValue ";
  86          }
  87          $updateQuery .= " WHEN prefkey = ? THEN $privileges ";
  88          $updateQuery .= " WHEN prefkey = ? THEN $defaultAssignee ";
  89          $updateQuery .= " ELSE prefvalue END";
  90  
  91          $db->pquery($updateQuery, array('userid', 'defaultassignee'));
  92  
  93          //Update the sequence of every module in Customer portal
  94          $updateSequenceQuery = "UPDATE vtiger_customerportal_tabs SET visible = CASE ";
  95  
  96          foreach ($portalModulesInfo as $tabId => $moduleDetails) {
  97              $visible = $moduleDetails['visible'];
  98              $updateSequenceQuery .= " WHEN tabid = $tabId THEN $visible ";
  99          }
 100  
 101          $updateSequenceQuery .= " END, sequence = CASE ";
 102          foreach ($portalModulesInfo as $tabId => $moduleDetails) {
 103              $sequence = $moduleDetails['sequence'];
 104              $updateSequenceQuery .= " WHEN tabid = $tabId THEN $sequence ";
 105          }
 106          $updateSequenceQuery .= "END";
 107          
 108          $db->pquery($updateSequenceQuery, array());
 109      }
 110  }


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