[ Index ]

PHP Cross Reference of vtigercrm-6.1.0

title

Body

[close]

/modules/Settings/Vtiger/models/ -> Systems.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_Vtiger_Systems_Model extends Vtiger_Base_Model{
  12  
  13      const tableName = 'vtiger_systems';
  14  
  15      public function getId() {
  16          return $this->get('id');
  17      }
  18  
  19      public function isSmtpAuthEnabled() {
  20          $smtp_auth_value = $this->get('smtp_auth');
  21          return ($smtp_auth_value == 'on' || $smtp_auth_value == 1 || $smtp_auth_value == 'true') ? true : false;
  22      }
  23  
  24      public function save() {
  25          $db = PearDatabase::getInstance();
  26  
  27          $id = $this->getId();
  28          $params = array();
  29          array_push($params, $this->get('server'),$this->get('server_port'),$this->get('server_username'),$this->get('server_password'),$this->get('server_type'),
  30                     $this->isSmtpAuthEnabled(),$this->get('server_path'),$this->get('from_email_field'));
  31  
  32          if(empty($id)) {
  33              $id = $db->getUniqueID(self::tableName);
  34              //To keep id in the beginning

  35              array_unshift($params, $id);
  36              $query = 'INSERT INTO '.self::tableName.' VALUES(?,?,?,?,?,?,?,?,?)';
  37          }else{
  38              $query = 'UPDATE '.self::tableName.' SET server = ?, server_port= ?, server_username = ?, server_password = ?,
  39                  server_type = ?,  smtp_auth= ?, server_path = ?, from_email_field=? WHERE id = ?';
  40              $params[] = $id;
  41          }
  42          $db->pquery($query,$params);
  43          return $id;
  44      }
  45  
  46      public static function getInstanceFromServerType($type,$componentName) {
  47          $db = PearDatabase::getInstance();
  48          $query = 'SELECT * FROM '.self::tableName.' WHERE server_type=?';
  49          $params = array($type);
  50          $result = $db->pquery($query,$params);
  51          try{
  52          $modelClassName = Vtiger_Loader::getComponentClassName('Model', $componentName, 'Settings:Vtiger');
  53          }catch(Exception $e) {
  54              $modelClassName = self;
  55          }
  56          $instance = new $modelClassName();
  57          if($db->num_rows($result) > 0 ){
  58              $rowData = $db->query_result_rowdata($result,0);
  59              $instance->setData($rowData);
  60          }
  61          return $instance;
  62      }
  63  
  64  }


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