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);
     }
 }
Пример #2
0
 protected function DeleteEntityQtypeCustomFields()
 {
     $objEntityQtypeCustomFieldArray = EntityQtypeCustomField::LoadArrayByCustomFieldId($this->objCustomField->CustomFieldId);
     if ($objEntityQtypeCustomFieldArray) {
         foreach ($objEntityQtypeCustomFieldArray as $objEntityQtypeCustomField) {
             // 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 there was Asset Type Custom field Delete AssetCustomField
             if ($objEntityQtypeCustomField->EntityQtypeId == 1) {
                 $this->DeleteAssetCustomFieldAssetModels();
             }
             // If the helper table exists for that EntityQtype delete the columns 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, $objEntityQtypeCustomField->CustomFieldId);
                 $objDatabase->NonQuery($strQuery);
             }
             // Delete the EntityQtypeCustomField last
             $objEntityQtypeCustomField->Delete();
         }
     }
 }