/** * Create or update a contribution_page * * @param array $params Associative array of property * name/value pairs to insert in new 'contribution_page' * @example ContributionPageCreate.php Std Create example * * @return array api result array * {@getfields contribution_page_create} * @access public */ function civicrm_api3_contribution_page_create($params) { $result = _civicrm_api3_basic_create(_civicrm_api3_get_BAO(__FUNCTION__), $params); CRM_Contribute_PseudoConstant::flush('contributionPageAll'); CRM_Contribute_PseudoConstant::flush('contributionPageActive'); return $result; }
/** * Add/Update a PaymentProcessor. * * @param array $params * * @return array * API result array */ function civicrm_api3_payment_processor_create($params) { if (empty($params['id']) && empty($params['payment_instrument_id'])) { $params['payment_instrument_id'] = civicrm_api3('PaymentProcessorType', 'getvalue', array('id' => $params['payment_processor_type_id'], 'return' => 'payment_instrument_id')); } return _civicrm_api3_basic_create(_civicrm_api3_get_BAO(__FUNCTION__), $params); }
/** * Add or update a Contribution. * * @param array $params * Input parameters. * * @throws API_Exception * @return array * Api result array */ function civicrm_api3_contribution_create(&$params) { $values = array(); _civicrm_api3_custom_format_params($params, $values, 'Contribution'); $params = array_merge($params, $values); if (!empty($params['id']) && !empty($params['contribution_status_id'])) { $error = array(); //throw error for invalid status change such as setting completed back to pending //@todo this sort of validation belongs in the BAO not the API - if it is not an OK // action it needs to be blocked there. If it is Ok through a form it needs to be OK through the api CRM_Contribute_BAO_Contribution::checkStatusValidation(NULL, $params, $error); if (array_key_exists('contribution_status_id', $error)) { throw new API_Exception($error['contribution_status_id']); } } if (!empty($params['id']) && !empty($params['financial_type_id'])) { $error = array(); CRM_Contribute_BAO_Contribution::checkFinancialTypeChange($params['financial_type_id'], $params['id'], $error); if (array_key_exists('financial_type_id', $error)) { throw new API_Exception($error['financial_type_id']); } } _civicrm_api3_contribution_create_legacy_support_45($params); // Make sure tax calculation is handled via api. $params = CRM_Contribute_BAO_Contribution::checkTaxAmount($params); return _civicrm_api3_basic_create(_civicrm_api3_get_BAO(__FUNCTION__), $params, 'Contribution'); }
/** * create/update grant * * This API is used to create new grant or update any of the existing * In case of updating existing grant, id of that particular grant must * be in $params array. * * @param array $params Associative array of property * name/value pairs to insert in new 'grant' * * @return array grant array * {@getfields grant_create} * @access public */ function civicrm_api3_grant_create($params) { $values = array(); _civicrm_api3_custom_format_params($params, $values, 'Grant'); $params = array_merge($values, $params); return _civicrm_api3_basic_create(_civicrm_api3_get_BAO(__FUNCTION__), $params, 'grant'); }
/** * Handle a queue event. * * @param array $params * Array of property. * * @throws Exception * @return array * api result array */ function civicrm_api3_mailing_event_queue_create($params) { if (!array_key_exists('id', $params) && !array_key_exists('email_id', $params) && !array_key_exists('phone_id', $params)) { throw new API_Exception("Mandatory key missing from params array: id, email_id, or phone_id field is required"); } civicrm_api3_verify_mandatory($params, 'CRM_Mailing_DAO_MailingJob', array('job_id', 'contact_id'), FALSE); return _civicrm_api3_basic_create('CRM_Mailing_Event_BAO_Queue', $params); }
/** * Create a new ActionSchedule. * * @param array $params * * @return array */ function civicrm_api3_action_schedule_create($params) { civicrm_api3_verify_one_mandatory($params, NULL, array('start_action_date', 'absolute_date')); if (!array_key_exists('name', $params) && !array_key_exists('id', $params)) { $params['name'] = CRM_Utils_String::munge($params['title']); } return _civicrm_api3_basic_create(_civicrm_api3_get_BAO(__FUNCTION__), $params, 'ActionSchedule'); }
/** * Add a Location Type * * Allowed @params array keys are: * * @example LocationTypeCreate.php Standard Create Example * * @return array API result array * {@getfields email_create} * @access public */ function civicrm_api3_location_type_create($params) { //set display_name equal to name if it's not defined if (!array_key_exists('display_name', $params) && array_key_exists('name', $params)) { $params['display_name'] = $params['name']; } return _civicrm_api3_basic_create(_civicrm_api3_get_BAO(__FUNCTION__), $params); }
/** * Create or update a project contact * * @param array $params Associative array of properties * name/value pairs to insert in new 'project contact' * @example * * @return array api result array * {@getfields volunteer_project_contact_create} * @access public */ function civicrm_api3_volunteer_project_contact_create($params) { if (!$params['check_permissions'] || CRM_Volunteer_Permission::checkProjectPerms(CRM_Core_Action::UPDATE, $params['project_id'])) { return _civicrm_api3_basic_create(_civicrm_api3_get_BAO(__FUNCTION__), $params); } else { return civicrm_api3_create_error(ts('You do not have permission to modify contacts for this project')); } }
/** * Creates or updates an Activity. See the example for usage * * @param array $params Associative array of property name/value * pairs for the activity. * {@getfields pledge_create} * * @return array Array containing 'is_error' to denote success or failure and details of the created pledge * * @example PledgeCreate.php Standard create example * */ function civicrm_api3_pledge_create($params) { _civicrm_api3_pledge_format_params($params, TRUE); $values = $params; //format the custom fields _civicrm_api3_custom_format_params($params, $values, 'Pledge'); return _civicrm_api3_basic_create(_civicrm_api3_get_BAO(__FUNCTION__), $values); }
/** * Slot.Create 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_slot_create($params) { if (CRM_Utils_Array::value('id', $params)) { if (!CRM_Booking_BAO_Slot::isValid($params)) { return civicrm_api3_create_error('Unable to create slot. Please check the slot date time is availables.'); } } return _civicrm_api3_basic_create(_civicrm_api3_get_BAO(__FUNCTION__), $params); }
/** * API to Create or update a Membership Type. * * @param array $params * Array of name/value property values of civicrm_membership_type. * * @return array * API result array. */ function civicrm_api3_membership_type_create($params) { // Workaround for fields using nonstandard serialization foreach (array('relationship_type_id', 'relationship_direction') as $field) { if (isset($params[$field]) && is_array($params[$field])) { $params[$field] = implode(CRM_Core_DAO::VALUE_SEPARATOR, $params[$field]); } } return _civicrm_api3_basic_create(_civicrm_api3_get_BAO(__FUNCTION__), $params, 'Membership_type'); }
/** * HRJobContractRevision.create API * * @param array $params * @return array API result descriptor * @throws API_Exception */ function civicrm_api3_h_r_job_contract_revision_create($params) { $result = _civicrm_api3_basic_create(_civicrm_api3_get_BAO(__FUNCTION__), $params); $editorName = ''; if (!empty($result['values'][0]['editor_uid'])) { $civiUser = civicrm_custom_user_profile_get_contact($result['values'][0]['editor_uid']); $editorName = $civiUser['sort_name']; } $result['values'][0]['editor_name'] = $editorName; return $result; }
/** * HRJobHour.create API * * @param array $params * @return array API result descriptor * @throws API_Exception */ function civicrm_api3_h_r_job_hour_create($params) { $result = _civicrm_api3_basic_create(_civicrm_api3_get_BAO(__FUNCTION__), $params); if (empty($result['is_error'])) { $row = CRM_Utils_Array::first($result['values']); $revision_id = $row['jobcontract_revision_id']; $revision = civicrm_api3('HRJobContractRevision', 'get', array('sequential' => 1, 'id' => $revision_id, 'options' => array('limit' => 1))); //CRM_Hrjobcontract_Estimator::updateEstimatesByRevision($revision); } return $result; }
/** * Add a OptionValue. OptionValues are used to classify CRM entities (including Contacts, Groups and Actions). * * Allowed @params array keys are: * * {@example OptionValueCreate.php} * * @param $params * * @throws API_Exception * @return array of newly created option_value property values. * {@getfields OptionValue_create} * @access public */ function civicrm_api3_option_value_create($params) { $result = _civicrm_api3_basic_create(_civicrm_api3_get_BAO(__FUNCTION__), $params); if (!empty($params['id']) && !array_key_exists('option_group_id', $params)) { $groupId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionValue', $params['id'], 'option_group_id', 'id'); } else { $groupId = $params['option_group_id']; } civicrm_api('option_value', 'getfields', array('version' => 3, 'cache_clear' => 1, 'option_group_id' => $groupId)); return $result; }
/** * Creates/Updates a new Dashboard Contact Entry. * * @param array $params * * @return array */ function civicrm_api3_dashboard_contact_create($params) { if (empty($params['id'])) { civicrm_api3_verify_one_mandatory($params, NULL, array('dashboard_id')); } $errors = _civicrm_api3_dashboard_contact_check_params($params); if ($errors !== NULL) { return $errors; } return _civicrm_api3_basic_create(_civicrm_api3_get_BAO(__FUNCTION__), $params); }
/** * HRJobPay.create API * * @param array $params * @return array API result descriptor * @throws API_Exception */ function civicrm_api3_h_r_job_pay_create($params) { $result = _civicrm_api3_basic_create(_civicrm_api3_get_BAO(__FUNCTION__), $params); if (empty($result['is_error'])) { if (empty($result['id'])) { throw new API_Exception("Cannot update estimates: missing job id"); } $job_id = CRM_Core_DAO::singleValueQuery('SELECT job_id FROM civicrm_hrjob_pay WHERE id = %1', array(1 => array($result['id'], 'Positive'))); CRM_HRJob_Estimator::updateEstimatesByJob($job_id); } return $result; }
/** * Create a Event * * This API is used for creating a Event * * @param array $params input parameters * Allowed @params array keys are: * {@getfields event_create} * * @return array API result Array. * @access public */ function civicrm_api3_event_create($params) { civicrm_api3_verify_one_mandatory($params, NULL, array('event_type_id', 'template_id')); // Clone event from template if (!empty($params['template_id']) && empty($params['id'])) { $copy = CRM_Event_BAO_Event::copy($params['template_id']); $params['id'] = $copy->id; unset($params['template_id']); } _civicrm_api3_event_create_legacy_support_42($params); return _civicrm_api3_basic_create(_civicrm_api3_get_BAO(__FUNCTION__), $params, 'Event'); }
/** * create/update contact_type * * This API is used to create new contact_type or update any of the existing * In case of updating existing contact_type, id of that particular contact_type must * be in $params array. * * @param array $params (referance) Associative array of property * name/value pairs to insert in new 'contact_type' * * @return array contact_type array * * @access public */ function civicrm_api3_contact_type_create($params) { civicrm_api3_verify_mandatory($params, _civicrm_api3_get_DAO(__FUNCTION__), array('name', 'parent_id')); if (!array_key_exists('label', $params)) { $params['label'] = $params['name']; } if (!array_key_exists('is_active', $params)) { $params['is_active'] = TRUE; } $params['name'] = CRM_Utils_String::munge($params['name']); return _civicrm_api3_basic_create(_civicrm_api3_get_BAO(__FUNCTION__), $params); }
/** * Add a OptionValue. OptionValues are used to classify CRM entities (including Contacts, Groups and Actions). * * Allowed @params array keys are: * * {@example OptionValueCreate.php} * * @return array of newly created option_value property values. * {@getfields OptionValue_create} * @access public */ function civicrm_api3_option_value_create($params) { $result = _civicrm_api3_basic_create(_civicrm_api3_get_BAO(__FUNCTION__), $params); // CRM-13814 : evalute option group id // option group id would be passed in case of adding a new option value record if (!empty($params['id']) && !array_key_exists('option_group_id', $params)) { $groupId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionValue', $params['id'], 'option_group_id', 'id'); } else { $groupId = $params['option_group_id']; } civicrm_api('option_value', 'getfields', array('version' => 3, 'cache_clear' => 1, 'option_group_id' => $groupId)); return $result; }
/** * Create or update case type. * * @param array $params * Input parameters. * * @throws API_Exception * @return array * API result array */ function civicrm_api3_case_type_create($params) { civicrm_api3_verify_mandatory($params, _civicrm_api3_get_DAO(__FUNCTION__)); // Computed properties. unset($params['is_forkable']); unset($params['is_forked']); if (!array_key_exists('is_active', $params) && empty($params['id'])) { $params['is_active'] = TRUE; } // This is an existing case-type. if (!empty($params['id']) && !CRM_Case_BAO_CaseType::isForked($params['id']) && !CRM_Case_BAO_CaseType::isForkable($params['id'])) { unset($params['definition']); } $result = _civicrm_api3_basic_create(_civicrm_api3_get_BAO(__FUNCTION__), $params, 'CaseType'); return _civicrm_api3_case_type_get_formatResult($result); }
/** * Use this API to create a new group. * * The 'extends' value accepts an array or a comma separated string. * e.g array( * 'Individual','Contact') or 'Individual,Contact' * See the CRM Data Model for custom_group property definitions * $params['class_name'] is a required field, class being extended. * * @param array $params * Array per getfields metadata. * * @return array * @todo $params['extends'] is array format - is that std compatible */ function civicrm_api3_custom_group_create($params) { if (isset($params['extends']) && is_string($params['extends'])) { $extends = explode(",", $params['extends']); unset($params['extends']); $params['extends'] = $extends; } if (!isset($params['extends'][0]) || !trim($params['extends'][0])) { return civicrm_api3_create_error("First item in params['extends'] must be a class name (e.g. 'Contact')."); } if (isset($params['extends_entity_column_value']) && !is_array($params['extends_entity_column_value'])) { // BAO fails if this is a string, but API getFields says this must be a string, so we'll do a double backflip $params['extends_entity_column_value'] = CRM_Utils_Array::explodePadded($params['extends_entity_column_value']); } return _civicrm_api3_basic_create(_civicrm_api3_get_BAO(__FUNCTION__), $params); }
/** * Create a Event. * * @param array $params * Input parameters. * * @return array * API result Array. */ function civicrm_api3_event_create($params) { // Required fields for creating an event if (empty($params['id']) && empty($params['is_template'])) { civicrm_api3_verify_mandatory($params, NULL, array('start_date', 'title', array('event_type_id', 'template_id'))); } elseif (empty($params['id']) && !empty($params['is_template'])) { civicrm_api3_verify_mandatory($params, NULL, array('template_title')); } // Clone event from template if (!empty($params['template_id']) && empty($params['id'])) { $copy = CRM_Event_BAO_Event::copy($params['template_id']); $params['id'] = $copy->id; unset($params['template_id']); } _civicrm_api3_event_create_legacy_support_42($params); return _civicrm_api3_basic_create(_civicrm_api3_get_BAO(__FUNCTION__), $params, 'Event'); }
/** * Create or update a PriceSet. * * @param array $params * name/value pairs to insert in new 'PriceSet' * * @return array * api result array */ function civicrm_api3_price_set_create($params) { $result = _civicrm_api3_basic_create(_civicrm_api3_get_BAO(__FUNCTION__), $params); // Handle price_set_entity if (!empty($result['id']) && !empty($params['entity_table']) && !empty($params['entity_id'])) { $entityId = $params['entity_id']; if (!is_array($params['entity_id'])) { $entityId = explode(',', $entityId); } foreach ($entityId as $eid) { $eid = (int) trim($eid); if ($eid) { CRM_Price_BAO_PriceSet::addTo($params['entity_table'], $eid, $result['id']); } } } return $result; }
/** * Create or update a saved search. * * @param array $params * Associative array of property name-value pairs to insert in new saved search. * @example SavedSearch/Create.php Std create example. * @return array api result array * {@getfields saved_search_create} * @access public */ function civicrm_api3_saved_search_create($params) { // The create function of the dao expects a 'formValues' that is // not serialized. The get function returns form_values, that is // serialized. // So for the create API, I guess it should work for serialized and // unserialized form_values. if (isset($params["form_values"])) { if (is_array($params["form_values"])) { $params["formValues"] = $params["form_values"]; } else { // Assume that form_values is serialized. $params["formValues"] = unserialize($params["form_values"]); } } $result = _civicrm_api3_basic_create(_civicrm_api3_get_BAO(__FUNCTION__), $params); _civicrm_api3_saved_search_result_cleanup($result); return $result; }
/** * Add or update a Contribution. * * @param array $params * Input parameters. * * @throws API_Exception * @return array * Api result array */ function civicrm_api3_contribution_create(&$params) { $values = array(); _civicrm_api3_custom_format_params($params, $values, 'Contribution'); $params = array_merge($params, $values); if (CRM_Financial_BAO_FinancialType::isACLFinancialTypeStatus()) { if (empty($params['id'])) { $op = CRM_Core_Action::ADD; } else { if (empty($params['financial_type_id'])) { $params['financial_type_id'] = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_Contribution', $params['id'], 'financial_type_id'); } $op = CRM_Core_Action::UPDATE; } CRM_Financial_BAO_FinancialType::getAvailableFinancialTypes($types, $op); if (!in_array($params['financial_type_id'], array_keys($types))) { return civicrm_api3_create_error('You do not have permission to create this contribution'); } } if (!empty($params['id']) && !empty($params['contribution_status_id'])) { $error = array(); //throw error for invalid status change such as setting completed back to pending //@todo this sort of validation belongs in the BAO not the API - if it is not an OK // action it needs to be blocked there. If it is Ok through a form it needs to be OK through the api CRM_Contribute_BAO_Contribution::checkStatusValidation(NULL, $params, $error); if (array_key_exists('contribution_status_id', $error)) { throw new API_Exception($error['contribution_status_id']); } } if (!empty($params['id']) && !empty($params['financial_type_id'])) { $error = array(); CRM_Contribute_BAO_Contribution::checkFinancialTypeChange($params['financial_type_id'], $params['id'], $error); if (array_key_exists('financial_type_id', $error)) { throw new API_Exception($error['financial_type_id']); } } _civicrm_api3_contribution_create_legacy_support_45($params); // Make sure tax calculation is handled via api. // @todo this belongs in the BAO NOT the api. $params = CRM_Contribute_BAO_Contribution::checkTaxAmount($params); return _civicrm_api3_basic_create(_civicrm_api3_get_BAO(__FUNCTION__), $params, 'Contribution'); }
/** * Add or update a contribution * * @param array $params (reference ) input parameters * * @return array Api result array * @static void * @access public * @example ContributionCreate.php * {@getfields Contribution_create} */ function civicrm_api3_contribution_create(&$params) { $values = array(); _civicrm_api3_custom_format_params($params, $values, 'Contribution'); $params = array_merge($params, $values); //legacy soft credit handling - recommended approach is chaining if (!empty($params['soft_credit_to'])) { $params['soft_credit'] = array(array('contact_id' => $params['soft_credit_to'], 'amount' => $params['total_amount'])); } if (CRM_Utils_Array::value('id', $params) && CRM_Utils_Array::value('contribution_status_id', $params)) { $error = array(); //throw error for invalid status change such as setting completed back to pending //@todo this sort of validation belongs in the BAO not the API - if it is not an OK // action it needs to be blocked there. If it is Ok through a form it needs to be OK through the api CRM_Contribute_BAO_Contribution::checkStatusValidation(NULL, $params, $error); if (array_key_exists('contribution_status_id', $error)) { throw new API_Exception($error['contribution_status_id']); } } return _civicrm_api3_basic_create(_civicrm_api3_get_BAO(__FUNCTION__), $params, 'Contribution'); }
/** * Handle a create event. * * @param array $params * * @return array * API Success Array * @throws \API_Exception * @throws \Civi\API\Exception\UnauthorizedException */ function civicrm_api3_mailing_create($params) { if (CRM_Mailing_Info::workflowEnabled()) { // Note: 'schedule mailings' and 'approve mailings' can update certain fields, but can't create. if (empty($params['id'])) { if (!CRM_Core_Permission::check('access CiviMail') && !CRM_Core_Permission::check('create mailings')) { throw new \Civi\API\Exception\UnauthorizedException("Cannot create new mailing. Required permission: 'access CiviMail' or 'create mailings'"); } } $safeParams = array(); $fieldPerms = CRM_Mailing_BAO_Mailing::getWorkflowFieldPerms(); foreach (array_keys($params) as $field) { if (CRM_Core_Permission::check($fieldPerms[$field])) { $safeParams[$field] = $params[$field]; } } } else { $safeParams = $params; } $safeParams['_evil_bao_validator_'] = 'CRM_Mailing_BAO_Mailing::checkSendable'; return _civicrm_api3_basic_create(_civicrm_api3_get_BAO(__FUNCTION__), $safeParams); }
/** * Create or update a need * * @param array $params Associative array of property * name/value pairs to insert in new 'need' * @example NeedCreate.php Std Create example * * @return array api result array * {@getfields volunteer_need create} * @access public */ function civicrm_api3_volunteer_need_create($params) { return _civicrm_api3_basic_create('CRM_Volunteer_BAO_Need', $params); }
/** * Add a record relating a contact with an activity * * Allowed @params array keys are: * * @example ActivityContact.php * * @param $params * * @return array of newly created activity contact records. * @access public */ function civicrm_api3_activity_contact_create($params) { return _civicrm_api3_basic_create(_civicrm_api3_get_BAO(__FUNCTION__), $params); }
/** * Create a new Domain. * * @param array $params * * @return array */ function civicrm_api3_domain_create($params) { $params['version'] = $params['domain_version']; return _civicrm_api3_basic_create(_civicrm_api3_get_BAO(__FUNCTION__), $params); }