Ejemplo n.º 1
0
    /**
     * This method will update the CustomFieldSelections for one Required Custom Field
     *
     */
    public function UpdateRequiredFieldSelections()
    {
        $objEntityQtypeCustomFieldArray = EntityQtypeCustomField::LoadArrayByCustomFieldId($this->CustomFieldId);
        if ($objEntityQtypeCustomFieldArray) {
            foreach ($objEntityQtypeCustomFieldArray as $objEntityQtypeCustomField) {
                //$strEntity = EntityQtype::ToStringPrimaryKeySql($objEntityQtypeCustomField->EntityQtypeId);
                $arrHelperTable = CustomField::ToStringHelperTable($objEntityQtypeCustomField->EntityQtypeId);
                // This query returns entities which do not have a custom_field_selection for this specific Custom Field/Entity QType combination
                /*$strQuery = sprintf("
                		SELECT %s AS entity_id
                		FROM %s
                		LEFT JOIN (custom_field_selection JOIN custom_field_value ON custom_field_selection.custom_field_value_id = custom_field_value.custom_field_value_id AND custom_field_value.custom_field_id = %s) ON %s = custom_field_selection.entity_id AND custom_field_selection.entity_qtype_id = %s
                		WHERE custom_field_selection.custom_field_selection_id IS NULL"
                		, $strEntity, $strEntityTable, $this->CustomFieldId, $strEntity, $objEntityQtypeCustomField->EntityQtypeId);*/
                if ($objEntityQtypeCustomField->EntityQtypeId === 1 && !$this->AllAssetModelsFlag) {
                    // This is an asset model specific custom field
                    $strQuery = sprintf('
						SELECT %1$s.%2$s AS entity_id
						FROM %1$s, asset_custom_field_asset_model, asset
						WHERE (%1$s.cfv_%3$s IS NULL OR %1$s.cfv_%3$s = \'\')
						AND asset_custom_field_asset_model.custom_field_id = %3$s
						AND asset.asset_model_id = asset_custom_field_asset_model.asset_model_id
						AND %1$s.asset_id = asset.asset_id
						', $arrHelperTable['strHelperTable'], $arrHelperTable['strPrimaryKey'], $this->CustomFieldId);
                } else {
                    $strQuery = sprintf("\n\t\t\t\t\t\tSELECT %s AS entity_id\n\t\t\t\t\t\tFROM %s\n\t\t\t\t\t\tWHERE cfv_%s IS NULL OR cfv_%s = ''", $arrHelperTable['strPrimaryKey'], $arrHelperTable['strHelperTable'], $this->CustomFieldId, $this->CustomFieldId);
                }
                $objDatabase = QApplication::$Database[1];
                $objDbResult = $objDatabase->Query($strQuery);
                while ($mixRow = $objDbResult->FetchArray()) {
                    // If it is not a SELECT custom field, then create a new CustomFieldValue
                    if ($this->CustomFieldQtypeId != 2) {
                        $objCustomFieldValue = new CustomFieldValue();
                        $objCustomFieldValue->CustomFieldId = $this->CustomFieldId;
                        $objCustomFieldValue->ShortDescription = $this->DefaultCustomFieldValue->ShortDescription;
                        $objCustomFieldValue->Save();
                        $intCustomFieldValueId = $objCustomFieldValue->CustomFieldValueId;
                    } else {
                        $intCustomFieldValueId = $this->DefaultCustomFieldValueId;
                    }
                    // Create the new CustomFieldSelection for this Entity Qtype/Entity Id/Custom Field Id
                    $objCustomFieldSelection = new CustomFieldSelection();
                    $objCustomFieldSelection->CustomFieldValueId = $intCustomFieldValueId;
                    $objCustomFieldSelection->EntityQtypeId = $objEntityQtypeCustomField->EntityQtypeId;
                    $objCustomFieldSelection->EntityId = $mixRow['entity_id'];
                    $objCustomFieldSelection->Save();
                }
            }
        }
    }
Ejemplo n.º 2
0
 /**
  * This method will update the CustomFieldSelections for one Required Custom Field
  *
  */
 public function UpdateRequiredFieldSelections()
 {
     $objEntityQtypeCustomFieldArray = EntityQtypeCustomField::LoadArrayByCustomFieldId($this->CustomFieldId);
     if ($objEntityQtypeCustomFieldArray) {
         foreach ($objEntityQtypeCustomFieldArray as $objEntityQtypeCustomField) {
             $strEntity = EntityQtype::ToStringPrimaryKeySql($objEntityQtypeCustomField->EntityQtypeId);
             $strEntityTable = EntityQtype::ToStringTable($objEntityQtypeCustomField->EntityQtypeId);
             // This query returns entities which do not have a custom_field_selection for this specific Custom Field/Entity QType combination
             $strQuery = sprintf("\n\t\t\t\t\tSELECT %s AS entity_id\n\t\t\t\t\tFROM %s\n\t\t\t\t\tLEFT JOIN (custom_field_selection JOIN custom_field_value ON custom_field_selection.custom_field_value_id = custom_field_value.custom_field_value_id AND custom_field_value.custom_field_id = %s) ON %s = custom_field_selection.entity_id AND custom_field_selection.entity_qtype_id = %s\n\t\t\t\t\tWHERE custom_field_selection.custom_field_selection_id IS NULL", $strEntity, $strEntityTable, $this->CustomFieldId, $strEntity, $objEntityQtypeCustomField->EntityQtypeId);
             $objDatabase = QApplication::$Database[1];
             $objDbResult = $objDatabase->Query($strQuery);
             while ($mixRow = $objDbResult->FetchArray()) {
                 // If it is not a SELECT custom field, then create a new CustomFieldValue
                 if ($this->CustomFieldQtypeId != 2) {
                     $objCustomFieldValue = new CustomFieldValue();
                     $objCustomFieldValue->CustomFieldId = $this->CustomFieldId;
                     $objCustomFieldValue->ShortDescription = $this->DefaultCustomFieldValue->ShortDescription;
                     $objCustomFieldValue->Save();
                     $intCustomFieldValueId = $objCustomFieldValue->CustomFieldValueId;
                 } else {
                     $intCustomFieldValueId = $this->DefaultCustomFieldValueId;
                 }
                 // Create the new CustomFieldSelection for this Entity Qtype/Entity Id/Custom Field Id
                 $objCustomFieldSelection = new CustomFieldSelection();
                 $objCustomFieldSelection->CustomFieldValueId = $intCustomFieldValueId;
                 $objCustomFieldSelection->EntityQtypeId = $objEntityQtypeCustomField->EntityQtypeId;
                 $objCustomFieldSelection->EntityId = $mixRow['entity_id'];
                 $objCustomFieldSelection->Save();
             }
         }
     }
 }