예제 #1
0
 /**
  * This function is to make a copy of a price set, including
  * all the fields in the page
  *
  * @return void
  * @access public
  */
 function copy()
 {
     $id = CRM_Utils_Request::retrieve('sid', 'Positive', $this, true, 0, 'GET');
     require_once 'CRM/Price/BAO/Set.php';
     CRM_Price_BAO_Set::copy($id);
     CRM_Utils_System::redirect(CRM_Utils_System::url(CRM_Utils_System::currentPath(), 'reset=1'));
 }
예제 #2
0
 /**
  * This function is to make a copy of a Event, including
  * all the fields in the event Wizard
  *
  * @param int $id the event id to copy
  *
  * @return void
  * @access public
  */
 static function copy($id)
 {
     $defaults = $eventValues = array();
     //get the require event values.
     $eventParams = array('id' => $id);
     $returnProperties = array('loc_block_id', 'is_show_location', 'default_fee_id', 'default_discount_fee_id');
     CRM_Core_DAO::commonRetrieve('CRM_Event_DAO_Event', $eventParams, $eventValues, $returnProperties);
     // since the location is sharable, lets use the same loc_block_id.
     $locBlockId = CRM_Utils_Array::value('loc_block_id', $eventValues);
     $fieldsFix = array('prefix' => array('title' => ts('Copy of') . ' '));
     if (!CRM_Utils_Array::value('is_show_location', $eventValues)) {
         $fieldsFix['prefix']['is_show_location'] = 0;
     }
     $copyEvent =& CRM_Core_DAO::copyGeneric('CRM_Event_DAO_Event', array('id' => $id), array('loc_block_id' => $locBlockId ? $locBlockId : NULL), $fieldsFix);
     $isQuickConfig = CRM_Price_BAO_Set::getFor('civicrm_event', $id, NULL, 1);
     if (!$isQuickConfig && $copyEvent->is_monetary) {
         $priceSetId = CRM_Price_BAO_Set::getFor('civicrm_event', $id);
         $copyPriceSet =& CRM_Price_BAO_Set::copy($priceSetId);
         CRM_Price_BAO_Set::addTo('civicrm_event', $copyEvent->id, $copyPriceSet->id);
     } else {
         $copyPriceSet =& CRM_Core_DAO::copyGeneric('CRM_Price_DAO_SetEntity', array('entity_id' => $id, 'entity_table' => 'civicrm_event'), array('entity_id' => $copyEvent->id));
     }
     $copyUF =& CRM_Core_DAO::copyGeneric('CRM_Core_DAO_UFJoin', array('entity_id' => $id, 'entity_table' => 'civicrm_event'), array('entity_id' => $copyEvent->id));
     $copyTellFriend =& CRM_Core_DAO::copyGeneric('CRM_Friend_DAO_Friend', array('entity_id' => $id, 'entity_table' => 'civicrm_event'), array('entity_id' => $copyEvent->id));
     $copyPCP =& CRM_Core_DAO::copyGeneric('CRM_PCP_DAO_PCPBlock', array('entity_id' => $id, 'entity_table' => 'civicrm_event'), array('entity_id' => $copyEvent->id), array('replace' => array('target_entity_id' => $copyEvent->id)));
     $copyReminder =& CRM_Core_DAO::copyGeneric('CRM_Core_DAO_ActionSchedule', array('entity_value' => $id, 'mapping_id' => 3), array('entity_value' => $copyEvent->id));
     //copy custom data
     $extends = array('event');
     $groupTree = CRM_Core_BAO_CustomGroup::getGroupDetail(NULL, NULL, $extends);
     if ($groupTree) {
         foreach ($groupTree as $groupID => $group) {
             $table[$groupTree[$groupID]['table_name']] = array('entity_id');
             foreach ($group['fields'] as $fieldID => $field) {
                 $table[$groupTree[$groupID]['table_name']][] = $groupTree[$groupID]['fields'][$fieldID]['column_name'];
             }
         }
         foreach ($table as $tableName => $tableColumns) {
             $insert = 'INSERT INTO ' . $tableName . ' (' . implode(', ', $tableColumns) . ') ';
             $tableColumns[0] = $copyEvent->id;
             $select = 'SELECT ' . implode(', ', $tableColumns);
             $from = ' FROM ' . $tableName;
             $where = " WHERE {$tableName}.entity_id = {$id}";
             $query = $insert . $select . $from . $where;
             $dao = CRM_Core_DAO::executeQuery($query, CRM_Core_DAO::$_nullArray);
         }
     }
     $copyEvent->save();
     CRM_Utils_System::flushCache();
     CRM_Utils_Hook::copy('Event', $copyEvent);
     return $copyEvent;
 }
 /**
  * Function to process the form
  *
  * @access public
  *
  * @return None
  */
 public function postProcess()
 {
     $params = $this->controller->exportValues($this->_name);
     //format params
     $params['start_date'] = CRM_Utils_Date::processDate($params['start_date'], $params['start_date_time']);
     $params['end_date'] = CRM_Utils_Date::processDate(CRM_Utils_Array::value('end_date', $params), CRM_Utils_Array::value('end_date_time', $params), TRUE);
     $params['has_waitlist'] = CRM_Utils_Array::value('has_waitlist', $params, FALSE);
     $params['is_map'] = CRM_Utils_Array::value('is_map', $params, FALSE);
     $params['is_active'] = CRM_Utils_Array::value('is_active', $params, FALSE);
     $params['is_public'] = CRM_Utils_Array::value('is_public', $params, FALSE);
     $params['is_share'] = CRM_Utils_Array::value('is_share', $params, FALSE);
     $params['default_role_id'] = CRM_Utils_Array::value('default_role_id', $params, FALSE);
     $params['id'] = $this->_id;
     $customFields = CRM_Core_BAO_CustomField::getFields('Event', FALSE, FALSE, CRM_Utils_Array::value('event_type_id', $params));
     $params['custom'] = CRM_Core_BAO_CustomField::postProcess($params, $customFields, $this->_id, 'Event');
     //merge params with defaults from templates
     if (CRM_Utils_Array::value('template_id', $params)) {
         $params = array_merge(CRM_Event_BAO_Event::getTemplateDefaultValues($params['template_id']), $params);
     }
     $event = CRM_Event_BAO_Event::create($params);
     // now that we have the event’s id, do some more template-based stuff
     if (CRM_Utils_Array::value('template_id', $params)) {
         // copy price sets if any
         $priceSetId = CRM_Price_BAO_Set::getFor('civicrm_event', $params['template_id']);
         if ($priceSetId) {
             $isQuickConfig = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_Set', $priceSetId, 'is_quick_config');
             if ($isQuickConfig) {
                 $copyPriceSet =& CRM_Price_BAO_Set::copy($priceSetId);
                 $priceSetId = $copyPriceSet->id;
             }
             CRM_Price_BAO_Set::addTo('civicrm_event', $event->id, $priceSetId);
         }
         // link profiles if none linked
         $ufParams = array('entity_table' => 'civicrm_event', 'entity_id' => $event->id);
         if (!CRM_Core_BAO_UFJoin::findUFGroupId($ufParams)) {
             CRM_Core_DAO::copyGeneric('CRM_Core_DAO_UFJoin', array('entity_id' => $params['template_id'], 'entity_table' => 'civicrm_event'), array('entity_id' => $event->id));
         }
         // if no Tell-a-Friend defined, check whether there’s one for template and copy if so
         $tafParams = array('entity_table' => 'civicrm_event', 'entity_id' => $event->id);
         if (!CRM_Friend_BAO_Friend::getValues($tafParams)) {
             $tafParams['entity_id'] = $params['template_id'];
             if (CRM_Friend_BAO_Friend::getValues($tafParams)) {
                 $tafParams['entity_id'] = $event->id;
                 if (isset($tafParams['id'])) {
                     unset($tafParams['id']);
                 }
                 CRM_Friend_BAO_Friend::addTellAFriend($tafParams);
             }
         }
         //copy pcp settings
         CRM_Core_DAO::copyGeneric('CRM_PCP_DAO_PCPBlock', array('entity_id' => $params['template_id'], 'entity_table' => 'civicrm_event'), array('entity_id' => $event->id), array('replace' => array('target_entity_id' => $event->id)));
         //copy event schedule remainder
         CRM_Core_DAO::copyGeneric('CRM_Core_DAO_ActionSchedule', array('entity_value' => $params['template_id']), array('entity_value' => $event->id));
     }
     $this->set('id', $event->id);
     if ($this->_action & CRM_Core_Action::ADD) {
         $url = 'civicrm/event/manage/location';
         $urlParams = "action=update&reset=1&id={$event->id}";
         // special case for 'Save and Done' consistency.
         if ($this->controller->getButtonName('submit') == '_qf_EventInfo_upload_done') {
             $url = 'civicrm/event/manage';
             $urlParams = 'reset=1';
             CRM_Core_Session::setStatus(ts("'%1' information has been saved.", array(1 => $this->getTitle())));
         }
         CRM_Utils_System::redirect(CRM_Utils_System::url($url, $urlParams));
     }
     parent::endPostProcess();
 }
예제 #4
0
 /**
  * This function is to make a copy of a price set, including
  * all the fields in the page
  *
  * @return void
  * @access public
  */
 function copy()
 {
     $id = CRM_Utils_Request::retrieve('sid', 'Positive', $this, TRUE, 0, 'GET');
     CRM_Price_BAO_Set::copy($id);
     CRM_Utils_System::redirect(CRM_Utils_System::url(CRM_Utils_System::currentPath(), 'reset=1'));
 }
 function upgrade_4_2_5($rev)
 {
     $this->addTask(ts('Upgrade DB to 4.2.5: SQL'), 'task_4_2_x_runSql', $rev);
     //CRM-11077
     $sql = " SELECT cpse.entity_id, cpse.price_set_id \nFROM `civicrm_price_set_entity` cpse\nLEFT JOIN civicrm_price_set cps ON cps.id = cpse.price_set_id\nLEFT JOIN civicrm_price_set_entity cpse1 ON cpse1.price_set_id = cpse.price_set_id \nWHERE cpse.entity_table = 'civicrm_event'  AND cps.is_quick_config = 1 \nGROUP BY cpse.id\nHAVING COUNT(cpse.price_set_id) > 1 AND MIN(cpse1.id) <> cpse.id ";
     $dao = CRM_Core_DAO::executeQuery($sql);
     while ($dao->fetch()) {
         if ($dao->price_set_id) {
             $copyPriceSet =& CRM_Price_BAO_Set::copy($dao->price_set_id);
             CRM_Price_BAO_Set::addTo('civicrm_event', $dao->entity_id, $copyPriceSet->id);
         }
     }
 }