当前位置: 首页>>代码示例>>PHP>>正文


PHP CRM_Core_Transaction::rollback方法代码示例

本文整理汇总了PHP中CRM_Core_Transaction::rollback方法的典型用法代码示例。如果您正苦于以下问题:PHP CRM_Core_Transaction::rollback方法的具体用法?PHP CRM_Core_Transaction::rollback怎么用?PHP CRM_Core_Transaction::rollback使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在CRM_Core_Transaction的用法示例。


在下文中一共展示了CRM_Core_Transaction::rollback方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: civicrm_api3_workflow_save

/**
 * 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');
}
开发者ID:robbrandt,项目名称:civicrm-workflow,代码行数:67,代码来源:Save.php

示例2: endTest

 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;
     }
 }
开发者ID:sdekok,项目名称:civicrm-core,代码行数:14,代码来源:CiviTestListener.php

示例3: ndiciviparty_add_default_dashboard

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
}
开发者ID:agh1,项目名称:civisociety-extension,代码行数:31,代码来源:ndiciviparty.php

示例4:

/**
 * 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;
}
开发者ID:bhirsch,项目名称:voipdev,代码行数:35,代码来源:MembershipContributionLink.php

示例5: create

 /**
  * 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;
 }
开发者ID:prashantgajare,项目名称:civicrm-core,代码行数:71,代码来源:PriceField.php

示例6: run

 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();
 }
开发者ID:Jagadees-zyxware,项目名称:civicrm-wci,代码行数:57,代码来源:ProgressBarList.php

示例7: create

 /**
  * Construct a new mailingab object.
  *
  * @params array $params
  *   Form values.
  *
  * @param array $params
  * @param array $ids
  *
  * @return object
  *   $mailingab      The new mailingab object
  */
 public static function create(&$params, $ids = array())
 {
     $transaction = new CRM_Core_Transaction();
     $mailingab = self::add($params, $ids);
     if (is_a($mailingab, 'CRM_Core_Error')) {
         $transaction->rollback();
         return $mailingab;
     }
     $transaction->commit();
     return $mailingab;
 }
开发者ID:nielosz,项目名称:civicrm-core,代码行数:23,代码来源:MailingAB.php

示例8:

 /**
  * @param array $params
  *
  * @return this|null
  */
 public static function &create(&$params)
 {
     $transaction = new CRM_Core_Transaction();
     $statusType = self::add($params);
     if (is_a($statusType, 'CRM_Core_Error')) {
         $transaction->rollback();
         return $statusType;
     }
     $transaction->commit();
     return $statusType;
 }
开发者ID:hyebahi,项目名称:civicrm-core,代码行数:16,代码来源:ParticipantStatusType.php

示例9: create

 /**
  * @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;
 }
开发者ID:FundingWorks,项目名称:civicrm-core,代码行数:17,代码来源:Cart.php

示例10: run

 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();
 }
开发者ID:Jagadees-zyxware,项目名称:civicrm-wci,代码行数:53,代码来源:WidgetList.php

示例11: create

 /**
  * @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;
 }
开发者ID:FundingWorks,项目名称:civicrm-core,代码行数:19,代码来源:EventInCart.php

示例12: delByResource

 /**
  * 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());
     }
 }
开发者ID:sushantpaste,项目名称:civibooking,代码行数:17,代码来源:Slot.php

示例13: civicrm_api3_membership_payment_create

/**
 * 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);
}
开发者ID:peteainsworth,项目名称:civicrm-4.2.9-drupal,代码行数:25,代码来源:MembershipPayment.php

示例14: create

 /**
  * 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;
 }
开发者ID:bhirsch,项目名称:voipdev,代码行数:58,代码来源:Field.php

示例15: create

 /**
  * 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;
 }
开发者ID:hampelm,项目名称:Ginsberg-CiviDemo,代码行数:56,代码来源:Field.php


注:本文中的CRM_Core_Transaction::rollback方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。