Exemplo n.º 1
0
 public function __construct($objParentObject, $intEntityQtypeId = null, $strControlId = null)
 {
     // First, call the parent to do most of the basic setup
     try {
         parent::__construct($objParentObject, $strControlId);
     } catch (QCallerException $objExc) {
         $objExc->IncrementOffset();
         throw $objExc;
     }
     $this->objParentObject = $objParentObject;
     $this->intEntityQtypeId = $intEntityQtypeId;
     $this->chkEntityView = new QCheckBox($this);
     $this->chkEntityEdit = new QCheckBox($this);
     $this->chkBuiltInView = new QCheckBox($this);
     $this->chkBuiltInView->Enabled = false;
     $this->chkBuiltInView->Checked = true;
     $intRoleId = QApplication::QueryString('intRoleId');
     if ($intRoleId) {
         $objBuiltInViewAuth = RoleEntityQtypeBuiltInAuthorization::LoadByRoleIdEntityQtypeIdAuthorizationId($intRoleId, $intEntityQtypeId, 1);
     }
     if (isset($objBuiltInViewAuth)) {
         $this->chkBuiltInView->Checked = $objBuiltInViewAuth->AuthorizedFlag;
     }
     $this->chkBuiltInEdit = new QCheckBox($this);
     if ($intRoleId) {
         $objBuiltInEditAuth = RoleEntityQtypeBuiltInAuthorization::LoadByRoleIdEntityQtypeIdAuthorizationId($intRoleId, $intEntityQtypeId, 2);
     }
     if (isset($objBuiltInEditAuth)) {
         $this->chkBuiltInEdit->Checked = $objBuiltInEditAuth->AuthorizedFlag;
     }
     // Load all custom fields and their values into an array arrCustomChecks
     $objCustomFieldArray = CustomField::LoadObjCustomFieldArray($intEntityQtypeId, false, null);
     foreach ($objCustomFieldArray as $objCustomField) {
         $chkCustomView = new QCheckBox($this);
         $chkCustomEdit = new QCheckBox($this);
         $objEntityQtypeCustomField = EntityQtypeCustomField::LoadByEntityQtypeIdCustomFieldId($intEntityQtypeId, $objCustomField->CustomFieldId);
         if ($objEntityQtypeCustomField) {
             $objCustomAuthView = RoleEntityQtypeCustomFieldAuthorization::LoadByRoleIdEntityQtypeCustomFieldIdAuthorizationId($intRoleId, $objEntityQtypeCustomField->EntityQtypeCustomFieldId, 1);
             if ($objCustomAuthView) {
                 $chkCustomView->Checked = $objCustomAuthView->AuthorizedFlag;
             }
             $objCustomAuthEdit = RoleEntityQtypeCustomFieldAuthorization::LoadByRoleIdEntityQtypeCustomFieldIdAuthorizationId($intRoleId, $objEntityQtypeCustomField->EntityQtypeCustomFieldId, 2);
             if ($objCustomAuthEdit) {
                 $chkCustomEdit->Checked = $objCustomAuthEdit->AuthorizedFlag;
             }
         }
         $this->arrCustomChecks[] = array('name' => $objCustomField->ShortDescription . ':', 'view' => $chkCustomView, 'edit' => $chkCustomEdit);
     }
 }
Exemplo n.º 2
0
 protected function chkCustom_Create()
 {
     $intRoleId = QApplication::QueryString('intRoleId');
     $objCustomFieldArray = CustomField::LoadObjCustomFieldArray($this->intEntityQtypeId, false, null);
     foreach ($objCustomFieldArray as $objCustomField) {
         //For each Custom Field, we setup one checkbox for View Access and one for Edit Access
         $chkCustomView = new QCheckBox($this);
         $chkCustomView->AddAction(new QClickEvent(), new QAjaxAction('chkCustom_Click'));
         $chkCustomEdit = new QCheckBox($this);
         //When we click in a View Checkbox, we need to control the Edit Checkbox Control too in the chkCustom_Click method.
         $chkCustomView->ActionParameter = $chkCustomEdit->ControlId;
         //In order to manipulate the RoleEntityQtypeCustomFieldAuthorization table, we need to obtain the EntityQtypeCustomFieldId field.
         $objEntityQtypeCustomField = EntityQtypeCustomField::LoadByEntityQtypeIdCustomFieldId($this->intEntityQtypeId, $objCustomField->CustomFieldId);
         if ($objEntityQtypeCustomField) {
             $objCustomAuthView = RoleEntityQtypeCustomFieldAuthorization::LoadByRoleIdEntityQtypeCustomFieldIdAuthorizationId($intRoleId, $objEntityQtypeCustomField->EntityQtypeCustomFieldId, 1);
             //If Creation Mode, the View Privilege of the Custom Fields is checked by default
             if (!$this->blnEditMode) {
                 $chkCustomView->Checked = 1;
             } elseif (isset($objCustomAuthView)) {
                 $chkCustomView->Checked = $objCustomAuthView->AuthorizedFlag;
             }
             $objCustomAuthEdit = RoleEntityQtypeCustomFieldAuthorization::LoadByRoleIdEntityQtypeCustomFieldIdAuthorizationId($intRoleId, $objEntityQtypeCustomField->EntityQtypeCustomFieldId, 2);
             //If Creation Mode, the Edit Privilege of the Custom Fields is checked by default
             if (!$this->blnEditMode) {
                 $chkCustomEdit->Checked = 1;
             } elseif (isset($objCustomAuthEdit)) {
                 $chkCustomEdit->Checked = $objCustomAuthEdit->AuthorizedFlag;
             }
             //if view access is not authorized, edit access won't be authorized
             if (!$chkCustomView->Checked) {
                 $chkCustomEdit->Enabled = false;
                 $chkCustomEdit->Checked = false;
             }
         }
         //In order to manipulate all the custom checkbox of the entity, we save them in an associated array.
         $this->arrCustomChecks[] = array('name' => $objCustomField->ShortDescription . ':', 'view' => $chkCustomView, 'edit' => $chkCustomEdit, 'id' => $objCustomField->CustomFieldId);
     }
 }
Exemplo n.º 3
0
 protected function UpdateFieldLevelAuthorizations()
 {
     if ($this->objModuleArray) {
         //First, we get all the panels that we need to manipulate
         foreach ($this->objModuleArray as $objModule) {
             switch ($objModule->ModuleId) {
                 case 2:
                     $arrEntity[] = array('objPanel' => $this->pnlAssets, 'intEntity' => EntityQtype::Asset);
                     $arrEntity[] = array('objPanel' => $this->pnlAssetModel, 'intEntity' => EntityQtype::AssetModel);
                     break;
                 case 3:
                     $arrEntity[] = array('objPanel' => $this->pnlInventory, 'intEntity' => EntityQtype::Inventory);
                     break;
                 case 4:
                     $arrEntity[] = array('objPanel' => $this->pnlCompany, 'intEntity' => EntityQtype::Company);
                     $arrEntity[] = array('objPanel' => $this->pnlContact, 'intEntity' => EntityQtype::Contact);
                     $arrEntity[] = array('objPanel' => $this->pnlAddress, 'intEntity' => EntityQtype::Address);
                     break;
                 case 5:
                     $arrEntity[] = array('objPanel' => $this->pnlShipping, 'intEntity' => EntityQtype::Shipment);
                     break;
                 case 6:
                     $arrEntity[] = array('objPanel' => $this->pnlReceiving, 'intEntity' => EntityQtype::Receipt);
                     break;
             }
         }
         //One Panel= One Entity. For each entity, we must save chkBuiltIn for View and Edit and several CustomChecks, for View and Edit
         foreach ($arrEntity as $entity) {
             //We look for the BuiltIn View entry, searching by RoleId, EntityId and authorizationId=1 (View)
             $objRoleEntityQTypeBuiltInAuthView = RoleEntityQtypeBuiltInAuthorization::LoadByRoleIdEntityQtypeIdAuthorizationId($this->objRole->RoleId, $entity['intEntity'], 1);
             // If the entry doesn't exists, we create it.
             if (!$objRoleEntityQTypeBuiltInAuthView) {
                 $objRoleEntityQTypeBuiltInAuthView = new RoleEntityQtypeBuiltInAuthorization();
                 $objRoleEntityQTypeBuiltInAuthView->RoleId = $this->objRole->RoleId;
                 $objRoleEntityQTypeBuiltInAuthView->EntityQtypeId = $entity['intEntity'];
                 $objRoleEntityQTypeBuiltInAuthView->AuthorizationId = 1;
             }
             $objRoleEntityQTypeBuiltInAuthView->AuthorizedFlag = $entity['objPanel']->chkBuiltInView->Checked;
             $objRoleEntityQTypeBuiltInAuthView->Save();
             //We look for the BuiltIn Edit entry, searching by RoleId, EntityId and authorizationId=2 (Edit)
             $objRoleEntityQTypeBuiltInAuthEdit = RoleEntityQtypeBuiltInAuthorization::LoadByRoleIdEntityQtypeIdAuthorizationId($this->objRole->RoleId, $entity['intEntity'], 2);
             // If the entry doesn't exists, we create it.
             if (!$objRoleEntityQTypeBuiltInAuthEdit) {
                 $objRoleEntityQTypeBuiltInAuthEdit = new RoleEntityQtypeBuiltInAuthorization();
                 $objRoleEntityQTypeBuiltInAuthEdit->RoleId = $this->objRole->RoleId;
                 $objRoleEntityQTypeBuiltInAuthEdit->EntityQtypeId = $entity['intEntity'];
                 $objRoleEntityQTypeBuiltInAuthEdit->AuthorizationId = 2;
             }
             $objRoleEntityQTypeBuiltInAuthEdit->AuthorizedFlag = $entity['objPanel']->chkBuiltInEdit->Checked;
             $objRoleEntityQTypeBuiltInAuthEdit->Save();
             //We must now save the View and Edit checkboxs values of the Custom checks.
             if ($entity['objPanel']->arrCustomChecks) {
                 foreach ($entity['objPanel']->arrCustomChecks as $objCustomCheck) {
                     //We look into EntityQtypeCustomFieldId because we need to get EntityQtypeCustomFieldId in order to save into the RoleEntityCustom tables
                     $objEntityQtypeCustomField = EntityQtypeCustomField::LoadByEntityQtypeIdCustomFieldId($entity['intEntity'], $objCustomCheck['id']);
                     //We look for the Custom View entry, searching by RoleId, EntityQtypeCustomFieldId and authorization_id=1(View)
                     $objRoleEntityQtypeCustomFieldView = RoleEntityQtypeCustomFieldAuthorization::LoadByRoleIdEntityQtypeCustomFieldIdAuthorizationId($this->objRole->RoleId, $objEntityQtypeCustomField->EntityQtypeCustomFieldId, 1);
                     // If the entry doesn't exists, we create it.
                     if (!$objRoleEntityQtypeCustomFieldView) {
                         $objRoleEntityQtypeCustomFieldView = new RoleEntityQtypeCustomFieldAuthorization();
                         $objRoleEntityQtypeCustomFieldView->RoleId = $this->objRole->RoleId;
                         $objRoleEntityQtypeCustomFieldView->EntityQtypeCustomFieldId = $objEntityQtypeCustomField->EntityQtypeCustomFieldId;
                         $objRoleEntityQtypeCustomFieldView->AuthorizationId = 1;
                     }
                     $objRoleEntityQtypeCustomFieldView->AuthorizedFlag = $objCustomCheck['view']->Checked;
                     $objRoleEntityQtypeCustomFieldView->Save();
                     //We look for the Custom View entry, searching by RoleId, EntityQtypeCustomFieldId and authorization_id=2(Edit)
                     $objRoleEntityQtypeCustomFieldEdit = RoleEntityQtypeCustomFieldAuthorization::LoadByRoleIdEntityQtypeCustomFieldIdAuthorizationId($this->objRole->RoleId, $objEntityQtypeCustomField->EntityQtypeCustomFieldId, 2);
                     // If the entry doesn't exists, we create it.
                     if (!$objRoleEntityQtypeCustomFieldEdit) {
                         $objRoleEntityQtypeCustomFieldEdit = new RoleEntityQtypeCustomFieldAuthorization();
                         $objRoleEntityQtypeCustomFieldEdit->RoleId = $this->objRole->RoleId;
                         $objRoleEntityQtypeCustomFieldEdit->EntityQtypeCustomFieldId = $objEntityQtypeCustomField->EntityQtypeCustomFieldId;
                         $objRoleEntityQtypeCustomFieldEdit->AuthorizationId = 2;
                     }
                     $objRoleEntityQtypeCustomFieldEdit->AuthorizedFlag = $objCustomCheck['edit']->Checked;
                     $objRoleEntityQtypeCustomFieldEdit->Save();
                 }
             }
         }
     }
 }
Exemplo n.º 4
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->chkEntityQtype->SelectedItems) {
                 foreach ($this->chkEntityQtype->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();
                     }
                 }
                 // If the helper table exists for that EntityQtype then will delete the column in the helper table
                 if ($strHelperTableArray = CustomFieldValue::GetHelperTableByEntityQtypeId($objEntityQtypeCustomField->EntityQtypeId)) {
                     $strHelperTable = $strHelperTableArray[0];
                     $objDatabase = CustomField::GetDatabase();
                     $strQuery = sprintf("ALTER TABLE %s DROP `cfv_%s`;", $strHelperTable, $this->objCustomField->CustomFieldId);
                     $objDatabase->NonQuery($strQuery);
                 }
                 if ($objEntityQtypeCustomField->EntityQtypeId == 1) {
                     $this->DeleteAssetCustomFieldAssetModels();
                 }
                 // Delete the EntityQtypeCustomField last
                 $objEntityQtypeCustomField->Delete();
             } else {
                 if ($objEntityQtypeCustomField->EntityQtypeId == 1) {
                     $this->UpadateAssetModels();
                 }
             }
         }
     }
     // Insert the new EntityQtypeCustomFields
     if ($this->lstCustomFieldQtype->SelectedItems) {
         foreach ($this->chkEntityQtype->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))) {
                 // add asset models
                 if ($objEntityQtypeItem->Value == 1) {
                     $this->AppendAssetModels();
                 }
                 $objEntityQtypeCustomField = new EntityQtypeCustomField();
                 $objEntityQtypeCustomField->CustomFieldId = $this->objCustomField->CustomFieldId;
                 $objEntityQtypeCustomField->EntityQtypeId = $objEntityQtypeItem->Value;
                 $objEntityQtypeCustomField->Save();
                 // If the helper table exists for that EntityQtype then create new column in the helper table
                 if ($strHelperTableArray = CustomFieldValue::GetHelperTableByEntityQtypeId($objEntityQtypeItem->Value)) {
                     $strHelperTable = $strHelperTableArray[0];
                     $objDatabase = CustomField::GetDatabase();
                     $strQuery = sprintf("ALTER TABLE %s ADD `cfv_%s` TEXT DEFAULT NULL;", $strHelperTable, $this->objCustomField->CustomFieldId);
                     $objDatabase->NonQuery($strQuery);
                     // If the helper table exists and have no values (empty).
                     // It happens when the QtypeItem does not yet have the custom fields.
                     // Uses SQL-hack to fix this issue.
                     $strParentTableName = $strHelperTableArray[1];
                     $strHelperTableItemId = sprintf("%s_id", $strParentTableName);
                     $strQuery = sprintf("INSERT INTO %s (`%s`) (SELECT `%s` FROM `%s` WHERE `%s` NOT IN (SELECT `%s` FROM %s));", $strHelperTable, $strHelperTableItemId, $strHelperTableItemId, $strParentTableName, $strHelperTableItemId, $strHelperTableItemId, $strHelperTable);
                     $objDatabase->NonQuery($strQuery);
                 }
                 // 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();
                 }
             }
             // If this field is a required field
             if ($this->objCustomField->RequiredFlag) {
                 // Add the DefaultValue into the helper table
                 if ($strHelperTableArray = CustomFieldValue::GetHelperTableByEntityQtypeId($objEntityQtypeItem->Value)) {
                     $strHelperTable = $strHelperTableArray[0];
                     $blnError = false;
                     // If the custom field is text or textarea
                     if ($this->objCustomField->CustomFieldQtypeId != 2) {
                         if ($this->txtDefaultValue->Text != null) {
                             $txtDefaultValue = $this->txtDefaultValue->Text;
                         } else {
                             $blnError = true;
                         }
                     } elseif ($this->objCustomField->DefaultCustomFieldValueId != null) {
                         $txtDefaultValue = CustomFieldValue::LoadByCustomFieldValueId($this->objCustomField->DefaultCustomFieldValueId);
                     } else {
                         $blnError = true;
                     }
                     if (!$blnError) {
                         if (!($objEntityQtypeItem->Value == 1 && $this->rblAllAssetModels->SelectedValue == 2)) {
                             //print($objEntityQtypeItem->Value.$this->rblAllAssetModels->SelectedValue);exit;
                             $objDatabase = CustomField::GetDatabase();
                             $strQuery = sprintf("UPDATE %s SET `cfv_%s`='%s' WHERE `cfv_%s` is NULL;", $strHelperTable, $this->objCustomField->CustomFieldId, $txtDefaultValue, $this->objCustomField->CustomFieldId);
                             $objDatabase->NonQuery($strQuery);
                         } else {
                             // 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);
                             //  Check if Model has any Assets need to be updated with new custom field and update them
                             if ($chosenAssetModels) {
                                 $objDatabase = CustomField::GetDatabase();
                                 $strQuery = sprintf("UPDATE %s SET `cfv_%s`='%s' WHERE `asset_id` IN ({$chosenAssetModels}) AND cfv_%s IS NULL;", $strHelperTable, $this->objCustomField->CustomFieldId, $txtDefaultValue, $this->objCustomField->CustomFieldId, $this->objCustomField->CustomFieldId);
                                 $objDatabase->NonQuery($strQuery);
                                 $strQuery = sprintf("UPDATE %s SET `cfv_%s`= NULL WHERE `asset_id` NOT IN({$chosenAssetModels});", $strHelperTable, $this->objCustomField->CustomFieldId);
                                 $objDatabase->NonQuery($strQuery);
                             }
                         }
                     }
                 }
             }
         }
     }
 }
Exemplo n.º 5
0
 /**
  * This loads the array of custom fields, and their selections and values if an existing entity
  * If it is a new entity, it only loads the custom fields without values.
  *
  * @param integer $intEntityQtypeId e.g., 1 == Asset, 2 == Inventory
  * @param bool $blnEditMode if creating a new entity or editing an existing one
  * @param integer $intEntityId e.g., AssetId, InventoryId
  * @return Array $objCustomFieldArray of CustomField objects
  */
 public static function LoadObjCustomFieldArray($intEntityQtypeId, $blnEditMode, $intEntityId = null, $searchable = false, $intAssetModel = null)
 {
     $objExpansionMap[CustomField::ExpandDefaultCustomFieldValue] = true;
     $objCustomFieldArray = CustomField::LoadArrayByActiveFlagEntity(true, $intEntityQtypeId, null, null, $objExpansionMap, $searchable);
     if ($objCustomFieldArray && $blnEditMode) {
         foreach ($objCustomFieldArray as $objCustomField) {
             $objCustomField->LoadExpandedArrayByEntity($intEntityQtypeId, $intEntityId);
         }
     }
     // Custom Fiedls load for Asset in asset_edit
     if ($intAssetModel) {
         $arrCustomFieldsForAssetModel = array();
         // Select only
         if (is_int($intAssetModel)) {
             $arrAssetCustomFields = AssetCustomFieldAssetModel::LoadArrayByAssetModelId($intAssetModel);
             foreach ($arrAssetCustomFields as $anAssetCustomField) {
                 $arrCustomFieldsForAssetModel[] = $anAssetCustomField->CustomField->CustomFieldId;
             }
         } elseif ($intAssetModel == 'all') {
             $arrAssetCustomFields = EntityQtypeCustomField::LoadArrayByEntityQtypeId(1);
             foreach ($arrAssetCustomFields as $anAssetCustomField) {
                 if ($anAssetCustomField->CustomField->AllAssetModelsFlag) {
                     $arrCustomFieldsForAssetModel[] = $anAssetCustomField->CustomField->CustomFieldId;
                 }
             }
         }
         $arrForAssetModel = array();
         foreach ($objCustomFieldArray as $objCustomField) {
             if (in_array($objCustomField->CustomFieldId, $arrCustomFieldsForAssetModel) || $objCustomField->AllAssetModelsFlag == 1) {
                 $arrForAssetModel[] = $objCustomField;
             }
         }
         $objCustomFieldArray = $arrForAssetModel;
     }
     if ($objCustomFieldArray) {
         foreach ($objCustomFieldArray as $objCustomField) {
             $objEntityQtypeCustomField = EntityQtypeCustomField::LoadByEntityQtypeIdCustomFieldId($intEntityQtypeId, $objCustomField->CustomFieldId);
             if ($objEntityQtypeCustomField) {
                 $objRoleEntityQtypeCustomFieldAuthorization = RoleEntityQtypeCustomFieldAuthorization::LoadByRoleIdEntityQtypeCustomFieldIdAuthorizationId(QApplication::$objUserAccount->RoleId, $objEntityQtypeCustomField->EntityQtypeCustomFieldId, 1);
                 if ($objRoleEntityQtypeCustomFieldAuthorization) {
                     $objCustomField->objRoleAuthView = $objRoleEntityQtypeCustomFieldAuthorization;
                 }
                 $objRoleEntityQtypeCustomFieldAuthorization2 = RoleEntityQtypeCustomFieldAuthorization::LoadByRoleIdEntityQtypeCustomFieldIdAuthorizationId(QApplication::$objUserAccount->RoleId, $objEntityQtypeCustomField->EntityQtypeCustomFieldId, 2);
                 if ($objRoleEntityQtypeCustomFieldAuthorization2) {
                     $objCustomField->objRoleAuthEdit = $objRoleEntityQtypeCustomFieldAuthorization2;
                 }
             }
         }
     }
     return $objCustomFieldArray;
 }
Exemplo n.º 6
0
 /**
  * This loads the array of custom fields, and their selections and values if an existing entity
  * If it is a new entity, it only loads the custom fields without values.
  *
  * @param integer $intEntityQtypeId e.g., 1 == Asset, 2 == Inventory
  * @param bool $blnEditMode if creating a new entity or editing an existing one
  * @param integer $intEntityId e.g., AssetId, InventoryId
  * @return Array $objCustomFieldArray of CustomField objects
  */
 public static function LoadObjCustomFieldArray($intEntityQtypeId, $blnEditMode, $intEntityId = null)
 {
     $objExpansionMap[CustomField::ExpandDefaultCustomFieldValue] = true;
     $objCustomFieldArray = CustomField::LoadArrayByActiveFlagEntity(true, $intEntityQtypeId, null, null, $objExpansionMap);
     if ($objCustomFieldArray && $blnEditMode) {
         foreach ($objCustomFieldArray as $objCustomField) {
             $objCustomField->LoadExpandedArrayByEntity($intEntityQtypeId, $intEntityId);
         }
     }
     if ($objCustomFieldArray) {
         foreach ($objCustomFieldArray as $objCustomField) {
             $objEntityQtypeCustomField = EntityQtypeCustomField::LoadByEntityQtypeIdCustomFieldId($intEntityQtypeId, $objCustomField->CustomFieldId);
             if ($objEntityQtypeCustomField) {
                 $objRoleEntityQtypeCustomFieldAuthorization = RoleEntityQtypeCustomFieldAuthorization::LoadByRoleIdEntityQtypeCustomFieldIdAuthorizationId(QApplication::$objUserAccount->RoleId, $objEntityQtypeCustomField->EntityQtypeCustomFieldId, 1);
                 if ($objRoleEntityQtypeCustomFieldAuthorization) {
                     $objCustomField->objRoleAuthView = $objRoleEntityQtypeCustomFieldAuthorization;
                 }
                 $objRoleEntityQtypeCustomFieldAuthorization2 = RoleEntityQtypeCustomFieldAuthorization::LoadByRoleIdEntityQtypeCustomFieldIdAuthorizationId(QApplication::$objUserAccount->RoleId, $objEntityQtypeCustomField->EntityQtypeCustomFieldId, 2);
                 if ($objRoleEntityQtypeCustomFieldAuthorization2) {
                     $objCustomField->objRoleAuthEdit = $objRoleEntityQtypeCustomFieldAuthorization2;
                 }
             }
         }
     }
     return $objCustomFieldArray;
 }
Exemplo n.º 7
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();
                 }
             }
         }
     }
 }