/** * Create or update a loc_block * * @param array $params Associative array of property * name/value pairs to insert in new 'loc_block' * @example LocBlockCreate.php Std Create example * * @return array api result array * {@getfields loc_block_create} * @access public */ function civicrm_api3_loc_block_create($params) { $entities = array(); // 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' $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 (count($info) == 1 && !empty($info['id'])) { $params[$key . '_id'] = $info['id']; } 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; } $entities[$key] = $result['values'][$result['id']]; $params[$key . '_id'] = $result['id']; } } } } $dao = new CRM_Core_DAO_LocBlock(); $dao->copyValues($params); $dao->save(); if (!empty($dao->id)) { $values = array($dao->id => $entities); _civicrm_api3_object_to_array($dao, $values[$dao->id]); return civicrm_api3_create_success($values, $params, 'loc_block', 'create', $dao); } return civicrm_api3_create_error('Unable to create LocBlock. Please check your params.'); }
/** * This function deletes the Location Block * * @param int $locBlockId id of the Location Block * * @return void * @access public * @static */ public static function deleteLocBlock($locBlockId) { if (!$locBlockId) { return; } $locBlock = new CRM_Core_DAO_LocBlock(); $locBlock->id = $locBlockId; $locBlock->find(TRUE); //resolve conflict of having same ids for multiple blocks $store = array('IM_1' => $locBlock->im_id, 'IM_2' => $locBlock->im_2_id, 'Email_1' => $locBlock->email_id, 'Email_2' => $locBlock->email_2_id, 'Phone_1' => $locBlock->phone_id, 'Phone_2' => $locBlock->phone_2_id, 'Address_1' => $locBlock->address_id, 'Address_2' => $locBlock->address_2_id); $locBlock->delete(); foreach ($store as $daoName => $id) { if ($id) { $daoName = 'CRM_Core_DAO_' . substr($daoName, 0, -2); $dao = new $daoName(); $dao->id = $id; $dao->find(TRUE); $dao->delete(); $dao->free(); } } }
/** * returns the list of fields that can be exported * * @access public * return array * @static */ static function &export($prefix = false) { if (!self::$_export) { self::$_export = array(); $fields = self::fields(); foreach ($fields as $name => $field) { if (CRM_Utils_Array::value('export', $field)) { if ($prefix) { self::$_export['loc_block'] =& $fields[$name]; } else { self::$_export[$name] =& $fields[$name]; } } } } return self::$_export; }
/** * This function deletes the Location Block * * @param int $locBlockId id of the Location Block * * @return void * @access public * @static */ public static function deleteLocBlock($locBlockId) { if (!$locBlockId) { return; } require_once 'CRM/Core/DAO/LocBlock.php'; $locBlock = new CRM_Core_DAO_LocBlock(); $locBlock->id = $locBlockId; $locBlock->find(true); //resolve conflict of having same ids for multiple blocks $store = array('IM_1' => $locBlock->im_id, 'IM_2' => $locBlock->im_2_id, 'Email_1' => $locBlock->email_id, 'Email_2' => $locBlock->email_2_id, 'Phone_1' => $locBlock->phone_id, 'Phone_2' => $locBlock->phone_2_id, 'Address_1' => $locBlock->address_id, 'Address_2' => $locBlock->address_2_id); $locBlock->delete(); foreach ($store as $daoName => $id) { if ($id) { $daoName = substr($daoName, 0, -2); eval('$dao = new CRM_Core_DAO_' . $daoName . '( );'); $dao->id = $id; $dao->find(true); $dao->delete(); $dao->free(); } } }