Exemplo n.º 1
0
    /**
     * Deletes all associated AssetCustomFieldAssetModels
     * @return void
     */
    public function DeleteAllAssetCustomFieldAssetModels()
    {
        if (is_null($this->intCustomFieldId)) {
            throw new QUndefinedPrimaryKeyException('Unable to call UnassociateAssetCustomFieldAssetModel on this unsaved CustomField.');
        }
        // Get the Database Object for this Class
        $objDatabase = CustomField::GetDatabase();
        // Journaling
        if ($objDatabase->JournalingDatabase) {
            foreach (AssetCustomFieldAssetModel::LoadArrayByCustomFieldId($this->intCustomFieldId) as $objAssetCustomFieldAssetModel) {
                $objAssetCustomFieldAssetModel->Journal('DELETE');
            }
        }
        // Perform the SQL Query
        $objDatabase->NonQuery('
				DELETE FROM
					`asset_custom_field_asset_model`
				WHERE
					`custom_field_id` = ' . $objDatabase->SqlVariable($this->intCustomFieldId) . '
			');
    }
Exemplo n.º 2
0
 private function UpadateAssetModels()
 {
     //If AssetModels not all or changed - some items might to be deleted
     if (!($this->rblAllAssetModels->SelectedValue == 1)) {
         $arrCurrentAssetModels = AssetCustomFieldAssetModel::LoadArrayByCustomFieldId($this->objCustomField->CustomFieldId);
         foreach ($arrCurrentAssetModels as $currentAssetModel) {
             $blnExists = false;
             foreach ($this->arrAssetModels as $newAssetModel) {
                 if ($newAssetModel->AssetModelId == $currentAssetModel->AssetModelId) {
                     $blnExists = true;
                 }
             }
             if (!$blnExists) {
                 $currentAssetModel->Delete();
             }
         }
     } else {
         //        $this->arrAssetModels = array();
         //        $arrAssetModels = AssetModel::LoadAll();
         //        foreach($arrAssetModels as $assetModel){
         //          $newAssetCustomFieldAssetModel = new AssetCustomFieldAssetModel();
         //          $newAssetCustomFieldAssetModel->CustomFieldId  = $this->objCustomField->CustomFieldId;
         //          $newAssetCustomFieldAssetModel->AssetModelId   = $assetModel->AssetModelId;
         //          array_push($this->arrAssetModels,$newAssetCustomFieldAssetModel);
         //        }
         $this->DeleteAssetCustomFieldAssetModels();
     }
     // Adding new assigned Model Assets
     $arrCurrentAssetModels = AssetCustomFieldAssetModel::LoadArrayByCustomFieldId($this->objCustomField->CustomFieldId);
     foreach ($this->arrAssetModels as $newAssetModel) {
         $blnExists = false;
         foreach ($arrCurrentAssetModels as $currentAssetModel) {
             if ($newAssetModel->AssetModelId == $currentAssetModel->AssetModelId) {
                 $blnExists = true;
                 break;
             }
         }
         if (!$blnExists) {
             $newAssetModel->Save();
         }
     }
 }