2018-08-13 21:59:23 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
class CRM_EntityTemplates_BAO_EntityTemplates extends CRM_Core_DAO_EntityTemplates {
|
|
|
|
|
|
|
|
/**
|
2018-08-13 22:42:25 +00:00
|
|
|
* Build Entity option list.
|
2018-08-13 21:59:23 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
public static function getEntityTypes() {
|
|
|
|
$result = civicrm_api3('OptionValue', 'get', [
|
|
|
|
'return' => ["value"],
|
|
|
|
'option_group_id' => "entity_template_for",
|
|
|
|
'options' => ['limit' => 0],
|
|
|
|
]);
|
|
|
|
return array_column($result['values'], 'value', 'value');
|
|
|
|
}
|
|
|
|
|
2018-08-13 22:42:25 +00:00
|
|
|
/**
|
|
|
|
* Create Entity Template.
|
|
|
|
*
|
|
|
|
* @param array $params
|
|
|
|
*
|
|
|
|
* @throws Exception
|
|
|
|
* @return CRM_EntityTemplates_BAO_EntityTemplates|CRM_Core_Error
|
|
|
|
*/
|
2018-08-13 21:59:23 +00:00
|
|
|
public static function create($params) {
|
|
|
|
|
|
|
|
if (empty($params['entity_table'])) {
|
|
|
|
throw new CRM_Core_Exception(ts('Entity Table is mandatory.'));
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
$optionValueName = civicrm_api3('OptionValue', 'getvalue', [
|
|
|
|
'option_group_id' => "entity_template_for",
|
|
|
|
'value' => $params['entity_table'],
|
|
|
|
'return' => 'name',
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
catch (CiviCRM_API3_Exception $e) {
|
|
|
|
throw new CRM_Core_Exception(ts('Invalid Entity Type.'));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (empty($params['form_values'])) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
$params['form_values'] = serialize($params['form_values']);
|
|
|
|
|
|
|
|
if (!empty($params['id'])) {
|
|
|
|
CRM_Utils_Hook::pre('edit', 'EntityTemplates', $params['id'], $params);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
CRM_Utils_Hook::pre('create', 'EntityTemplates', NULL, $params);
|
|
|
|
}
|
|
|
|
|
|
|
|
$entityTemplates = new CRM_EntityTemplates_BAO_EntityTemplates();
|
|
|
|
$entityTemplates->copyValues($params);
|
|
|
|
$entityTemplates->save();
|
|
|
|
|
|
|
|
if (!empty($params['id'])) {
|
|
|
|
CRM_Utils_Hook::post('edit', 'EntityTemplates', $entityTemplates->id, $entityTemplates);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
CRM_Utils_Hook::post('create', 'EntityTemplates', $entityTemplates->id, $entityTemplates);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $entityTemplates;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|