本文整理汇总了PHP中CRM_Core_DAO::copyGeneric方法的典型用法代码示例。如果您正苦于以下问题:PHP CRM_Core_DAO::copyGeneric方法的具体用法?PHP CRM_Core_DAO::copyGeneric怎么用?PHP CRM_Core_DAO::copyGeneric使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CRM_Core_DAO
的用法示例。
在下文中一共展示了CRM_Core_DAO::copyGeneric方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: copy
/**
* 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;
}
示例2: copyLocBlock
/**
* @param $locBlockId
* @param null $updateLocBlockId
*
* @return mixed
*/
static function copyLocBlock($locBlockId, $updateLocBlockId = NULL)
{
//get the location info.
$defaults = $updateValues = array();
$locBlock = array('id' => $locBlockId);
CRM_Core_DAO::commonRetrieve('CRM_Core_DAO_LocBlock', $locBlock, $defaults);
if ($updateLocBlockId) {
//get the location info for update.
$copyLocationParams = array('id' => $updateLocBlockId);
CRM_Core_DAO::commonRetrieve('CRM_Core_DAO_LocBlock', $copyLocationParams, $updateValues);
foreach ($updateValues as $key => $value) {
if ($key != 'id') {
$copyLocationParams[$key] = 'null';
}
}
}
//copy all location blocks (email, phone, address, etc)
foreach ($defaults as $key => $value) {
if ($key != 'id') {
$tbl = explode("_", $key);
$name = ucfirst($tbl[0]);
$updateParams = NULL;
if ($updateId = CRM_Utils_Array::value($key, $updateValues)) {
$updateParams = array('id' => $updateId);
}
$copy = CRM_Core_DAO::copyGeneric('CRM_Core_DAO_' . $name, array('id' => $value), $updateParams);
$copyLocationParams[$key] = $copy->id;
}
}
$copyLocation =& CRM_Core_DAO::copyGeneric('CRM_Core_DAO_LocBlock', array('id' => $locBlock['id']), $copyLocationParams);
return $copyLocation->id;
}
示例3: copy
/**
* 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;
}
示例4: copy
/**
* 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;
}
示例5: 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;
}
示例6: postProcess
/**
* 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();
}
示例7: copy
/**
* 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;
}
示例8: postProcess
/**
* 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();
}
示例9: copy
/**
* Copy a price set, including all the fields
*
* @param int $id
* The price set id to copy.
*
* @return CRM_Upgrade_Snapshot_V4p2_Price_DAO_Field
*/
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_Upgrade_Snapshot_V4p2_Price_DAO_Set', array('id' => $id), NULL, $fieldsFix);
//copying all the blocks pertaining to the price set
$copyPriceField =& CRM_Core_DAO::copyGeneric('CRM_Upgrade_Snapshot_V4p2_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
foreach ($price as $originalId => $copyId) {
CRM_Core_DAO::copyGeneric('CRM_Upgrade_Snapshot_V4p2_Price_DAO_FieldValue', array('price_field_id' => $originalId), array('price_field_id' => $copyId));
}
}
$copy->save();
CRM_Utils_Hook::copy('Set', $copy);
return $copy;
}
示例10: copy
/**
* This function is to make a copy of a Vacancy
*
* @param int $id the vacancy id to copy
* obj $newVacancy object of CRM_HRRecruitment_DAO_HRVacancy
* boolean $afterCreate call to copy after the create function
* @return void
* @access public
*/
static function copy($id, $newVacancy = NULL, $afterCreate = FALSE)
{
$vacancyValues = array();
$vacancyParams = array('id' => $id);
$returnProperties = array('position', 'salary', 'status_id', 'is_template');
CRM_Core_DAO::commonRetrieve('CRM_HRRecruitment_DAO_HRVacancy', $vacancyParams, $vacancyValues, $returnProperties);
$fieldsFix = $afterCreate ? array() : array('prefix' => array('position' => ts('Copy of') . ' '));
if ($newVacancy && is_a($newVacancy, 'CRM_HRRecruitment_DAO_HRVacancy')) {
$copyVacancy = $newVacancy;
}
if (!isset($copyVacancy)) {
$copyVacancy =& CRM_Core_DAO::copyGeneric('CRM_HRRecruitment_DAO_HRVacancy', array('id' => $id), '', $fieldsFix);
}
CRM_Core_DAO::copyGeneric('CRM_HRRecruitment_DAO_HRVacancyStage', array('vacancy_id' => $id), array('vacancy_id' => $copyVacancy->id));
CRM_Core_DAO::copyGeneric('CRM_Core_DAO_UFJoin', array('entity_id' => $id, 'entity_table' => 'civicrm_hrvacancy'), array('entity_id' => $copyVacancy->id));
CRM_Core_DAO::copyGeneric('CRM_HRRecruitment_DAO_HRVacancyPermission', array('vacancy_id' => $id), array('vacancy_id' => $copyVacancy->id));
CRM_Utils_System::flushCache();
return $copyVacancy;
}
示例11: copy
/**
* 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;
}
示例12: copyCreateEntity
/**
* This function copies the information from parent entity and creates other entities with same information.
*
* @param string $entityTable
* Entity table name .
* @param array $fromCriteria
* Array of all the fields & values on which basis to copy .
* @param array $newParams
* Array of all the fields & values to be copied besides the other fields .
* @param bool $createRecurringEntity
* If to create a record in recurring_entity table .
*
*
* @return object
*/
public static function copyCreateEntity($entityTable, $fromCriteria, $newParams, $createRecurringEntity = TRUE)
{
$daoName = self::$_tableDAOMapper[$entityTable];
if (!$daoName) {
CRM_Core_Error::fatal("DAO Mapper missing for {$entityTable}.");
}
$newObject = CRM_Core_DAO::copyGeneric($daoName, $fromCriteria, $newParams);
if (is_a($newObject, 'CRM_Core_DAO') && $newObject->id && $createRecurringEntity) {
$object = new $daoName();
foreach ($fromCriteria as $key => $value) {
$object->{$key} = $value;
}
$object->find(TRUE);
CRM_Core_BAO_RecurringEntity::quickAdd($object->id, $newObject->id, $entityTable);
}
return $newObject;
}
示例13: copyValue
/**
* Function to copy the option group and values
*
* @param String $component - component page for which custom
* option group and values need to be copied
* @param int $fromId - component page id on which
* basis copy is to be made
* @param int $toId - component page id to be copied onto
* @param int $defaultId - default custom value id on the
* component page
* @param String $discountSuffix - discount suffix for the discounted
* option group
*
* @return int $id - default custom value id for the
* copied component page
*
* @access public
* @static
*/
static function copyValue($component, $fromId, $toId, $defaultId = false, $discountSuffix = null)
{
$page = '_page';
if ($component == 'event') {
//fix for CRM-3391.
//as for event we remove 'page' from group name.
$page = null;
} elseif ($component == 'price') {
$page = '_field';
}
$fromGroupName = 'civicrm_' . $component . $page . '.amount.' . $fromId . $discountSuffix;
$toGroupName = 'civicrm_' . $component . $page . '.amount.' . $toId . $discountSuffix;
$optionGroupId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionGroup', $fromGroupName, 'id', 'name');
if ($optionGroupId) {
$copyOptionGroup =& CRM_Core_DAO::copyGeneric('CRM_Core_DAO_OptionGroup', array('name' => $fromGroupName), array('name' => $toGroupName));
$copyOptionValue =& CRM_Core_DAO::copyGeneric('CRM_Core_DAO_OptionValue', array('option_group_id' => $optionGroupId), array('option_group_id' => $copyOptionGroup->id));
if ($discountSuffix) {
$copyDiscount =& CRM_Core_DAO::copyGeneric('CRM_Core_DAO_Discount', array('entity_id' => $fromId, 'entity_table' => 'civicrm_' . $component, 'option_group_id' => $optionGroupId), array('entity_id' => $toId, 'option_group_id' => $copyOptionGroup->id));
}
if ($defaultId) {
$query = "\nSELECT second.id default_id \nFROM civicrm_option_value first, civicrm_option_value second\nWHERE second.option_group_id =%1\nAND first.option_group_id =%2\nAND first.weight = second.weight\nAND first.id =%3\n";
$params = array(1 => array($copyOptionGroup->id, 'Int'), 2 => array($optionGroupId, 'Int'), 3 => array($defaultId, 'Int'));
$dao = CRM_Core_DAO::executeQuery($query, $params);
while ($dao->fetch()) {
$id = $dao->default_id;
}
return $id;
}
return false;
}
}
示例14: copy
/**
* 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;
}
示例15: copyPriceSet
/**
* Copy priceSet when event/contibution page is copied
*
* @param string $baoName
* BAO name.
* @param int $id
* Old event/contribution page id.
* @param int $newId
* Newly created event/contribution page id.
*/
public static function copyPriceSet($baoName, $id, $newId)
{
$priceSetId = CRM_Price_BAO_PriceSet::getFor($baoName, $id);
if ($priceSetId) {
$isQuickConfig = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceSet', $priceSetId, 'is_quick_config');
if ($isQuickConfig) {
$copyPriceSet = CRM_Price_BAO_PriceSet::copy($priceSetId);
CRM_Price_BAO_PriceSet::addTo($baoName, $newId, $copyPriceSet->id);
} else {
$copyPriceSet =& CRM_Core_DAO::copyGeneric('CRM_Price_DAO_PriceSetEntity', array('entity_id' => $id, 'entity_table' => $baoName), array('entity_id' => $newId));
}
// copy event discount
if ($baoName == 'civicrm_event') {
$discount = CRM_Core_BAO_Discount::getOptionGroup($id, 'civicrm_event');
foreach ($discount as $discountId => $setId) {
$copyPriceSet =& CRM_Price_BAO_PriceSet::copy($setId);
CRM_Core_DAO::copyGeneric('CRM_Core_DAO_Discount', array('id' => $discountId), array('entity_id' => $newId, 'price_set_id' => $copyPriceSet->id));
}
}
}
}