From 499efd708797ed9bf52bd9f4e120fd973269010f Mon Sep 17 00:00:00 2001 From: Civiware Solutions Date: Tue, 14 Aug 2018 03:29:23 +0530 Subject: [PATCH] Added more changes --- CRM/EntityTemplates/BAO/EntityTemplates.php | 60 ++++++++++++++++ CRM/EntityTemplates/Page/EntityTemplates.php | 71 ++++++++++++++++++- entitytemplates.php | 16 +++-- .../EntityTemplates/Page/EntityTemplates.tpl | 10 +-- 4 files changed, 143 insertions(+), 14 deletions(-) create mode 100644 CRM/EntityTemplates/BAO/EntityTemplates.php diff --git a/CRM/EntityTemplates/BAO/EntityTemplates.php b/CRM/EntityTemplates/BAO/EntityTemplates.php new file mode 100644 index 0000000..678fe18 --- /dev/null +++ b/CRM/EntityTemplates/BAO/EntityTemplates.php @@ -0,0 +1,60 @@ + ["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; + } + +} diff --git a/CRM/EntityTemplates/Page/EntityTemplates.php b/CRM/EntityTemplates/Page/EntityTemplates.php index 0cffeed..e4fc4b0 100644 --- a/CRM/EntityTemplates/Page/EntityTemplates.php +++ b/CRM/EntityTemplates/Page/EntityTemplates.php @@ -2,6 +2,13 @@ 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. * @@ -19,7 +26,23 @@ class CRM_EntityTemplates_Page_EntityTemplates extends CRM_Core_Page_Basic { * (reference) of action 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')) { 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(); if (empty($entityType)) { $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 = ''; foreach ($entityTypes as $key => $value) { $extra = ''; @@ -45,6 +82,36 @@ class CRM_EntityTemplates_Page_EntityTemplates extends CRM_Core_Page_Basic { $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); } diff --git a/entitytemplates.php b/entitytemplates.php index bbb2173..c05b325 100644 --- a/entitytemplates.php +++ b/entitytemplates.php @@ -103,8 +103,9 @@ function entitytemplates_civicrm_managed(&$entities) { ], ]; foreach ([ - 'Contact' => 'CRM_Contact_Form_Contact', - 'Contribution' => 'CRM_Contribute_Form_Contribution', + 'Individual' => ['CRM_Contact_Form_Contact', 'civicrm/contact/add?reset=1&ct=Individual'], + '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) { $entities[] = [ 'module' => 'com.megaphonetech.entitytemplates', @@ -112,10 +113,11 @@ function entitytemplates_civicrm_managed(&$entities) { 'entity' => 'OptionValue', 'params' => [ 'version' => 3, - 'option_group_id' => $ApprovalStatusOptionGroup, + 'option_group_id' => 'entity_template_for', 'label' => ts("{$entityType}"), - 'value' => $formClassName, - 'name' => $entityType, + 'value' => $entityType, + 'name' => $formClassName[1], + 'description' => $formClassName[0], 'is_default' => '0', 'weight' => '1', 'is_optgroup' => '0', @@ -171,7 +173,7 @@ function entitytemplates_civicrm_alterSettingsFolders(&$metaDataFolders = NULL) */ function entitytemplates_civicrm_entityTypes(&$entityTypes) { _entitytemplates_civix_civicrm_entityTypes($entityTypes); - $entityTypes = [ + $entityTypes[] = [ 'name' => 'EntityTemplates', 'class' => 'CRM_Core_DAO_EntityTemplates', 'table' => 'civicrm_entity_templates', @@ -185,7 +187,7 @@ function entitytemplates_civicrm_entityTypes(&$entityTypes) { * */ 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']), 'name' => 'entity_templates', 'url' => CRM_Utils_System::url('civicrm/entity/templates', 'reset=1&action=browse', TRUE), diff --git a/templates/CRM/EntityTemplates/Page/EntityTemplates.tpl b/templates/CRM/EntityTemplates/Page/EntityTemplates.tpl index 09b003e..0d5be3d 100644 --- a/templates/CRM/EntityTemplates/Page/EntityTemplates.tpl +++ b/templates/CRM/EntityTemplates/Page/EntityTemplates.tpl @@ -1,6 +1,6 @@
- - {$entityTypeOptions}

@@ -10,20 +10,20 @@ {foreach from=$rows item=row} - + {$row.title} {$row.links} {/foreach} - {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}
{literal}