Example #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
  *        obj     $newEvent    object of CRM_Event_DAO_Event
  *        boolean $afterCreate call to copy after the create function
  * @param null $newEvent
  * @param bool $afterCreate
  *
  * @return void
  * @access public
  */
 static function copy($id, $newEvent = NULL, $afterCreate = FALSE)
 {
     $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', 'is_template');
     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 = $afterCreate ? array() : array('prefix' => array('title' => ts('Copy of') . ' '));
     if (empty($eventValues['is_show_location'])) {
         $fieldsFix['prefix']['is_show_location'] = 0;
     }
     if ($newEvent && is_a($newEvent, 'CRM_Event_DAO_Event')) {
         $copyEvent = $newEvent;
     }
     if (!isset($copyEvent)) {
         $copyEvent =& CRM_Core_DAO::copyGeneric('CRM_Event_DAO_Event', array('id' => $id), array('loc_block_id' => $locBlockId ? $locBlockId : NULL), $fieldsFix);
     }
     CRM_Price_BAO_PriceSet::copyPriceSet('civicrm_event', $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)));
     if ($eventValues['is_template']) {
         $field = 'event_template';
     } else {
         $field = 'civicrm_event';
     }
     $mappingId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_ActionMapping', $field, 'id', 'entity_value');
     $oldData = array('entity_value' => $id, 'mapping_id' => $mappingId);
     if ($copyEvent->is_template == 1) {
         $field = 'event_template';
     } else {
         $field = 'civicrm_event';
     }
     $copyMappingId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_ActionMapping', $field, 'id', 'entity_value');
     $newData = array('entity_value' => $copyEvent->id, 'mapping_id' => $copyMappingId);
     $copyReminder =& CRM_Core_DAO::copyGeneric('CRM_Core_DAO_ActionSchedule', $oldData, $newData);
     if (!$afterCreate) {
         //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();
     if (!$afterCreate) {
         CRM_Utils_Hook::copy('Event', $copyEvent);
     }
     return $copyEvent;
 }
Example #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);
     $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;
 }
Example #3
0
 /**
  * make a copy of a profile, including
  * all the fields in the profile
  *
  * @param int $id
  *   The profile id to copy.
  *
  * @return \CRM_Core_DAO
  */
 public static function copy($id)
 {
     $fieldsFix = array('prefix' => array('title' => ts('Copy of ')));
     $copy =& CRM_Core_DAO::copyGeneric('CRM_Core_DAO_UFGroup', array('id' => $id), NULL, $fieldsFix);
     if ($pos = strrpos($copy->name, "_{$id}")) {
         $copy->name = substr_replace($copy->name, '', $pos);
     }
     $copy->name = CRM_Utils_String::munge($copy->name, '_', 56) . "_{$copy->id}";
     $copy->save();
     $copyUFJoin =& CRM_Core_DAO::copyGeneric('CRM_Core_DAO_UFJoin', array('uf_group_id' => $id), array('uf_group_id' => $copy->id), NULL, 'entity_table');
     $copyUFField =& CRM_Core_DAO::copyGeneric('CRM_Core_BAO_UFField', array('uf_group_id' => $id), array('uf_group_id' => $copy->id));
     $maxWeight = CRM_Utils_Weight::getMax('CRM_Core_DAO_UFJoin', NULL, 'weight');
     //update the weight
     $query = "\nUPDATE civicrm_uf_join\nSET    weight = %1\nWHERE  uf_group_id = %2\nAND    ( entity_id IS NULL OR entity_id <= 0 )\n";
     $p = array(1 => array($maxWeight + 1, 'Integer'), 2 => array($copy->id, 'Integer'));
     CRM_Core_DAO::executeQuery($query, $p);
     if ($copy->is_reserved) {
         $query = "UPDATE civicrm_uf_group SET is_reserved = 0 WHERE id = %1";
         $params = array(1 => array($copy->id, 'Integer'));
         CRM_Core_DAO::executeQuery($query, $params);
     }
     CRM_Utils_Hook::copy('UFGroup', $copy);
     return $copy;
 }
Example #4
0
 /**
  * This function is to make a copy of a profile, including
  * all the fields in the profile
  *
  * @param int $id the profile id to copy
  *
  * @return void
  * @access public
  */
 static function copy($id)
 {
     $fieldsFix = array('prefix' => array('title' => ts('Copy of ')));
     $copy =& CRM_Core_DAO::copyGeneric('CRM_Core_DAO_UFGroup', array('id' => $id), null, $fieldsFix);
     $copyUFJoin =& CRM_Core_DAO::copyGeneric('CRM_Core_DAO_UFJoin', array('uf_group_id' => $id), array('uf_group_id' => $copy->id), null, 'entity_table');
     $copyUFField =& CRM_Core_DAO::copyGeneric('CRM_Core_BAO_UFField', array('uf_group_id' => $id), array('uf_group_id' => $copy->id));
     require_once "CRM/Utils/Weight.php";
     $maxWeight = CRM_Utils_Weight::getMax('CRM_Core_DAO_UFJoin', null, 'weight');
     //update the weight
     $query = "\nUPDATE civicrm_uf_join \nSET    weight = %1\nWHERE  uf_group_id = %2\nAND    ( entity_id IS NULL OR entity_id <= 0 )\n";
     $p = array(1 => array($maxWeight + 1, 'Integer'), 2 => array($copy->id, 'Integer'));
     CRM_Core_DAO::executeQuery($query, $p);
     if ($copy->is_reserved) {
         $query = "UPDATE civicrm_uf_group SET is_reserved = 0 WHERE id = %1";
         $params = array(1 => array($copy->id, 'Integer'));
         CRM_Core_DAO::executeQuery($query, $params);
     }
     require_once 'CRM/Utils/Hook.php';
     CRM_Utils_Hook::copy('UFGroup', $copy);
     return $copy;
 }
 /**
  * make a copy of a contribution page, including
  * all the blocks in the page
  *
  * @param int $id
  *   The contribution page id to copy.
  *
  * @return CRM_Contribute_DAO_ContributionPage
  */
 public 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 price sets
     CRM_Price_BAO_PriceSet::copyPriceSet('civicrm_contribution_page', $id, $copy->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, 'target_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;
 }
Example #6
0
 /**
  * Copy a price set, including all the fields
  *
  * @param int $id
  *   The price set id to copy.
  *
  * @return CRM_Price_DAO_PriceSet
  */
 public 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_PriceSet', array('id' => $id), NULL, $fieldsFix);
     //copying all the blocks pertaining to the price set
     $copyPriceField =& CRM_Core_DAO::copyGeneric('CRM_Price_DAO_PriceField', 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
         foreach ($price as $originalId => $copyId) {
             CRM_Core_DAO::copyGeneric('CRM_Price_DAO_PriceFieldValue', array('price_field_id' => $originalId), array('price_field_id' => $copyId));
         }
     }
     $copy->save();
     CRM_Utils_Hook::copy('Set', $copy);
     return $copy;
 }
Example #7
0
 /**
  * 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
     require_once "CRM/Core/BAO/OptionGroup.php";
     $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_Contribute_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();
     require_once 'CRM/Utils/Hook.php';
     CRM_Utils_Hook::copy('ContributionPage', $copy);
     return $copy;
 }