本文整理汇总了PHP中CRM_Core_DAO::transaction方法的典型用法代码示例。如果您正苦于以下问题:PHP CRM_Core_DAO::transaction方法的具体用法?PHP CRM_Core_DAO::transaction怎么用?PHP CRM_Core_DAO::transaction使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CRM_Core_DAO
的用法示例。
在下文中一共展示了CRM_Core_DAO::transaction方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: CRM_Mailing_Event_BAO_Bounce
/**
* Create a new bounce event, update the email address if necessary
*/
function &create(&$params)
{
$q =& CRM_Mailing_Event_BAO_Queue::verify($params['job_id'], $params['event_queue_id'], $params['hash']);
if (!$q) {
return null;
}
CRM_Core_DAO::transaction('BEGIN');
$bounce =& new CRM_Mailing_Event_BAO_Bounce();
$bounce->time_stamp = date('YmdHis');
$bounce->copyValues($params);
$bounce->save();
$bounceTable = CRM_Mailing_Event_BAO_Bounce::getTableName();
$bounceType = CRM_Mailing_DAO_BounceType::getTableName();
$emailTable = CRM_Core_BAO_Email::getTableName();
$queueTable = CRM_Mailing_Event_BAO_Queue::getTableName();
$bounce->reset();
// might want to put distinct inside the count
$query = "SELECT count({$bounceTable}.id) as bounces,\n {$bounceType}.hold_threshold as threshold\n FROM {$bounceTable}\n INNER JOIN {$bounceType}\n ON {$bounceTable}.bounce_type_id = {$bounceType}.id\n INNER JOIN {$queueTable}\n ON {$bounceTable}.event_queue_id = {$queueTable}.id\n INNER JOIN {$emailTable}\n ON {$queueTable}.email_id = {$emailTable}.id\n WHERE {$emailTable}.id = {$q->email_id}\n AND ({$emailTable}.reset_date IS NULL\n OR {$bounceTable}.time_stamp >= {$emailTable}.reset_date)\n GROUP BY {$bounceTable}.bounce_type_id\n ORDER BY threshold, bounces desc";
$bounce->query($query);
while ($bounce->fetch()) {
if ($bounce->bounces >= $bounce->threshold) {
$email =& new CRM_Core_BAO_Email();
$email->id = $q->email_id;
$email->on_hold = true;
$email->hold_date = date('YmdHis');
$email->save();
break;
}
}
CRM_Core_DAO::transaction('COMMIT');
}
示例2: confirm
/**
* Confirm a pending subscription
*
* @param int $contact_id The id of the contact
* @param int $subscribe_id The id of the subscription event
* @param string $hash The hash
* @return boolean True on success
* @access public
* @static
*/
function confirm($contact_id, $subscribe_id, $hash)
{
$se =& CRM_Mailing_Event_BAO_Subscribe::verify($contact_id, $subscribe_id, $hash);
if (!$se) {
return false;
}
CRM_Core_DAO::transaction('BEGIN');
$ce =& new CRM_Mailing_Event_BAO_Confirm();
$ce->event_subscribe_id = $se->id;
$ce->time_stamp = date('YmdHis');
$ce->save();
CRM_Contact_BAO_GroupContact::updateGroupMembershipStatus($contact_id, $se->group_id, 'Email', $ce->id);
CRM_Core_DAO::transaction('COMMIT');
$config =& CRM_Core_Config::singleton();
$domain =& CRM_Mailing_Event_BAO_Subscribe::getDomain($subscribe_id);
list($display_name, $email) = CRM_Contact_BAO_Contact::getEmailDetails($se->contact_id);
$group =& new CRM_Contact_DAO_Group();
$group->id = $se->group_id;
$group->find(true);
require_once 'CRM/Mailing/BAO/Component.php';
$component =& new CRM_Mailing_BAO_Component();
$component->domain_id = $domain->id;
$component->is_default = 1;
$component->is_active = 1;
$component->component_type = 'Welcome';
$component->find(true);
$headers = array('Subject' => $component->subject, 'From' => ts('"%1 Administrator" <do-not-reply@%2>', array(1 => $domain->name, 2 => $domain->email_domain)), 'To' => $email, 'Reply-To' => "do-not-reply@{$domain->email_domain}", 'Return-Path' => "do-not-reply@{$domain->email_domain}");
$html = $component->body_html;
require_once 'CRM/Utils/Token.php';
$html = CRM_Utils_Token::replaceDomainTokens($html, $domain, true);
$html = CRM_Utils_Token::replaceWelcomeTokens($html, $group->name, true);
$text = $component->body_text;
$text = CRM_Utils_Token::replaceDomainTokens($text, $domain, false);
$text = CRM_Utils_Token::replaceWelcomeTokens($text, $group->name, false);
$message =& new Mail_Mime("\n");
$message->setHTMLBody($html);
$message->setTxtBody($text);
$b = $message->get();
$h = $message->headers($headers);
$mailer =& $config->getMailer();
PEAR::setErrorHandling(PEAR_ERROR_CALLBACK, array('CRM_Mailing_BAO_Mailing', 'catchSMTP'));
$mailer->send($email, $h, $b);
CRM_Core_Error::setCallback();
return true;
}
示例3: postProcess
/**
* Process the form when submitted
*
* @return void
* @access public
*/
function postProcess()
{
CRM_Core_DAO::transaction('BEGIN');
// first delete the join entries associated with this contribution page
require_once 'CRM/Core/DAO/UFJoin.php';
$dao =& new CRM_Core_DAO_UFJoin();
$params = array('entity_table' => 'civicrm_contribution_page', 'entity_id' => $this->_id);
$dao->copyValues($params);
$dao->delete();
// next delete the amount option fields
$dao =& new CRM_Core_DAO_CustomOption();
$dao->entity_table = 'civicrm_contribution_page';
$dao->entity_id = $this->_id;
$dao->delete();
// finally delete the contribution page
$dao =& new CRM_Contribute_DAO_ContributionPage();
$dao->id = $this->_id;
$dao->delete();
CRM_Core_DAO::transaction('COMMIT');
CRM_Core_Session::setStatus(ts('The contribution page "%1" has been deleted.', array(1 => $this->_title)));
}
示例4: create
/**
* function to create the event
*
* @param array $params reference array contains the values submitted by the form
*
* @access public
* @static
*
*/
public static function create(&$params)
{
require_once 'CRM/Core/Transaction.php';
$transaction = new CRM_Core_Transaction();
$event = self::add($params);
if (is_a($event, 'CRM_Core_Error')) {
CRM_Core_DAO::transaction('ROLLBACK');
return $event;
}
$session =& CRM_Core_Session::singleton();
$contactId = $session->get('userID');
if (!$contactId) {
$contactId = CRM_Utils_Array::value('contact_id', $params);
}
// Log the information on successful add/edit of Event
require_once 'CRM/Core/BAO/Log.php';
$logParams = array('entity_table' => 'civicrm_event', 'entity_id' => $event->id, 'modified_id' => $contactId, 'modified_date' => date('Ymd'));
CRM_Core_BAO_Log::add($logParams);
if (CRM_Utils_Array::value('custom', $params) && is_array($params['custom'])) {
require_once 'CRM/Core/BAO/CustomValueTable.php';
CRM_Core_BAO_CustomValueTable::store($params['custom'], 'civicrm_event', $event->id);
}
$transaction->commit();
return $event;
}
示例5: create
/**
* function to create the event
*
* @param array $params reference array contains the values submitted by the form
*
* @return object
* @access public
* @static
*
*/
public static function create(&$params)
{
$transaction = new CRM_Core_Transaction();
if (empty($params['is_template'])) {
$params['is_template'] = 0;
}
// check if new event, if so set the created_id (if not set)
// and always set created_date to now
if (empty($params['id'])) {
if (empty($params['created_id'])) {
$session = CRM_Core_Session::singleton();
$params['created_id'] = $session->get('userID');
}
$params['created_date'] = date('YmdHis');
}
$event = self::add($params);
CRM_Price_BAO_PriceSet::setPriceSets($params, $event, 'event');
if (is_a($event, 'CRM_Core_Error')) {
CRM_Core_DAO::transaction('ROLLBACK');
return $event;
}
$session = CRM_Core_Session::singleton();
$contactId = $session->get('userID');
if (!$contactId) {
$contactId = CRM_Utils_Array::value('contact_id', $params);
}
// Log the information on successful add/edit of Event
$logParams = array('entity_table' => 'civicrm_event', 'entity_id' => $event->id, 'modified_id' => $contactId, 'modified_date' => date('Ymd'));
CRM_Core_BAO_Log::add($logParams);
if (!empty($params['custom']) && is_array($params['custom'])) {
CRM_Core_BAO_CustomValueTable::store($params['custom'], 'civicrm_event', $event->id);
}
$transaction->commit();
return $event;
}
示例6: create
/**
* function to create the auction
*
* @param array $params reference array contains the values submitted by the form
*
* @access public
* @static
*
*/
public static function create(&$params)
{
require_once 'CRM/Core/Transaction.php';
$transaction = new CRM_Core_Transaction();
$auction = self::add($params);
if (is_a($auction, 'CRM_Core_Error')) {
CRM_Core_DAO::transaction('ROLLBACK');
return $auction;
}
$transaction->commit();
return $auction;
}
示例7: runJobs
/**
* Initiate all pending/ready jobs
*
* @return void
* @access public
* @static
*/
function runJobs()
{
$job =& new CRM_Mailing_BAO_Job();
$mailing =& new CRM_Mailing_DAO_Mailing();
$jobTable = CRM_Mailing_DAO_Job::getTableName();
$config =& CRM_Core_Config::singleton();
$mailer =& $config->getMailer();
/* FIXME: we might want to go to a progress table.. */
$query = " SELECT *\n FROM {$jobTable}\n WHERE (start_date IS null\n AND scheduled_date <= NOW()\n AND status = 'Scheduled')\n OR (status = 'Running'\n AND end_date IS null)\n ORDER BY scheduled_date, start_date";
$job->query($query);
/* TODO We should parallelize or prioritize this */
while ($job->fetch()) {
/* Queue up recipients for all jobs being launched */
if ($job->status != 'Running') {
CRM_Core_DAO::transaction('BEGIN');
$job->queue();
/* Start the job */
$job->start_date = date('YmdHis');
$job->status = 'Running';
// CRM-992 - MySQL can't eat its own dates
$job->scheduled_date = CRM_Utils_Date::isoToMysql($job->scheduled_date);
$job->save();
CRM_Core_DAO::transaction('COMMIT');
}
/* Compose and deliver */
$job->deliver($mailer);
/* Finish the job */
CRM_Core_DAO::transaction('BEGIN');
$job->end_date = date('YmdHis');
$job->status = 'Complete';
// CRM-992 - MySQL can't eat its own dates
$job->scheduled_date = CRM_Utils_Date::isoToMysql($job->scheduled_date);
$job->start_date = CRM_Utils_Date::isoToMysql($job->start_date);
$job->save();
$mailing->reset();
$mailing->id = $job->mailing_id;
$mailing->is_completed = true;
$mailing->save();
CRM_Core_DAO::transaction('COMMIT');
}
}
示例8: CRM_Core_DAO
/**
* Unsubscribe a contact from all groups that received this mailing
*
* @param int $job_id The job ID
* @param int $queue_id The Queue Event ID of the recipient
* @param string $hash The hash
* @return array|null $groups Array of all groups from which the contact was removed, or null if the queue event could not be found.
* @access public
* @static
*/
function &unsub_from_mailing($job_id, $queue_id, $hash)
{
/* First make sure there's a matching queue event */
$q =& CRM_Mailing_Event_BAO_Queue::verify($job_id, $queue_id, $hash);
if (!$q) {
return null;
}
$contact_id = $q->contact_id;
CRM_Core_DAO::transaction('BEGIN');
$do =& new CRM_Core_DAO();
$mg = CRM_Mailing_DAO_Group::getTableName();
$job = CRM_Mailing_BAO_Job::getTableName();
$mailing = CRM_Mailing_BAO_Mailing::getTableName();
$group = CRM_Contact_BAO_Group::getTableName();
$gc = CRM_Contact_BAO_GroupContact::getTableName();
$do->query("\n SELECT {$mg}.entity_table as entity_table,\n {$mg}.entity_id as entity_id\n FROM {$mg}\n INNER JOIN {$job}\n ON {$job}.mailing_id = {$mg}.mailing_id\n WHERE {$job}.id = " . CRM_Utils_Type::escape($job_id, 'Integer') . "\n AND {$mg}.group_type = 'Include'");
/* Make a list of groups and a list of prior mailings that received
* this mailing */
$groups = array();
$mailings = array();
while ($do->fetch()) {
if ($do->entity_table == $group) {
$groups[$do->entity_id] = true;
} else {
if ($do->entity_table == $mailing) {
$mailings[] = $do->entity_id;
}
}
}
/* As long as we have prior mailings, find their groups and add to the
* list */
while (!empty($mailings)) {
$do->query("\n SELECT {$mg}.entity_table as entity_table,\n {$mg}.entity_id as entity_id\n FROM {$mg}\n WHERE {$mg}.mailing_id IN (" . implode(', ', $mailings) . ")\n AND {$mg}.group_type = 'Include'");
$mailings = array();
while ($do->fetch()) {
if ($do->entity_table == $group) {
$groups[$do->entity_id] = true;
} else {
if ($do->entity_table == $mailing) {
$mailings[] = $do->entity_id;
}
}
}
}
/* Now we have a complete list of recipient groups. Filter out all
* those except smart groups and those that the contact belongs to */
$do->query("\n SELECT {$group}.id as group_id,\n {$group}.name as name\n FROM {$group}\n LEFT JOIN {$gc}\n ON {$gc}.group_id = {$group}.id\n WHERE {$group}.id IN (" . implode(', ', array_keys($groups)) . ")\n AND ({$group}.saved_search_id is not null\n OR ({$gc}.contact_id = {$contact_id}\n AND {$gc}.status = 'Added')\n )");
$groups = array();
while ($do->fetch()) {
$groups[$do->group_id] = $do->name;
}
$contacts = array($contact_id);
foreach ($groups as $group_id => $group_name) {
list($total, $removed, $notremoved) = CRM_Contact_BAO_GroupContact::removeContactsFromGroup($contacts, $group_id, 'Email', $queue_id);
if ($notremoved) {
unset($groups[$group_id]);
}
}
$ue =& new CRM_Mailing_Event_BAO_Unsubscribe();
$ue->event_queue_id = $queue_id;
$ue->org_unsubscribe = 0;
$ue->time_stamp = date('YmdHis');
$ue->save();
CRM_Core_DAO::transaction('COMMIT');
return $groups;
}
示例9: array
/**
* takes an associative array and creates a contribution object
*
* @param array $params (reference ) an assoc array of name/value pairs
* @param array $ids the array that holds all the db ids
*
* @return object CRM_Contribute_BAO_Contribution object
* @access public
* @static
*/
function &create(&$params, &$ids)
{
require_once 'CRM/Utils/Money.php';
require_once 'CRM/Utils/Date.php';
// FIXME: a cludgy hack to fix the dates to MySQL format
$dateFields = array('receive_date', 'cancel_date', 'receipt_date', 'thankyou_date');
foreach ($dateFields as $df) {
if (isset($params[$df])) {
$params[$df] = CRM_Utils_Date::isoToMysql($params[$df]);
}
}
CRM_Core_DAO::transaction('BEGIN');
$contribution = CRM_Contribute_BAO_Contribution::add($params, $ids);
if (is_a($contribution, 'CRM_Core_Error')) {
CRM_Core_DAO::transaction('ROLLBACK');
return $contribution;
}
$params['contribution_id'] = $contribution->id;
// add custom field values
if (CRM_Utils_Array::value('custom', $params)) {
foreach ($params['custom'] as $customValue) {
$cvParams = array('entity_table' => 'civicrm_contribution', 'entity_id' => $contribution->id, 'value' => $customValue['value'], 'type' => $customValue['type'], 'custom_field_id' => $customValue['custom_field_id']);
if ($customValue['id']) {
$cvParams['id'] = $customValue['id'];
}
CRM_Core_BAO_CustomValue::create($cvParams);
}
}
// let's create an (or update the relevant) Acitivity History record
$contributionType = CRM_Contribute_PseudoConstant::contributionType($contribution->contribution_type_id);
if (!$contributionType) {
$contributionType = ts('Contribution');
}
if (!$GLOBALS['_CRM_CONTRIBUTE_BAO_CONTRIBUTION']['insertDate']) {
$GLOBALS['_CRM_CONTRIBUTE_BAO_CONTRIBUTION']['insertDate'] = CRM_Utils_Date::customFormat(date('Y-m-d H:i'));
}
$activitySummary = ts('%1 - %2 (updated on %3)', array(1 => CRM_Utils_Money::format($contribution->total_amount, $contribution->currency), 2 => $contributionType, 3 => $GLOBALS['_CRM_CONTRIBUTE_BAO_CONTRIBUTION']['insertDate']));
$historyParams = array('entity_table' => 'civicrm_contact', 'entity_id' => $contribution->contact_id, 'activity_type' => $contributionType, 'module' => 'CiviContribute', 'callback' => 'CRM_Contribute_Page_Contribution::details', 'activity_id' => $contribution->id, 'activity_summary' => $activitySummary, 'activity_date' => $contribution->receive_date);
if (CRM_Utils_Array::value('contribution', $ids)) {
// this contribution should have an Activity History record already
$getHistoryParams = array('module' => 'CiviContribute', 'activity_id' => $contribution->id);
$getHistoryValues =& CRM_Core_BAO_History::getHistory($getHistoryParams, 0, 1, null, 'Activity');
if (!empty($getHistoryValues)) {
$tmp = array_keys($getHistoryValues);
$ids['activity_history'] = $tmp[0];
}
}
$historyDAO =& CRM_Core_BAO_History::create($historyParams, $ids, 'Activity');
if (is_a($historyDAO, 'CRM_Core_Error')) {
CRM_Core_Error::fatal("Failed creating Activity History for contribution of id {$contribution->id}");
}
CRM_Core_DAO::transaction('COMMIT');
return $contribution;
}
示例10: _process_csv
function _process_csv($csv_array, $csv_name, $mail_date)
{
$this->_addToSummary("Processing {$csv_name}");
foreach ($csv_array as $row) {
$this->_addToSummary(null);
// insert blank line.
// check if this is a blank line
if (count($row) <= 1) {
continue;
}
$subscriptionId = $row[0];
$subscriptionStatus = $row[1];
$paymentNum = $row[2];
$totalRecurrences = $row[3];
$transactionId = $row[4];
$amount = $row[5];
$currency = $row[6];
$custFirstName = $row[8];
$custLastName = $row[9];
$contributionStatus = $row[10];
$recur =& new CRM_Contribute_DAO_ContributionRecur();
$first_contribution =& new CRM_Contribute_DAO_Contribution();
// If this is the first payment, load recurring contribution and update
if ($paymentNum == 1) {
// Load contribution using SubscriptionID as trxn_id
$first_contribution->trxn_id = $subscriptionId;
if (!$first_contribution->find(true)) {
$this->_addToSummary("THE RECURRING TRANSACTION FOR SUBSCRIPTION {$subscriptionId} COULD NOT BE FOUND. A TRANSACTION HAS OCCURED THAT WAS NOT EXPECTED. PLEASE REVIEW {$csv_name}.");
continue;
}
// Load recurring contribution from contribution
$recur->id = $first_contribution->contribution_recur_id;
if (!$recur->find(true)) {
$this->_addToSummary("INITIAL RECURRING CONTRIBUTION NOT FOUND FOR {$subscriptionId}. PLEASE REVIEW {$csv_name}");
continue;
}
$recur->start_date = $mail_date;
$recur->processor_id = $subscriptionId;
$recur->trxn_id = $subscriptionId;
$recur->contribution_status_id = _CRM_PROCESS_AUTHORIZE_REPORT_STATUS_CURRENT;
// update transaction id for contribution
$first_contribution->trxn_id = $transactionId;
$first_contribution->receive_date = $mail_date;
$first_contribution->contribution_status_id = $this->_get_contribution_status($contributionStatus);
// load contribution page
$contribution_page =& new CRM_Contribute_DAO_ContributionPage();
$contribution_page->id = $first_contribution->contribution_page_id;
if (!$contribution_page->find(true)) {
$this->_addToSummary("COULD NOT FIND CONTRIBUTION PAGE FOR {$subscriptionId}. PLEASE REVIEW {$csv_name}");
continue;
}
// is there an email receipt
if ($contribution_page->is_email_receipt) {
$first_contribution->receipt_date = date('YmdHis');
}
} else {
$recur->processor_id = $subscriptionId;
if (!$recur->find(true)) {
$this->_addToSummary("THE RECURRING TRANSACTION FOR SUBSCRIPTION {$subscriptionId} COULD NOT BE FOUND. A TRANSACTION HAS OCCURED THAT WAS NOT EXPECTED. PLEASE REVIEW {$csv_name}.");
continue;
}
$recur->modified_date = $mail_date;
// load first contribution
$first_contribution->contribution_recur_id = $recur->id;
$first_contribution->orderBy('receive_date');
$first_contribution->limit(1);
if (!$first_contribution->find(true)) {
$this->_addToSummary("CONTRIBUTION RECORD FOR SUBSCRIPTION {$subscriptonId} COULD NOT BE FOUND. PLEASE REVIEW {$csv_name}");
continue;
}
// load contribution page
$contribution_page =& new CRM_Contribute_DAO_ContributionPage();
$contribution_page->id = $first_contribution->contribution_page_id;
if (!$contribution_page->find(true)) {
$this->_addToSummary("COULD NOT FIND CONTRIBUTION PAGE FOR {$subscriptionId}. PLEASE REVIEW {$csv_name}");
continue;
}
}
// is this valid for failed transactions also?
if ($amount != $recur->amount) {
$this->_addToSummary("AN UNEXPECTED AMOUNT WAS RECEIVED FOR SUBSCRIPTION {$subscriptionId}. SKIPPING THIS TRANSACTION. PLEASE REVIEW {$csv_name}");
continue;
}
// Verify contact exists
if (!$recur->contact_id) {
// assuming if contact_id is set, contact exists
$this->_addToSummary("NO USER IS ASSOCIATED WITH THE CONTRIBUTION FOR SUBSCRIPTION {$subscrptionId}, EXPECTED '{$custFirstName} {$custLastName}'. PLEASE REVIEW {$csv_name}");
continue;
}
// Verify number of recurrences
if ($recur->installments != $totalRecurrences) {
$this->_addToSummary("SUBSCRIPTION {$subscriptionId} EXPECTS {$recur->installments}, OFFERED {$totalRecurrences}. PLEASE REVIEW {$csv_name}");
continue;
}
// Check if this contribution is complete
if (!empty($recur->end_date) && $recur->end_date != '0000-00-00 00:00:00') {
$this->_addToSummary("SUBSCRIPTION {$subscriptionId} IS MARKED AS COMPLETE. PLEASE REVIEW {$csv_name}");
continue;
}
if (!empty($recur->cancel_date) && $recur->cancel_date != '0000-00-00 00:00:00') {
//.........这里部分代码省略.........
示例11: postProcess
/**
* Process the form
*
* @return void
* @access public
*/
function postProcess()
{
// get the submitted form values.
$params = $this->controller->exportValues($this->_name);
if ($this->_action & CRM_CORE_ACTION_UPDATE) {
$params['id'] = $this->_id;
}
$params['domain_id'] = CRM_Core_Config::domainID();
CRM_Core_DAO::transaction('BEGIN');
// also update the ProfileModule tables
$ufJoinParams = array('is_active' => 1, 'module' => 'CiviContribute', 'entity_table' => 'civicrm_contribution_page', 'entity_id' => $this->_id, 'weight' => 1, 'uf_group_id' => $params['custom_pre_id']);
require_once 'CRM/Core/BAO/UFJoin.php';
CRM_Core_BAO_UFJoin::create($ufJoinParams);
unset($ufJoinParams['id']);
$ufJoinParams['weight'] = 2;
$ufJoinParams['uf_group_id'] = $params['custom_post_id'];
CRM_Core_BAO_UFJoin::create($ufJoinParams);
CRM_Core_DAO::transaction('COMMIT');
}
示例12: CRM_Core_Dao
/**
* Create a new forward event, create a new contact if necessary
*/
function &forward($job_id, $queue_id, $hash, $forward_email)
{
$q =& CRM_Mailing_Event_BAO_Queue::verify($job_id, $queue_id, $hash);
if (!$q) {
return null;
}
/* Find the email address/contact, if it exists */
$contact = CRM_Contact_BAO_Contact::getTableName();
$location = CRM_Core_BAO_Location::getTableName();
$email = CRM_Core_BAO_Email::getTableName();
$queueTable = CRM_Mailing_Event_BAO_Queue::getTableName();
$job = CRM_Mailing_BAO_Job::getTableName();
$mailing = CRM_Mailing_BAO_Mailing::getTableName();
$forward = CRM_Mailing_Event_BAO_Forward::getTableName();
$domain =& CRM_Mailing_Event_BAO_Queue::getDomain($queue_id);
$dao =& new CRM_Core_Dao();
$dao->query("\n SELECT {$contact}.id as contact_id,\n {$email}.id as email_id,\n {$contact}.do_not_email as do_not_email,\n {$queueTable}.id as queue_id\n FROM {$email}, {$job} as temp_job\n INNER JOIN {$location}\n ON {$email}.location_id = {$location}.id\n INNER JOIN {$contact}\n ON {$location}.entity_table = '{$contact}'\n AND {$location}.entity_id = {$contact}.id\n LEFT JOIN {$queueTable}\n ON {$email}.id = {$queueTable}.email_id\n LEFT JOIN {$job}\n ON {$queueTable}.job_id = {$job}.id\n AND temp_job.mailing_id = {$job}.mailing_id\n WHERE temp_job.id = {$job_id}\n AND {$email}.email = '" . CRM_Utils_Type::escape($forward_email, 'String') . "'");
$dao->fetch();
CRM_Core_DAO::transaction('BEGIN');
if (isset($dao->queue_id) || $dao->do_not_email == 1) {
/* We already sent this mailing to $forward_email, or we should
* never email this contact. Give up. */
return false;
} elseif (empty($dao->contact_id)) {
/* No contact found, we'll have to create a new one */
$contact_params = array('email' => $forward_email);
$contact =& crm_create_contact($contact_params);
if (is_a($contact, 'CRM_Core_Error')) {
return false;
}
/* This is an ugly hack, but the API doesn't really support
* overriding the domain ID any other way */
$contact->domain_id = $domain->id;
$contact->save();
$contact_id = $contact->id;
$email_id = $contact->location[1]->email[1]->id;
} else {
$contact_id = $dao->contact_id;
$email_id = $dao->email_id;
}
/* Create a new queue event */
$queue_params = array('email_id' => $email_id, 'contact_id' => $contact_id, 'job_id' => $job_id);
$queue =& CRM_Mailing_Event_BAO_Queue::create($queue_params);
$forward =& new CRM_Mailing_Event_BAO_Forward();
$forward->time_stamp = date('YmdHis');
$forward->event_queue_id = $queue_id;
$forward->dest_queue_id = $queue->id;
$forward->save();
$dao->reset();
$dao->query(" SELECT {$job}.mailing_id as mailing_id \n FROM {$job}\n WHERE {$job}.id = " . CRM_Utils_Type::escape($job_id, 'Integer'));
$dao->fetch();
$mailing_obj =& new CRM_Mailing_BAO_Mailing();
$mailing_obj->id = $dao->mailing_id;
$mailing_obj->find(true);
$config =& CRM_Core_Config::singleton();
$mailer =& $config->getMailer();
$recipient = null;
$message =& $mailing_obj->compose($job_id, $queue->id, $queue->hash, $queue->contact_id, $forward_email, $recipient);
$body = $message->get();
$headers = $message->headers();
PEAR::setErrorHandling(PEAR_ERROR_CALLBACK, array('CRM_Mailing_BAO_Mailing', 'catchSMTP'));
$result = $mailer->send($recipient, $headers, $body);
CRM_Core_Error::setCallback();
$params = array('event_queue_id' => $queue->id, 'job_id' => $job_id, 'hash' => $queue->hash);
if (is_a($result, PEAR_Error)) {
/* Register the bounce event */
$params = array_merge($params, CRM_Mailing_BAO_BouncePattern::match($result->getMessage()));
CRM_Mailing_Event_BAO_Bounce::create($params);
} else {
/* Register the delivery event */
CRM_Mailing_Event_BAO_Delivered::create($params);
}
CRM_Core_DAO::transaction('COMMIT');
return true;
}
示例13: create
/**
* Construct a new mailing object, along with job and mailing_group
* objects, from the form values of the create mailing wizard.
*
* @params array $params Form values
* @return object $mailing The new mailing object
* @access public
* @static
*/
function create(&$params)
{
CRM_Core_DAO::transaction('BEGIN');
$mailing =& new CRM_Mailing_BAO_Mailing();
$mailing->domain_id = $params['domain_id'];
$mailing->header_id = $params['header_id'];
$mailing->footer_id = $params['footer_id'];
$mailing->reply_id = $params['reply_id'];
$mailing->unsubscribe_id = $params['unsubscribe_id'];
$mailing->optout_id = $params['optout_id'];
$mailing->name = $params['mailing_name'];
$mailing->from_name = $params['from_name'];
$mailing->from_email = $params['from_email'];
if (!isset($params['replyto_email'])) {
$mailing->replyto_email = $params['from_email'];
} else {
$mailing->replyto_email = $params['replyto_email'];
}
$mailing->subject = $params['subject'];
$mailing->body_text = file_get_contents($params['textFile']);
if (file_exists($params['htmlFile'])) {
$mailing->body_html = file_get_contents($params['htmlFile']);
}
$mailing->is_template = $params['template'] ? true : false;
$mailing->auto_responder = $params['auto_responder'] ? true : false;
$mailing->url_tracking = $params['track_urls'] ? true : false;
$mailing->open_tracking = $params['track_opens'] ? true : false;
$mailing->forward_replies = $params['forward_reply'] ? true : false;
$mailing->is_completed = false;
$mailing->save();
if (!$mailing->is_template) {
/* Create the job record */
$job =& new CRM_Mailing_BAO_Job();
$job->mailing_id = $mailing->id;
$job->status = 'Scheduled';
$job->is_retry = false;
if ($params['now']) {
$job->scheduled_date = date('YmdHis');
} else {
$job->scheduled_date = CRM_Utils_Date::format($params['start_date']);
}
$job->save();
}
/* Create the mailing group record */
$mg =& new CRM_Mailing_DAO_Group();
foreach (array('groups', 'mailings') as $entity) {
foreach (array('include', 'exclude') as $type) {
if (is_array($params[$entity][$type])) {
foreach ($params[$entity][$type] as $entityId) {
$mg->reset();
$mg->mailing_id = $mailing->id;
$mg->entity_table = $entity == 'groups' ? CRM_Contact_BAO_Group::getTableName() : CRM_Mailing_BAO_Mailing::getTableName();
$mg->entity_id = $entityId;
$mg->group_type = $type;
$mg->save();
}
}
}
}
CRM_Core_DAO::transaction('COMMIT');
return $mailing;
}
示例14: array
/**
* Register a subscription event. Create a new contact if one does not
* already exist.
*
* @param int $domain_id The domain id of the new subscription
* @param int $group_id The group id to subscribe to
* @param string $email The email address of the (new) contact
* @return int|null $se_id The id of the subscription event, null on failure
* @access public
* @static
*/
function &subscribe($domain_id, $group_id, $email)
{
/* First, find out if the contact already exists */
$params = array('email' => $email, 'domain_id' => $domain_id);
require_once 'CRM/Core/BAO/UFGroup.php';
$contact_id = CRM_Core_BAO_UFGroup::findContact($params);
CRM_Core_DAO::transaction('BEGIN');
if (is_a($contact_id, CRM_Core_Error)) {
require_once 'CRM/Core/BAO/LocationType.php';
/* If the contact does not exist, create one. */
$formatted = array('contact_type' => 'Individual');
$value = array('email' => $email, 'location_type' => CRM_Core_BAO_LocationType::getDefaultID());
_crm_add_formatted_param($value, $formatted);
$contact =& crm_create_contact_formatted($formatted, CRM_IMPORT_PARSER_DUPLICATE_SKIP);
if (is_a($contact, CRM_Core_Error)) {
return null;
}
$contact_id = $contact->id;
}
require_once 'CRM/Core/BAO/Email.php';
require_once 'CRM/Core/BAO/Location.php';
require_once 'CRM/Contact/BAO/Contact.php';
/* Get the primary email id from the contact to use as a hash input */
$dao =& new CRM_Core_DAO();
$emailTable = CRM_Core_BAO_Email::getTableName();
$locTable = CRM_Core_BAO_Location::getTableName();
$contactTable = CRM_Contact_BAO_Contact::getTableName();
$dao->query("SELECT {$emailTable}.id as email_id\n FROM {$emailTable}\n INNER JOIN {$locTable}\n ON {$emailTable}.location_id = {$locTable}.id\n WHERE {$emailTable}.is_primary = 1\n AND {$locTable}.is_primary = 1\n AND {$locTable}.entity_table = '{$contactTable}'\n AND {$locTable}.entity_id = " . CRM_Utils_Type::escape($contact_id, 'Integer'));
$dao->fetch();
$se =& new CRM_Mailing_Event_BAO_Subscribe();
$se->group_id = $group_id;
$se->contact_id = $contact_id;
$se->time_stamp = date('YmdHis');
$se->hash = sha1("{$group_id}:{$contact_id}:{$dao->email_id}");
$se->save();
$contacts = array($contact_id);
require_once 'CRM/Contact/BAO/GroupContact.php';
CRM_Contact_BAO_GroupContact::addContactsToGroup($contacts, $group_id, 'Email', 'Pending', $se->id);
CRM_Core_DAO::transaction('COMMIT');
return $se;
}
示例15: postProcess
//.........这里部分代码省略.........
$month = substr($fixed_period_start_day, 0, strlen($fixed_period_start_day) - 2);
$day = substr($fixed_period_start_day, -2) . "<br>";
$year = $date[0];
$startDate = $year . '-' . $month . '-' . $day;
} else {
$startDate = date('Y-m-d');
}
}
}
$date = explode('-', $startDate);
$year = $date[0];
$month = $date[1];
$day = $date[2];
switch ($duration_unit) {
case 'year':
$year = $year + $duration_interval;
break;
case 'month':
$month = $month + $duration_interval;
break;
case 'day':
$day = $day + $duration_interval;
break;
case 'week':
$day = $day + $duration_interval * 7;
}
$endDate = date('Y-m-d H:i:s', mktime($hour, $minute, $second, $month, $day, $year));
$this->assign('start_date', $startDate);
$this->assign('end_date', $endDate);
}
require_once 'CRM/Contribute/DAO/Premium.php';
$dao =& new CRM_Contribute_DAO_Premium();
$dao->entity_table = 'civicrm_contribution_page';
$dao->entity_id = $this->_id;
$dao->find(true);
$this->assign('contact_phone', $dao->premiums_contact_phone);
$this->assign('contact_email', $dao->premiums_contact_email);
}
CRM_Core_DAO::transaction('BEGIN');
$nonDeductibleAmount = $result['gross_amount'];
if ($contributionType->is_deductible) {
if ($premiumParams['selectProduct'] != 'no_thanks') {
require_once 'CRM/Contribute/DAO/Product.php';
$productDAO =& new CRM_Contribute_DAO_Product();
$productDAO->id = $premiumParams['selectProduct'];
$productDAO->find(true);
if ($result['gross_amount'] < $productDAO->price) {
$nonDeductibleAmount = $result['gross_amount'];
} else {
$nonDeductibleAmount = $productDAO->price;
}
} else {
$nonDeductibleAmount = '0.00';
}
}
// check contribution Type
// first create the contribution record
$params = array('contact_id' => $contactID, 'contribution_type_id' => $contributionType->id, 'payment_instrument_id' => 1, 'receive_date' => $now, 'non_deductible_amount' => $nonDeductibleAmount, 'total_amount' => $result['gross_amount'], 'fee_amount' => CRM_Utils_Array::value('fee_amount', $result), 'net_amount' => CRM_Utils_Array::value('net_amount', $result, $result['gross_amount']), 'trxn_id' => $result['trxn_id'], 'invoice_id' => $this->_params['invoiceID'], 'currency' => $this->_params['currencyID'], 'receipt_date' => $receiptDate, 'source' => ts('Online Contribution:') . ' ' . $this->_values['title']);
$ids = array();
$contribution =& CRM_Contribute_BAO_Contribution::add($params, $ids);
//create Premium record
if ($premiumParams['selectProduct'] && $premiumParams['selectProduct'] != 'no_thanks') {
require_once 'CRM/Contribute/DAO/Product.php';
$productDAO =& new CRM_Contribute_DAO_Product();
$productDAO->id = $premiumParams['selectProduct'];
$productDAO->find(true);
$periodType = $productDAO->period_type;
require_once 'CRM/Utils/Date.php';
$params = array('product_id' => $premiumParams['selectProduct'], 'contribution_id' => $contribution->id, 'product_option' => $premiumParams['options_' . $premiumParams['selectProduct']], 'quantity' => 1, 'start_date' => CRM_Utils_Date::customFormat($startDate, '%Y%m%d'), 'end_date' => CRM_Utils_Date::customFormat($endDate, '%Y%m%d'));
CRM_Contribute_BAO_Contribution::addPremium($params);
}
// process the custom data that is submitted or that came via the url
$groupTree = $this->get('groupTree');
$customValues = $this->get('customGetValues');
$customValues = array_merge($this->_params, $customValues);
require_once 'CRM/Core/BAO/CustomGroup.php';
CRM_Core_BAO_CustomGroup::postProcess($groupTree, $customValues);
CRM_Core_BAO_CustomGroup::updateCustomData($groupTree, 'Contribution', $contribution->id);
// next create the transaction record
$params = array('entity_table' => 'civicrm_contribution', 'entity_id' => $contribution->id, 'trxn_date' => $now, 'trxn_type' => 'Debit', 'total_amount' => $result['gross_amount'], 'fee_amount' => CRM_Utils_Array::value('fee_amount', $result), 'net_amount' => CRM_Utils_Array::value('net_amount', $result, $result['gross_amount']), 'currency' => $this->_params['currencyID'], 'payment_processor' => $config->paymentProcessor, 'trxn_id' => $result['trxn_id']);
require_once 'CRM/Contribute/BAO/FinancialTrxn.php';
$trxn =& CRM_Contribute_BAO_FinancialTrxn::create($params);
// also create an activity history record
require_once 'CRM/Utils/Money.php';
$params = array('entity_table' => 'civicrm_contact', 'entity_id' => $contactID, 'activity_type' => $contributionType->name, 'module' => 'CiviContribute', 'callback' => 'CRM_Contribute_Page_Contribution::details', 'activity_id' => $contribution->id, 'activity_summary' => 'Online - ' . CRM_Utils_Money::format($this->_params['amount']), 'activity_date' => $now);
if (is_a(crm_create_activity_history($params), 'CRM_Core_Error')) {
CRM_Core_Error::fatal("Could not create a system record");
}
CRM_Core_DAO::transaction('COMMIT');
// finally send an email receipt
if ($this->_values['is_email_receipt']) {
list($displayName, $email) = CRM_Contact_BAO_Contact::getEmailDetails($contactID);
$template =& CRM_Core_Smarty::singleton();
$subject = trim($template->fetch('CRM/Contribute/Form/Contribution/ReceiptSubject.tpl'));
$message = $template->fetch('CRM/Contribute/Form/Contribution/ReceiptMessage.tpl');
$receiptFrom = '"' . $this->_values['receipt_from_name'] . '" <' . $this->_values['receipt_from_email'] . '>';
require_once 'CRM/Utils/Mail.php';
CRM_Utils_Mail::send($receiptFrom, $displayName, $email, $subject, $message, $this->_values['cc_receipt'], $this->_values['bcc_receipt']);
}
}