Added more changes
This commit is contained in:
parent
8bfc1afd21
commit
499efd7087
60
CRM/EntityTemplates/BAO/EntityTemplates.php
Normal file
60
CRM/EntityTemplates/BAO/EntityTemplates.php
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
<?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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -2,6 +2,13 @@
|
|||||||
|
|
||||||
class CRM_EntityTemplates_Page_EntityTemplates extends CRM_Core_Page_Basic {
|
class CRM_EntityTemplates_Page_EntityTemplates extends CRM_Core_Page_Basic {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The action links that we need to display for the browse screen.
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
static $_links = NULL;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get BAO Name.
|
* Get BAO Name.
|
||||||
*
|
*
|
||||||
@ -19,7 +26,23 @@ class CRM_EntityTemplates_Page_EntityTemplates extends CRM_Core_Page_Basic {
|
|||||||
* (reference) of action links
|
* (reference) of action links
|
||||||
*/
|
*/
|
||||||
public function &links() {
|
public function &links() {
|
||||||
return [];
|
if (!(self::$_links)) {
|
||||||
|
self::$_links = [
|
||||||
|
CRM_Core_Action::UPDATE => [
|
||||||
|
'name' => ts('Edit'),
|
||||||
|
'url' => '%%url%%',
|
||||||
|
'qs' => '%%query%%&isTemplate=1&templateId=%%id%%',
|
||||||
|
'title' => ts('Edit template'),
|
||||||
|
],
|
||||||
|
CRM_Core_Action::DELETE => [
|
||||||
|
'name' => ts('Delete'),
|
||||||
|
'url' => 'civicrm/entity/templates',
|
||||||
|
'qs' => 'action=delete&id=%%id%%',
|
||||||
|
'title' => ts('Delete template'),
|
||||||
|
],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
return self::$_links;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -31,11 +54,25 @@ class CRM_EntityTemplates_Page_EntityTemplates extends CRM_Core_Page_Basic {
|
|||||||
if (!CRM_Core_Permission::check('administer CiviCRM')) {
|
if (!CRM_Core_Permission::check('administer CiviCRM')) {
|
||||||
return CRM_Utils_System::permissionDenied();
|
return CRM_Utils_System::permissionDenied();
|
||||||
}
|
}
|
||||||
$entityType = CRM_Utils_Request::retrieve('entityType', 'Positive');
|
$entityType = CRM_Utils_Request::retrieve('entityType', 'String');
|
||||||
$entityTypes = CRM_EntityTemplates_BAO_EntityTemplates::getEntityTypes();
|
$entityTypes = CRM_EntityTemplates_BAO_EntityTemplates::getEntityTypes();
|
||||||
if (empty($entityType)) {
|
if (empty($entityType)) {
|
||||||
$entityType = key($entityTypes);
|
$entityType = key($entityTypes);
|
||||||
}
|
}
|
||||||
|
try {
|
||||||
|
$optionValueName = civicrm_api3('OptionValue', 'getvalue', [
|
||||||
|
'option_group_id' => "entity_template_for",
|
||||||
|
'value' => $entityType,
|
||||||
|
'return' => 'name',
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
catch (CiviCRM_API3_Exception $e) {
|
||||||
|
CRM_Core_Error::statusBounce(
|
||||||
|
ts('Invalid Entity type.'),
|
||||||
|
CRM_Utils_System::url('civicrm', "reset=1")
|
||||||
|
);
|
||||||
|
}
|
||||||
|
list($url, $query) = explode('?', $optionValueName);
|
||||||
$entityTypeOptions = '';
|
$entityTypeOptions = '';
|
||||||
foreach ($entityTypes as $key => $value) {
|
foreach ($entityTypes as $key => $value) {
|
||||||
$extra = '';
|
$extra = '';
|
||||||
@ -45,6 +82,36 @@ class CRM_EntityTemplates_Page_EntityTemplates extends CRM_Core_Page_Basic {
|
|||||||
$entityTypeOptions .= "<option value='{$key}' {$extra}>{$value}</option>";
|
$entityTypeOptions .= "<option value='{$key}' {$extra}>{$value}</option>";
|
||||||
}
|
}
|
||||||
$this->assign('entityTypeOptions', $entityTypeOptions);
|
$this->assign('entityTypeOptions', $entityTypeOptions);
|
||||||
|
|
||||||
|
$results = civicrm_api3('EntityTemplates', 'get', [
|
||||||
|
'entity_table' => $entityType,
|
||||||
|
'return' => ['title', 'id'],
|
||||||
|
]);
|
||||||
|
$rows = [];
|
||||||
|
$action = array_sum(array_keys($this->links()));
|
||||||
|
foreach ($results['values'] as $values) {
|
||||||
|
$rows[] = [
|
||||||
|
'title' => $values['title'],
|
||||||
|
'links' => CRM_Core_Action::formLink(
|
||||||
|
self::links(),
|
||||||
|
$action,
|
||||||
|
[
|
||||||
|
'id' => $values['id'],
|
||||||
|
'url' => $url,
|
||||||
|
'query' => $query,
|
||||||
|
],
|
||||||
|
ts('more'),
|
||||||
|
FALSE,
|
||||||
|
'entitytemplates.manage.action',
|
||||||
|
'EntityTemplates',
|
||||||
|
$values['id']
|
||||||
|
),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->assign('rows', $rows);
|
||||||
|
$this->assign('url', $url);
|
||||||
|
$this->assign('query', $query);
|
||||||
$this->assign('entityType', $entityType);
|
$this->assign('entityType', $entityType);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -103,8 +103,9 @@ function entitytemplates_civicrm_managed(&$entities) {
|
|||||||
],
|
],
|
||||||
];
|
];
|
||||||
foreach ([
|
foreach ([
|
||||||
'Contact' => 'CRM_Contact_Form_Contact',
|
'Individual' => ['CRM_Contact_Form_Contact', 'civicrm/contact/add?reset=1&ct=Individual'],
|
||||||
'Contribution' => 'CRM_Contribute_Form_Contribution',
|
'Organization' => ['CRM_Contact_Form_Contact', 'civicrm/contact/add?reset=1&ct=Organization'],
|
||||||
|
'Contribution' => ['CRM_Contribute_Form_Contribution', 'civicrm/contribute/add?reset=1&action=add&context=standalone'],
|
||||||
] as $entityType => $formClassName) {
|
] as $entityType => $formClassName) {
|
||||||
$entities[] = [
|
$entities[] = [
|
||||||
'module' => 'com.megaphonetech.entitytemplates',
|
'module' => 'com.megaphonetech.entitytemplates',
|
||||||
@ -112,10 +113,11 @@ function entitytemplates_civicrm_managed(&$entities) {
|
|||||||
'entity' => 'OptionValue',
|
'entity' => 'OptionValue',
|
||||||
'params' => [
|
'params' => [
|
||||||
'version' => 3,
|
'version' => 3,
|
||||||
'option_group_id' => $ApprovalStatusOptionGroup,
|
'option_group_id' => 'entity_template_for',
|
||||||
'label' => ts("{$entityType}"),
|
'label' => ts("{$entityType}"),
|
||||||
'value' => $formClassName,
|
'value' => $entityType,
|
||||||
'name' => $entityType,
|
'name' => $formClassName[1],
|
||||||
|
'description' => $formClassName[0],
|
||||||
'is_default' => '0',
|
'is_default' => '0',
|
||||||
'weight' => '1',
|
'weight' => '1',
|
||||||
'is_optgroup' => '0',
|
'is_optgroup' => '0',
|
||||||
@ -171,7 +173,7 @@ function entitytemplates_civicrm_alterSettingsFolders(&$metaDataFolders = NULL)
|
|||||||
*/
|
*/
|
||||||
function entitytemplates_civicrm_entityTypes(&$entityTypes) {
|
function entitytemplates_civicrm_entityTypes(&$entityTypes) {
|
||||||
_entitytemplates_civix_civicrm_entityTypes($entityTypes);
|
_entitytemplates_civix_civicrm_entityTypes($entityTypes);
|
||||||
$entityTypes = [
|
$entityTypes[] = [
|
||||||
'name' => 'EntityTemplates',
|
'name' => 'EntityTemplates',
|
||||||
'class' => 'CRM_Core_DAO_EntityTemplates',
|
'class' => 'CRM_Core_DAO_EntityTemplates',
|
||||||
'table' => 'civicrm_entity_templates',
|
'table' => 'civicrm_entity_templates',
|
||||||
@ -185,7 +187,7 @@ function entitytemplates_civicrm_entityTypes(&$entityTypes) {
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
function entitytemplates_civicrm_navigationMenu(&$menu) {
|
function entitytemplates_civicrm_navigationMenu(&$menu) {
|
||||||
_entitytemplates_civix_insert_navigation_menu($menu, 'Administer/CiviGrant', [
|
_entitytemplates_civix_insert_navigation_menu($menu, 'Administer/Customize Data and Screens', [
|
||||||
'label' => ts('Entity Templates', ['domain' => 'com.megaphonetech.entitytemplates']),
|
'label' => ts('Entity Templates', ['domain' => 'com.megaphonetech.entitytemplates']),
|
||||||
'name' => 'entity_templates',
|
'name' => 'entity_templates',
|
||||||
'url' => CRM_Utils_System::url('civicrm/entity/templates', 'reset=1&action=browse', TRUE),
|
'url' => CRM_Utils_System::url('civicrm/entity/templates', 'reset=1&action=browse', TRUE),
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
<div class="crm-content-block crm-block">
|
<div class="crm-content-block crm-block">
|
||||||
<label>{ts}Fiscal Year: {/ts}</label>
|
<label>{ts}Entity Type: {/ts}</label>
|
||||||
<select name="entityType" type="text" id="entityType" class="crm-form-select required crm-select2 six">
|
<select name="entityType" type="text" id="entityType" class="crm-form-select required crm-select2 twelve">
|
||||||
{$entityTypeOptions}
|
{$entityTypeOptions}
|
||||||
</select>
|
</select>
|
||||||
</br></br>
|
</br></br>
|
||||||
@ -10,20 +10,20 @@
|
|||||||
<th></th>
|
<th></th>
|
||||||
</thead>
|
</thead>
|
||||||
{foreach from=$rows item=row}
|
{foreach from=$rows item=row}
|
||||||
<tr id="EntityTemplates-{$rowId}" class="crm-entity {cycle values="odd-row,even-row"}">
|
<tr id="EntityTemplates-{$row.title}" class="crm-entity {cycle values="odd-row,even-row"}">
|
||||||
<td class='EntityTemplates-title'>{$row.title}</td>
|
<td class='EntityTemplates-title'>{$row.title}</td>
|
||||||
<td class='EntityTemplates-links'>{$row.links}</td>
|
<td class='EntityTemplates-links'>{$row.links}</td>
|
||||||
</tr>
|
</tr>
|
||||||
{/foreach}
|
{/foreach}
|
||||||
</table>
|
</table>
|
||||||
{crmButton p="civicrm" q="reset=1" class="cancel" icon="times"}{ts}Add Template{/ts}{/crmButton}
|
{crmButton p=$url q="`$query`&isTemplate=1" class="cancel" icon="times"}{ts}Add Template{/ts}{/crmButton}
|
||||||
{crmButton p="civicrm" q="reset=1" class="cancel" icon="times"}{ts}Done{/ts}{/crmButton}
|
{crmButton p="civicrm" q="reset=1" class="cancel" icon="times"}{ts}Done{/ts}{/crmButton}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{literal}
|
{literal}
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
CRM.$(function($) {
|
CRM.$(function($) {
|
||||||
$('#fiscal_year').change(loadPage);
|
$('#entityType').change(loadPage);
|
||||||
function loadPage() {
|
function loadPage() {
|
||||||
window.location.href = CRM.url('civicrm/entity/templates', {
|
window.location.href = CRM.url('civicrm/entity/templates', {
|
||||||
reset: '1',
|
reset: '1',
|
||||||
|
Loading…
Reference in New Issue
Block a user