Ejemplo n.º 1
0
 /**
  * Function to process the form
  *
  * @access public
  * @return None
  */
 public function postProcess()
 {
     $params = $this->exportValues();
     $delteOldBlock = false;
     // if 'use existing location' option is selected -
     if ($params['location_option'] == 2 && CRM_Utils_Array::value('loc_event_id', $params) && $params['loc_event_id'] != $this->_oldLocBlockId) {
         // if new selected loc is different from old loc, update the loc_block_id
         // so that loc update would affect the selected loc and not the old one.
         $delteOldBlock = true;
         CRM_Core_DAO::setFieldValue('CRM_Event_DAO_Event', $this->_id, 'loc_block_id', $params['loc_event_id']);
     }
     // if 'create new loc' option is selected, set the loc_block_id for this event to null
     // so that an update would result in creating a new loc.
     if ($this->_oldLocBlockId && $params['location_option'] == 1) {
         $delteOldBlock = true;
         CRM_Core_DAO::setFieldValue('CRM_Event_DAO_Event', $this->_id, 'loc_block_id', 'null');
     }
     // if 'create new loc' optioin is selected OR selected new loc is different
     // from old one, go ahead and delete the old loc provided thats not being
     // used by any other event
     if ($this->_oldLocBlockId && $delteOldBlock) {
         CRM_Event_BAO_Event::deleteEventLocBlock($this->_oldLocBlockId, $this->_id);
     }
     // get ready with location block params
     $params['entity_table'] = 'civicrm_event';
     $params['entity_id'] = $this->_id;
     require_once 'CRM/Core/BAO/LocationType.php';
     $defaultLocationType =& CRM_Core_BAO_LocationType::getDefault();
     foreach (array('address', 'phone', 'email') as $block) {
         if (!CRM_Utils_Array::value($block, $params) || !is_array($params[$block])) {
             continue;
         }
         foreach ($params[$block] as $count => &$values) {
             if ($count == 1) {
                 $values['is_primary'] = 1;
             }
             $values['location_type_id'] = $defaultLocationType->id ? $defaultLocationType->id : 1;
         }
     }
     // create/update event location
     require_once 'CRM/Core/BAO/Location.php';
     $location = CRM_Core_BAO_Location::create($params, true, 'event');
     $params['loc_block_id'] = $location['id'];
     // finally update event params
     $params['id'] = $this->_id;
     require_once 'CRM/Event/BAO/Event.php';
     CRM_Event_BAO_Event::add($params);
     parent::endPostProcess();
 }