Commit eed5d938 authored by mattwire's avatar mattwire
Browse files

Add docs framework. Add ability to create templates from existing events

parent d075b934
......@@ -3,6 +3,8 @@ use CRM_AdvancedEvents_ExtensionUtil as E;
class CRM_AdvancedEvents_BAO_EventTemplate extends CRM_AdvancedEvents_DAO_EventTemplate {
const ENTITYNAME = 'EventTemplate';
public static function eventAlreadyExists($templateId, $params) {
$eventParams = array_merge([
'return' => ["id"],
......@@ -27,4 +29,5 @@ class CRM_AdvancedEvents_BAO_EventTemplate extends CRM_AdvancedEvents_DAO_EventT
}
return FALSE;
}
}
<?php
/* https://civicrm.org/licensing */
trait CRM_AdvancedEvents_OldVersionSupportTrait {
/**
* @fixme: Remove and increment min core version once https://github.com/civicrm/civicrm-core/pull/14602 is merged.
*
* Set the active tab
*
* @param string $default
*
* @throws \CRM_Core_Exception
*/
public function setSelectedChild($default = NULL) {
$selectedChild = CRM_Utils_Request::retrieve('selectedChild', 'Alphanumeric', $form, FALSE, $default);
if (!empty($selectedChild)) {
$this->set('selectedChild', $selectedChild);
$this->assign('selectedChild', $selectedChild);
}
}
}
......@@ -87,6 +87,28 @@ class CRM_AdvancedEvents_Page_ManageEventTemplate extends CRM_Core_Page_Basic {
return self::$_links;
}
/**
* Run the page.
*
* This method is called after the page is created. It checks for the
* type of action and executes that action.
* Finally it calls the parent's run method.
*
* @return void
*/
public function run() {
// get the requested action
$action = CRM_Utils_Request::retrieve('action', 'String', $this, FALSE, 'browse');
if ($action & CRM_Core_Action::COPY) {
$this->copy();
}
else {
// parent run
return parent::run();
}
}
/**
* Browse all event templates.
*/
......@@ -179,4 +201,25 @@ class CRM_AdvancedEvents_Page_ManageEventTemplate extends CRM_Core_Page_Basic {
return 'civicrm/admin/eventTemplate';
}
/**
* Create a template from an event
*
* @throws \CRM_Core_Exception
* @throws \CiviCRM_API3_Exception
*/
public function copy() {
$id = CRM_Utils_Request::retrieve('id', 'Positive', $this, TRUE, 0, 'GET');
$urlString = 'civicrm/event/manage';
$copyEvent = civicrm_api3('EventTemplate', 'create', ['event_id' => $id]);
$urlParams = 'reset=1';
// Redirect to Copied Event Configuration
if ($copyEvent['id']) {
$urlString = 'civicrm/event/manage/settings';
$urlParams .= '&action=update&id=' . $copyEvent['id'];
}
CRM_Utils_System::redirect(CRM_Utils_System::url($urlString, $urlParams));
}
}
......@@ -7,6 +7,8 @@
class CRM_Event_Form_ManageEvent_Repeat extends CRM_Event_Form_ManageEvent {
use CRM_AdvancedEvents_OldVersionSupportTrait;
/**
* Parent Event Start Date.
* @var string
......@@ -32,6 +34,7 @@ class CRM_Event_Form_ManageEvent_Repeat extends CRM_Event_Form_ManageEvent {
->addStyleFile('civicrm', 'css/searchForm.css', 1, 'html-header');
parent::preProcess();
$this->setSelectedChild('repeat');
if (empty($this->getEventId())) {
CRM_Core_Error::statusBounce(ts('You do not have permission to access this page.'));
......
......@@ -30,32 +30,14 @@ Requires: https://github.com/civicrm/civicrm-core/pull/12781 *Without this chang
If using event locations you may require: https://github.com/civicrm/civicrm-core/pull/12459
## Installation (Web UI)
## Installation
This extension has not yet been published for installation via the web UI.
Download the latest release and install in the standard way. There are no special installation requirements.
## Installation (CLI, Zip)
## Uninstall
Sysadmins and developers may download the `.zip` file for this extension and
install it with the command-line tool [cv](https://github.com/civicrm/cv).
```bash
cd <extension-dir>
cv dl advanced-events@https://github.com/mattwire/civicrm-advanced-events/archive/master.zip
```
## Installation (CLI, Git)
Sysadmins and developers may clone the [Git](https://en.wikipedia.org/wiki/Git) repo for this extension and
install it with the command-line tool [cv](https://github.com/civicrm/cv).
```bash
git clone https://github.com/mattwire/civicrm-advanced-events.git
cv en advanced_events
```
Uninstalling will remove all "Event Template" links. No event data will be lost but events will no longer be linked to templates.
## Usage
Navigate to Administer->CiviEvent->Advanced Events Configuration.
## Known Issues
......@@ -210,6 +210,28 @@ function advanced_events_civicrm_tabset($tabsetName, &$tabs, $context) {
}
}
function advanced_events_civicrm_links($op, $objectName, $objectId, &$links, &$mask, &$values) {
//create a "Enable/Disable Auto-Renew link with the context of a contact membership
switch ($objectName) {
case 'Event':
switch ($op) {
case 'event.manage.list':
// Add a "Create Template" link
$links[] = [
'name' => 'Create Template',
'title' => 'Create Template from Event',
'url' => 'civicrm/admin/eventTemplate',
'qs' => 'reset=1&action=copy&id=%%id%%',
'extra' => 'onclick = "return confirm(\'Are you sure you want to create a template from this Event?\');"',
];
break;
}
break;
}
}
function advanced_events_civicrm_pre($op, $objectName, $id, &$params) {
switch ($objectName) {
case 'Event':
......
......@@ -21,7 +21,17 @@ function _civicrm_api3_event_template_create_spec(&$spec) {
* @throws API_Exception
*/
function civicrm_api3_event_template_create($params) {
return _civicrm_api3_basic_create(_civicrm_api3_get_BAO(__FUNCTION__), $params);
if (!empty($params['event_id']) && empty($params['template_id'])) {
// We are creating an event template from an existing event
$copy = CRM_Event_BAO_Event::copy($params['event_id']);
$copy->is_template = 1;
$copy->template_title = $copy->title;
$copy->save();
return civicrm_api3_create_success($copy->toArray());
}
else {
return _civicrm_api3_basic_create(_civicrm_api3_get_BAO(__FUNCTION__), $params);
}
}
/**
......
# CiviCRM Advanced Events Extension
![Example Event Config](/images/event_config_tab.png)
![Advanced Event Settings](/images/advanced_event_settings.png)
This extension provides a number of useful features to complement/improve the CiviEvent component in CiviCRM.
The extension is licensed under [AGPL-3.0](LICENSE.txt).
## Features
* Ability to hide functionality in the UI that is not required (eg. Tell a Friend, Personal Campaigns).
* Replace existing repeat events functionality with new based directly on Event templates.
* Add an "Event Search/Selector" that allows "Copy Participants" and "Delete Event" actions.
* Allow to create templates from existing events.
## Requirements
* PHP v7.1+
* CiviCRM 5.13+
### CiviCRM 5.7
Requires: https://github.com/civicrm/civicrm-core/pull/12769
Recommended: https://github.com/civicrm/civicrm-core/pull/12747 *without this change some page/form redirects may go to the wrong tab on submit (eg. "Info and Settings" instead of "Repeat")*
### CiviCRM 5.6
Requires: https://github.com/civicrm/civicrm-core/pull/12781 *Without this change advanced events will not work correctly.*
### CiviCRM 5.5
If using event locations you may require: https://github.com/civicrm/civicrm-core/pull/12459
## Installation
Download the latest release and install in the standard way. There are no special installation requirements.
## Uninstall
Uninstalling will remove all "Event Template" links. No event data will be lost but events will no longer be linked to templates.
## Usage
Navigate to Administer->CiviEvent->Advanced Events Configuration.
## Release 0.10
* EventTemplate.create API now accepts event_id to create a template from an existing event.
* A new "link" is provided on the event list to "Create Template" from event.
## Release 0.9
* Drop support for CiviCRM 5.7 (minimum version is now 5.13)
* Only show one button on event repetition (the cancel button is not useful).
* Use our version of formRule instead of core version (this fixes issues on 5.13+).
* Convert to short array syntax.
* Fix php notices on event template.
## Release 0.8
* Fix copying more than 25 participants from source event
## Release 0.2
* New implementation of repeating events. Create an event template and then "Add Event" or use the repeat tab on the template.
......@@ -13,8 +13,8 @@
<url desc="Support">https://www.mjwconsult.co.uk</url>
<url desc="Licensing">http://www.gnu.org/licenses/agpl-3.0.html</url>
</urls>
<releaseDate>2019-06-18</releaseDate>
<version>0.9</version>
<releaseDate>2019-06-22</releaseDate>
<version>0.10.dev</version>
<develStage>beta</develStage>
<compatibility>
<ver>5.13</ver>
......
site_name: Advanced Events
repo_url: https://lab.civicrm.org/extensions/civicrm-advanced-events
theme: material
markdown_extensions:
- attr_list
- admonition
- def_list
- codehilite
- toc(permalink=true)
- pymdownx.superfences
- pymdownx.inlinehilite
- pymdownx.tilde
- pymdownx.betterem
- pymdownx.mark
pages:
- Overview: index.md
- Release Notes: release/release_notes.md
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment