Exemplo n.º 1
0
 function add_participant_to_cart()
 {
     require 'CRM/Core/Transaction.php';
     $transaction = new CRM_Core_Transaction();
     $cart_id = $_GET['cart_id'];
     $event_id = $_GET['event_id'];
     $cart = CRM_Event_Cart_BAO_Cart::find_by_id($_GET['cart_id']);
     $params_array = array('cart_id' => $cart->id, 'contact_id' => CRM_Event_Cart_Form_Cart::find_or_create_contact(), 'event_id' => $event_id);
     //XXX security?
     $participant = CRM_Event_Cart_BAO_MerParticipant::create($params_array);
     $participant->save();
     $form = new CRM_Core_Form();
     $pform = new CRM_Event_Cart_Form_MerParticipant($participant);
     $pform->appendQuickForm($form);
     $renderer = $form->getRenderer();
     $config = CRM_Core_Config::singleton();
     $templateDir = $config->templateDir;
     if (is_array($templateDir)) {
         $templateDir = array_pop($templateDir);
     }
     $requiredTemplate = file_get_contents($templateDir . '/CRM/Form/label.tpl');
     $renderer->setRequiredTemplate($requiredTemplate);
     $form->accept($renderer);
     $template = CRM_Core_Smarty::singleton();
     $template->assign('form', $renderer->toArray());
     $template->assign('participant', $participant);
     $output = $template->fetch("CRM/Event/Cart/Form/Checkout/Participant.tpl");
     $transaction->commit();
     echo $output;
     CRM_Utils_System::civiExit();
 }
Exemplo n.º 2
0
 /**
  * takes an associative array and creates a price field object
  *
  * This function is invoked from within the web form layer and also from the api layer
  *
  * @param array $params (reference) an assoc array of name/value pairs
  *
  * @return object CRM_Price_DAO_PriceField object
  * @access public
  * @static
  */
 static function create(&$params)
 {
     if (empty($params['id']) && empty($params['name'])) {
         $params['name'] = strtolower(CRM_Utils_String::munge($params['label'], '_', 242));
     }
     $transaction = new CRM_Core_Transaction();
     $priceField = self::add($params);
     if (is_a($priceField, 'CRM_Core_Error')) {
         $transaction->rollback();
         return $priceField;
     }
     $optionsIds = array();
     $maxIndex = CRM_Price_Form_Field::NUM_OPTION;
     if ($priceField->html_type == 'Text') {
         $maxIndex = 1;
         $fieldValue = new CRM_Price_DAO_PriceFieldValue();
         $fieldValue->price_field_id = $priceField->id;
         // update previous field values( if any )
         if ($fieldValue->find(TRUE)) {
             $optionsIds['id'] = $fieldValue->id;
         }
     }
     $defaultArray = array();
     //html type would be empty in update scenario not sure what would happen ...
     if (!empty($params['html_type']) && $params['html_type'] == 'CheckBox' && isset($params['default_checkbox_option'])) {
         $tempArray = array_keys($params['default_checkbox_option']);
         foreach ($tempArray as $v) {
             if ($params['option_amount'][$v]) {
                 $defaultArray[$v] = 1;
             }
         }
     } else {
         if (!empty($params['default_option'])) {
             $defaultArray[$params['default_option']] = 1;
         }
     }
     for ($index = 1; $index <= $maxIndex; $index++) {
         if (array_key_exists('option_amount', $params) && array_key_exists($index, $params['option_amount']) && (CRM_Utils_Array::value($index, CRM_Utils_Array::value('option_label', $params)) || !empty($params['is_quick_config'])) && !CRM_Utils_System::isNull($params['option_amount'][$index])) {
             $options = array('price_field_id' => $priceField->id, 'label' => trim($params['option_label'][$index]), 'name' => CRM_Utils_String::munge($params['option_label'][$index], '_', 64), 'amount' => CRM_Utils_Rule::cleanMoney(trim($params['option_amount'][$index])), 'count' => CRM_Utils_Array::value($index, CRM_Utils_Array::value('option_count', $params), NULL), 'max_value' => CRM_Utils_Array::value($index, CRM_Utils_Array::value('option_max_value', $params), NULL), 'description' => CRM_Utils_Array::value($index, CRM_Utils_Array::value('option_description', $params), NULL), 'membership_type_id' => CRM_Utils_Array::value($index, CRM_Utils_Array::value('membership_type_id', $params), NULL), 'weight' => $params['option_weight'][$index], 'is_active' => 1, 'is_default' => CRM_Utils_Array::value($params['option_weight'][$index], $defaultArray) ? $defaultArray[$params['option_weight'][$index]] : 0, 'membership_num_terms' => NULL);
             if ($options['membership_type_id']) {
                 $options['membership_num_terms'] = CRM_Utils_Array::value($index, CRM_Utils_Array::value('membership_num_terms', $params), 1);
             }
             if (CRM_Utils_Array::value($index, CRM_Utils_Array::value('option_financial_type_id', $params))) {
                 $options['financial_type_id'] = $params['option_financial_type_id'][$index];
             } elseif (!empty($params['financial_type_id'])) {
                 $options['financial_type_id'] = $params['financial_type_id'];
             }
             if ($opIds = CRM_Utils_Array::value('option_id', $params)) {
                 if ($opId = CRM_Utils_Array::value($index, $opIds)) {
                     $optionsIds['id'] = $opId;
                 } else {
                     $optionsIds['id'] = NULL;
                 }
             }
             CRM_Price_BAO_PriceFieldValue::create($options, $optionsIds);
         }
     }
     $transaction->commit();
     return $priceField;
 }
/**
 * Add or update a link between contribution and membership
 *
 * @param  array   $params           (reference ) input parameters
 *
 * @return array (reference )        membership_payment_id of created or updated record
 * @static void
 * @access public
 */
function &civicrm_membershipcontributionlink_create(&$params)
{
    _civicrm_initialize();
    if (empty($params)) {
        return civicrm_create_error(ts('No input parameters present'));
    }
    if (!is_array($params)) {
        return civicrm_create_error(ts('Input parameters is not an array'));
    }
    if (!isset($params['contribution_id']) || !isset($params['membership_id'])) {
        return civicrm_create_error(ts('Required parameters missing'));
    }
    require_once 'CRM/Core/Transaction.php';
    $transaction = new CRM_Core_Transaction();
    require_once 'CRM/Member/DAO/MembershipPayment.php';
    $mpDAO =& new CRM_Member_DAO_MembershipPayment();
    $mpDAO->copyValues($params);
    $result = $mpDAO->save();
    if (is_a($result, 'CRM_Core_Error')) {
        $transaction->rollback();
        return civicrm_create_error($result->_errors[0]['message']);
    }
    $transaction->commit();
    _civicrm_object_to_array($mpDAO, $mpArray);
    return $mpArray;
}
Exemplo n.º 4
0
/**
 * Create a new domain - with a domain group.
 *
 * This is not fully developed & need to work on creating admin menus etc
 *
 * @param array $params
 *
 * @return array
 * @example DomainCreate.php
 * {@getfields domain_create}
 */
function civicrm_api3_multisite_domain_create($params)
{
    $transaction = new CRM_Core_Transaction();
    if (empty($params['contact_id'])) {
        $params['contact_id'] = _civicrm_api3_multisite_domain_create_if_not_exists('Contact', array('organization_name' => $params['name'], 'contact_type' => 'organization'));
    }
    $domain = civicrm_api('domain', 'getsingle', array('version' => 3, 'current_domain' => TRUE));
    $fullParams = array_merge($domain, $params);
    $fullParams['domain_version'] = $domain['version'];
    $fullParams['version'] = 3;
    unset($fullParams['id']);
    if (empty($params['group_id'])) {
        $groupParams = array('title' => !empty($params['group_name']) ? $params['group_name'] : $params['name']);
        $group = civicrm_api3('Group', 'get', array_merge($groupParams, array('options' => array('limit' => 1))));
        if (empty($group['id'])) {
            // Ideally would fix the api to be more consistent & not assume default but...
            $groupParams['group_type'] = array(1 => 1);
            $group = civicrm_api3('Group', 'create', $groupParams);
        }
        $domainGroupID = $group['id'];
    } else {
        $domainGroupID = $params['group_id'];
    }
    _civicrm_api3_multisite_domain_create_if_not_exists('GroupOrganization', array('group_id' => $domainGroupID, 'organization_id' => $params['contact_id']));
    $domainID = _civicrm_api3_multisite_domain_create_if_not_exists('domain', $fullParams);
    if (!$domainID || $domainID != civicrm_api3('Domain', 'getvalue', array('name' => $params['name'], 'return' => 'id'))) {
        throw new CiviCRM_API3_Exception('Failed to create domain', 'unknown');
    }
    $transaction->commit();
    if (!civicrm_api3('Navigation', 'getcount', array('domain_id' => $domainID))) {
        _civicrm_load_navigation($params['name'], $domainID);
    }
    civicrm_api3('Setting', 'create', array('is_enabled' => TRUE, 'domain_group_id' => $domainGroupID, 'domain_id' => $domainID));
    return civicrm_api3_create_success(array($domainID => array('id' => $domainID)));
}
Exemplo n.º 5
0
function ndiciviparty_add_default_dashboard($contactid)
{
    $result = civicrm_api3('Dashboard', 'get', array('name' => "contact_per_month"));
    $exists = 0;
    $dashletid = 0;
    if ($result['count'] > 0) {
        $dashletid = $result['id'];
        $result = civicrm_api3('DashboardContact', 'get', array('contact_id' => $contactid, 'return' => array("dashboard_id", "contact_id")));
        if ($result['count'] > 0) {
            foreach ($result['values'] as $key => $value) {
                if ($value['dashboard_id'] == $dashletid) {
                    $exists = 1;
                }
            }
        }
        if ($exists != 1) {
            $tx = new CRM_Core_Transaction();
            $dashlet = array('dashboard_id' => $dashletid, 'contact_id' => $contactid, 'is_active' => 1, 'column_no' => 0, 'is_minimized' => 0, 'is_fullscreen' => 0, 'weight' => 0);
            try {
                $add = civicrm_api3('DashboardContact', 'create', $dashlet);
            } catch (CiviCRM_API3_Exception $e) {
                $tx->rollback();
                echo get_class($e) . ' -- ' . $e->getMessage() . "\n";
                echo $e->getTraceAsString() . "\n";
                print_r($e->getExtraParams());
            }
        }
        //end if exists
    }
    //end if dashlet found
}
Exemplo n.º 6
0
 function postProcess()
 {
     $values = $this->exportValues();
     $title = str_replace("'", "''", $values['title']);
     $params = array(1 => array($title, 'String'), 2 => array($values['widget'], 'Integer'));
     if (isset($this->_id)) {
         $params += array(3 => array($this->_id, 'Integer'));
         $sql = "UPDATE civicrm_wci_embed_code SET name = %1, widget_id = %2 where id = %3";
     } else {
         $sql = "INSERT INTO civicrm_wci_embed_code (name, widget_id)VALUES (%1, %2)";
     }
     $errorScope = CRM_Core_TemporaryErrorScope::useException();
     try {
         $transaction = new CRM_Core_Transaction();
         CRM_Core_DAO::executeQuery($sql, $params);
         $transaction->commit();
         CRM_Core_Session::setStatus(ts('Embed code created successfully'), '', 'success');
         if (isset($_REQUEST['_qf_NewEmbedCode_next'])) {
             isset($this->_id) ? $embed_id = $this->_id : ($embed_id = CRM_Core_DAO::singleValueQuery('SELECT LAST_INSERT_ID()'));
             CRM_Utils_System::redirect('?action=update&reset=1&id=' . $embed_id);
         } else {
             CRM_Utils_System::redirect('embed-code?reset=1');
         }
     } catch (Exception $e) {
         CRM_Core_Session::setStatus(ts('Failed to create embed code'), '', 'error');
         $transaction->rollback();
     }
     parent::postProcess();
 }
Exemplo n.º 7
0
/**
 * PriceSet.FetchSection API
 *
 * @param array $params
 * @return array API result descriptor
 * @see civicrm_api3_create_success
 * @see civicrm_api3_create_error
 * @throws API_Exception
 */
function civicrm_api3_workflow_save($params)
{
    if (!array_key_exists("data", $params) || !$params['data']) {
        throw new API_Exception('Missing parameter: data', 170);
    }
    if (!array_key_exists("wid", $params) || !$params['wid']) {
        throw new API_Exception('Missing parameter: wid', 170);
    }
    $wid = $params['wid'];
    $d = urldecode($params['data']);
    $data = parse_str($d);
    //I don't know why this is important, but it made things work.
    $try2 = parse_str($params['data']);
    //Hook in case someone wants to alter the data
    CRM_Workflow_hook::beforeSave($wid, $data);
    $transaction = new CRM_Core_Transaction();
    $dsql = "DELETE FROM civicrm_workflow_detail WHERE workflow_id = {$wid}";
    $dao =& CRM_Core_DAO::executeQuery($dsql);
    if (!empty($data)) {
        $sql = "INSERT INTO civicrm_workflow_detail ( workflow_id, entity_table, entity_id, `order`, breadcrumb, `next`, title) VALUES ";
        $i = 1;
        $vals = array();
        foreach ($data as $key => $d) {
            //$did = (strpos($id, ":")) ? 0 : $id;
            $eid = $d['entity_id'];
            $e_type = $d['entity_table'];
            $order = $d['order'];
            $breadcrumb = $d['breadcrumb'];
            $next = $d['next'];
            $title = $d['title'];
            $sql = $sql . "( %" . ($i + 0) . ", %" . ($i + 1) . ", %" . ($i + 2) . ", %" . ($i + 3) . ", %" . ($i + 4) . ", %" . ($i + 5) . ", %" . ($i + 6) . "),";
            //$vals[$i++] = array($did, 'Integer');
            $vals[$i++] = array($wid, 'Integer');
            $vals[$i++] = array($e_type, 'String');
            $vals[$i++] = array($eid, 'String');
            $vals[$i++] = array($order, 'Integer');
            $vals[$i++] = array($breadcrumb, 'String');
            $vals[$i++] = array($next, 'String');
            $vals[$i++] = array($title, 'String');
        }
        $sql = substr($sql, 0, -1);
        try {
            $dao =& CRM_Core_DAO::executeQuery($sql, $vals);
        } catch (Exception $e) {
            $transaction->rollback();
            return civicrm_api3_create_error($e . message);
        }
        //TODO: Better error checking?
        if ($dao->_lastError) {
            $transaction->rollback();
        } else {
            $transaction->commit();
            CRM_Workflow_hook::afterSave($wid, $data);
        }
    }
    $returnValues = array();
    return civicrm_api3_create_success($returnValues, $params, 'PriceSet', 'FetchSection');
}
 function run()
 {
     // get the requested action
     $action = CRM_Utils_Request::retrieve('action', 'String', $this, FALSE, 'browse');
     // assign vars to templates
     $this->assign('action', $action);
     $id = CRM_Utils_Request::retrieve('id', 'Positive', $this, FALSE, 0);
     if ($action & CRM_Core_Action::UPDATE) {
         $controller = new CRM_Core_Controller_Simple('CRM_Wci_Form_ProgressBar', 'Edit Progressbar', CRM_Core_Action::UPDATE);
         $controller->set('id', $id);
         $controller->process();
         return $controller->run();
     } elseif ($action & CRM_Core_Action::COPY) {
         try {
             $sql = "INSERT INTO civicrm_wci_progress_bar (name, starting_amount, goal_amount)\n        SELECT concat(name, '-', (SELECT MAX(id) FROM civicrm_wci_progress_bar)),\n        starting_amount, goal_amount FROM civicrm_wci_progress_bar\n        WHERE id=%1";
             CRM_Core_DAO::executeQuery($sql, array(1 => array($id, 'Integer')));
             $new_pb_id = CRM_Core_DAO::singleValueQuery('SELECT LAST_INSERT_ID()');
             $sql = "INSERT INTO civicrm_wci_progress_bar_formula\n            (contribution_page_id, financial_type_id, progress_bar_id, start_date, end_date, percentage)\n            SELECT contribution_page_id, financial_type_id, %1, start_date,\n            end_date, percentage FROM civicrm_wci_progress_bar_formula WHERE progress_bar_id=%2";
             CRM_Core_DAO::executeQuery($sql, array(1 => array($new_pb_id, 'Integer'), 2 => array($id, 'Integer')));
         } catch (Exception $e) {
             CRM_Core_Session::setStatus(ts('Failed to create Progress bar. ') . $e->getMessage(), '', 'error');
             $transaction->rollback();
         }
     } elseif ($action & CRM_Core_Action::DELETE) {
         $errorScope = CRM_Core_TemporaryErrorScope::useException();
         try {
             $transaction = new CRM_Core_Transaction();
             $sql = "DELETE FROM civicrm_wci_progress_bar_formula where progress_bar_id = %1";
             $params = array(1 => array($id, 'Integer'));
             CRM_Core_DAO::executeQuery($sql, $params);
             $sql = "DELETE FROM civicrm_wci_progress_bar where id = %1";
             $params = array(1 => array($id, 'Integer'));
             CRM_Core_DAO::executeQuery($sql, $params);
             $transaction->commit();
         } catch (Exception $e) {
             $errmgs = $e->getMessage() . ts('. Check whether progressbar is used by any widget or not');
             CRM_Core_Session::setStatus($errmgs, '', 'error');
             $transaction->rollback();
         }
     }
     // Example: Set the page-title dynamically; alternatively, declare a static title in xml/Menu/*.xml
     CRM_Utils_System::setTitle(ts('Progress Bar List'));
     $query = "SELECT * FROM civicrm_wci_progress_bar";
     $params = array();
     $dao = CRM_Core_DAO::executeQuery($query, $params, TRUE, 'CRM_Wci_DAO_ProgressBar');
     while ($dao->fetch()) {
         $con_page[$dao->id] = array();
         CRM_Core_DAO::storeValues($dao, $con_page[$dao->id]);
         $action = array_sum(array_keys($this->actionLinks()));
         //build the normal action links.
         $con_page[$dao->id]['action'] = CRM_Core_Action::formLink(self::actionLinks(), $action, array('id' => $dao->id));
     }
     if (isset($con_page)) {
         $this->assign('rows', $con_page);
     }
     return parent::run();
 }
 function run()
 {
     $transaction = new CRM_Core_Transaction();
     $cart = CRM_Event_Cart_BAO_Cart::find_or_create_for_current_session();
     $cart->load_associations();
     $this->assign_by_ref('events_in_carts', $cart->get_main_events_in_carts());
     $this->assign('events_count', count($cart->get_main_events_in_carts()));
     $transaction->commit();
     return parent::run();
 }
Exemplo n.º 10
0
 /**
  * @param array $params
  *
  * @return $this
  * @throws Exception
  */
 public static function create($params)
 {
     $transaction = new CRM_Core_Transaction();
     $cart = self::add($params);
     if (is_a($cart, 'CRM_Core_Error')) {
         $transaction->rollback();
         CRM_Core_Error::fatal(ts('There was an error creating an event cart'));
     }
     $transaction->commit();
     return $cart;
 }
Exemplo n.º 11
0
 /**
  * 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
  */
 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;
     }
     // before we proceed lets just check if this contact is already 'Added'
     // if so, we should ignore this request and hence avoid sending multiple
     // emails - CRM-11157
     $details = CRM_Contact_BAO_GroupContact::getMembershipDetail($contact_id, $se->group_id);
     if ($details && $details->status == 'Added') {
         // This contact is already subscribed
         // lets return the group title
         return CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Group', $se->group_id, 'title');
     }
     $transaction = new CRM_Core_Transaction();
     $ce = new CRM_Mailing_Event_BAO_Confirm();
     $ce->event_subscribe_id = $se->id;
     $ce->time_stamp = date('YmdHis');
     $ce->save();
     CRM_Contact_BAO_GroupContact::addContactsToGroup(array($contact_id), $se->group_id, 'Email', 'Added', $ce->id);
     $transaction->commit();
     $config = CRM_Core_Config::singleton();
     $domain = CRM_Core_BAO_Domain::getDomain();
     list($domainEmailName, $_) = CRM_Core_BAO_Domain::getNameAndEmail();
     list($display_name, $email) = CRM_Contact_BAO_Contact_Location::getEmailDetails($se->contact_id);
     $group = new CRM_Contact_DAO_Group();
     $group->id = $se->group_id;
     $group->find(TRUE);
     $component = new CRM_Mailing_BAO_Component();
     $component->is_default = 1;
     $component->is_active = 1;
     $component->component_type = 'Welcome';
     $component->find(TRUE);
     $emailDomain = CRM_Core_BAO_MailSettings::defaultDomain();
     $html = $component->body_html;
     if ($component->body_text) {
         $text = $component->body_text;
     } else {
         $text = CRM_Utils_String::htmlToText($component->body_html);
     }
     $bao = new CRM_Mailing_BAO_Mailing();
     $bao->body_text = $text;
     $bao->body_html = $html;
     $tokens = $bao->getTokens();
     $html = CRM_Utils_Token::replaceDomainTokens($html, $domain, TRUE, $tokens['html']);
     $html = CRM_Utils_Token::replaceWelcomeTokens($html, $group->title, TRUE);
     $text = CRM_Utils_Token::replaceDomainTokens($text, $domain, FALSE, $tokens['text']);
     $text = CRM_Utils_Token::replaceWelcomeTokens($text, $group->title, FALSE);
     $mailParams = array('groupName' => 'Mailing Event ' . $component->component_type, 'subject' => $component->subject, 'from' => "\"{$domainEmailName}\" <do-not-reply@{$emailDomain}>", 'toEmail' => $email, 'toName' => $display_name, 'replyTo' => "do-not-reply@{$emailDomain}", 'returnPath' => "do-not-reply@{$emailDomain}", 'html' => $html, 'text' => $text);
     // send - ignore errors because the desired status change has already been successful
     $unused_result = CRM_Utils_Mail::send($mailParams);
     return $group->title;
 }
 static function &create(&$params)
 {
     require_once 'CRM/Core/Transaction.php';
     $transaction = new CRM_Core_Transaction();
     $statusType = self::add($params);
     if (is_a($statusType, 'CRM_Core_Error')) {
         $transaction->rollback();
         return $statusType;
     }
     $transaction->commit();
     return $statusType;
 }
Exemplo n.º 13
0
 function run()
 {
     // get the requested action
     $action = CRM_Utils_Request::retrieve('action', 'String', $this, FALSE, 'browse');
     // assign vars to templates
     $this->assign('action', $action);
     $id = CRM_Utils_Request::retrieve('id', 'Positive', $this, FALSE, 0);
     if ($action & CRM_Core_Action::UPDATE) {
         $controller = new CRM_Core_Controller_Simple('CRM_Wci_Form_CreateWidget', 'Edit Widget', CRM_Core_Action::UPDATE);
         $controller->set('id', $id);
         $controller->process();
         return $controller->run();
     } elseif ($action & CRM_Core_Action::COPY) {
         try {
             $sql = "INSERT INTO civicrm_wci_widget (title, logo_image, image,\n        button_title, button_link_to, progress_bar_id, description,\n        email_signup_group_id, size_variant, color_title, color_title_bg,\n        color_progress_bar, color_progress_bar_bg, color_widget_bg, color_description, color_border,\n        color_button, color_button_bg, hide_title, hide_border, hide_pbcap,\n        color_btn_newsletter, color_btn_newsletter_bg, newsletter_text,\n        color_newsletter_text, style_rules, override, custom_template, show_pb_perc)\n        SELECT concat(title, '-', (SELECT MAX(id) FROM civicrm_wci_widget)), logo_image, image,\n        button_title, button_link_to, progress_bar_id, description,\n        email_signup_group_id, size_variant, color_title, color_title_bg,\n        color_progress_bar, color_progress_bar_bg, color_widget_bg, color_description, color_border,\n        color_button, color_button_bg, hide_title, hide_border, hide_pbcap,\n        color_btn_newsletter, color_btn_newsletter_bg, newsletter_text,\n        color_newsletter_text, style_rules, override, custom_template, show_pb_perc FROM civicrm_wci_widget WHERE id=%1";
             CRM_Core_DAO::executeQuery("SET foreign_key_checks = 0;");
             CRM_Core_DAO::executeQuery($sql, array(1 => array($id, 'Integer')));
             CRM_Core_DAO::executeQuery("SET foreign_key_checks = 1;");
         } catch (Exception $e) {
             CRM_Core_Session::setStatus(ts('Failed to create widget. ') . $e->getMessage(), '', 'error');
             $transaction->rollback();
         }
     } elseif ($action & CRM_Core_Action::DELETE) {
         try {
             $transaction = new CRM_Core_Transaction();
             $sql = "DELETE FROM civicrm_wci_widget where id = %1";
             $params = array(1 => array($id, 'Integer'));
             CRM_Core_DAO::executeQuery($sql, $params);
             $transaction->commit();
         } catch (Exception $e) {
             CRM_Core_Session::setStatus(ts('Failed to delete widget. ') . $e->getMessage(), '', 'error');
             $transaction->rollback();
         }
     }
     CRM_Utils_System::setTitle(ts('Widget List'));
     $query = "SELECT * FROM civicrm_wci_widget";
     $params = array();
     $dao = CRM_Core_DAO::executeQuery($query, $params, TRUE, 'CRM_Wci_DAO_Widget');
     while ($dao->fetch()) {
         $wid_page[$dao->id] = array();
         CRM_Core_DAO::storeValues($dao, $wid_page[$dao->id]);
         $wid_page[$dao->id]['title'] = $wid_page[$dao->id]['title'];
         $description = $wid_page[$dao->id]['description'];
         $wid_page[$dao->id]['description'] = strip_tags($description);
         $action = array_sum(array_keys($this->actionLinks()));
         //build the normal action links.
         $wid_page[$dao->id]['action'] = CRM_Core_Action::formLink(self::actionLinks(), $action, array('id' => $dao->id));
     }
     if (isset($wid_page)) {
         $this->assign('rows', $wid_page);
     }
     parent::run();
 }
Exemplo n.º 14
0
 function stub_out_and_inherit()
 {
     $transaction = new CRM_Core_Transaction();
     foreach ($this->cart->get_main_events_in_carts() as $event_in_cart) {
         if (empty($event_in_cart->participants)) {
             $participant = CRM_Event_Cart_BAO_MerParticipant::create(array('cart_id' => $this->cart->id, 'event_id' => $event_in_cart->event_id, 'contact_id' => self::find_or_create_contact($this->getContactID())));
             $participant->save();
             $event_in_cart->add_participant($participant);
         }
         $event_in_cart->save();
     }
     $transaction->commit();
 }
Exemplo n.º 15
0
 /**
  * @param array $params
  *
  * @return object $this|CRM_Event_Cart_BAO_EventInCart
  * @throws Exception
  */
 public static function create(&$params)
 {
     $transaction = new CRM_Core_Transaction();
     $event_in_cart = new CRM_Event_Cart_BAO_EventInCart();
     $event_in_cart->copyValues($params);
     $event_in_cart = $event_in_cart->save();
     if (is_a($event_in_cart, 'CRM_Core_Error')) {
         $transaction->rollback();
         CRM_Core_Error::fatal(ts('There was an error creating an event_in_cart'));
     }
     $transaction->commit();
     return $event_in_cart;
 }
Exemplo n.º 16
0
 /**
  * This function takes care of all the things common to all pages.
  *
  * This typically involves assigning the appropriate smarty variables :)
  */
 public function run()
 {
     $transaction = new CRM_Core_Transaction();
     $this->_id = CRM_Utils_Request::retrieve('id', 'Positive', $this, TRUE);
     $cart = CRM_Event_Cart_BAO_Cart::find_or_create_for_current_session();
     $cart->load_associations();
     $event_in_cart = $cart->get_event_in_cart_by_event_id($this->_id);
     $removed_event = $cart->remove_event_in_cart($event_in_cart->id);
     $removed_event_title = $removed_event->event->title;
     CRM_Core_Session::setStatus(ts("<b>%1</b> has been removed from your cart.", array(1 => $removed_event_title)), '', 'success');
     $transaction->commit();
     return CRM_Utils_System::redirect($_SERVER['HTTP_REFERER']);
 }
Exemplo n.º 17
0
 /**
  * This function takes care of all the things common to all pages.
  *
  * This typically involves assigning the appropriate smarty variables :)
  */
 public function run()
 {
     $transaction = new CRM_Core_Transaction();
     $this->_id = CRM_Utils_Request::retrieve('id', 'Positive', $this, TRUE);
     if (!CRM_Core_Permission::event(CRM_Core_Permission::VIEW, $this->_id, 'register for events')) {
         CRM_Core_Error::fatal(ts('You do not have permission to register for this event'));
     }
     $cart = CRM_Event_Cart_BAO_Cart::find_or_create_for_current_session();
     $event_in_cart = $cart->add_event($this->_id);
     $url = CRM_Utils_System::url('civicrm/event/view_cart');
     CRM_Utils_System::setUFMessage(ts("<b>%1</b> has been added to your cart. <a href='%2'>View your cart.</a>", array(1 => $event_in_cart->event->title, 2 => $url)));
     $transaction->commit();
     return CRM_Utils_System::redirect($_SERVER['HTTP_REFERER']);
 }
Exemplo n.º 18
0
 public function endTest(\PHPUnit_Framework_Test $test, $time)
 {
     if ($test instanceof TransactionalInterface) {
         $this->tx->rollback()->commit();
         $this->tx = NULL;
     }
     if ($test instanceof HookInterface) {
         \CRM_Utils_Hook::singleton()->reset();
     }
     if ($this->isCiviTest($test)) {
         error_reporting(E_ALL & ~E_NOTICE);
         $this->errorScope = NULL;
     }
 }
Exemplo n.º 19
0
 /**
  * Delete all slots (associated bookings) for a particular resource
  */
 static function delByResource($resourceId)
 {
     $result = civicrm_api3('Slot', 'get', array('resource_id' => $resourceId, 'is_deleted' => 0));
     $slots = $result['values'];
     $transaction = new CRM_Core_Transaction();
     try {
         foreach ($slots as $slotId => $slot) {
             self::del($slotId);
         }
     } catch (Exception $e) {
         $transaction->rollback();
         CRM_Core_Error::fatal($e->getMessage());
     }
 }
/**
 * Add or update a link between contribution and membership
 *
 * @param  array   $params           (reference ) input parameters
 *
 * @return array (reference )        membership_payment_id of created or updated record
 * {@getfields MembershipPayment_create}
 * @example MembershipPaymentCreate.php
 * @access public
 */
function civicrm_api3_membership_payment_create($params)
{
    require_once 'CRM/Core/Transaction.php';
    $transaction = new CRM_Core_Transaction();
    $mpDAO = new CRM_Member_DAO_MembershipPayment();
    $mpDAO->copyValues($params);
    $result = $mpDAO->save();
    if (is_a($result, 'CRM_Core_Error')) {
        $transaction->rollback();
        return civicrm_api3_create_error($result->_errors[0]['message']);
    }
    $transaction->commit();
    _civicrm_api3_object_to_array($mpDAO, $mpArray[$mpDAO->id]);
    return civicrm_api3_create_success($mpArray, $params);
}
Exemplo n.º 21
0
 public static function UpgradeFromQueue(CRM_Queue_TaskContext $ctx, $mid, $params)
 {
     $today = new DateTime();
     $membership = civicrm_api3('Membership', 'getsingle', array('id' => $mid));
     $oldMembershipStatus = $params['rood_mstatus'];
     $migratie_lidmaatschappen_cg = civicrm_api3('CustomGroup', 'getvalue', array('return' => 'id', 'name' => 'Migratie_Lidmaatschappen'));
     $reason_fid = civicrm_api3('CustomField', 'getvalue', array('return' => 'id', 'name' => 'Reden', 'custom_group_id' => $migratie_lidmaatschappen_cg));
     unset($membership['id']);
     $dao = CRM_Core_DAO::executeQuery("\n      SELECT `c`.`id` AS `contribution_id`\nFROM `civicrm_membership`\nINNER JOIN `civicrm_membership_payment` `mp` ON `civicrm_membership`.`id` = `mp`.`membership_id`\nINNER JOIN `civicrm_contribution` `c` ON `mp`.`contribution_id` = `c`.`id` AND c.receive_date <= civicrm_membership.end_date\nWHERE civicrm_membership.id = %1\nORDER BY c.receive_date DESC\nLIMIT 0, 1", array(1 => array($mid, 'Integer')));
     if ($dao->fetch()) {
         $contribution = self::getRenewalPayment($dao->contribution_id);
         $renewTransaction = new CRM_Core_Transaction();
         $membership['membership_type_id'] = $params['sp_mtype'];
         $membership['start_date'] = $today->format('Ymd');
         if ($today->format('m') >= 10) {
             $newEndDate = clone $today;
             $newEndDate->modify('last day of +1 year');
             $membership['end_date'] = $newEndDate->format('Ymd');
         }
         $new_membership = civicrm_api3('Membership', 'create', $membership);
         if ($contribution) {
             $contribution['financial_type_id'] = civicrm_api3('MembershipType', 'getvalue', array('return' => 'financial_type_id', 'id' => $params['sp_mtype']));
             if ((double) $contribution['total_amount'] < (double) $params['minimum_fee']) {
                 $contribution['total_amount'] = $params['minimum_fee'];
             }
             $result = civicrm_api3('Contribution', 'create', $contribution);
             // Get Soft contributions
             $softContributions = civicrm_api3('ContributionSoft', 'get', array('contribution_id' => $dao->contribution_id));
             foreach ($softContributions['values'] as $softContribution) {
                 $newSoftContribution = $softContribution;
                 unset($newSoftContribution['id']);
                 $newSoftContribution['contribution_id'] = $result['id'];
                 civicrm_api3('ContributionSoft', 'create', $newSoftContribution);
             }
             $membershipPayment['contribution_id'] = $result['id'];
             $membershipPayment['membership_id'] = $new_membership['id'];
             civicrm_api3('MembershipPayment', 'create', $membershipPayment);
         }
         $oldMembership['id'] = $mid;
         $oldMembership['is_override'] = 1;
         $oldMembership['status_id'] = $oldMembershipStatus;
         $oldMembership['custom_' . $reason_fid] = '28 jarige';
         $oldMembership['end_date'] = $today->format('Ymd');
         civicrm_api3('Membership', 'create', $oldMembership);
         $renewTransaction->commit();
     }
     return true;
 }
Exemplo n.º 22
0
 /**
  * Following a change to an activity or case, fire the case-change event.
  *
  * @param \Civi\Core\Event\PostEvent $event
  * @throws \CRM_Core_Exception
  */
 public static function fireCaseChange(\Civi\Core\Event\PostEvent $event)
 {
     $caseId = NULL;
     switch ($event->entity) {
         case 'Activity':
             if (!empty($event->object->case_id)) {
                 $caseId = $event->object->case_id;
             }
             break;
         case 'Case':
             // by the time we get the post-delete event, the record is gone, so
             // there's nothing to analyze
             if ($event->action != 'delete') {
                 $caseId = $event->id;
             }
             break;
         default:
             throw new \CRM_Core_Exception("CRM_Case_Listener does not support entity {$event->entity}");
     }
     if ($caseId) {
         if (!isset(self::$isActive[$caseId])) {
             $tx = new \CRM_Core_Transaction();
             \CRM_Core_Transaction::addCallback(\CRM_Core_Transaction::PHASE_POST_COMMIT, array(__CLASS__, 'fireCaseChangeForRealz'), array($caseId), "Civi_CCase_Events::fire::{$caseId}");
         }
     }
 }
Exemplo n.º 23
0
 /**
  * takes an associative array and creates a price field object
  *
  * This function is invoked from within the web form layer and also from the api layer
  *
  * @param array $params (reference) an assoc array of name/value pairs
  *
  * @return object CRM_Price_DAO_Field object
  * @access public
  * @static
  */
 static function create(&$params, $ids)
 {
     require_once 'CRM/Core/Transaction.php';
     $transaction = new CRM_Core_Transaction();
     $priceField =& self::add($params, $ids);
     if (is_a($priceField, 'CRM_Core_Error')) {
         $transaction->rollback();
         return $priceField;
     }
     $options = array();
     require_once 'CRM/Price/Form/Field.php';
     $maxIndex = CRM_Price_Form_Field::NUM_OPTION;
     if ($priceField->html_type == 'Text') {
         $maxIndex = 1;
     }
     $defaultArray = array();
     if ($params['html_type'] == 'CheckBox' && isset($params['default_checkbox_option'])) {
         $tempArray = array_keys($params['default_checkbox_option']);
         foreach ($tempArray as $v) {
             if ($params['option_value'][$v]) {
                 $defaultArray[$v] = 1;
             }
         }
     } else {
         if (CRM_Utils_Array::value('default_option', $params) && isset($params['option_value'][$params['default_option']])) {
             $defaultArray[$params['default_option']] = 1;
         }
     }
     for ($index = 1; $index <= $maxIndex; $index++) {
         if ($maxIndex == 1) {
             $description = $params['label'];
         } else {
             $description = $params['label'] . " - " . trim($params['option_label'][$index]);
         }
         if (CRM_Utils_Array::value($index, $params['option_label']) && !CRM_Utils_System::isNull($params['option_value'][$index])) {
             $options[] = array('label' => trim($params['option_label'][$index]), 'name' => CRM_Utils_Rule::cleanMoney(trim($params['option_name'][$index])), 'value' => CRM_Utils_Rule::cleanMoney(trim($params['option_value'][$index])), 'description' => $description, 'weight' => $params['option_weight'][$index], 'is_active' => 1, 'is_default' => CRM_Utils_Array::value($index, $defaultArray));
         }
     }
     if (!empty($options)) {
         $params['default_amount_id'] = null;
         $groupName = "civicrm_price_field.amount.{$priceField->id}";
         require_once 'CRM/Core/OptionGroup.php';
         CRM_Core_OptionGroup::createAssoc($groupName, $options, $params['default_amount_id']);
     }
     $transaction->commit();
     return $priceField;
 }
Exemplo n.º 24
0
 /**
  * takes an associative array and creates a price field object
  *
  * This function is invoked from within the web form layer and also from the api layer
  *
  * @param array $params (reference) an assoc array of name/value pairs
  *
  * @return object CRM_Price_DAO_Field object
  * @access public
  * @static
  */
 static function create(&$params, $ids)
 {
     require_once 'CRM/Core/Transaction.php';
     require_once 'CRM/Price/BAO/FieldValue.php';
     $transaction = new CRM_Core_Transaction();
     $priceField =& self::add($params, $ids);
     if (is_a($priceField, 'CRM_Core_Error')) {
         $transaction->rollback();
         return $priceField;
     }
     $options = $optionsIds = array();
     require_once 'CRM/Price/Form/Field.php';
     $maxIndex = CRM_Price_Form_Field::NUM_OPTION;
     if ($priceField->html_type == 'Text') {
         $maxIndex = 1;
         require_once 'CRM/Price/BAO/FieldValue.php';
         $fieldValue = new CRM_Price_DAO_FieldValue();
         $fieldValue->price_field_id = $priceField->id;
         // update previous field values( if any )
         if ($fieldValue->find(true)) {
             $optionsIds['id'] = $fieldValue->id;
         }
     }
     $defaultArray = array();
     if ($params['html_type'] == 'CheckBox' && isset($params['default_checkbox_option'])) {
         $tempArray = array_keys($params['default_checkbox_option']);
         foreach ($tempArray as $v) {
             if ($params['option_amount'][$v]) {
                 $defaultArray[$v] = 1;
             }
         }
     } else {
         if (CRM_Utils_Array::value('default_option', $params) && isset($params['option_amount'][$params['default_option']])) {
             $defaultArray[$params['default_option']] = 1;
         }
     }
     for ($index = 1; $index <= $maxIndex; $index++) {
         if (CRM_Utils_Array::value($index, $params['option_label']) && !CRM_Utils_System::isNull($params['option_amount'][$index])) {
             $options = array('price_field_id' => $priceField->id, 'label' => trim($params['option_label'][$index]), 'name' => CRM_Utils_String::munge($params['option_label'][$index], '_', 64), 'amount' => CRM_Utils_Rule::cleanMoney(trim($params['option_amount'][$index])), 'count' => CRM_Utils_Array::value($index, $params['option_count'], null), 'max_value' => CRM_Utils_Array::value($index, $params['option_max_value'], null), 'description' => CRM_Utils_Array::value($index, $params['option_description'], null), 'weight' => $params['option_weight'][$index], 'is_active' => 1, 'is_default' => CRM_Utils_Array::value($index, $defaultArray));
             CRM_Price_BAO_FieldValue::add($options, $optionsIds);
         }
     }
     $transaction->commit();
     return $priceField;
 }
Exemplo n.º 25
0
 /**
  * takes an associative array and creates a cancellation object
  *
  * the function extract all the params it needs to initialize the create a
  * resource object. the params array could contain additional unused name/value
  * pairs
  *
  * @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_Booking_BAO_Cancellation object
  * @access public
  * @static
  */
 static function create(&$values)
 {
     $bookingID = CRM_Utils_Array::value('booking_id', $values);
     if (!$bookingID) {
         return;
     } else {
         $transaction = new CRM_Core_Transaction();
         try {
             $params = array('option_group_name' => CRM_Booking_Utils_Constants::OPTION_BOOKING_STATUS, 'name' => CRM_Booking_Utils_Constants::OPTION_VALUE_CANCELLED);
             $result = civicrm_api3('OptionValue', 'get', $params);
             $params = array();
             $params['id'] = $bookingID;
             $params['status_id'] = CRM_Utils_Array::value('value', CRM_Utils_Array::value($result['id'], $result['values']));
             $booking = CRM_Booking_BAO_Booking::create($params);
             $params = array();
             $params['booking_id'] = $bookingID;
             $percentage = CRM_Utils_Array::value('cancellation_percentage', $values);
             $bookingTotal = CRM_Utils_Array::value('booking_total', $values);
             $cancellationFee = $bookingTotal * $percentage / 100;
             $additionalCharge = CRM_Utils_Array::value('additional_charge', $values);
             if (is_numeric($additionalCharge)) {
                 $cancellationFee += $additionalCharge;
                 $params['additional_fee'] = $additionalCharge;
             }
             $params['cancellation_date'] = CRM_Utils_Date::processDate(CRM_Utils_Array::value('cancellation_date', $values));
             $params['comment'] = CRM_Utils_Array::value('comment', $values);
             $params['cancellation_fee'] = $cancellationFee;
             self::add($params);
             $slots = CRM_Booking_BAO_Slot::getBookingSlot($bookingID);
             foreach ($slots as $slotId => $slots) {
                 $subSlots = CRM_Booking_BAO_SubSlot::getSubSlotSlot($slotId);
                 foreach ($subSlots as $subSlotId => $subSlot) {
                     CRM_Booking_BAO_SubSlot::cancel($subSlotId);
                 }
                 CRM_Booking_BAO_Slot::cancel($slotId);
             }
             // return TRUE;
         } catch (Exception $e) {
             $transaction->rollback();
             CRM_Core_Error::fatal($e->getMessage());
         }
     }
 }
 function run()
 {
     // get the requested action
     $action = CRM_Utils_Request::retrieve('action', 'String', $this, FALSE, 'browse');
     // assign vars to templates
     $this->assign('action', $action);
     $id = CRM_Utils_Request::retrieve('id', 'Positive', $this, FALSE, 0);
     if ($action & CRM_Core_Action::UPDATE) {
         $controller = new CRM_Core_Controller_Simple('CRM_Wci_Form_NewEmbedCode', 'Edit Embed Code', CRM_Core_Action::UPDATE);
         $controller->set('id', $id);
         $controller->process();
         return $controller->run();
     } elseif ($action & CRM_Core_Action::DELETE) {
         try {
             $transaction = new CRM_Core_Transaction();
             $sql = "DELETE FROM civicrm_wci_embed_code where id = %1";
             $params = array(1 => array($id, 'Integer'));
             CRM_Core_DAO::executeQuery($sql, $params);
             $transaction->commit();
         } catch (Exception $e) {
             CRM_Core_Session::setStatus(ts('Failed to delete embed code. ') . $e->getMessage(), '', 'error');
             $transaction->rollback();
         }
     }
     CRM_Utils_System::setTitle(ts('Embed Code List'));
     $query = "SELECT * FROM civicrm_wci_embed_code";
     $params = array();
     $dao = CRM_Core_DAO::executeQuery($query, $params, TRUE, 'CRM_Wci_DAO_EmbedCode');
     while ($dao->fetch()) {
         $emb_code[$dao->id] = array();
         CRM_Core_DAO::storeValues($dao, $emb_code[$dao->id]);
         $emb_code[$dao->id]['id'] = $emb_code[$dao->id]['id'];
         $emb_code[$dao->id]['name'] = $emb_code[$dao->id]['name'];
         $action = array_sum(array_keys($this->actionLinks()));
         //build the normal action links.
         $emb_code[$dao->id]['action'] = CRM_Core_Action::formLink(self::actionLinks(), $action, array('id' => $dao->id));
     }
     if (isset($emb_code)) {
         $this->assign('rows', $emb_code);
     }
     parent::run();
 }
Exemplo n.º 27
0
 static function nodeapi(&$params, $op)
 {
     $transaction = new CRM_Core_Transaction();
     // first create or update the CiviCRM group
     $groupParams = $params;
     $groupParams['source'] = CRM_Bridge_OG_Utils::ogSyncName($params['og_id']);
     $groupParams['group_type'] = array('2' => 1);
     self::updateCiviGroup($groupParams, $op);
     if (CRM_Bridge_OG_Utils::aclEnabled()) {
         // next create or update the CiviCRM ACL group
         $aclParams = $params;
         $aclParams['name'] = $aclParams['title'] = "{$aclParams['name']}: Administrator";
         $aclParams['source'] = CRM_Bridge_OG_Utils::ogSyncACLName($params['og_id']);
         $aclParams['group_type'] = array('1');
         self::updateCiviGroup($aclParams, $op);
         $aclParams['acl_group_id'] = $aclParams['group_id'];
         $aclParams['civicrm_group_id'] = $groupParams['group_id'];
         self::updateCiviACLTables($aclParams, $op);
     }
     $transaction->commit();
 }
 /**
  * Delete Mailchimp sync settings.
  */
 static function deleteSettings($mailchimp_sync_setting)
 {
     $transaction = new CRM_Core_Transaction();
     try {
         $mailchimp_sync_setting->delete();
         CRM_CiviMailchimp_Utils::deleteWebhookFromMailchimpList($mailchimp_sync_setting->mailchimp_list_id);
     } catch (Exception $e) {
         $transaction->rollback();
         throw $e;
     }
     $transaction->commit();
     return $mailchimp_sync_setting;
 }
Exemplo n.º 29
0
 /**
  * Create a new bounce event, update the email address if necessary
  */
 static function &create(&$params)
 {
     $q =& CRM_Mailing_Event_BAO_Queue::verify($params['job_id'], $params['event_queue_id'], $params['hash']);
     $success = NULL;
     if (!$q) {
         return $success;
     }
     $transaction = new CRM_Core_Transaction();
     $bounce = new CRM_Mailing_Event_BAO_Bounce();
     $bounce->time_stamp = date('YmdHis');
     // if we dont have a valid bounce type, we should set it
     // to bounce_type_id 11 which is Syntax error. this allows such email
     // addresses to be bounce a few more time before being put on hold
     // CRM-4814
     // we changed this behavior since this bounce type might be due to some issue
     // with the connection or smtp server etc
     if (empty($params['bounce_type_id'])) {
         $params['bounce_type_id'] = 11;
         if (empty($params['bounce_reason'])) {
             $params['bounce_reason'] = ts('Unknown bounce type: Could not parse bounce email');
         }
     }
     // CRM-11989
     $params['bounce_reason'] = substr($params['bounce_reason'], 0, 254);
     $bounce->copyValues($params);
     $bounce->save();
     $success = TRUE;
     $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;
         }
     }
     $transaction->commit();
     return $success;
 }
Exemplo n.º 30
0
 /**
  * Delete the group and all the object that connect to this group.
  *
  * Incredibly destructive.
  *
  * @param int $id Group id.
  */
 public static function discard($id)
 {
     CRM_Utils_Hook::pre('delete', 'Group', $id, CRM_Core_DAO::$_nullArray);
     $transaction = new CRM_Core_Transaction();
     // added for CRM-1631 and CRM-1794
     // delete all subscribed mails with the selected group id
     $subscribe = new CRM_Mailing_Event_DAO_Subscribe();
     $subscribe->group_id = $id;
     $subscribe->delete();
     // delete all Subscription  records with the selected group id
     $subHistory = new CRM_Contact_DAO_SubscriptionHistory();
     $subHistory->group_id = $id;
     $subHistory->delete();
     // delete all crm_group_contact records with the selected group id
     $groupContact = new CRM_Contact_DAO_GroupContact();
     $groupContact->group_id = $id;
     $groupContact->delete();
     // make all the 'add_to_group_id' field of 'civicrm_uf_group table', pointing to this group, as null
     $params = array(1 => array($id, 'Integer'));
     $query = "UPDATE civicrm_uf_group SET `add_to_group_id`= NULL WHERE `add_to_group_id` = %1";
     CRM_Core_DAO::executeQuery($query, $params);
     $query = "UPDATE civicrm_uf_group SET `limit_listings_group_id`= NULL WHERE `limit_listings_group_id` = %1";
     CRM_Core_DAO::executeQuery($query, $params);
     // make sure u delete all the entries from civicrm_mailing_group and civicrm_campaign_group
     // CRM-6186
     $query = "DELETE FROM civicrm_mailing_group where entity_table = 'civicrm_group' AND entity_id = %1";
     CRM_Core_DAO::executeQuery($query, $params);
     $query = "DELETE FROM civicrm_campaign_group where entity_table = 'civicrm_group' AND entity_id = %1";
     CRM_Core_DAO::executeQuery($query, $params);
     $query = "DELETE FROM civicrm_acl_entity_role where entity_table = 'civicrm_group' AND entity_id = %1";
     CRM_Core_DAO::executeQuery($query, $params);
     if (CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::MULTISITE_PREFERENCES_NAME, 'is_enabled')) {
         // clear any descendant groups cache if exists
         CRM_Core_BAO_Cache::deleteGroup('descendant groups for an org');
     }
     // delete from group table
     $group = new CRM_Contact_DAO_Group();
     $group->id = $id;
     $group->delete();
     $transaction->commit();
     CRM_Utils_Hook::post('delete', 'Group', $id, $group);
     // delete the recently created Group
     $groupRecent = array('id' => $id, 'type' => 'Group');
     CRM_Utils_Recent::del($groupRecent);
 }