[ Index ]

PHP Cross Reference of vtigercrm-6.1.0

title

Body

[close]

/modules/Settings/LayoutEditor/models/ -> Field.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_LayoutEditor_Field_Model extends Vtiger_Field_Model {
  13  
  14      public function delete() {
  15          $adb = PearDatabase::getInstance();
  16          parent::delete();
  17  
  18          $fld_module = $this->getModuleName();
  19          $id = $this->getId();
  20          $uitype = $this->get('uitype');
  21          $typeofdata = $this->get('typeofdata');
  22          $fieldname = $this->getName();
  23          $oldfieldlabel = $this->get('fieldlabel');
  24          $tablename = $this->get('tablename');
  25          $columnname = $this->get('column');
  26          $fieldtype =  explode("~",$typeofdata);
  27  
  28          $focus = CRMEntity::getInstance($fld_module);
  29  
  30          $deletecolumnname =$tablename .":". $columnname .":".$fieldname.":".$fld_module. "_" .str_replace(" ","_",$oldfieldlabel).":".$fieldtype[0];
  31          $column_cvstdfilter =     $tablename .":". $columnname .":".$fieldname.":".$fld_module. "_" .str_replace(" ","_",$oldfieldlabel);
  32          $select_columnname = $tablename.":".$columnname .":".$fld_module. "_" . str_replace(" ","_",$oldfieldlabel).":".$fieldname.":".$fieldtype[0];
  33          $reportsummary_column = $tablename.":".$columnname.":".str_replace(" ","_",$oldfieldlabel);
  34  
  35          $dbquery = 'alter table '. $adb->sql_escape_string($focus->customFieldTable[0]).' drop column '. $adb->sql_escape_string($columnname);
  36          $adb->pquery($dbquery, array());
  37  
  38  
  39          //we have to remove the entries in customview and report related tables which have this field ($colName)
  40          $adb->pquery("delete from vtiger_cvcolumnlist where columnname = ? ", array($deletecolumnname));
  41          $adb->pquery("delete from vtiger_cvstdfilter where columnname = ?", array($column_cvstdfilter));
  42          $adb->pquery("delete from vtiger_cvadvfilter where columnname = ?", array($deletecolumnname));
  43          $adb->pquery("delete from vtiger_selectcolumn where columnname = ?", array($select_columnname));
  44          $adb->pquery("delete from vtiger_relcriteria where columnname = ?", array($select_columnname));
  45          $adb->pquery("delete from vtiger_reportsortcol where columnname = ?", array($select_columnname));
  46          $adb->pquery("delete from vtiger_reportdatefilter where datecolumnname = ?", array($column_cvstdfilter));
  47          $adb->pquery("delete from vtiger_reportsummary where columnname like ?", array('%'.$reportsummary_column.'%'));
  48  
  49  
  50          //Deleting from convert lead mapping vtiger_table- Jaguar
  51          if($fld_module=="Leads") {
  52              $deletequery = 'delete from vtiger_convertleadmapping where leadfid=?';
  53              $adb->pquery($deletequery, array($id));
  54          }elseif($fld_module=="Accounts" || $fld_module=="Contacts" || $fld_module=="Potentials") {
  55              $map_del_id = array("Accounts"=>"accountfid","Contacts"=>"contactfid","Potentials"=>"potentialfid");
  56              $map_del_q = "update vtiger_convertleadmapping set ".$map_del_id[$fld_module]."=0 where ".$map_del_id[$fld_module]."=?";
  57              $adb->pquery($map_del_q, array($id));
  58          }
  59  
  60          //HANDLE HERE - we have to remove the table for other picklist type values which are text area and multiselect combo box
  61          if($this->getFieldDataType() == 'picklist' || $this->getFieldDataType() == 'multipicklist') {
  62              $deltablequery = 'drop table vtiger_'.$adb->sql_escape_string($columnname);
  63              $adb->pquery($deltablequery, array());
  64              //To Delete Sequence Table 
  65              $deltableseqquery = 'drop table vtiger_'.$adb->sql_escape_string($columnname).'_seq'; 
  66              $adb->pquery($deltableseqquery, array()); 
  67              $adb->pquery("delete from  vtiger_picklist_dependency where sourcefield=? or targetfield=?", array($columnname,$columnname));
  68          }
  69      }
  70  
  71      /**
  72       * Function to Move the field
  73       * @param <Array> $fieldNewDetails
  74       * @param <Array> $fieldOlderDetails
  75       */
  76  	public function move($fieldNewDetails, $fieldOlderDetails) {
  77          $db = PearDatabase::getInstance();
  78  
  79          $newBlockId = $fieldNewDetails['blockId'];
  80          $olderBlockId = $fieldOlderDetails['blockId'];
  81  
  82          $newSequence = $fieldNewDetails['sequence'];
  83          $olderSequence = $fieldOlderDetails['sequence'];
  84  
  85          if ($olderBlockId == $newBlockId) {
  86              if ($newSequence > $olderSequence) {
  87                  $updateQuery = 'UPDATE vtiger_field SET sequence = sequence-1 WHERE sequence > ? AND sequence <= ? AND block = ?';
  88                  $params = array($olderSequence, $newSequence, $olderBlockId);
  89                  $db->pquery($updateQuery, $params);
  90  
  91              } else if($newSequence < $olderSequence) {
  92                  $updateQuery = 'UPDATE vtiger_field SET sequence = sequence+1 WHERE sequence < ? AND sequence >= ? AND block = ?';
  93                  $params = array($olderSequence, $newSequence, $olderBlockId);
  94                  $db->pquery($updateQuery, $params);
  95  
  96              }
  97              $query = 'UPDATE vtiger_field SET sequence = ? WHERE fieldid = ?';
  98              $params = array($newSequence, $this->getId());
  99              $db->pquery($query, $params);
 100          } else {
 101              $updateOldBlockQuery = 'UPDATE vtiger_field SET sequence = sequence-1 WHERE sequence > ? AND block = ?';
 102              $params = array($olderSequence, $olderBlockId);
 103              $db->pquery($updateOldBlockQuery, $params);
 104  
 105              $updateNewBlockQuery = 'UPDATE vtiger_field SET sequence = sequence+1 WHERE sequence >= ? AND block = ?';
 106              $params = array($newSequence, $newBlockId);
 107              $db->pquery($updateNewBlockQuery, $params);
 108  
 109              $query = 'UPDATE vtiger_field SET sequence = ?, block = ? WHERE fieldid = ?';
 110              $params = array($newSequence, $newBlockId, $this->getId());
 111              $db->pquery($query, $params);
 112          }
 113      }
 114  
 115      public static function makeFieldActive($fieldIdsList=array(), $blockId) {
 116          $db = PearDatabase::getInstance();
 117          $maxSequenceQuery = "SELECT MAX(sequence) AS maxsequence FROM vtiger_field WHERE block = ? AND presence IN (0,2) ";
 118          $res = $db->pquery($maxSequenceQuery,array($blockId));
 119          $maxSequence = $db->query_result($res,0,'maxsequence');
 120  
 121          $query = 'UPDATE vtiger_field SET presence = 2, sequence = CASE';
 122          foreach ($fieldIdsList as $fieldId) {
 123              $maxSequence = $maxSequence + 1;
 124              $query .= ' WHEN fieldid = ? THEN '. $maxSequence;
 125          }
 126          $query .= ' ELSE sequence END';
 127          $query .= ' WHERE fieldid IN ('.generateQuestionMarks($fieldIdsList).')';
 128  
 129          $db->pquery($query, array_merge($fieldIdsList,$fieldIdsList));
 130      }
 131  
 132      /**
 133       * Function which specifies whether the field can have mandatory switch to happen
 134       * @return <Boolean> - true if we can make a field mandatory and non mandatory , false if we cant change previous state
 135       */
 136      public function isMandatoryOptionDisabled() {
 137          $moduleModel = $this->getModule();
 138          $complusoryMandatoryFieldList = $moduleModel->getCumplosoryMandatoryFieldList();
 139          //uitypes for which mandatory switch is disabled
 140          $mandatoryRestrictedUitypes = array('4','70');
 141          if(in_array($this->getName(), $complusoryMandatoryFieldList)){
 142              return true;
 143          }
 144          if(in_array($this->get('uitype'),$mandatoryRestrictedUitypes) || $this->get('displaytype') == 2){
 145              return true;
 146          }
 147          return false;
 148      }
 149  
 150      /**
 151       * Function which will specify whether the active option is disabled
 152       * @return boolean
 153       */
 154      public function isActiveOptionDisabled() {
 155          if($this->get('presence') == 0 ||  $this->get('displaytype') == 2 || $this->isMandatoryOptionDisabled()){
 156              return true;
 157          }
 158          return false;
 159      }
 160  
 161      /**
 162       * Function which will specify whether the quickcreate option is disabled
 163       * @return boolean
 164       */
 165      public function isQuickCreateOptionDisabled() {
 166          $moduleModel = $this->getModule();
 167          if($this->get('quickcreate') == 0 || $this->get('quickcreate') == 3 || !$moduleModel->isQuickCreateSupported() || $this->get('uitype') == 69) {
 168              return true;
 169          }
 170          return false;
 171      }
 172  
 173      /**
 174       * Function which will specify whether the mass edit option is disabled
 175       * @return boolean
 176       */
 177      public function isMassEditOptionDisabled() {
 178          if($this->get('masseditable') == 0 || $this->get('displaytype') != 1 || $this->get('masseditable') == 3 || $this->get('uitype') == 69) {
 179              return true;
 180          }
 181          return false;
 182      }
 183  
 184      /**
 185       * Function which will specify whether the default value option is disabled
 186       * @return boolean
 187       */
 188      public function isDefaultValueOptionDisabled() {
 189          if($this->isMandatoryOptionDisabled() || $this->getFieldDataType() == Vtiger_Field_Model::REFERENCE_TYPE || $this->get('uitype') == 69){
 190              return true;
 191          }
 192          return false;
 193      }
 194  
 195      /**
 196       * Function to check whether summary field option is disable or not
 197       * @return <Boolean> true/false
 198       */
 199      public function isSummaryFieldOptionDisabled() {
 200          $moduleModel = $this->getModule();
 201          if($this->get('uitype') == 70) {
 202              return true;
 203          }
 204          return false;
 205      }
 206  
 207      /**
 208       * Function to check field is editable or not
 209       * @return <Boolean> true/false
 210       */
 211  	public function isEditable() {
 212          $moduleName = $this->block->module->name;
 213          if (in_array($moduleName, array('Calendar', 'Events'))) {
 214              return false;
 215          }
 216          return true;
 217      }
 218  
 219      /**
 220       * Function to get instance
 221       * @param <String> $value - fieldname or fieldid
 222       * @param <type> $module - optional - module instance
 223       * @return <Settings_LayoutEditor_Field_Model>
 224       */
 225  	public static function  getInstance($value, $module = false) {
 226          $fieldObject = parent::getInstance($value, $module);
 227          $objectProperties = get_object_vars($fieldObject);
 228          $fieldModel = new self();
 229          foreach($objectProperties as $properName=>$propertyValue) {
 230              $fieldModel->$properName = $propertyValue;
 231          }
 232          return $fieldModel;
 233      }
 234  
 235  	public static function getDetailsForMove($fieldIdsList = array()) {
 236          if ($fieldIdsList) {
 237              $db = PearDatabase::getInstance();
 238              $result = $db->pquery('SELECT fieldid, sequence, block, fieldlabel FROM vtiger_field WHERE fieldid IN ('. generateQuestionMarks($fieldIdsList) .')', $fieldIdsList);
 239              $numOfRows = $db->num_rows($result);
 240  
 241              for ($i=0; $i<$numOfRows; $i++) {
 242                  $blockIdsList[$db->query_result($result, $i, 'fieldid')] = array('blockId' => $db->query_result($result, $i, 'block'),
 243                                                                                   'sequence' => $db->query_result($result, $i, 'sequence'),
 244                                                                                   'label' => $db->query_result($result, $i, 'fieldlabel'));
 245              }
 246              return $blockIdsList;
 247          }
 248          return false;
 249      }
 250  
 251      /**
 252       * Function to get all fields list for all blocks
 253       * @param <Array> List of block ids
 254       * @param <Vtiger_Module_Model> $moduleInstance
 255       * @return <Array> List of Field models <Settings_LayoutEditor_Field_Model>
 256       */
 257  	public static function getInstanceFromBlockIdList($blockId, $moduleInstance= false) {
 258          $db = PearDatabase::getInstance();
 259  
 260          if(!is_array($blockId)) {
 261              $blockId = array($blockId);
 262          }
 263  
 264          $query = 'SELECT * FROM vtiger_field WHERE block IN('. generateQuestionMarks($blockId) .') AND vtiger_field.displaytype IN (1,2,4) ORDER BY sequence';
 265          $result = $db->pquery($query, $blockId);
 266          $numOfRows = $db->num_rows($result);
 267  
 268          $fieldModelsList = array();
 269          for($i=0; $i<$numOfRows; $i++) {
 270              $rowData = $db->query_result_rowdata($result, $i);
 271              //static is use to refer to the called class instead of defined class
 272              //http://php.net/manual/en/language.oop5.late-static-bindings.php
 273              $fieldModel = new self();
 274              $fieldModel->initialize($rowData);
 275              if($moduleInstance) {
 276                  $fieldModel->setModule($moduleInstance);
 277              }
 278              $fieldModelsList[] = $fieldModel;
 279          }
 280          return $fieldModelsList;
 281      }
 282  
 283      /**
 284       * Function to get the field details
 285       * @return <Array> - array of field values
 286       */
 287  	public function getFieldInfo() {
 288          $fieldInfo = parent::getFieldInfo();
 289          $fieldInfo['isQuickCreateDisabled'] = $this->isQuickCreateOptionDisabled();
 290          $fieldInfo['isSummaryField'] = $this->isSummaryField();
 291          $fieldInfo['isSummaryFieldDisabled'] = $this->isSummaryFieldOptionDisabled();
 292          $fieldInfo['isMassEditDisabled'] = $this->isMassEditOptionDisabled();
 293          $fieldInfo['isDefaultValueDisabled'] = $this->isDefaultValueOptionDisabled();
 294          return $fieldInfo;
 295      }
 296  
 297  
 298      public static function getInstanceFromFieldId($fieldId, $moduleTabId) {
 299          $db = PearDatabase::getInstance();
 300  
 301          if(is_string($fieldId)) {
 302              $fieldId = array($fieldId);
 303          }
 304  
 305          $query = 'SELECT * FROM vtiger_field WHERE fieldid IN ('.generateQuestionMarks($fieldId).') AND tabid=?';
 306          $result = $db->pquery($query, array($fieldId,$moduleTabId));
 307          $fieldModelList = array();
 308          $num_rows = $db->num_rows($result);
 309          for($i=0; $i<$num_rows; $i++) {
 310              $row = $db->query_result_rowdata($result, $i);
 311              $fieldModel = new self();
 312              $fieldModel->initialize($row);
 313              $fieldModelList[] = $fieldModel;
 314          }
 315          return $fieldModelList;
 316      }
 317  }


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