示例#1
0
文件: Set.php 项目: bhirsch/voipdev
 /**
  * Delete the price set
  *
  * @param int $id Price Set id
  *
  * @return boolean false if fields exist for this set, true if the
  * set could be deleted
  *
  * @access public
  * @static
  */
 public static function deleteSet($id)
 {
     // remove from all inactive forms
     $usedBy =& self::getUsedBy($id);
     if (isset($usedBy['civicrm_event'])) {
         require_once 'CRM/Event/DAO/Event.php';
         foreach ($usedBy['civicrm_event'] as $eventId => $unused) {
             $eventDAO =& new CRM_Event_DAO_Event();
             $eventDAO->id = $eventId;
             $eventDAO->find();
             while ($eventDAO->fetch()) {
                 self::removeFrom('civicrm_event', $eventDAO->id);
             }
         }
     }
     // delete price fields
     $priceField =& new CRM_Price_DAO_Field();
     $priceField->price_set_id = $id;
     $priceField->find();
     while ($priceField->fetch()) {
         // delete options first
         CRM_Price_BAO_Field::deleteField($priceField->id);
     }
     $set =& new CRM_Price_DAO_Set();
     $set->id = $id;
     return $set->delete();
 }
 /**
  * Process the form when submitted
  *
  * @param null
  *
  * @return void
  * @access public
  */
 public function postProcess()
 {
     if (CRM_Price_BAO_Field::deleteField($this->_fid)) {
         CRM_Core_Session::setStatus(ts('The Price Field \'%1\' has been deleted.', array(1 => $this->_title)));
     }
 }
示例#3
0
 /**
  * fixEventLevel() method (Setting ',' values), resolveDefaults(assinging value to array) method
  */
 function testfixEventLevel()
 {
     require_once 'CRM/Utils/String.php';
     require_once 'CRM/Utils/Array.php';
     $paramsSet['title'] = 'Price Set';
     $paramsSet['name'] = CRM_Utils_String::titleToVar('Price Set');
     $paramsSet['is_active'] = CRM_Utils_Array::value('is_active', $params, false);
     require_once 'CRM/Price/BAO/Set.php';
     $priceset = CRM_Price_BAO_Set::create($paramsSet);
     //Checking for priceset added in the table.
     $this->assertDBCompareValue('CRM_Price_BAO_Set', $priceset->id, 'title', 'id', $paramsSet['title'], 'Check DB for created priceset');
     $paramsField = array('label' => 'Price Field', 'name' => CRM_Utils_String::titleToVar('Price Field'), 'html_type' => 'Text', 'price' => 10, 'option_label' => array('1' => 'Price Field'), 'option_value' => array('1' => 10), 'is_display_amounts' => 1, 'weight' => 1, 'options_per_line' => 1, 'is_active' => array('1' => 1), 'price_set_id' => $priceset->id, 'is_enter_qty' => 1);
     $ids = array();
     require_once 'CRM/Price/BAO/Field.php';
     $pricefield = CRM_Price_BAO_Field::create($paramsField, $ids);
     //Checking for priceset added in the table.
     $this->assertDBCompareValue('CRM_Price_BAO_Field', $pricefield->id, 'label', 'id', $paramsField['label'], 'Check DB for created pricefield');
     $eventId = $this->_eventId;
     $participantParams = array('send_receipt' => 1, 'is_test' => 0, 'is_pay_later' => 0, 'event_id' => $eventId, 'register_date' => date('Y-m-d') . " 00:00:00", 'role_id' => 1, 'status_id' => 1, 'source' => 'Event_' . $eventId, 'contact_id' => $this->_contactId, 'note' => 'Note added for Event_' . $eventId, 'fee_level' => 'Price_Field - 55');
     $participant = CRM_Event_BAO_Participant::add($participantParams);
     //Checking for participant added in the table.
     $this->assertDBCompareValue('CRM_Event_BAO_Participant', $this->_contactId, 'id', 'contact_id', $participant->id, 'Check DB for created participant');
     $values = array();
     $ids = array();
     $params = array('id' => $participant->id);
     CRM_Event_BAO_Participant::getValues($params, $values, $ids);
     $this->assertNotEquals(count($values), 0, 'Checking for empty array.');
     CRM_Event_BAO_Participant::resolveDefaults($values[$participant->id]);
     if ($values[$participant->id]['fee_level']) {
         CRM_Event_BAO_Participant::fixEventLevel($values[$participant->id]['fee_level']);
     }
     $deletePricefield = CRM_Price_BAO_Field::deleteField($pricefield->id);
     $this->assertDBNull('CRM_Price_BAO_Field', $pricefield->id, 'name', 'id', 'Check DB for non-existence of Price Field.');
     $deletePriceset = CRM_Price_BAO_Set::deleteSet($priceset->id);
     $this->assertDBNull('CRM_Price_BAO_Set', $priceset->id, 'title', 'id', 'Check DB for non-existence of Price Set.');
     Participant::delete($participant->id);
     Contact::delete($this->_contactId);
     Event::delete($eventId);
 }