public function Save($blnForceInsert = false, $blnForceUpdate = false)
 {
     if (!$this->__blnRestored || $blnForceInsert) {
         $this->CreatedBy = QApplication::$objUserAccount->UserAccountId;
         $this->CreationDate = new QDateTime(QDateTime::Now);
         parent::Save($blnForceInsert, $blnForceUpdate);
     } else {
         $this->ModifiedBy = QApplication::$objUserAccount->UserAccountId;
         // Load the CustomFieldValue object before modifing
         $objOldCustomFieldValue = CustomFieldValue::LoadByCustomFieldValueId($this->CustomFieldValueId);
         parent::Save($blnForceInsert, $blnForceUpdate);
         // If short_description have been modified
         if ($this->ShortDescription != $objOldCustomFieldValue->ShortDescription) {
             if ($objCustomField = $this->CustomField) {
                 $objDatabase = CustomFieldValue::GetDatabase();
                 $objCustomFieldSelectionArray = CustomFieldSelection::LoadArrayByCustomFieldValueId($this->CustomFieldValueId);
                 foreach ($objCustomFieldSelectionArray as $objCustomFieldSelection) {
                     // If helper table exists
                     if ($strHelperTableArray = $this->GetHelperTableByEntityQtypeId($objCustomFieldSelection->EntityQtypeId)) {
                         $strHelperTable = $strHelperTableArray[0];
                         $strTableName = $strHelperTableArray[1];
                         // Update the data into helper table
                         $strQuery = sprintf("UPDATE %s SET `cfv_%s`=%s WHERE `%s_id`='%s';", $strHelperTable, $objCustomField->CustomFieldId, $objDatabase->SqlVariable($this->ShortDescription), $strTableName, $objCustomFieldSelection->EntityId);
                         $objDatabase->NonQuery($strQuery);
                     }
                 }
             }
         }
     }
 }
 protected function SetupCustomFieldSelection()
 {
     // Lookup Object PK information from Query String (if applicable)
     // Set mode to Edit or New depending on what's found
     $intCustomFieldSelectionId = QApplication::QueryString('intCustomFieldSelectionId');
     if ($intCustomFieldSelectionId) {
         $this->objCustomFieldSelection = CustomFieldSelection::Load($intCustomFieldSelectionId);
         if (!$this->objCustomFieldSelection) {
             throw new Exception('Could not find a CustomFieldSelection object with PK arguments: ' . $intCustomFieldSelectionId);
         }
         $this->strTitleVerb = QApplication::Translate('Edit');
         $this->blnEditMode = true;
     } else {
         $this->objCustomFieldSelection = new CustomFieldSelection();
         $this->strTitleVerb = QApplication::Translate('Create');
         $this->blnEditMode = false;
     }
 }
 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);
     }
 }
 public function dtgCustomFieldSelection_Bind()
 {
     // Get Total Count b/c of Pagination
     $this->dtgCustomFieldSelection->TotalItemCount = CustomFieldSelection::CountAll();
     $objClauses = array();
     if ($objClause = $this->dtgCustomFieldSelection->OrderByClause) {
         array_push($objClauses, $objClause);
     }
     if ($objClause = $this->dtgCustomFieldSelection->LimitClause) {
         array_push($objClauses, $objClause);
     }
     $this->dtgCustomFieldSelection->DataSource = CustomFieldSelection::LoadAll($objClauses);
 }
    /**
     * This loads an expanded array of CustomFieldSelections and their associated values
     * The values for each selection can be accessed by looping through: $CustomFieldSelections[$i]->CustomFieldValue->ShortDescription
     *
     * @param integer $intAssetId
     * @param integer $intCustomAssetFieldId
     * @param string $strOrderBy
     * @param string $strLimit
     * @param ExpansionMap Object $objExpansionMap
     * @return CustomAssetFieldSelection
     */
    public static function LoadExpandedArray($intEntityId, $intEntityQtypeId, $intCustomFieldId, $strOrderBy = null, $strLimit = null, $objExpansionMap = null)
    {
        // Expand to include Values
        $objExpansionMap[CustomFieldSelection::ExpandCustomFieldValue] = true;
        // Call to ArrayQueryHelper to Get Database Object and Get SQL Clauses
        CustomFieldSelection::ArrayQueryHelper($strOrderBy, $strLimit, $strLimitPrefix, $strLimitSuffix, $strExpandSelect, $strExpandFrom, $objExpansionMap, $objDatabase);
        // Properly Escape All Input Parameters using Database->SqlVariable()
        $intEntityId = $objDatabase->SqlVariable($intEntityId);
        $intEntityQtypeId = $objDatabase->SqlVariable($intEntityQtypeId);
        $intCustomFieldId = $objDatabase->SqlVariable($intCustomFieldId);
        $strQuery = sprintf('
				SELECT
					%s
					`custom_field_selection`.*
					%s
				FROM
					`custom_field_selection`
					%s
				WHERE
					`custom_field_selection` . `entity_id` = %s AND
					`custom_field_selection` . `entity_qtype_id` = %s AND
					`custom_field_selection__custom_field_value_id` . `custom_field_id` = %s
				%s
				%s', $strLimitPrefix, $strExpandSelect, $strExpandFrom, $intEntityId, $intEntityQtypeId, $intCustomFieldId, $strOrderBy, $strLimitSuffix);
        // Perform the Query and Instantiate the Result
        $objDbResult = $objDatabase->Query($strQuery);
        return CustomFieldSelection::InstantiateDbRow($objDbResult->GetNextRow());
    }
 protected function dtgCustomFieldSelection_Bind()
 {
     // Because we want to enable pagination AND sorting, we need to setup the $objClauses array to send to LoadAll()
     // Remember!  We need to first set the TotalItemCount, which will affect the calcuation of LimitClause below
     $this->dtgCustomFieldSelection->TotalItemCount = CustomFieldSelection::CountAll();
     // Setup the $objClauses Array
     $objClauses = array();
     // If a column is selected to be sorted, and if that column has a OrderByClause set on it, then let's add
     // the OrderByClause to the $objClauses array
     if ($objClause = $this->dtgCustomFieldSelection->OrderByClause) {
         array_push($objClauses, $objClause);
     }
     // Add the LimitClause information, as well
     if ($objClause = $this->dtgCustomFieldSelection->LimitClause) {
         array_push($objClauses, $objClause);
     }
     // Set the DataSource to be the array of all CustomFieldSelection objects, given the clauses above
     $this->dtgCustomFieldSelection->DataSource = CustomFieldSelection::LoadAll($objClauses);
 }
 public static function GetSoapArrayFromArray($objArray)
 {
     if (!$objArray) {
         return null;
     }
     $objArrayToReturn = array();
     foreach ($objArray as $objObject) {
         array_push($objArrayToReturn, CustomFieldSelection::GetSoapObjectFromObject($objObject, true));
     }
     return unserialize(serialize($objArrayToReturn));
 }
 /**
  * Counts all associated CustomFieldSelections
  * @return int
  */
 public function CountCustomFieldSelections()
 {
     if (is_null($this->intCustomFieldValueId)) {
         return 0;
     }
     return CustomFieldSelection::CountByCustomFieldValueId($this->intCustomFieldValueId);
 }
Example #9
0
 /**
  * Loads selections and values into a CustomField object
  * Locally called protected method.
  *
  * @param integer $intEntityQtypeId e.g., 1 == Asset, 2 == Inventory
  * @param integer $intEntityId e.g., AssetId, InvetoryId
  */
 protected function LoadExpandedArrayByEntity($intEntityQtypeId, $intEntityId)
 {
     $this->CustomFieldSelection = CustomFieldSelection::LoadExpandedArray($intEntityId, $intEntityQtypeId, $this->intCustomFieldId);
 }
Example #10
0
 protected function UpdateEntityQtypeCustomFields()
 {
     // Delete any EntityQtypeCustomFields that were selected but are no longer selected
     $objEntityQtypeCustomFieldArray = EntityQtypeCustomField::LoadArrayByCustomFieldId($this->objCustomField->CustomFieldId);
     if ($objEntityQtypeCustomFieldArray) {
         foreach ($objEntityQtypeCustomFieldArray as $objEntityQtypeCustomField) {
             // Determines whether or not a entityqtypecustomfield can stay or gets deleted
             $blnKeep = false;
             if ($this->lstEntityQtype->SelectedItems) {
                 foreach ($this->lstEntityQtype->SelectedItems as $objEntityQtypeItem) {
                     if ($objEntityQtypeCustomField->EntityQtypeId == $objEntityQtypeItem->Value) {
                         $blnKeep = true;
                     }
                 }
             }
             // If the EntityQtype needs to be deleted, you must delete the CustomFieldValues for text and textarea, and CustomFieldSelections for all types
             if (!$blnKeep) {
                 $objAndCondition = QQ::AndCondition(QQ::Equal(QQN::CustomFieldSelection()->EntityQtypeId, $objEntityQtypeCustomField->EntityQtypeId), QQ::Equal(QQN::CustomFieldSelection()->CustomFieldValue->CustomFieldId, $this->objCustomField->CustomFieldId));
                 $objClauses = QQ::Clause(QQ::Expand(QQN::CustomFieldSelection()->CustomFieldValue));
                 // Select all CustomFieldSelections (and expanded CustomFieldValues) by EntityQtypeId and CustomFieldId
                 $objCustomFieldSelectionArray = CustomFieldSelection::QueryArray($objAndCondition, $objClauses);
                 if ($objCustomFieldSelectionArray) {
                     foreach ($objCustomFieldSelectionArray as $objCustomFieldSelection) {
                         if ($this->objCustomField->CustomFieldQtypeId != 2) {
                             // Deleting the CustomFieldValue will MySQL CASCADE to delete the CustomFieldSelection also
                             $objCustomFieldSelection->CustomFieldValue->Delete();
                         } else {
                             // If it is a select box, only delete the CustomFieldSelection (the CustomFieldValue stays unless it is removed as a selection entirely)
                             $objCustomFieldSelection->Delete();
                         }
                     }
                 }
                 // If the EntityQtype needs to be deleted, you must delete EntityQtypeId for all roles in RoleEntityQTypeCustomFieldAuthorization
                 $objRoleEntityCustomAuthArray = RoleEntityQtypeCustomFieldAuthorization::LoadArrayByEntityQtypeCustomFieldId($objEntityQtypeCustomField->EntityQtypeCustomFieldId);
                 if ($objRoleEntityCustomAuthArray) {
                     foreach ($objRoleEntityCustomAuthArray as $objRoleEntityCustomAuth) {
                         $objRoleEntityCustomAuth->Delete();
                     }
                 }
                 // Delete the EntityQtypeCustomField last
                 $objEntityQtypeCustomField->Delete();
             }
         }
     }
     // Insert the new EntityQtypeCustomFields
     if ($this->lstCustomFieldQtype->SelectedItems) {
         foreach ($this->lstEntityQtype->SelectedItems as $objEntityQtypeItem) {
             // If the field doesn't already exist, then it needs to be created
             if (!($objEntityQtypeCustomField = EntityQtypeCustomField::LoadByEntityQtypeIdCustomFieldId($objEntityQtypeItem->Value, $this->objCustomField->CustomFieldId))) {
                 $objEntityQtypeCustomField = new EntityQtypeCustomField();
                 $objEntityQtypeCustomField->CustomFieldId = $this->objCustomField->CustomFieldId;
                 $objEntityQtypeCustomField->EntityQtypeId = $objEntityQtypeItem->Value;
                 $objEntityQtypeCustomField->Save();
                 //// Insert the new EntityQtypeCustomField to the RoleEntityQTypeCustomFieldAuthorization table, to all the roles, with authorized_flag set to true, one for View Auth and another for Edit Auth
                 foreach (Role::LoadAll() as $objRole) {
                     //Insert the view Auth
                     $objRoleEntityQtypeCustomFieldAuth = new RoleEntityQtypeCustomFieldAuthorization();
                     $objRoleEntityQtypeCustomFieldAuth->RoleId = $objRole->RoleId;
                     $objRoleEntityQtypeCustomFieldAuth->EntityQtypeCustomFieldId = $objEntityQtypeCustomField->EntityQtypeCustomFieldId;
                     $objRoleEntityQtypeCustomFieldAuth->AuthorizationId = 1;
                     $objRoleEntityQtypeCustomFieldAuth->AuthorizedFlag = 1;
                     $objRoleEntityQtypeCustomFieldAuth->Save();
                     //Insert the Edit Auth
                     $objRoleEntityQtypeCustomFieldAuth = new RoleEntityQtypeCustomFieldAuthorization();
                     $objRoleEntityQtypeCustomFieldAuth->RoleId = $objRole->RoleId;
                     $objRoleEntityQtypeCustomFieldAuth->EntityQtypeCustomFieldId = $objEntityQtypeCustomField->EntityQtypeCustomFieldId;
                     $objRoleEntityQtypeCustomFieldAuth->AuthorizationId = 2;
                     $objRoleEntityQtypeCustomFieldAuth->AuthorizedFlag = 1;
                     $objRoleEntityQtypeCustomFieldAuth->Save();
                 }
             }
         }
     }
 }