com.megaphonetech.entitytem.../CRM/EntityTemplates/BAO/EntityTemplates.php

61 lines
1.6 KiB
PHP

<?php
class CRM_EntityTemplates_BAO_EntityTemplates extends CRM_Core_DAO_EntityTemplates {
/**
* Build Fiscal year option list.
*
*/
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');
}
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;
}
}