[ Index ]

PHP Cross Reference of vtigercrm-6.1.0

title

Body

[close]

/modules/Settings/Currency/models/ -> Record.php (source)

   1  <?php
   2  
   3  /*+**********************************************************************************
   4   * The contents of this file are subject to the vtiger CRM Public License Version 1.1
   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 Settings_Currency_Record_Model extends Settings_Vtiger_Record_Model{
  13      
  14      public function getId() {
  15          return $this->get('id');
  16      }
  17      
  18      public function getName() {
  19          return $this->get('currency_name');
  20      }
  21      
  22      public function isDisabledRestricted() {
  23          $db = PearDatabase::getInstance();
  24          $disabledRestircted = $this->get('_disable_restricted');
  25          if(!empty($disabledRestircted)) {
  26              return $disabledRestircted;
  27          }
  28          $query = 'SELECT 1 FROM vtiger_users WHERE currency_id = ?';
  29          $params = array($this->getId());
  30          $result = $db->pquery($query,$params);
  31          
  32          $disabledRestircted = ($db->num_rows($result) > 0 ) ? true : false;
  33          $this->set('_disable_restricted',$disabledRestircted);
  34          return $disabledRestircted;
  35      }
  36      
  37      public function isBaseCurrency() {
  38          return ($this->get('defaultid') != '-11') ? false : true;
  39      }
  40  
  41  	public function getRecordLinks() {
  42          if($this->isBaseCurrency()){
  43              //NO Edit and delete link for base currency 
  44              return array(); 
  45          } 
  46          $editLink = array(
  47              'linkurl' => "javascript:Settings_Currency_Js.triggerEdit(event, '".$this->getId()."')",
  48              'linklabel' => 'LBL_EDIT',
  49              'linkicon' => 'icon-pencil'
  50          );
  51          $editLinkInstance = Vtiger_Link_Model::getInstanceFromValues($editLink);
  52          
  53          $deleteLink = array(
  54              'linkurl' => "javascript:Settings_Currency_Js.triggerDelete(event,'".$this->getId()."')",
  55              'linklabel' => 'LBL_DELETE',
  56              'linkicon' => 'icon-trash'
  57          );
  58          $deleteLinkInstance = Vtiger_Link_Model::getInstanceFromValues($deleteLink);
  59          return array($editLinkInstance,$deleteLinkInstance);
  60      }
  61      
  62      public function getDeleteStatus() {
  63          if($this->has('deleted')) {
  64              return $this->get('deleted');
  65          }
  66          //by default non deleted
  67          return 0;
  68      }
  69      
  70      public function save() {
  71          $db = PearDatabase::getInstance();
  72          $id = $this->getId();
  73          $tableName = Settings_Currency_Module_Model::tableName;
  74          if(!empty($id)) {
  75              $query = 'UPDATE '.$tableName.' SET currency_name=?, currency_code=?, 
  76                  currency_status=?,currency_symbol=?,conversion_rate=?, deleted=? WHERE id=?' ;
  77              $params = array(
  78                  $this->get('currency_name'), $this->get('currency_code'),
  79                  $this->get('currency_status'), $this->get('currency_symbol'),
  80                  $this->get('conversion_rate'),$this->getDeleteStatus(), $id
  81              );
  82          }else {
  83              $id = $db->getUniqueID($tableName);
  84              $query = 'INSERT INTO '. $tableName .' VALUES(?,?,?,?,?,?,?,?)';
  85              $params = array(
  86                  $id , $this->get('currency_name'), $this->get('currency_code'),
  87                  $this->get('currency_symbol'), $this->get('conversion_rate'), 
  88                  $this->get('currency_status'),0, 0
  89              );
  90          }
  91          $db->pquery($query,$params);
  92          return $id;
  93      }
  94  
  95      public static function getInstance($id) {
  96          $db = PearDatabase::getInstance();
  97          if(Vtiger_Utils::isNumber($id)){
  98              $query = 'SELECT * FROM ' . Settings_Currency_Module_Model::tableName . ' WHERE id=?';
  99          }else{
 100              $query = 'SELECT * FROM ' . Settings_Currency_Module_Model::tableName . ' WHERE currency_name=?';
 101          }
 102          
 103          $params = array($id);
 104          $result = $db->pquery($query,$params);
 105          if($db->num_rows($result) > 0) {
 106              $instance = new self();
 107              $row = $db->query_result_rowdata($result,0);
 108              $instance->setData($row);
 109          }
 110          return $instance;
 111      }
 112      
 113      public static function getAllNonMapped($includedIds = array()) {
 114          $db = PearDatabase::getInstance();
 115          if(!is_array($includedIds)) {
 116              if(!empty($includedIds)){
 117                  $includedIds = array($includedIds);
 118              }else{
 119                  $includedIds = array();
 120              }
 121          }
 122          
 123          $query = 'SELECT vtiger_currencies.* FROM vtiger_currencies 
 124                      LEFT JOIN vtiger_currency_info ON vtiger_currency_info.currency_name = vtiger_currencies.currency_name
 125                      WHERE vtiger_currency_info.currency_name IS NULL or vtiger_currency_info.deleted=1';
 126          $params = array();
 127          if(!empty($includedIds)) {
 128              $params = $includedIds;
 129              $query .= ' or vtiger_currency_info.id IN('.generateQuestionMarks($includedIds).')';
 130          }
 131          $result = $db->pquery($query,$params);
 132          $currencyModelList = array();
 133          $num_rows = $db->num_rows($result);
 134          
 135          for($i=0; $i<$num_rows; $i++) {
 136              $row = $db->query_result_rowdata($result,$i);
 137              $modelInstance = new self();
 138              $modelInstance->setData($row);
 139              $currencyModelList[$row['currencyid']] = $modelInstance;
 140          }
 141          return $currencyModelList;
 142      }
 143      
 144      public static function getAll($excludedIds = array()) {
 145          $db = PearDatabase::getInstance();
 146          
 147          if(!is_array($excludedIds)) {
 148              $excludedIds = array($excludedIds); 
 149          }
 150          
 151          $query = 'SELECT * FROM '.Settings_Currency_Module_Model::tableName.' WHERE deleted=0 AND currency_status="Active"';
 152          $params = array();
 153          if(!empty($excludedIds)) {
 154              $params = $excludedIds;
 155              $query .= ' AND id NOT IN ('.generateQuestionMarks($excludedIds).')';
 156          }
 157          $result = $db->pquery($query, $params);
 158          $num_rows = $db->num_rows($result);
 159          $instanceList = array();
 160          
 161          for($i=0; $i<$num_rows; $i++) {
 162              $row = $db->query_result_rowdata($result,$i);
 163              $instanceList[$row['id']] = new Settings_Currency_Record_Model($row); 
 164          }
 165          return $instanceList;
 166      }
 167      
 168  }


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