+--------------------------------------------------------------------+
*/
-
/**
* This api exposes CiviCRM LocBlock records.
*
* Create or update a LocBlock.
*
* @param array $params
- * name/value pairs to insert in new 'LocBlock'
+ * Name/value pairs to insert in new 'LocBlock'.
*
* @return array
* API result array.
+ *
+ * @throws \API_Exception
*/
function civicrm_api3_loc_block_create($params) {
$entities = array();
- // Call the appropriate api to create entities if any are passed in the params
+ $any_mandatory = array(
+ 'address',
+ 'address_id',
+ 'phone',
+ 'phone_id',
+ 'im',
+ 'im_id',
+ 'email',
+ 'email_id',
+ );
+ civicrm_api3_verify_one_mandatory($params, NULL, $any_mandatory);
+ // Call the appropriate api to create entities if any are passed in the params.
// This is basically chaining but in reverse - we create the sub-entities first
- // This exists because chainging does not work in reverse, or with keys like 'email_2'
+ // because chaining does not work in reverse, or with keys like 'email_2'.
$items = array('address', 'email', 'phone', 'im');
foreach ($items as $item) {
foreach (array('', '_2') as $suf) {
$key = $item . $suf;
if (!empty($params[$key]) && is_array($params[$key])) {
$info = $params[$key];
- // If all we get is an id don't bother calling the api
+ // If all we get is an id don't bother calling the api.
if (count($info) == 1 && !empty($info['id'])) {
$params[$key . '_id'] = $info['id'];
}
- // Bother calling the api
+ // Bother calling the api.
else {
- $info['version'] = $params['version'];
$info['contact_id'] = CRM_Utils_Array::value('contact_id', $info, 'null');
- $result = civicrm_api($item, 'create', $info);
- if (!empty($result['is_error'])) {
- return $result;
- }
+ $result = civicrm_api3($item, 'create', $info);
$entities[$key] = $result['values'][$result['id']];
$params[$key . '_id'] = $result['id'];
}
_civicrm_api3_object_to_array($dao, $values[$dao->id]);
return civicrm_api3_create_success($values, $params, 'LocBlock', 'create', $dao);
}
- return civicrm_api3_create_error('Unable to create LocBlock. Please check your params.');
+ throw New API_Exception('Unable to create LocBlock. Please check your params.');
}
/**
*
* @param array $params
* Array of one or more valid property_name=>value pairs. If $params is set.
- * as null, all loc_blocks will be returned (default limit is 25)
+ * as null, all loc_blocks will be returned (default limit is 25).
*
* @return array
* API result array.
function civicrm_api3_loc_block_get($params) {
$options = _civicrm_api3_get_options_from_params($params);
// If a return param has been set then fetch the appropriate fk objects
- // This is a helper because api chaining does not work with a key like 'email_2'
+ // This is a helper because api chaining does not work with a key like 'email_2'.
if (!empty($options['return'])) {
unset($params['return']);
$values = array();