[ Index ]

PHP Cross Reference of vtigercrm-6.1.0

title

Body

[close]

/modules/Vtiger/models/ -> Field.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  include_once  'vtlib/Vtiger/Field.php';
  11  
  12  /**
  13   * Vtiger Field Model Class
  14   */
  15  class Vtiger_Field_Model extends Vtiger_Field {
  16  
  17      var $webserviceField = false;
  18  
  19      const REFERENCE_TYPE = 'reference';
  20      const OWNER_TYPE = 'owner';
  21      const CURRENCY_LIST = 'currencyList';
  22  
  23      const QUICKCREATE_MANDATORY = 0;
  24      const QUICKCREATE_NOT_ENABLED = 1;
  25      const QUICKCREATE_ENABLED = 2;
  26      const QUICKCREATE_NOT_PERMITTED = 3;
  27  
  28      /**
  29       * Function to get the value of a given property
  30       * @param <String> $propertyName
  31       * @return <Object>
  32       * @throws Exception
  33       */
  34  	public function get($propertyName) {
  35          if(property_exists($this,$propertyName)) {
  36              return $this->$propertyName;
  37          }
  38          return null;
  39      }
  40  
  41      /**
  42       * Function which sets value for given name
  43       * @param <String> $name - name for which value need to be assinged
  44       * @param <type> $value - values that need to be assigned
  45       * @return Vtiger_Field_Model
  46       */
  47  	public function set($name, $value) {
  48          $this->$name = $value;
  49          return $this;
  50      }
  51  
  52      /**
  53       * Function to get the Field Id
  54       * @return <Number>
  55       */
  56  	public function getId() {
  57          return $this->id;
  58      }
  59  
  60  	public function getName() {
  61          return $this->name;
  62      }
  63  
  64  	public function getFieldName() {
  65          return $this->name;
  66      }
  67  
  68      /**
  69       * Function to retrieve full data
  70       * @return <array>
  71       */
  72  	public function getData(){
  73          return get_object_vars($this);
  74      }
  75  
  76  	public function getModule() {
  77          if(!$this->module) {
  78              $moduleObj = $this->block->module;
  79                          //fix for opensource emailTemplate listview break
  80                          if(empty($moduleObj)){ 
  81                              return false; 
  82                          } 
  83              $this->module = Vtiger_Module_Model::getInstanceFromModuleObject($moduleObj);
  84          }
  85          return $this->module;
  86      }
  87  
  88      public function setModule($moduleInstance) {
  89          $this->module = $moduleInstance;
  90      }
  91  
  92      /**
  93       * Function to retieve display value for a value
  94       * @param <String> $value - value which need to be converted to display value
  95       * @return <String> - converted display value
  96       */
  97  	public function getDisplayValue($value, $record=false, $recordInstance = false) {
  98          if(!$this->uitype_instance) {
  99              $this->uitype_instance = Vtiger_Base_UIType::getInstanceFromField($this);
 100          }
 101          $uiTypeInstance = $this->uitype_instance;
 102          return $uiTypeInstance->getDisplayValue($value, $record, $recordInstance);
 103      }
 104  
 105      /**
 106       * Function to retrieve display type of a field
 107       * @return <String> - display type of the field
 108       */
 109  	public function getDisplayType() {
 110          return $this->get('displaytype');
 111      }
 112  
 113      /**
 114       * Function to get the Webservice Field Object for the current Field Object
 115       * @return WebserviceField instance
 116       */
 117  	public function getWebserviceFieldObject() {
 118          if($this->webserviceField == false) {
 119              $db = PearDatabase::getInstance();
 120  
 121              $row = array();
 122              $row['uitype'] = $this->get('uitype');
 123              $row['block'] = $this->get('block');
 124              $row['tablename'] = $this->get('table');
 125              $row['columnname'] = $this->get('column');
 126              $row['fieldname'] = $this->get('name');
 127              $row['fieldlabel'] = $this->get('label');
 128              $row['displaytype'] = $this->get('displaytype');
 129              $row['masseditable'] = $this->get('masseditable');
 130              $row['typeofdata'] = $this->get('typeofdata');
 131              $row['presence'] = $this->get('presence');
 132              $row['tabid'] = $this->getModuleId();
 133              $row['fieldid'] = $this->get('id');
 134              $row['readonly'] = !$this->getProfileReadWritePermission();
 135              $row['defaultvalue'] = $this->get('defaultvalue');
 136  
 137              $this->webserviceField = WebserviceField::fromArray($db, $row);
 138          }
 139          return $this->webserviceField;
 140      }
 141  
 142      /**
 143       * Function to get the Webservice Field data type
 144       * @return <String> Data type of the field
 145       */
 146  	public function getFieldDataType() {
 147          if(!$this->fieldDataType) {
 148              $uiType = $this->get('uitype');
 149              if($uiType == '69') {
 150                  $fieldDataType = 'image';
 151              } else if($uiType == '26') {
 152                  $fieldDataType = 'documentsFolder';
 153              } else if($uiType == '27') {
 154                  $fieldDataType = 'fileLocationType';
 155              } else if($uiType == '9') {
 156                  $fieldDataType = 'percentage';
 157              } else if($uiType == '28') {
 158                  $fieldDataType = 'documentsFileUpload';
 159              } else if($uiType == '83') {
 160                  $fieldDataType = 'productTax';
 161              } else if($uiType == '117') {
 162                  $fieldDataType = 'currencyList';
 163              } else if($uiType == '55' && $this->getName() === 'salutationtype') {
 164                  $fieldDataType = 'picklist';
 165              } else if($uiType == '55' && $this->getName() === 'firstname') {
 166                  $fieldDataType = 'salutation';
 167              } else if($uiType == '54') {
 168                  $fieldDataType = 'multiowner';
 169              } else {
 170                  $webserviceField = $this->getWebserviceFieldObject();
 171                  $fieldDataType = $webserviceField->getFieldDataType();
 172              }
 173              $this->fieldDataType = $fieldDataType;
 174          }
 175          return $this->fieldDataType;
 176      }
 177  
 178      /**
 179       * Function to get list of modules the field refernced to
 180       * @return <Array> -  list of modules for which field is refered to
 181       */
 182  	public function getReferenceList() {
 183          $webserviceField = $this->getWebserviceFieldObject();
 184          return $webserviceField->getReferenceList();
 185      }
 186  
 187      /**
 188       * Function to check if the field is named field of the module
 189       * @return <Boolean> - True/False
 190       */
 191  	public function isNameField() {
 192          $nameFieldObject = Vtiger_Cache::get('EntityField',$this->getModuleName());
 193          if(!$nameFieldObject){
 194              $moduleModel = $this->getModule();
 195              if(!empty($moduleModel)) {
 196                  $moduleEntityNameFields = $moduleModel->getNameFields();
 197              }else{
 198                  $moduleEntityNameFields = array();
 199              }
 200  
 201          }else{
 202              $moduleEntityNameFields = explode(',', $nameFieldObject->fieldname);
 203          }
 204  
 205          if(in_array($this->get('name'), $moduleEntityNameFields)) {
 206              return true;
 207          }
 208          return false;
 209      }
 210  
 211      /**
 212       * Function to check whether the current field is read-only
 213       * @return <Boolean> - true/false
 214       */
 215  	public function isReadOnly() {
 216          $webserviceField = $this->getWebserviceFieldObject();
 217          return $webserviceField->isReadOnly();
 218      }
 219  
 220      /**
 221       * Function to get the UI Type model for the uitype of the current field
 222       * @return Vtiger_Base_UIType or UI Type specific model instance
 223       */
 224  	public function getUITypeModel() {
 225          return Vtiger_Base_UIType::getInstanceFromField($this);
 226      }
 227  
 228      public function isRoleBased() {
 229          if($this->get('uitype') == '15' || $this->get('uitype') == '33' || ($this->get('uitype') == '55' && $this->getFieldName() == 'salutationtype')) {
 230              return true;
 231          }
 232          return false;
 233      }
 234  
 235      /**
 236       * Function to get all the available picklist values for the current field
 237       * @return <Array> List of picklist values if the field is of type picklist or multipicklist, null otherwise.
 238       */
 239  	public function getPicklistValues() {
 240          $fieldDataType = $this->getFieldDataType();
 241          if($this->getName() == 'hdnTaxType') return null;
 242  
 243          if($fieldDataType == 'picklist' || $fieldDataType == 'multipicklist') {
 244              $currentUser = Users_Record_Model::getCurrentUserModel();
 245              if($this->isRoleBased()) {
 246                  $userModel = Users_Record_Model::getCurrentUserModel();
 247                  $picklistValues = Vtiger_Util_Helper::getRoleBasedPicklistValues($this->getName(), $userModel->get('roleid'));
 248              }else{
 249                  $picklistValues = Vtiger_Util_Helper::getPickListValues($this->getName());
 250              }
 251              foreach($picklistValues as $value) {
 252                  $fieldPickListValues[$value] = vtranslate($value,$this->getModuleName());
 253              }
 254              return $fieldPickListValues;
 255              }
 256          return null;
 257      }
 258  
 259      /**
 260       * Function to check if the current field is mandatory or not
 261       * @return <Boolean> - true/false
 262       */
 263  	public function isMandatory() {
 264          list($type,$mandatory)= explode('~',$this->get('typeofdata'));
 265          return $mandatory=='M' ? true:false;
 266      }
 267  
 268      /**
 269       * Function to get the field type
 270       * @return <String> type of the field
 271       */
 272  	public function getFieldType(){
 273          $webserviceField = $this->getWebserviceFieldObject();
 274          return $webserviceField->getFieldType();
 275      }
 276  
 277      /**
 278       * Function to check if the field is shown in detail view
 279       * @return <Boolean> - true/false
 280       */
 281  	public function isViewEnabled() {
 282          $permision = $this->getPermissions();
 283          if ($this->getDisplayType() == '4' || in_array($this->get('presence'), array(1, 3))) {
 284              return false;
 285          }
 286          return $permision;
 287      }
 288  
 289  
 290      /**
 291       * Function to check if the field is shown in detail view
 292       * @return <Boolean> - true/false
 293       */
 294  	public function isViewable() {
 295          if(!$this->isViewEnabled()) {
 296              return false;
 297          }
 298          return true;
 299      }
 300  
 301      /**
 302       * Function to check if the field is shown in detail view
 303       * @return <Boolean> - true/false
 304       */
 305  	public function isViewableInDetailView() {
 306          if(!$this->isViewable() || $this->getDisplayType() == '3' || $this->getDisplayType() == '5') {
 307              return false;
 308          }
 309          return true;
 310      }
 311  
 312  	public function isEditEnabled() {
 313          $displayType = (int)$this->get('displaytype');
 314          $editEnabledDisplayTypes = array(1,3);
 315          if(!$this->isViewEnabled() ||
 316                  !in_array($displayType, $editEnabledDisplayTypes) ||
 317                  strcasecmp($this->getFieldDataType(),"autogenerated") ===0 ||
 318                  strcasecmp($this->getFieldDataType(),"id") ===0) {
 319  
 320              return false;
 321          }
 322          return true;
 323      }
 324  
 325      public function isQuickCreateEnabled() {
 326          $moduleModel = $this->getModule();
 327          $quickCreate = $this->get('quickcreate');
 328          if(($quickCreate == self::QUICKCREATE_MANDATORY || $quickCreate == self::QUICKCREATE_ENABLED
 329                  || $this->isMandatory()) && $this->get('uitype') != 69) {
 330              //isQuickCreateSupported will not be there for settings
 331              if(method_exists($moduleModel,'isQuickCreateSupported') && $moduleModel->isQuickCreateSupported()) {
 332              return true;
 333          }
 334          }
 335          return false;
 336      }
 337  
 338      /**
 339       * Function to check whether summary field or not
 340       * @return <Boolean> true/false
 341       */
 342  	 public function isSummaryField() {
 343           return ($this->get('summaryfield')) ? true : false;
 344      }
 345  
 346      /**
 347       * Function to check whether the current field is editable
 348       * @return <Boolean> - true/false
 349       */
 350  	public function isEditable() {
 351          if(!$this->isEditEnabled()
 352                  || !$this->isViewable() ||
 353                  ((int)$this->get('displaytype')) != 1 ||
 354                  $this->isReadOnly() == true ||
 355                  $this->get('uitype') ==  4) {
 356  
 357              return false;
 358          }
 359          return true;
 360      }
 361  
 362      /**
 363       * Function to check whether field is ajax editable'
 364       * @return <Boolean>
 365       */
 366  	public function isAjaxEditable() {
 367          $ajaxRestrictedFields = array('4', '72');
 368          if(!$this->isEditable() || in_array($this->get('uitype'), $ajaxRestrictedFields)) {
 369              return false;
 370          }
 371          return true;
 372      }
 373  
 374      /**
 375       * Static Function to get the instance fo Vtiger Field Model from a given Vtiger_Field object
 376       * @param Vtiger_Field $fieldObj - vtlib field object
 377       * @return Vtiger_Field_Model instance
 378       */
 379  	public static function getInstanceFromFieldObject(Vtiger_Field $fieldObj) {
 380          $objectProperties = get_object_vars($fieldObj);
 381          $className = Vtiger_Loader::getComponentClassName('Model', 'Field', $fieldObj->getModuleName());
 382          $fieldModel = new $className();
 383          foreach($objectProperties as $properName=>$propertyValue) {
 384              $fieldModel->$properName = $propertyValue;
 385          }
 386          return $fieldModel;
 387      }
 388  
 389      /**
 390       * Function to get the custom view column name transformation of the field for a date field used in date filters
 391       * @return <String> - tablename:columnname:fieldname:module_fieldlabel
 392       */
 393  	public function getCVDateFilterColumnName() {
 394          $moduleName = $this->getModuleName();
 395          $tableName = $this->get('table');
 396          $columnName = $this->get('column');
 397          $fieldName = $this->get('name');
 398          $fieldLabel = $this->get('label');
 399  
 400          $escapedFieldLabel = str_replace(' ', '_', $fieldLabel);
 401          $moduleFieldLabel = $moduleName.'_'.$escapedFieldLabel;
 402  
 403          return $tableName.':'.$columnName.':'.$fieldName.':'.$moduleFieldLabel;
 404      }
 405  
 406      /**
 407       * Function to get the custom view column name transformation of the field
 408       * @return <String> - tablename:columnname:fieldname:module_fieldlabel:fieldtype
 409       */
 410  	public function getCustomViewColumnName() {
 411          $moduleName = $this->getModuleName();
 412          $tableName = $this->get('table');
 413          $columnName = $this->get('column');
 414          $fieldName = $this->get('name');
 415          $fieldLabel = $this->get('label');
 416          $typeOfData = $this->get('typeofdata');
 417  
 418          $fieldTypeOfData = explode('~', $typeOfData);
 419          $fieldType = $fieldTypeOfData[0];
 420  
 421          //Special condition need for reference field as they should be treated as string field
 422          if($this->getFieldDataType() == 'reference') {
 423              $fieldType = 'V';
 424          } else {
 425              $fieldType = ChangeTypeOfData_Filter($tableName, $columnName, $fieldType);
 426          }
 427  
 428          $escapedFieldLabel = str_replace(' ', '_', $fieldLabel);
 429          $moduleFieldLabel = $moduleName.'_'.$escapedFieldLabel;
 430  
 431          return $tableName.':'.$columnName.':'.$fieldName.':'.$moduleFieldLabel.':'.$fieldType;
 432      }
 433  
 434      /**
 435       * Function to get the Report column name transformation of the field
 436       * @return <String> - tablename:columnname:module_fieldlabel:fieldname:fieldtype
 437       */
 438  	public function getReportFilterColumnName() {
 439          $moduleName = $this->getModuleName();
 440          $tableName = $this->get('table');
 441          $columnName = $this->get('column');
 442          $fieldName = $this->get('name');
 443          $fieldLabel = $this->get('label');
 444          $typeOfData = $this->get('typeofdata');
 445  
 446          $fieldTypeOfData = explode('~', $typeOfData);
 447          $fieldType = $fieldTypeOfData[0];
 448          if($this->getFieldDataType() == 'reference') {
 449              $fieldType = 'V';
 450          } else {
 451              $fieldType = ChangeTypeOfData_Filter($tableName, $columnName, $fieldType);
 452          }
 453          $escapedFieldLabel = str_replace(' ', '_', $fieldLabel);
 454          $moduleFieldLabel = $moduleName.'_'.$escapedFieldLabel;
 455  
 456          if($tableName == 'vtiger_crmentity' && $columnName !='smownerid'){
 457              $tableName = 'vtiger_crmentity'.$moduleName;
 458          } elseif($columnName == 'smownerid') {
 459              $tableName = 'vtiger_users'.$moduleName;
 460              $columnName ='user_name';
 461          }
 462  
 463          return $tableName.':'.$columnName.':'.$moduleFieldLabel.':'.$fieldName.':'.$fieldType;
 464      }
 465  
 466      /**
 467       * This is set from Workflow Record Structure, since workflow expects the field name
 468       * in a different format in its filter. Eg: for module field its fieldname and for reference
 469       * fields its reference_field_name : (reference_module_name) field - salesorder_id: (SalesOrder) subject
 470       * @return <String>
 471       */
 472  	function getWorkFlowFilterColumnName() {
 473          return $this->get('workflow_columnname');
 474      }
 475  
 476      /**
 477       * Function to get the field details
 478       * @return <Array> - array of field values
 479       */
 480  	public function getFieldInfo() {
 481          $currentUser = Users_Record_Model::getCurrentUserModel();
 482          $fieldDataType = $this->getFieldDataType();
 483  
 484          $this->fieldInfo['mandatory'] = $this->isMandatory();
 485          $this->fieldInfo['presence'] = $this->isActiveField();
 486          $this->fieldInfo['quickcreate'] = $this->isQuickCreateEnabled();
 487          $this->fieldInfo['masseditable'] = $this->isMassEditable();
 488          $this->fieldInfo['defaultvalue'] = $this->hasDefaultValue();
 489          $this->fieldInfo['type'] = $fieldDataType;
 490          $this->fieldInfo['name'] = $this->get('name');
 491          $this->fieldInfo['label'] = vtranslate($this->get('label'), $this->getModuleName());
 492  
 493          if($fieldDataType == 'picklist' || $fieldDataType == 'multipicklist' || $fieldDataType == 'multiowner') {
 494              $pickListValues = $this->getPicklistValues();
 495              if(!empty($pickListValues)) {
 496                  $this->fieldInfo['picklistvalues'] = $pickListValues;
 497              } else {
 498                  $this->fieldInfo['picklistvalues'] = array();
 499              }
 500          }
 501  
 502          if($this->getFieldDataType() == 'date' || $this->getFieldDataType() == 'datetime'){
 503              $currentUser = Users_Record_Model::getCurrentUserModel();
 504              $this->fieldInfo['date-format'] = $currentUser->get('date_format');
 505          }
 506  
 507          if($this->getFieldDataType() == 'time') {
 508              $currentUser = Users_Record_Model::getCurrentUserModel();
 509              $this->fieldInfo['time-format'] = $currentUser->get('hour_format');
 510          }
 511  
 512          if($this->getFieldDataType() == 'currency') {
 513              $currentUser = Users_Record_Model::getCurrentUserModel();
 514              $this->fieldInfo['currency_symbol'] = $currentUser->get('currency_symbol');
 515              $this->fieldInfo['decimal_seperator'] = $currentUser->get('currency_decimal_separator');
 516              $this->fieldInfo['group_seperator'] = $currentUser->get('currency_grouping_separator');
 517          }
 518  
 519          if($this->getFieldDataType() == 'owner') {
 520              $userList = $currentUser->getAccessibleUsers();
 521              $groupList = $currentUser->getAccessibleGroups();
 522              $pickListValues = array();
 523              $pickListValues[vtranslate('LBL_USERS', $this->getModuleName())] = $userList;
 524              $pickListValues[vtranslate('LBL_GROUPS', $this->getModuleName())] = $groupList;
 525              $this->fieldInfo['picklistvalues'] = $pickListValues;
 526          }
 527  
 528          return $this->fieldInfo;
 529      }
 530  
 531  	function setFieldInfo($fieldInfo) {
 532          $this->fieldInfo = $fieldInfo;
 533      }
 534      /**
 535       * Function to get the date values for the given type of Standard filter
 536       * @param <String> $type
 537       * @return <Array> - 2 date values representing the range for the given type of Standard filter
 538       */
 539  	protected static function getDateForStdFilterBytype($type) {
 540          $today = date("Y-m-d", mktime(0, 0, 0, date("m"), date("d"), date("Y")));
 541          $todayName =  date('l', strtotime( $today));
 542  
 543          $tomorrow = date("Y-m-d", mktime(0, 0, 0, date("m"), date("d") + 1, date("Y")));
 544          $yesterday = date("Y-m-d", mktime(0, 0, 0, date("m"), date("d") - 1, date("Y")));
 545  
 546          $currentmonth0 = date("Y-m-d", mktime(0, 0, 0, date("m"), "01", date("Y")));
 547          $currentmonth1 = date("Y-m-t");
 548          $lastmonth0 = date("Y-m-d", mktime(0, 0, 0, date("m") - 1, "01", date("Y")));
 549          $lastmonth1 = date("Y-m-t", strtotime($lastmonth0));
 550          $nextmonth0 = date("Y-m-d", mktime(0, 0, 0, date("m") + 1, "01", date("Y")));
 551          $nextmonth1 = date("Y-m-t", strtotime($nextmonth0));
 552  
 553            // (Last Week) If Today is "Sunday" then "-2 week Sunday" will give before last week Sunday date
 554          if($todayName == "Sunday")
 555              $lastweek0 = date("Y-m-d",strtotime("-1 week Sunday"));
 556          else
 557              $lastweek0 = date("Y-m-d", strtotime("-2 week Sunday"));
 558          $lastweek1 = date("Y-m-d", strtotime("-1 week Saturday"));
 559  
 560          // (This Week) If Today is "Sunday" then "-1 week Sunday" will give last week Sunday date
 561          if($todayName == "Sunday")
 562              $thisweek0 = date("Y-m-d",strtotime("-0 week Sunday"));
 563          else
 564              $thisweek0 = date("Y-m-d", strtotime("-1 week Sunday"));
 565          $thisweek1 = date("Y-m-d", strtotime("this Saturday"));
 566  
 567           // (Next Week) If Today is "Sunday" then "this Sunday" will give Today's date
 568          if($todayName == "Sunday")
 569              $nextweek0 = date("Y-m-d",strtotime("+1 week Sunday"));
 570          else
 571              $nextweek0 = date("Y-m-d", strtotime("this Sunday"));
 572          $nextweek1 = date("Y-m-d", strtotime("+1 week Saturday"));
 573  
 574          $next7days = date("Y-m-d", mktime(0, 0, 0, date("m"), date("d") + 6, date("Y")));
 575          $next30days = date("Y-m-d", mktime(0, 0, 0, date("m"), date("d") + 29, date("Y")));
 576          $next60days = date("Y-m-d", mktime(0, 0, 0, date("m"), date("d") + 59, date("Y")));
 577          $next90days = date("Y-m-d", mktime(0, 0, 0, date("m"), date("d") + 89, date("Y")));
 578          $next120days = date("Y-m-d", mktime(0, 0, 0, date("m"), date("d") + 119, date("Y")));
 579  
 580          $last7days = date("Y-m-d", mktime(0, 0, 0, date("m"), date("d") - 6, date("Y")));
 581          $last30days = date("Y-m-d", mktime(0, 0, 0, date("m"), date("d") - 29, date("Y")));
 582          $last60days = date("Y-m-d", mktime(0, 0, 0, date("m"), date("d") - 59, date("Y")));
 583          $last90days = date("Y-m-d", mktime(0, 0, 0, date("m"), date("d") - 89, date("Y")));
 584          $last120days = date("Y-m-d", mktime(0, 0, 0, date("m"), date("d") - 119, date("Y")));
 585  
 586          $currentFY0 = date("Y-m-d", mktime(0, 0, 0, "01", "01", date("Y")));
 587          $currentFY1 = date("Y-m-t", mktime(0, 0, 0, "12", date("d"), date("Y")));
 588          $lastFY0 = date("Y-m-d", mktime(0, 0, 0, "01", "01", date("Y") - 1));
 589          $lastFY1 = date("Y-m-t", mktime(0, 0, 0, "12", date("d"), date("Y") - 1));
 590          $nextFY0 = date("Y-m-d", mktime(0, 0, 0, "01", "01", date("Y") + 1));
 591          $nextFY1 = date("Y-m-t", mktime(0, 0, 0, "12", date("d"), date("Y") + 1));
 592  
 593          if (date("m") <= 3) {
 594              $cFq = date("Y-m-d", mktime(0, 0, 0, "01", "01", date("Y")));
 595              $cFq1 = date("Y-m-d", mktime(0, 0, 0, "03", "31", date("Y")));
 596              $nFq = date("Y-m-d", mktime(0, 0, 0, "04", "01", date("Y")));
 597              $nFq1 = date("Y-m-d", mktime(0, 0, 0, "06", "30", date("Y")));
 598              $pFq = date("Y-m-d", mktime(0, 0, 0, "10", "01", date("Y") - 1));
 599              $pFq1 = date("Y-m-d", mktime(0, 0, 0, "12", "31", date("Y") - 1));
 600          } else if (date("m") > 3 and date("m") <= 6) {
 601              $cFq = date("Y-m-d", mktime(0, 0, 0, "04", "01", date("Y")));
 602              $cFq1 = date("Y-m-d", mktime(0, 0, 0, "06", "30", date("Y")));
 603              $nFq = date("Y-m-d", mktime(0, 0, 0, "07", "01", date("Y")));
 604              $nFq1 = date("Y-m-d", mktime(0, 0, 0, "09", "30", date("Y")));
 605              $pFq = date("Y-m-d", mktime(0, 0, 0, "01", "01", date("Y")));
 606              $pFq1 = date("Y-m-d", mktime(0, 0, 0, "03", "31", date("Y")));
 607          } else if (date("m") > 6 and date("m") <= 9) {
 608              $cFq = date("Y-m-d", mktime(0, 0, 0, "07", "01", date("Y")));
 609              $cFq1 = date("Y-m-d", mktime(0, 0, 0, "09", "30", date("Y")));
 610              $nFq = date("Y-m-d", mktime(0, 0, 0, "10", "01", date("Y")));
 611              $nFq1 = date("Y-m-d", mktime(0, 0, 0, "12", "31", date("Y")));
 612              $pFq = date("Y-m-d", mktime(0, 0, 0, "04", "01", date("Y")));
 613              $pFq1 = date("Y-m-d", mktime(0, 0, 0, "06", "30", date("Y")));
 614          } else {
 615              $cFq = date("Y-m-d", mktime(0, 0, 0, "10", "01", date("Y")));
 616              $cFq1 = date("Y-m-d", mktime(0, 0, 0, "12", "31", date("Y")));
 617              $nFq = date("Y-m-d", mktime(0, 0, 0, "01", "01", date("Y") + 1));
 618              $nFq1 = date("Y-m-d", mktime(0, 0, 0, "03", "31", date("Y") + 1));
 619              $pFq = date("Y-m-d", mktime(0, 0, 0, "07", "01", date("Y")));
 620              $pFq1 = date("Y-m-d", mktime(0, 0, 0, "09", "30", date("Y")));
 621          }
 622  
 623          $dateValues = array();
 624          if ($type == "today") {
 625              $dateValues[0] = $today;
 626              $dateValues[1] = $today;
 627          } elseif ($type == "yesterday") {
 628              $dateValues[0] = $yesterday;
 629              $dateValues[1] = $yesterday;
 630          } elseif ($type == "tomorrow") {
 631              $dateValues[0] = $tomorrow;
 632              $dateValues[1] = $tomorrow;
 633          } elseif ($type == "thisweek") {
 634              $dateValues[0] = $thisweek0;
 635              $dateValues[1] = $thisweek1;
 636          } elseif ($type == "lastweek") {
 637              $dateValues[0] = $lastweek0;
 638              $dateValues[1] = $lastweek1;
 639          } elseif ($type == "nextweek") {
 640              $dateValues[0] = $nextweek0;
 641              $dateValues[1] = $nextweek1;
 642          } elseif ($type == "thismonth") {
 643              $dateValues[0] = $currentmonth0;
 644              $dateValues[1] = $currentmonth1;
 645          } elseif ($type == "lastmonth") {
 646              $dateValues[0] = $lastmonth0;
 647              $dateValues[1] = $lastmonth1;
 648          } elseif ($type == "nextmonth") {
 649              $dateValues[0] = $nextmonth0;
 650              $dateValues[1] = $nextmonth1;
 651          } elseif ($type == "next7days") {
 652              $dateValues[0] = $today;
 653              $dateValues[1] = $next7days;
 654          } elseif ($type == "next30days") {
 655              $dateValues[0] = $today;
 656              $dateValues[1] = $next30days;
 657          } elseif ($type == "next60days") {
 658              $dateValues[0] = $today;
 659              $dateValues[1] = $next60days;
 660          } elseif ($type == "next90days") {
 661              $dateValues[0] = $today;
 662              $dateValues[1] = $next90days;
 663          } elseif ($type == "next120days") {
 664              $dateValues[0] = $today;
 665              $dateValues[1] = $next120days;
 666          } elseif ($type == "last7days") {
 667              $dateValues[0] = $last7days;
 668              $dateValues[1] = $today;
 669          } elseif ($type == "last30days") {
 670              $dateValues[0] = $last30days;
 671              $dateValues[1] = $today;
 672          } elseif ($type == "last60days") {
 673              $dateValues[0] = $last60days;
 674              $dateValues[1] = $today;
 675          } else if ($type == "last90days") {
 676              $dateValues[0] = $last90days;
 677              $dateValues[1] = $today;
 678          } elseif ($type == "last120days") {
 679              $dateValues[0] = $last120days;
 680              $dateValues[1] = $today;
 681          } elseif ($type == "thisfy") {
 682              $dateValues[0] = $currentFY0;
 683              $dateValues[1] = $currentFY1;
 684          } elseif ($type == "prevfy") {
 685              $dateValues[0] = $lastFY0;
 686              $dateValues[1] = $lastFY1;
 687          } elseif ($type == "nextfy") {
 688              $dateValues[0] = $nextFY0;
 689              $dateValues[1] = $nextFY1;
 690          } elseif ($type == "nextfq") {
 691              $dateValues[0] = $nFq;
 692              $dateValues[1] = $nFq1;
 693          } elseif ($type == "prevfq") {
 694              $dateValues[0] = $pFq;
 695              $dateValues[1] = $pFq1;
 696          } elseif ($type == "thisfq") {
 697              $dateValues[0] = $cFq;
 698              $dateValues[1] = $cFq1;
 699          } else {
 700              $dateValues[0] = "";
 701              $dateValues[1] = "";
 702          }
 703  
 704          return $dateValues;
 705      }
 706  
 707      /**
 708       * Function to get all the date filter type informations
 709       * @return <Array>
 710       */
 711  	public static function getDateFilterTypes() {
 712          $dateFilters = Array('custom' => array('label' => 'LBL_CUSTOM'),
 713                                  'prevfy' => array('label' => 'LBL_PREVIOUS_FY'),
 714                                  'thisfy' => array('label' => 'LBL_CURRENT_FY'),
 715                                  'nextfy' => array('label' => 'LBL_NEXT_FY'),
 716                                  'prevfq' => array('label' => 'LBL_PREVIOUS_FQ'),
 717                                  'thisfq' => array('label' => 'LBL_CURRENT_FQ'),
 718                                  'nextfq' => array('label' => 'LBL_NEXT_FQ'),
 719                                  'yesterday' => array('label' => 'LBL_YESTERDAY'),
 720                                  'today' => array('label' => 'LBL_TODAY'),
 721                                  'tomorrow' => array('label' => 'LBL_TOMORROW'),
 722                                  'lastweek' => array('label' => 'LBL_LAST_WEEK'),
 723                                  'thisweek' => array('label' => 'LBL_CURRENT_WEEK'),
 724                                  'nextweek' => array('label' => 'LBL_NEXT_WEEK'),
 725                                  'lastmonth' => array('label' => 'LBL_LAST_MONTH'),
 726                                  'thismonth' => array('label' => 'LBL_CURRENT_MONTH'),
 727                                  'nextmonth' => array('label' => 'LBL_NEXT_MONTH'),
 728                                  'last7days' => array('label' => 'LBL_LAST_7_DAYS'),
 729                                  'last30days' => array('label' => 'LBL_LAST_30_DAYS'),
 730                                  'last60days' => array('label' => 'LBL_LAST_60_DAYS'),
 731                                  'last90days' => array('label' => 'LBL_LAST_90_DAYS'),
 732                                  'last120days' => array('label' => 'LBL_LAST_120_DAYS'),
 733                                  'next30days' => array('label' => 'LBL_NEXT_30_DAYS'),
 734                                  'next60days' => array('label' => 'LBL_NEXT_60_DAYS'),
 735                                  'next90days' => array('label' => 'LBL_NEXT_90_DAYS'),
 736                                  'next120days' => array('label' => 'LBL_NEXT_120_DAYS')
 737                              );
 738  
 739          foreach($dateFilters as $filterType => $filterDetails) {
 740              $dateValues = self::getDateForStdFilterBytype($filterType);
 741              $dateFilters[$filterType]['startdate'] = $dateValues[0];
 742              $dateFilters[$filterType]['enddate'] = $dateValues[1];
 743          }
 744          return $dateFilters;
 745      }
 746  
 747      /**
 748       * Function to get all the supported advanced filter operations
 749       * @return <Array>
 750       */
 751  	public static function getAdvancedFilterOptions() {
 752          return array(
 753              'e' => 'LBL_EQUALS',
 754              'n' => 'LBL_NOT_EQUAL_TO',
 755              's' => 'LBL_STARTS_WITH',
 756              'ew' => 'LBL_ENDS_WITH',
 757              'c' => 'LBL_CONTAINS',
 758              'k' => 'LBL_DOES_NOT_CONTAIN',
 759              'l' => 'LBL_LESS_THAN',
 760              'g' => 'LBL_GREATER_THAN',
 761              'm' => 'LBL_LESS_THAN_OR_EQUAL',
 762              'h' => 'LBL_GREATER_OR_EQUAL',
 763              'b' => 'LBL_BEFORE',
 764              'a' => 'LBL_AFTER',
 765              'bw' => 'LBL_BETWEEN',
 766              'y' => 'LBL_IS_EMPTY',
 767              'ny'=> 'LBL_IS_NOT_EMPTY'
 768          );
 769      }
 770  
 771  
 772      /**
 773       * Function to get the advanced filter option names by Field type
 774       * @return <Array>
 775       */
 776  	public static function getAdvancedFilterOpsByFieldType() {
 777          return array(
 778              'V' => array('e','n','s','ew','c','k','y','ny'),
 779              'N' => array('e','n','l','g','m','h', 'y','ny'),
 780              'T' => array('e','n','l','g','m','h','bw','b','a','y','ny'),
 781              'I' => array('e','n','l','g','m','h','y','ny'),
 782              'C' => array('e','n','y','ny'),
 783              'D' => array('e','n','bw','b','a','y','ny'),
 784              'DT' => array('e','n','bw','b','a','y','ny'),
 785              'NN' => array('e','n','l','g','m','h','y','ny'),
 786              'E' => array('e','n','s','ew','c','k','y','ny')
 787          );
 788      }
 789  
 790  
 791       /**
 792       * Function to retrieve field model for specific block and module
 793       * @param <Vtiger_Module_Model> $blockModel - block instance
 794       * @return <array> List of field model
 795       */
 796  	public static function getAllForModule($moduleModel){
 797          $fieldModelList = Vtiger_Cache::get('ModuleFields',$moduleModel->id);
 798          if(!$fieldModelList){
 799              $fieldObjects = parent::getAllForModule($moduleModel);
 800  
 801              $fieldModelList = array();
 802              //if module dont have any fields
 803              if(!is_array($fieldObjects)){
 804                  $fieldObjects = array();
 805              }
 806  
 807              foreach($fieldObjects as $fieldObject){
 808                  $fieldModelObject= self::getInstanceFromFieldObject($fieldObject);
 809                  $fieldModelList[$fieldModelObject->get('block')->id][] = $fieldModelObject;
 810                  Vtiger_Cache::set('field-'.$moduleModel->getId(),$fieldModelObject->getId(),$fieldModelObject);
 811                  Vtiger_Cache::set('field-'.$moduleModel->getId(),$fieldModelObject->getName(),$fieldModelObject);
 812              }
 813  
 814              Vtiger_Cache::set('ModuleFields',$moduleModel->id,$fieldModelList);
 815          }
 816          return $fieldModelList;
 817      }
 818  
 819      /**
 820       * Function to get instance
 821       * @param <String> $value - fieldname or fieldid
 822       * @param <type> $module - optional - module instance
 823       * @return <Vtiger_Field_Model>
 824       */
 825  	public static function  getInstance($value, $module = false) {
 826          $fieldObject = null;
 827          if($module){
 828              $fieldObject = Vtiger_Cache::get('field-'.$module->getId(), $value);
 829          }
 830          if(!$fieldObject){
 831              $fieldObject = parent::getInstance($value, $module);
 832              if($module){
 833                  Vtiger_Cache::set('field-'.$module->getId(),$value,$fieldObject);
 834              }
 835          }
 836  
 837          if($fieldObject) {
 838              return self::getInstanceFromFieldObject($fieldObject);
 839          }
 840          return false;
 841      }
 842  
 843      /**
 844       * Added function that returns the folders in a Document
 845       * @return <Array>
 846       */
 847  	function getDocumentFolders() {
 848          $db = PearDatabase::getInstance();
 849          $result = $db->pquery('SELECT * FROM vtiger_attachmentsfolder', array());
 850          $rows = $db->num_rows($result);
 851          $folders = array();
 852          for($i=0; $i<$rows; $i++){
 853              $folderId = $db->query_result($result, $i, 'folderid');
 854              $folderName = $db->query_result($result, $i, 'foldername');
 855              $folders[$folderId] = $folderName;
 856          }
 857          return $folders;
 858      }
 859  
 860      /**
 861       * Function checks if the current Field is Read/Write
 862       * @return <Boolean>
 863       */
 864  	function getProfileReadWritePermission() {
 865          return $this->getPermissions('readwrite');
 866      }
 867  
 868      /**
 869       * Function returns Client Side Validators name
 870       * @return <Array> [name=>Name of the Validator, params=>Extra Parameters]
 871      */
 872      /**TODO: field validator need to be handled in specific module getValidator api  **/
 873  	function getValidator() {
 874          $validator = array();
 875          $fieldName = $this->getName();
 876          switch($fieldName) {
 877              case 'birthday' : $funcName = array('name'=>'lessThanToday');
 878                                array_push($validator, $funcName);
 879                                  break;
 880              case 'support_end_date' : $funcName = array('name' => 'greaterThanDependentField',
 881                                                          'params' => array('support_start_date'));
 882                                      array_push($validator, $funcName);
 883                                      break;
 884              case 'support_start_date' : $funcName = array('name' => 'lessThanDependentField',
 885                                                          'params' => array('support_end_date'));
 886                                      array_push($validator, $funcName);
 887                                      break;
 888              case 'targetenddate' :
 889              case 'actualenddate':
 890              case 'enddate':
 891                              $funcName = array('name' => 'greaterThanDependentField',
 892                                  'params' => array('startdate'));
 893                              array_push($validator, $funcName);
 894                              break;
 895              case 'startdate':
 896                              if($this->getModule()->get('name') == 'Project') {
 897                                  $params = array('targetenddate');
 898                              }else{
 899                                  //for project task
 900                                  $params = array('enddate');
 901                              }
 902                              $funcName = array('name' => 'lessThanDependentField',
 903                                  'params' => $params);
 904                              array_push($validator, $funcName);
 905                              break;
 906              case 'expiry_date':
 907              case 'due_date':
 908                                  $funcName = array('name' => 'greaterThanDependentField',
 909                                      'params' => array('start_date'));
 910                                  array_push($validator, $funcName);
 911                                  break;
 912              case 'sales_end_date':
 913                                  $funcName = array('name' => 'greaterThanDependentField',
 914                                      'params' => array('sales_start_date'));
 915                                  array_push($validator, $funcName);
 916                                  break;
 917              case 'sales_start_date':
 918                                  $funcName = array('name' => 'lessThanDependentField',
 919                                      'params' => array('sales_end_date'));
 920                                  array_push($validator, $funcName);
 921                                  break;
 922              case 'qty_per_unit' :
 923              case 'qtyindemand' :
 924              case 'hours':
 925              case 'days':
 926                                  $funcName = array('name'=>'PositiveNumber');
 927                                array_push($validator, $funcName);
 928                                  break;
 929              case 'employees':
 930                                  $funcName = array('name'=>'WholeNumber');
 931                                array_push($validator, $funcName);
 932                                  break;
 933              case 'related_to':
 934                                  $funcName = array('name'=>'ReferenceField');
 935                                array_push($validator, $funcName);
 936                                  break;
 937              //SalesOrder field sepecial validators
 938              case 'end_period' : $funcName1 = array('name' => 'greaterThanDependentField',
 939                                                      'params' => array('start_period'));
 940                                                  array_push($validator, $funcName1);
 941                                  $funcName2 = array('name' => 'lessThanDependentField',
 942                                                      'params' => array('duedate'));
 943                                                  array_push($validator, $funcName2);
 944  
 945             case 'start_period' :
 946                                  $funcName = array('name' => 'lessThanDependentField',
 947                                                      'params' => array('end_period'));
 948                                  array_push($validator, $funcName);
 949                                  break;
 950          }
 951          return $validator;
 952      }
 953  
 954      /**
 955       * Function to retrieve display value in edit view
 956       * @param <String> $value - value which need to be converted to display value
 957       * @return <String> - converted display value
 958       */
 959  	public function getEditViewDisplayValue($value) {
 960          if(!$this->uitype_instance) {
 961              $this->uitype_instance = Vtiger_Base_UIType::getInstanceFromField($this);
 962          }
 963          $uiTypeInstance = $this->uitype_instance;
 964          return $uiTypeInstance->getEditViewDisplayValue($value);
 965      }
 966  
 967      /**
 968       * Function to retieve types of file locations in Documents Edit
 969       * @return <array> - List of file location types
 970       */
 971  	public function getFileLocationType() {
 972          return array('I'=>'LBL_INTERNAL', 'E'=>'LBL_EXTERNAL');
 973      }
 974  
 975      /**
 976       * Function returns list of Currencies available in the system
 977       * @return <Array>
 978       */
 979  	public function getCurrencyList() {
 980          $db = PearDatabase::getInstance();
 981          $result = $db->pquery('SELECT * FROM vtiger_currency_info WHERE currency_status = ? AND deleted=0', array('Active'));
 982          for($i=0; $i<$db->num_rows($result); $i++) {
 983              $currencyId = $db->query_result($result, $i, 'id');
 984              $currencyName = $db->query_result($result, $i, 'currency_name');
 985              $currencies[$currencyId] = $currencyName;
 986          }
 987          return $currencies;
 988      }
 989  
 990      /**
 991       * Function to get Display value for RelatedList
 992       * @param <String> $value
 993       * @return <String>
 994       */
 995  	public function getRelatedListDisplayValue($value) {
 996          if(!$this->uitype_instance) {
 997              $this->uitype_instance = Vtiger_Base_UIType::getInstanceFromField($this);
 998          }
 999          $uiTypeInstance = $this->uitype_instance;
1000          return $uiTypeInstance->getRelatedListDisplayValue($value);
1001      }
1002  
1003      /**
1004       * Function to get Default Field Value
1005       * @return <String> defaultvalue
1006       */
1007  	public function getDefaultFieldValue(){
1008          return $this->defaultvalue;
1009      }
1010  
1011  
1012      /**
1013       * Function whcih will get the databse insert value format from user format
1014       * @param type $value in user format
1015       * @return type
1016       */
1017      public function getDBInsertValue($value) {
1018          if(!$this->uitype_instance) {
1019              $this->uitype_instance = Vtiger_Base_UIType::getInstanceFromField($this);
1020          }
1021          $uiTypeInstance = $this->uitype_instance;
1022          return $uiTypeInstance->getDBInsertValue($value);
1023      }
1024  
1025      /**
1026       * Function to get visibilty permissions of a Field
1027       * @param <String> $accessmode
1028       * @return <Boolean>
1029       */
1030      public function getPermissions($accessmode = 'readonly') {
1031          $user = Users_Record_Model::getCurrentUserModel();
1032          $privileges = $user->getPrivileges();
1033          if ($privileges->hasGlobalReadPermission()) {
1034              return true;
1035          } else {
1036              $modulePermission = Vtiger_Cache::get('modulePermission-'.$accessmode, $this->getModuleId());
1037              if (!$modulePermission) {
1038                  $modulePermission = self::preFetchModuleFieldPermission($this->getModuleId(), $accessmode);
1039              }
1040              if (array_key_exists($this->getId(), $modulePermission)) {
1041                  return true;
1042              } else {
1043                  return false;
1044              }
1045          }
1046      }
1047  
1048      /**
1049       * Function to Preinitialize the module Field Permissions
1050       * @param <Integer> $tabid
1051       * @param <String> $accessmode
1052       * @return <Array>
1053       */
1054      public static function preFetchModuleFieldPermission($tabid,$accessmode = 'readonly'){
1055          $adb = PearDatabase::getInstance();
1056          $user = Users_Record_Model::getCurrentUserModel();
1057          $privileges = $user->getPrivileges();
1058          $profilelist = $privileges->get('profiles');
1059  
1060                  if (count($profilelist) > 0) {
1061                      if ($accessmode == 'readonly') {
1062                          $query = "SELECT vtiger_profile2field.visible,vtiger_field.fieldid FROM vtiger_field INNER JOIN vtiger_profile2field ON vtiger_profile2field.fieldid=vtiger_field.fieldid INNER JOIN vtiger_def_org_field ON vtiger_def_org_field.fieldid=vtiger_field.fieldid WHERE vtiger_field.tabid=? AND vtiger_profile2field.visible=0 AND vtiger_def_org_field.visible=0  AND vtiger_profile2field.profileid in (" . generateQuestionMarks($profilelist) . ") AND vtiger_field.presence in (0,2) GROUP BY vtiger_field.fieldid";
1063                      } else {
1064                          $query = "SELECT vtiger_profile2field.visible,vtiger_field.fieldid FROM vtiger_field INNER JOIN vtiger_profile2field ON vtiger_profile2field.fieldid=vtiger_field.fieldid INNER JOIN vtiger_def_org_field ON vtiger_def_org_field.fieldid=vtiger_field.fieldid WHERE vtiger_field.tabid=? AND vtiger_profile2field.visible=0 AND vtiger_profile2field.readonly=0 AND vtiger_def_org_field.visible=0  AND vtiger_profile2field.profileid in (" . generateQuestionMarks($profilelist) . ") AND vtiger_field.presence in (0,2) GROUP BY vtiger_field.fieldid";
1065                      }
1066                      $params = array($tabid, $profilelist);
1067                  } else {
1068                      if ($accessmode == 'readonly') {
1069                          $query = "SELECT vtiger_profile2field.visible,vtiger_field.fieldid FROM vtiger_field INNER JOIN vtiger_profile2field ON vtiger_profile2field.fieldid=vtiger_field.fieldid INNER JOIN vtiger_def_org_field ON vtiger_def_org_field.fieldid=vtiger_field.fieldid WHERE vtiger_field.tabid=? AND vtiger_profile2field.visible=0 AND vtiger_def_org_field.visible=0  AND vtiger_field.presence in (0,2) GROUP BY vtiger_field.fieldid";
1070                      } else {
1071                          $query = "SELECT vtiger_profile2field.visible,vtiger_field.fieldid FROM vtiger_field INNER JOIN vtiger_profile2field ON vtiger_profile2field.fieldid=vtiger_field.fieldid INNER JOIN vtiger_def_org_field ON vtiger_def_org_field.fieldid=vtiger_field.fieldid WHERE vtiger_field.tabid=? AND vtiger_profile2field.visible=0 AND vtiger_profile2field.readonly=0 AND vtiger_def_org_field.visible=0  AND vtiger_field.presence in (0,2) GROUP BY vtiger_field.fieldid";
1072                      }
1073                      $params = array($tabid);
1074                  }
1075  
1076                  $result = $adb->pquery($query, $params);
1077                  $modulePermission = array();
1078                  $noOfFields = $adb->num_rows($result);
1079                  for ($i = 0; $i < $noOfFields; ++$i) {
1080                      $row = $adb->query_result_rowdata($result, $i);
1081                      $modulePermission[$row['fieldid']] = $row['visible'];
1082                  }
1083                  Vtiger_Cache::set('modulePermission-'.$accessmode,$tabid,$modulePermission);
1084  
1085                  return $modulePermission;
1086      }
1087  
1088      public function __update() {
1089          $db = PearDatabase::getInstance();
1090          $query = 'UPDATE vtiger_field SET typeofdata=?,presence=?,quickcreate=?,masseditable=?,defaultvalue=?,summaryfield=? WHERE fieldid=?';
1091          $params = array($this->get('typeofdata'), $this->get('presence'), $this->get('quickcreate'), $this->get('masseditable'),
1092                          $this->get('defaultvalue'), $this->get('summaryfield'), $this->get('id'));
1093          $db->pquery($query,$params);
1094      }
1095  
1096      public function updateTypeofDataFromMandatory($mandatoryValue='O') {
1097          $mandatoryValue = strtoupper($mandatoryValue);
1098          $supportedMandatoryLiterals = array('O','M');
1099          if(!in_array($mandatoryValue, $supportedMandatoryLiterals)) {
1100              return;
1101          }
1102          $typeOfData = $this->get('typeofdata');
1103          $components = explode('~', $typeOfData);
1104          $components[1] = $mandatoryValue;
1105          $this->set('typeofdata',  implode('~', $components));
1106          return $this;
1107      }
1108  
1109      public function isCustomField() {
1110          return (substr($this->getName(),0,3) == 'cf_') ? true : false;
1111      }
1112  
1113  	public function hasDefaultValue() {
1114          return $this->defaultvalue == '' ? false : true;
1115      }
1116  
1117      public function isActiveField() {
1118          $presence = $this->get('presence');
1119          return in_array($presence, array(0,2));
1120      }
1121  
1122  	public function isMassEditable() {
1123          return $this->masseditable == 1 ? true : false;
1124      }
1125  
1126      /**
1127       * Function which will check if empty piclist option should be given
1128       */
1129      public function isEmptyPicklistOptionAllowed() {
1130          return true;
1131      }
1132  
1133      public function isReferenceField() {
1134          return ($this->getFieldDataType() == self::REFERENCE_TYPE) ? true : false;
1135      }
1136  
1137  	public function isOwnerField() {
1138          return ($this->getFieldDataType() == self::OWNER_TYPE) ? true : false;
1139      }
1140  
1141      public static function getInstanceFromFieldId($fieldId, $moduleTabId) {
1142          $db = PearDatabase::getInstance();
1143  
1144          if(is_string($fieldId)) {
1145              $fieldId = array($fieldId);
1146          }
1147  
1148          $query = 'SELECT * FROM vtiger_field WHERE fieldid IN ('.generateQuestionMarks($fieldId).') AND tabid=?';
1149          $result = $db->pquery($query, array($fieldId,$moduleTabId));
1150          $fieldModelList = array();
1151          $num_rows = $db->num_rows($result);
1152          for($i=0; $i<$num_rows; $i++) {
1153              $row = $db->query_result_rowdata($result, $i);
1154              $fieldModel = new self();
1155              $fieldModel->initialize($row);
1156              $fieldModelList[] = $fieldModel;
1157          }
1158          return $fieldModelList;
1159      }
1160  
1161  }


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