copyValues($params); if ($premium->find(TRUE)) { $premium->product_name = $premium->name; CRM_Core_DAO::storeValues($premium, $defaults); return $premium; } return NULL; } /** * update the is_active flag in the db * * @param int $id id of the database record * @param boolean $is_active value we want to set the is_active field * * @return Object DAO object on sucess, null otherwise * @static */ static function setIsActive($id, $is_active) { if (!$is_active) { $dao = new CRM_Contribute_DAO_PremiumsProduct(); $dao->product_id = $id; $dao->delete(); } return CRM_Core_DAO::setFieldValue('CRM_Contribute_DAO_Product', $id, 'is_active', $is_active); } /** * function to add the financial types * * @param array $params reference array contains the values submitted by the form * @param array $ids reference array contains the id * * @access public * @static * * @return object */ static function add(&$params, &$ids) { $params['is_active'] = CRM_Utils_Array::value('is_active', $params, FALSE); $params['is_deductible'] = CRM_Utils_Array::value('is_deductible', $params, FALSE); // action is taken depending upon the mode $premium = new CRM_Contribute_DAO_Product(); $premium->copyValues($params); $premium->id = CRM_Utils_Array::value('premium', $ids); // set currency for CRM-1496 if (!isset($premium->currency)) { $config = CRM_Core_Config::singleton(); $premium->currency = $config->defaultCurrency; } $premium->save(); return $premium; } /** * Function to delete premium Types * * @param int $productID * @static */ static function del($productID) { //check dependencies $premiumsProduct = new CRM_Contribute_DAO_PremiumsProduct(); $premiumsProduct->product_id = $productID; if ($premiumsProduct->find(TRUE)) { $session = CRM_Core_Session::singleton(); $message .= ts('This Premium is being linked to Online Contribution page. Please remove it in order to delete this Premium.', array(1 => CRM_Utils_System::url('civicrm/admin/contribute', 'reset=1')), ts('Deletion Error'), 'error'); CRM_Core_Session::setStatus($message); return CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/admin/contribute/managePremiums', 'reset=1&action=browse')); } //delete from financial Type table $premium = new CRM_Contribute_DAO_Product(); $premium->id = $productID; $premium->delete(); } }