protected function SetupCustomFieldValue()
 {
     // Lookup Object PK information from Query String (if applicable)
     // Set mode to Edit or New depending on what's found
     $intCustomFieldValueId = QApplication::QueryString('intCustomFieldValueId');
     if ($intCustomFieldValueId) {
         $this->objCustomFieldValue = CustomFieldValue::Load($intCustomFieldValueId);
         if (!$this->objCustomFieldValue) {
             throw new Exception('Could not find a CustomFieldValue object with PK arguments: ' . $intCustomFieldValueId);
         }
         $this->strTitleVerb = QApplication::Translate('Edit');
         $this->blnEditMode = true;
     } else {
         $this->objCustomFieldValue = new CustomFieldValue();
         $this->strTitleVerb = QApplication::Translate('Create');
         $this->blnEditMode = false;
     }
 }
 /**
  * Static Helper Method to Create using PK arguments
  * You must pass in the PK arguments on an object to load, or leave it blank to create a new one.
  * If you want to load via QueryString or PathInfo, use the CreateFromQueryString or CreateFromPathInfo
  * static helper methods.  Finally, specify a CreateType to define whether or not we are only allowed to 
  * edit, or if we are also allowed to create a new one, etc.
  * 
  * @param mixed $objParentObject QForm or QPanel which will be using this CustomFieldValueMetaControl
  * @param integer $intCustomFieldValueId primary key value
  * @param QMetaControlCreateType $intCreateType rules governing CustomFieldValue object creation - defaults to CreateOrEdit
  * @return CustomFieldValueMetaControl
  */
 public static function Create($objParentObject, $intCustomFieldValueId = null, $intCreateType = QMetaControlCreateType::CreateOrEdit)
 {
     // Attempt to Load from PK Arguments
     if (strlen($intCustomFieldValueId)) {
         $objCustomFieldValue = CustomFieldValue::Load($intCustomFieldValueId);
         // CustomFieldValue was found -- return it!
         if ($objCustomFieldValue) {
             return new CustomFieldValueMetaControl($objParentObject, $objCustomFieldValue);
         } else {
             if ($intCreateType != QMetaControlCreateType::CreateOnRecordNotFound) {
                 throw new QCallerException('Could not find a CustomFieldValue object with PK arguments: ' . $intCustomFieldValueId);
             }
         }
         // If EditOnly is specified, throw an exception
     } else {
         if ($intCreateType == QMetaControlCreateType::EditOnly) {
             throw new QCallerException('No PK arguments specified');
         }
     }
     // If we are here, then we need to create a new record
     return new CustomFieldValueMetaControl($objParentObject, new CustomFieldValue());
 }
 public function Delete()
 {
     $objCustomFieldValue = CustomFieldValue::Load($this->CustomFieldValueId);
     //parent::Delete();
     $objDatabase = CustomFieldSelection::GetDatabase();
     // If the helper table exists
     if ($objCustomFieldValue && ($strHelperTableArray = CustomFieldValue::GetHelperTableByEntityQtypeId($this->EntityQtypeId))) {
         $strHelperTable = $strHelperTableArray[0];
         $strTableName = $strHelperTableArray[1];
         $strQuery = sprintf("UPDATE %s SET `cfv_%s`='' WHERE `%s_id`='%s';", $strHelperTable, $objCustomFieldValue->CustomFieldId, $strTableName, $this->EntityId);
         $objDatabase->NonQuery($strQuery);
     }
 }
예제 #4
0
 /**
  * Override method to perform a property "Get"
  * This will get the value of $strName
  *
  * @param string $strName Name of the property to get
  * @return mixed
  */
 public function __get($strName)
 {
     switch ($strName) {
         ///////////////////
         // Member Variables
         ///////////////////
         case 'CustomFieldId':
             /**
              * Gets the value for intCustomFieldId (Read-Only PK)
              * @return integer
              */
             return $this->intCustomFieldId;
         case 'CustomFieldQtypeId':
             /**
              * Gets the value for intCustomFieldQtypeId (Not Null)
              * @return integer
              */
             return $this->intCustomFieldQtypeId;
         case 'DefaultCustomFieldValueId':
             /**
              * Gets the value for intDefaultCustomFieldValueId 
              * @return integer
              */
             return $this->intDefaultCustomFieldValueId;
         case 'ShortDescription':
             /**
              * Gets the value for strShortDescription (Not Null)
              * @return string
              */
             return $this->strShortDescription;
         case 'ActiveFlag':
             /**
              * Gets the value for blnActiveFlag 
              * @return boolean
              */
             return $this->blnActiveFlag;
         case 'RequiredFlag':
             /**
              * Gets the value for blnRequiredFlag 
              * @return boolean
              */
             return $this->blnRequiredFlag;
         case 'CreatedBy':
             /**
              * Gets the value for intCreatedBy 
              * @return integer
              */
             return $this->intCreatedBy;
         case 'CreationDate':
             /**
              * Gets the value for dttCreationDate 
              * @return QDateTime
              */
             return $this->dttCreationDate;
         case 'ModifiedBy':
             /**
              * Gets the value for intModifiedBy 
              * @return integer
              */
             return $this->intModifiedBy;
         case 'ModifiedDate':
             /**
              * Gets the value for strModifiedDate (Read-Only Timestamp)
              * @return string
              */
             return $this->strModifiedDate;
             ///////////////////
             // Member Objects
             ///////////////////
         ///////////////////
         // Member Objects
         ///////////////////
         case 'DefaultCustomFieldValue':
             /**
              * Gets the value for the CustomFieldValue object referenced by intDefaultCustomFieldValueId 
              * @return CustomFieldValue
              */
             try {
                 if (!$this->objDefaultCustomFieldValue && !is_null($this->intDefaultCustomFieldValueId)) {
                     $this->objDefaultCustomFieldValue = CustomFieldValue::Load($this->intDefaultCustomFieldValueId);
                 }
                 return $this->objDefaultCustomFieldValue;
             } catch (QCallerException $objExc) {
                 $objExc->IncrementOffset();
                 throw $objExc;
             }
         case 'CreatedByObject':
             /**
              * Gets the value for the UserAccount object referenced by intCreatedBy 
              * @return UserAccount
              */
             try {
                 if (!$this->objCreatedByObject && !is_null($this->intCreatedBy)) {
                     $this->objCreatedByObject = UserAccount::Load($this->intCreatedBy);
                 }
                 return $this->objCreatedByObject;
             } catch (QCallerException $objExc) {
                 $objExc->IncrementOffset();
                 throw $objExc;
             }
         case 'ModifiedByObject':
             /**
              * Gets the value for the UserAccount object referenced by intModifiedBy 
              * @return UserAccount
              */
             try {
                 if (!$this->objModifiedByObject && !is_null($this->intModifiedBy)) {
                     $this->objModifiedByObject = UserAccount::Load($this->intModifiedBy);
                 }
                 return $this->objModifiedByObject;
             } catch (QCallerException $objExc) {
                 $objExc->IncrementOffset();
                 throw $objExc;
             }
             ////////////////////////////
             // Virtual Object References (Many to Many and Reverse References)
             // (If restored via a "Many-to" expansion)
             ////////////////////////////
         ////////////////////////////
         // Virtual Object References (Many to Many and Reverse References)
         // (If restored via a "Many-to" expansion)
         ////////////////////////////
         case '_CustomFieldValue':
             /**
              * Gets the value for the private _objCustomFieldValue (Read-Only)
              * if set due to an expansion on the custom_field_value.custom_field_id reverse relationship
              * @return CustomFieldValue
              */
             return $this->_objCustomFieldValue;
         case '_CustomFieldValueArray':
             /**
              * Gets the value for the private _objCustomFieldValueArray (Read-Only)
              * if set due to an ExpandAsArray on the custom_field_value.custom_field_id reverse relationship
              * @return CustomFieldValue[]
              */
             return (array) $this->_objCustomFieldValueArray;
         case '_EntityQtypeCustomField':
             /**
              * Gets the value for the private _objEntityQtypeCustomField (Read-Only)
              * if set due to an expansion on the entity_qtype_custom_field.custom_field_id reverse relationship
              * @return EntityQtypeCustomField
              */
             return $this->_objEntityQtypeCustomField;
         case '_EntityQtypeCustomFieldArray':
             /**
              * Gets the value for the private _objEntityQtypeCustomFieldArray (Read-Only)
              * if set due to an ExpandAsArray on the entity_qtype_custom_field.custom_field_id reverse relationship
              * @return EntityQtypeCustomField[]
              */
             return (array) $this->_objEntityQtypeCustomFieldArray;
         default:
             try {
                 return parent::__get($strName);
             } catch (QCallerException $objExc) {
                 $objExc->IncrementOffset();
                 throw $objExc;
             }
     }
 }
예제 #5
0
 protected function btnSave_Click($strFormId, $strControlId, $strParameter)
 {
     try {
         $arrRestrictedFields = array('asset code', 'asset tag', 'model', 'category', 'manufacturer', 'location', 'assets', 'name', 'asset model code', 'model number', 'inventory code', 'quantity', 'company name', 'city', 'state/province', 'country', 'title', 'company', 'email', 'address', 'shipment number', 'ship date', 'ship to company', 'ship to contact', 'ship to address', 'scheduled by', 'status', 'tracking', 'receipt number', 'receive from company', 'receive from contact', 'description', 'account', 'courier', 'account number', 'field name', 'type', 'enabled', 'required', 'role', 'username', 'user role', 'active', 'admin');
         $blnError = false;
         /*if ($this->chkRequiredFlag->Checked) {
         			if ($this->lstCustomFieldQtype->SelectedValue != 2 && $this->txtDefaultValue->Text == '') {
         				$blnError = true;
         				$this->btnCancel->Warning = 'A custom field must have a default value if it is required.';
         			}
         		}*/
         if (count($this->chkEntityQtype->SelectedItems) == 0) {
             $blnError = true;
             $this->btnCancel->Warning = 'You must select at least one field in the Apply To list box.';
         }
         if (in_array(strtolower($this->txtShortDescription->Text), $arrRestrictedFields, false)) {
             $blnError = true;
             $this->btnCancel->Warning = sprintf("'%s' is a Tracmor restricted word. Please choose another name for this custom field", $this->txtShortDescription->Text);
         }
         if (in_array('1', $this->chkEntityQtype->SelectedValues) && $this->rblAllAssetModels->SelectedValue == 2 && count($this->arrAssetModels) == 0) {
             $blnError = true;
             $this->btnCancel->Warning = 'You must apply at least one Model.';
         }
         if ($this->blnEditMode) {
             $objCustomFieldDuplicate = CustomField::QuerySingle(QQ::AndCondition(QQ::Equal(QQN::CustomField()->ShortDescription, $this->txtShortDescription->Text), QQ::NotEqual(QQN::CustomField()->CustomFieldId, $this->objCustomField->CustomFieldId)));
         } else {
             $objCustomFieldDuplicate = CustomField::QuerySingle(QQ::Equal(QQN::CustomField()->ShortDescription, $this->txtShortDescription->Text));
         }
         if ($objCustomFieldDuplicate) {
             $blnError = true;
             $this->btnCancel->Warning = 'A custom field already exists with that name. Please choose another.';
         }
         if (!$blnError) {
             $this->UpdateCustomFieldFields();
             $this->objCustomField->Save();
             // If this field is a required field
             if ($this->objCustomField->RequiredFlag) {
                 $blnDefaultIsNone = false;
                 // If this custom field is a text or textarea,
                 if ($this->lstCustomFieldQtype->SelectedValue != 2) {
                     if ($this->txtDefaultValue->Text != null) {
                         // Assign the existing DefaultCustomFieldValue
                         if ($this->blnEditMode && $this->objCustomField->DefaultCustomFieldValueId) {
                             $objCustomFieldValue = CustomFieldValue::Load($this->objCustomField->DefaultCustomFieldValueId);
                         } else {
                             $objCustomFieldValue = new CustomFieldValue();
                             $objCustomFieldValue->CustomFieldId = $this->objCustomField->CustomFieldId;
                         }
                         // Save the new CustomFieldValue
                         $objCustomFieldValue->ShortDescription = $this->txtDefaultValue->Text;
                         $objCustomFieldValue->Save();
                         // Set the DefaultCustomFieldValueId of the custom field
                         $this->objCustomField->DefaultCustomFieldValueId = $objCustomFieldValue->CustomFieldValueId;
                     } else {
                         $this->objCustomField->DefaultCustomFieldValueId = null;
                         $blnDefaultIsNone = true;
                     }
                 } elseif ($this->lstCustomFieldQtype->SelectedValue == 2) {
                     $this->objCustomField->DefaultCustomFieldValueId = $this->lstDefaultValue->SelectedValue;
                     if ($this->lstDefaultValue->SelectedValue == null) {
                         $blnDefaultIsNone = true;
                     }
                 }
                 // Save the custom field
                 $this->objCustomField->Save();
                 // Update the EntityQtypeCustomFields if they have changed (or if it is a new custom field
                 $this->UpdateEntityQtypeCustomFields();
                 // Update all of the CustomFieldSelections and values for the EntityQtypes
                 if (!$blnDefaultIsNone) {
                     $this->objCustomField->UpdateRequiredFieldSelections();
                     // impove logic for asset customfields
                     if ($this->blnAssetEntityType && $this->rblAllAssetModels->SelectedValue == 2) {
                         // define assets to set default value
                         $chosenAssetModels = array();
                         foreach ($this->arrAssetModels as $chosenAssetModel) {
                             $assetsToFill = Asset::LoadArrayByAssetModelId($chosenAssetModel->AssetModelId);
                             if (count($assetsToFill > 0)) {
                                 foreach ($assetsToFill as $assetToFill) {
                                     array_push($chosenAssetModels, $assetToFill->AssetId);
                                 }
                             }
                         }
                         $chosenAssetModels = implode(",", $chosenAssetModels);
                         if ($chosenAssetModels) {
                             $objDatabase = CustomField::GetDatabase();
                             $strQuery = sprintf("UPDATE `asset_custom_field_helper` SET `cfv_%s`= NULL WHERE `asset_id` NOT IN({$chosenAssetModels});", $this->objCustomField->CustomFieldId);
                             $objDatabase->NonQuery($strQuery);
                         }
                     }
                 }
             } else {
                 $this->objCustomField->DefaultCustomFieldValueId = null;
                 $this->objCustomField->Save();
                 $this->UpdateEntityQtypeCustomFields();
             }
             // If it is a new select Custom Field, then stay to add options
             if (!$this->blnEditMode && $this->objCustomField->CustomFieldQtypeId == 2) {
                 QApplication::Redirect('custom_field_edit.php?intCustomFieldId=' . $this->objCustomField->CustomFieldId);
             } else {
                 QApplication::Redirect('custom_field_list.php');
             }
         }
     } catch (QExtendedOptimisticLockingException $objExc) {
         $this->btnCancel->Warning = sprintf('This custom field has been updated by another user. You must <a href="custom_field_edit.php?intCustomFieldId=%s">Refresh</a> to edit this custom field.', $this->objCustomField->CustomFieldId);
     }
 }
 public function btnEdit_Click($strFormId, $strControlId, $strParameter)
 {
     $strParameterArray = explode(',', $strParameter);
     $objCustomFieldValue = CustomFieldValue::Load($strParameterArray[0]);
     $objEditPanel = new CustomFieldValueEditPanel($this, $this->strCloseEditPanelMethod, $objCustomFieldValue);
     $strMethodName = $this->strSetEditPanelMethod;
     $this->objForm->{$strMethodName}($objEditPanel);
 }
 /**
  * Override method to perform a property "Get"
  * This will get the value of $strName
  *
  * @param string $strName Name of the property to get
  * @return mixed
  */
 public function __get($strName)
 {
     switch ($strName) {
         ///////////////////
         // Member Variables
         ///////////////////
         case 'CustomFieldSelectionId':
             /**
              * Gets the value for intCustomFieldSelectionId (Read-Only PK)
              * @return integer
              */
             return $this->intCustomFieldSelectionId;
         case 'CustomFieldValueId':
             /**
              * Gets the value for intCustomFieldValueId (Not Null)
              * @return integer
              */
             return $this->intCustomFieldValueId;
         case 'EntityQtypeId':
             /**
              * Gets the value for intEntityQtypeId (Not Null)
              * @return integer
              */
             return $this->intEntityQtypeId;
         case 'EntityId':
             /**
              * Gets the value for intEntityId (Not Null)
              * @return integer
              */
             return $this->intEntityId;
             ///////////////////
             // Member Objects
             ///////////////////
         ///////////////////
         // Member Objects
         ///////////////////
         case 'CustomFieldValue':
             /**
              * Gets the value for the CustomFieldValue object referenced by intCustomFieldValueId (Not Null)
              * @return CustomFieldValue
              */
             try {
                 if (!$this->objCustomFieldValue && !is_null($this->intCustomFieldValueId)) {
                     $this->objCustomFieldValue = CustomFieldValue::Load($this->intCustomFieldValueId);
                 }
                 return $this->objCustomFieldValue;
             } catch (QCallerException $objExc) {
                 $objExc->IncrementOffset();
                 throw $objExc;
             }
             ////////////////////////////
             // Virtual Object References (Many to Many and Reverse References)
             // (If restored via a "Many-to" expansion)
             ////////////////////////////
         ////////////////////////////
         // Virtual Object References (Many to Many and Reverse References)
         // (If restored via a "Many-to" expansion)
         ////////////////////////////
         default:
             try {
                 return parent::__get($strName);
             } catch (QCallerException $objExc) {
                 $objExc->IncrementOffset();
                 throw $objExc;
             }
     }
 }
 /**
  * Reload this CustomFieldValue from the database.
  * @return void
  */
 public function Reload()
 {
     // Make sure we are actually Restored from the database
     if (!$this->__blnRestored) {
         throw new QCallerException('Cannot call Reload() on a new, unsaved CustomFieldValue object.');
     }
     // Reload the Object
     $objReloaded = CustomFieldValue::Load($this->intCustomFieldValueId);
     // Update $this's local variables to match
     $this->CustomFieldId = $objReloaded->CustomFieldId;
     $this->strShortDescription = $objReloaded->strShortDescription;
     $this->CreatedBy = $objReloaded->CreatedBy;
     $this->dttCreationDate = $objReloaded->dttCreationDate;
     $this->ModifiedBy = $objReloaded->ModifiedBy;
     $this->strModifiedDate = $objReloaded->strModifiedDate;
 }
예제 #9
0
 protected function btnSave_Click($strFormId, $strControlId, $strParameter)
 {
     try {
         $arrRestrictedFields = array('asset code', 'model', 'category', 'manufacturer', 'location', 'assets', 'name', 'asset model code', 'inventory code', 'quantity', 'company name', 'city', 'state/province', 'country', 'title', 'company', 'email', 'address', 'shipment number', 'ship date', 'ship to company', 'ship to contact', 'ship to address', 'scheduled by', 'status', 'tracking', 'receipt number', 'receive from company', 'receive from contact', 'description', 'account', 'courier', 'account number', 'field name', 'type', 'enabled', 'required', 'role', 'username', 'user role', 'active', 'admin');
         $blnError = false;
         if ($this->chkRequiredFlag->Checked) {
             if ($this->lstCustomFieldQtype->SelectedValue != 2 && $this->txtDefaultValue->Text == '') {
                 $blnError = true;
                 $this->btnCancel->Warning = 'A custom field must have a default value if it is required.';
             }
         }
         if (count($this->lstEntityQtype->SelectedItems) == 0) {
             $blnError = true;
             $this->btnCancel->Warning = 'You must select at least one field in the Apply To list box.';
         }
         if (in_array(strtolower($this->txtShortDescription->Text), $arrRestrictedFields, false)) {
             $blnError = true;
             $this->btnCancel->Warning = sprintf("'%s' is a Tracmor restricted word. Please choose another name for this custom field", $this->txtShortDescription->Text);
         }
         if ($this->blnEditMode) {
             $objCustomFieldDuplicate = CustomField::QuerySingle(QQ::AndCondition(QQ::Equal(QQN::CustomField()->ShortDescription, $this->txtShortDescription->Text), QQ::NotEqual(QQN::CustomField()->CustomFieldId, $this->objCustomField->CustomFieldId)));
         } else {
             $objCustomFieldDuplicate = CustomField::QuerySingle(QQ::Equal(QQN::CustomField()->ShortDescription, $this->txtShortDescription->Text));
         }
         if ($objCustomFieldDuplicate) {
             $blnError = true;
             $this->btnCancel->Warning = 'A custom field already exists with that name. Please choose another.';
         }
         if (!$blnError) {
             $this->UpdateCustomFieldFields();
             $this->objCustomField->Save();
             // If this field is a required field
             if ($this->objCustomField->RequiredFlag) {
                 // If this custom field is a text or textarea,
                 if ($this->lstCustomFieldQtype->SelectedValue != 2) {
                     // Assign the existing DefaultCustomFieldValue
                     if ($this->blnEditMode && $this->objCustomField->DefaultCustomFieldValueId) {
                         $objCustomFieldValue = CustomFieldValue::Load($this->objCustomField->DefaultCustomFieldValueId);
                     } else {
                         $objCustomFieldValue = new CustomFieldValue();
                         $objCustomFieldValue->CustomFieldId = $this->objCustomField->CustomFieldId;
                     }
                     // Save the new CustomFieldValue
                     $objCustomFieldValue->ShortDescription = $this->txtDefaultValue->Text;
                     $objCustomFieldValue->Save();
                     // Set the DefaultCustomFieldValueId of the custom field
                     $this->objCustomField->DefaultCustomFieldValueId = $objCustomFieldValue->CustomFieldValueId;
                 } elseif ($this->lstCustomFieldQtype->SelectedValue == 2) {
                     $this->objCustomField->DefaultCustomFieldValueId = $this->lstDefaultValue->SelectedValue;
                 }
                 // Save the custom field
                 $this->objCustomField->Save();
                 // Update the EntityQtypeCustomFields if they have changed (or if it is a new custom field
                 $this->UpdateEntityQtypeCustomFields();
                 // Update all of the CustomFieldSelections and values for the EntityQtypes
                 $this->objCustomField->UpdateRequiredFieldSelections();
             } else {
                 $this->objCustomField->DefaultCustomFieldValueId = null;
                 $this->objCustomField->Save();
                 $this->UpdateEntityQtypeCustomFields();
             }
             // If it is a new select Custom Field, then stay to add options
             if (!$this->blnEditMode && $this->objCustomField->CustomFieldQtypeId == 2) {
                 QApplication::Redirect('custom_field_edit.php?intCustomFieldId=' . $this->objCustomField->CustomFieldId);
             } else {
                 QApplication::Redirect('custom_field_list.php');
             }
         }
     } catch (QExtendedOptimisticLockingException $objExc) {
         $this->btnCancel->Warning = sprintf('This custom field has been updated by another user. You must <a href="custom_field_edit.php?intCustomFieldId=%s">Refresh</a> to edit this custom field.', $this->objCustomField->CustomFieldId);
     }
 }