Пример #1
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);
     $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));
     require_once "CRM/Core/BAO/OptionGroup.php";
     //copy option Group and values
     $copyEvent->default_fee_id = CRM_Core_BAO_OptionGroup::copyValue('event', $id, $copyEvent->id, CRM_Utils_Array::value('default_fee_id', $eventValues));
     //copy discounted fee levels
     require_once 'CRM/Core/BAO/Discount.php';
     $discount = CRM_Core_BAO_Discount::getOptionGroup($id, 'civicrm_event');
     if (!empty($discount)) {
         foreach ($discount as $discountOptionGroup) {
             $name = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionGroup', $discountOptionGroup);
             $length = substr_compare($name, "civicrm_event.amount." . $id, 0);
             $discountSuffix = substr($name, $length * -1);
             $copyEvent->default_discount_fee_id = CRM_Core_BAO_OptionGroup::copyValue('event', $id, $copyEvent->id, CRM_Utils_Array::value('default_discount_fee_id', $eventValues), $discountSuffix);
         }
     }
     //copy custom data
     require_once 'CRM/Core/BAO/CustomGroup.php';
     $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();
     require_once 'CRM/Utils/Hook.php';
     CRM_Utils_Hook::copy('Event', $copyEvent);
     return $copyEvent;
 }
 /**
  * This function is to make a copy of a contribution page, including
  * all the blocks in the page
  *
  * @param int $id the contribution page id to copy
  *
  * @return the copy object
  * @access public
  * @static
  */
 static function copy($id)
 {
     $fieldsFix = array('prefix' => array('title' => ts('Copy of') . ' '));
     $copy =& CRM_Core_DAO::copyGeneric('CRM_Contribute_DAO_ContributionPage', array('id' => $id), NULL, $fieldsFix);
     //copying all the blocks pertaining to the contribution page
     $copyPledgeBlock =& CRM_Core_DAO::copyGeneric('CRM_Pledge_DAO_PledgeBlock', array('entity_id' => $id, 'entity_table' => 'civicrm_contribution_page'), array('entity_id' => $copy->id));
     $copyMembershipBlock =& CRM_Core_DAO::copyGeneric('CRM_Member_DAO_MembershipBlock', array('entity_id' => $id, 'entity_table' => 'civicrm_contribution_page'), array('entity_id' => $copy->id));
     $copyUFJoin =& CRM_Core_DAO::copyGeneric('CRM_Core_DAO_UFJoin', array('entity_id' => $id, 'entity_table' => 'civicrm_contribution_page'), array('entity_id' => $copy->id));
     $copyWidget =& CRM_Core_DAO::copyGeneric('CRM_Contribute_DAO_Widget', array('contribution_page_id' => $id), array('contribution_page_id' => $copy->id));
     //copy option group and values
     $copy->default_amount_id = CRM_Core_BAO_OptionGroup::copyValue('contribution', $id, $copy->id, CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_ContributionPage', $id, 'default_amount_id'));
     $copyTellFriend =& CRM_Core_DAO::copyGeneric('CRM_Friend_DAO_Friend', array('entity_id' => $id, 'entity_table' => 'civicrm_contribution_page'), array('entity_id' => $copy->id));
     $copyPersonalCampaignPages =& CRM_Core_DAO::copyGeneric('CRM_PCP_DAO_PCPBlock', array('entity_id' => $id, 'entity_table' => 'civicrm_contribution_page'), array('entity_id' => $copy->id));
     $copyPremium =& CRM_Core_DAO::copyGeneric('CRM_Contribute_DAO_Premium', array('entity_id' => $id, 'entity_table' => 'civicrm_contribution_page'), array('entity_id' => $copy->id));
     $premiumQuery = "\nSELECT id\nFROM civicrm_premiums\nWHERE entity_table = 'civicrm_contribution_page'\n      AND entity_id ={$id}";
     $premiumDao = CRM_Core_DAO::executeQuery($premiumQuery, CRM_Core_DAO::$_nullArray);
     while ($premiumDao->fetch()) {
         if ($premiumDao->id) {
             $copyPremiumProduct =& CRM_Core_DAO::copyGeneric('CRM_Contribute_DAO_PremiumsProduct', array('premiums_id' => $premiumDao->id), array('premiums_id' => $copyPremium->id));
         }
     }
     $copy->save();
     CRM_Utils_Hook::copy('ContributionPage', $copy);
     return $copy;
 }
Пример #3
0
 /**
  * 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($params['end_date'], $params['end_date_time'], 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['default_role_id'] = CRM_Utils_Array::value('default_role_id', $params, false);
     $params['id'] = $this->_id;
     //new event, so lets set the created_id
     if ($this->_action & CRM_Core_Action::ADD) {
         $session =& CRM_Core_Session::singleton();
         $params['created_id'] = $session->get('userID');
         $params['created_date'] = date('YmdHis');
     }
     $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');
     require_once 'CRM/Event/BAO/Event.php';
     // copy all not explicitely set $params keys from the template (if it should be sourced)
     if (CRM_Utils_Array::value('template_id', $params)) {
         $defaults = array();
         $templateParams = array('id' => $params['template_id']);
         CRM_Event_BAO_Event::retrieve($templateParams, $defaults);
         unset($defaults['id']);
         unset($defaults['default_fee_id']);
         unset($defaults['default_discount_fee_id']);
         foreach ($defaults as $key => $value) {
             if (!isset($params[$key])) {
                 $params[$key] = $value;
             }
         }
     }
     $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 event fees
         $ogParams = array('name' => "civicrm_event.amount.{$event->id}");
         $defaults = array();
         require_once 'CRM/Core/BAO/OptionGroup.php';
         if (is_null(CRM_Core_BAO_OptionGroup::retrieve($ogParams, $defaults))) {
             // Copy the Main Event Fees
             CRM_Core_BAO_OptionGroup::copyValue('event', $params['template_id'], $event->id);
             // Copy the Discount option Group and Values
             require_once 'CRM/Core/BAO/Discount.php';
             $optionGroupIds = CRM_Core_BAO_Discount::getOptionGroup($params['template_id'], "civicrm_event");
             foreach ($optionGroupIds as $id) {
                 $discountSuffix = '.discount.' . CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionGroup', $id, 'label');
                 CRM_Core_BAO_OptionGroup::copyValue('event', $params['template_id'], $event->id, false, $discountSuffix);
             }
         }
         // copy price sets if any
         require_once 'CRM/Price/BAO/Set.php';
         $priceSetId = CRM_Price_BAO_Set::getFor('civicrm_event', $params['template_id']);
         if ($priceSetId) {
             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);
         require_once 'CRM/Core/BAO/UFJoin.php';
         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);
         require_once 'CRM/Friend/BAO/Friend.php';
         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;
                 CRM_Friend_BAO_Friend::addTellAFriend($tafParams);
             }
         }
     }
     $this->set('id', $event->id);
     if ($this->_action & CRM_Core_Action::ADD) {
         $urlParam = "action=update&reset=1&subPage=Location&id={$event->id}";
         // special case for 'Save and Done' consistency.
         if ($this->controller->getButtonName('submit') == "_qf_EventInfo_upload_done") {
             $urlParam = "action=update&reset=1&id={$event->id}";
             CRM_Core_Session::setStatus(ts("'%1' information has been saved.", array(1 => $this->getTitle())));
         }
         CRM_Utils_System::redirect(CRM_Utils_System::url(CRM_Utils_System::currentPath(), $urlParam));
     }
     parent::endPostProcess();
 }
Пример #4
0
 /**
  * This function is to make a copy of a price set, including
  * all the fields
  *
  * @param int $id the price set id to copy
  *
  * @return the copy object 
  * @access public
  * @static
  */
 static function copy($id)
 {
     $maxId = CRM_Core_DAO::singleValueQuery("SELECT max(id) FROM civicrm_price_set");
     $title = ts('[Copy id %1]', array(1 => $maxId + 1));
     $fieldsFix = array('suffix' => array('title' => ' ' . $title, 'name' => '__Copy_id_' . ($maxId + 1) . '_'));
     $copy =& CRM_Core_DAO::copyGeneric('CRM_Price_DAO_Set', array('id' => $id), null, $fieldsFix);
     //copying all the blocks pertaining to the price set
     $copyPriceField =& CRM_Core_DAO::copyGeneric('CRM_Price_DAO_Field', array('price_set_id' => $id), array('price_set_id' => $copy->id));
     if (!empty($copyPriceField)) {
         $price = array_combine(self::getFieldIds($id), self::getFieldIds($copy->id));
         //copy option group and values
         require_once "CRM/Core/BAO/OptionGroup.php";
         foreach ($price as $originalId => $copyId) {
             CRM_Core_BAO_OptionGroup::copyValue('price', $originalId, $copyId);
         }
     }
     $copy->save();
     require_once 'CRM/Utils/Hook.php';
     CRM_Utils_Hook::copy('Set', $copy);
     return $copy;
 }