[ Index ]

PHP Cross Reference of vtigercrm-6.1.0

title

Body

[close]

/modules/Vtiger/models/ -> Block.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  require_once  'vtlib/Vtiger/Block.php';
  11  
  12  class Vtiger_Block_Model extends Vtiger_Block {
  13  
  14      public $fields = false;
  15  
  16  	public function getFields() {
  17          if(empty($this->fields)) {
  18              $moduleFields = Vtiger_Field_Model::getAllForModule($this->module);
  19              $this->fields = array();
  20              
  21              // if block does not contains any fields 
  22              if(!is_array($moduleFields[$this->id])){
  23                  $moduleFields[$this->id] = array();
  24              }
  25              
  26              foreach($moduleFields[$this->id] as $field){
  27                      $this->fields[$field->get('name')] = $field;
  28              }
  29          }
  30          return $this->fields;
  31      }
  32      
  33      public function setFields($fieldModelList) {
  34          $this->fields = $fieldModelList;
  35          return $this;
  36      }
  37  
  38      /**
  39       * Function to get the value of a given property
  40       * @param <String> $propertyName
  41       * @return <Object>
  42       */
  43  	public function get($propertyName) {
  44          if(property_exists($this,$propertyName)){
  45              return $this->$propertyName;
  46          }
  47      }
  48      
  49      public function set($propertyName, $value) {
  50          if(property_exists($this,$propertyName)){
  51              $this->$propertyName = $value;
  52          }
  53          return $this;
  54      }
  55      
  56      public function isCustomized() {
  57          return ($this->iscustom != 0) ? true : false;
  58      }
  59      
  60      public function __update() {
  61          $db = PearDatabase::getInstance();
  62          
  63          $query = 'UPDATE vtiger_blocks SET blocklabel=?,display_status=? WHERE blockid=?';
  64          $params = array($this->label, $this->display_status, $this->id);
  65          $db->pquery($query, $params);
  66      }
  67  
  68      /**
  69       * Function which indicates whether the block is shown or hidden
  70       * @return : <boolean>
  71       */
  72      public function isHidden(){
  73          if($this->get('display_status') == '0') {
  74              return true;
  75          }
  76          return false;
  77      }
  78      
  79      /**
  80       * Function to get the in active fields for the block
  81       * @param type $raw - true to send field in model format or false to send in array format
  82       * @return type - arrays
  83       */
  84      public function getInActiveFields($raw=true) {
  85          $inActiveFields = array();
  86          $fields = $this->getFields();
  87          foreach($fields as $fieldName => $fieldModel) {
  88              if(!$fieldModel->isActiveField()) {
  89                  if($raw){
  90                      $inActiveFields[$fieldName] = $fieldModel;
  91                  }else{
  92                      $fieldDetails = $fieldModel->getFieldInfo();
  93                      $fieldDetails['fieldid'] = $fieldModel->getId();
  94                      $inActiveFields[$fieldName] = $fieldDetails;
  95                  }
  96              }
  97          }
  98          return $inActiveFields;
  99      }
 100  
 101      /**
 102       * Function to retrieve block instances for a module
 103       * @param <type> $moduleModel - module instance
 104       * @return <array> - list of Vtiger_Block_Model
 105       */
 106  	public static function getAllForModule($moduleModel) {
 107          $blockObjects = Vtiger_Cache::get('ModuleBlock',$moduleModel->getName());
 108          
 109          if(!$blockObjects){
 110              $blockObjects = parent::getAllForModule($moduleModel);
 111              Vtiger_Cache::set('ModuleBlock',$moduleModel->getName(),$blockObjects);
 112          }
 113          $blockModelList = array();
 114  
 115          if($blockObjects) {
 116              foreach($blockObjects as $blockObject) {
 117                  $blockModelList[] = self::getInstanceFromBlockObject($blockObject);
 118              }
 119          }
 120          return $blockModelList;
 121      }
 122      
 123  	public static function getInstance($value, $moduleInstance = false) {
 124          $blockInstance = parent::getInstance($value, $moduleInstance);
 125          $blockModel = self::getInstanceFromBlockObject($blockInstance);
 126          return $blockModel;
 127      }
 128  
 129      /**
 130       * Function to retrieve block instance from Vtiger_Block object
 131       * @param Vtiger_Block $blockObject - vtlib block object
 132       * @return Vtiger_Block_Model
 133       */
 134  	public static function getInstanceFromBlockObject(Vtiger_Block $blockObject) {
 135          $objectProperties = get_object_vars($blockObject);
 136          $blockClassName = Vtiger_Loader::getComponentClassName('Model', 'Block', $blockObject->module->name);
 137          $blockModel = new $blockClassName();
 138          foreach($objectProperties as $properName=>$propertyValue) {
 139              $blockModel->$properName = $propertyValue;
 140          }
 141          return $blockModel;
 142      }
 143      
 144      public static function updateSequenceNumber($sequenceList) {
 145          $db = PearDatabase::getInstance();
 146          $query = 'UPDATE vtiger_blocks SET sequence = CASE blockid ';
 147          foreach ($sequenceList as $blockId => $sequence){
 148              $query .=' WHEN '.$blockId.' THEN '.$sequence;
 149          }
 150          $query .=' END ';
 151          $query .= ' WHERE blockid IN ('.generateQuestionMarks($sequenceList).')';
 152          $db->pquery($query, array_keys($sequenceList));
 153      }
 154      
 155      public static function checkFieldsExists($blockId) {
 156          $db = PearDatabase::getInstance();
 157          $query = 'SELECT 1 FROM vtiger_field WHERE block=?';
 158          $result = $db->pquery($query, array($blockId));
 159          return ($db->num_rows($result) > 0) ? true : false;
 160      }
 161      
 162      /**
 163       * Function to push all blocks down after sequence number
 164       * @param type $fromSequence 
 165       */
 166  	public static function pushDown($fromSequence, $sourceModuleTabId) {
 167          $db = PearDatabase::getInstance();
 168          $query = 'UPDATE vtiger_blocks SET sequence=sequence+1 WHERE sequence > ? and tabid=?';
 169          $result = $db->pquery($query, array($fromSequence,$sourceModuleTabId));
 170      }
 171      
 172      public static function getAllBlockSequenceList($moduleTabId) {
 173          $db = PearDatabase::getInstance();
 174          $query = 'SELECT blockid,sequence FROM vtiger_blocks where tabid=?';
 175          $result = $db->pquery($query, array($moduleTabId));
 176          $response = array();
 177          $num_rows = $db->num_rows($result);
 178          for($i=0; $i<$num_rows; $i++) {
 179              $row = $db->query_result_rowdata($result, $i);
 180              $response[$row['blockid']] = $row['sequence'];
 181          }
 182          return $response;
 183      }
 184  
 185      /**
 186       * Function to check whether duplicate exist or not
 187       * @param <String> $blockLabel
 188       * @param <Number> ModuleId
 189       * @return <Boolean> true/false
 190       */
 191  	public static function checkDuplicate($blockLabel, $tabId) {
 192          $db = PearDatabase::getInstance();
 193  
 194          $result = $db->pquery('SELECT 1 FROM vtiger_blocks WHERE blocklabel = ? AND tabid = ?', array($blockLabel, $tabId));
 195          if ($db->num_rows($result)) {
 196              return true;
 197          }
 198          return false;
 199      }
 200      
 201  }


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