Commit a802fb54 authored by Matthew Wire's avatar Matthew Wire
Browse files

Initial commit - add functionality to hide unused event config tabs

parents
<?php
/*--------------------------------------------------------------------+
| CiviCRM version 5.0 |
+------------------------------0--------------------------------------+
| Copyright CiviCRM LLC (c) 2004-2017 |
+------------------------------0--------------------------------------+
| This file is a part of CiviCRM. |
| |
| CiviCRM is free software; you can copy, modify, and distribute it |
| under the terms of the GNU Affero General Public License |
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
| |
| CiviCRM is distributed in the hope that it will be useful, but |
| WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| See the GNU Affero General Public License for more details. |
| |
| You should have received a copy of the GNU Affero General Public |
| License and the CiviCRM Licensing Exception along |
| with this program; if not, contact CiviCRM LLC |
| at info[AT]civicrm[DOT]org. If you have questions about the |
| GNU Affero General Public License or the licensing of CiviCRM, |
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
+-------------------------------------------------------------------*/
use CRM_AdvancedEvents_ExtensionUtil as E;
/**
* Form controller class
*
* @see http://wiki.civicrm.org/confluence/display/CRMDOC43/QuickForm+Reference
*/
class CRM_AdvancedEvents_Form_Settings extends CRM_Core_Form {
function buildQuickForm() {
parent::buildQuickForm();
$className = E::CLASS_PREFIX . '_Settings';
CRM_Utils_System::setTitle($className::TITLE . ' - ' . E::ts('Settings'));
$className = E::CLASS_PREFIX . '_Form_SettingsCustom';
if (method_exists($className, 'buildQuickFormPre')) {
$className::buildQuickFormPre($this);
}
$settings = $this->getFormSettings();
foreach ($settings as $name => $setting) {
if (isset($setting['html_type'])) {
Switch (strtolower($setting['html_type'])) {
case 'text':
$this->addElement('text', $name, ts($setting['description']), $setting['html_attributes'], array());
break;
case 'checkbox':
$this->addElement('checkbox', $name, ts($setting['description']), '', '');
break;
case 'datepicker':
foreach ($setting['html_extra'] as $key => $value) {
if ($key == 'minDate') {
$minDate = new DateTime('now');
$minDate->modify($value);
$setting['html_extra'][$key] = $minDate->format('Y-m-d');
}
}
$this->add('datepicker', $name, ts($setting['description']), $setting['html_attributes'], FALSE, $setting['html_extra']);
break;
case 'select2':
$className = E::CLASS_PREFIX . '_Form_SettingsCustom';
if (method_exists($className, 'addSelect2Element')) {
$className::addSelect2Element($this, $name, $setting);
}
break;
case 'select':
$className = E::CLASS_PREFIX . '_Form_SettingsCustom';
if (method_exists($className, 'addSelectElement')) {
$className::addSelectElement($this, $name, $setting);
}
break;
case 'hidden':
$hidden = TRUE;
}
if (isset($hidden)) {
continue;
}
$adminGroup = isset($setting['admin_group']) ? $setting['admin_group'] : 'default';
$elementGroups[$adminGroup]['elementNames'][] = $name;
// Title and description may not be defined on all elements (they only need to be on one)
if (!empty($setting['admin_grouptitle'])) {
$elementGroups[$setting['admin_group']]['title'] = $setting['admin_grouptitle'];
}
if (!empty($setting['admin_groupdescription'])) {
$elementGroups[$setting['admin_group']]['description'] = $setting['admin_groupdescription'];
}
}
}
$this->addButtons(array(
array (
'type' => 'submit',
'name' => ts('Submit'),
'isDefault' => TRUE,
),
array (
'type' => 'cancel',
'name' => ts('Cancel'),
)
));
// export form elements
$this->assign('elementGroups', $elementGroups);
}
function postProcess() {
$className = E::CLASS_PREFIX . '_Settings';
$changed = $this->_submitValues;
$settings = $this->getFormSettings(TRUE);
foreach ($settings as &$setting) {
if ($setting['html_type'] == 'Checkbox') {
$setting = false;
}
else {
$setting = NULL;
}
}
// Make sure we have all settings elements set (boolean settings will be unset by default and wouldn't be saved)
$settingsToSave = array_merge($settings, array_intersect_key($changed, $settings));
$className::save($settingsToSave);
parent::postProcess();
CRM_Core_Session::singleton()->setStatus('Configuration Updated', $className::TITLE, 'success');
}
/**
* Get the settings we are going to allow to be set on this form.
*
* @return array
*/
function getFormSettings($metadata=TRUE) {
$className = E::CLASS_PREFIX . '_Settings';
$unprefixedSettings = array();
$settings = civicrm_api3('setting', 'getfields', array('filters' => $className::getFilter()));
if (!empty($settings['values'])) {
foreach ($settings['values'] as $name => $values) {
if ($metadata) {
$unprefixedSettings[$className::getName($name, FALSE)] = $values;
}
else {
$unprefixedSettings[$className::getName($name, FALSE)] = NULL;
}
}
}
return $unprefixedSettings;
}
/**
* Set defaults for form.
*
* @see CRM_Core_Form::setDefaultValues()
*/
function setDefaultValues() {
$className = E::CLASS_PREFIX . '_Settings';
$settings = $this->getFormSettings(FALSE);
$defaults = array();
$existing = $className::get(array_keys($settings));
if ($existing) {
foreach ($existing as $name => $value) {
$defaults[$name] = $value;
}
}
return $defaults;
}
}
<?php
/*--------------------------------------------------------------------+
| CiviCRM version 5.0 |
+---------------------------------------------------------------------+
| Copyright CiviCRM LLC (c) 2004-2017 |
+---------------------------------------------------------------------+
| This file is a part of CiviCRM. |
| |
| CiviCRM is free software; you can copy, modify, and distribute it |
| under the terms of the GNU Affero General Public License |
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
| |
| CiviCRM is distributed in the hope that it will be useful, but |
| WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| See the GNU Affero General Public License for more details. |
| |
| You should have received a copy of the GNU Affero General Public |
| License and the CiviCRM Licensing Exception along |
| with this program; if not, contact CiviCRM LLC |
| at info[AT]civicrm[DOT]org. If you have questions about the |
| GNU Affero General Public License or the licensing of CiviCRM, |
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
+-------------------------------------------------------------------*/
use CRM_AdvancedEvents_ExtensionUtil as E;
class CRM_AdvancedEvents_Functions {
public static function getEnabled() {
// 'settings', 'location', 'fee', 'registration', 'reminder', 'friend', 'pcp', 'repeat'
return [
'location' => CRM_AdvancedEvents_Settings::getValue('function_location'),
'fee' => CRM_AdvancedEvents_Settings::getValue('function_fee'),
'registration' => CRM_AdvancedEvents_Settings::getValue('function_registration'),
'reminder' => CRM_AdvancedEvents_Settings::getValue('function_reminder'),
'friend' => CRM_AdvancedEvents_Settings::getValue('function_friend'),
'pcp' => CRM_AdvancedEvents_Settings::getValue('function_pcp'),
'repeat' => CRM_AdvancedEvents_Settings::getValue('function_repeat'),
];
}
}
\ No newline at end of file
<?php
/*--------------------------------------------------------------------+
| CiviCRM version 5.0 |
+---------------------------------------------------------------------+
| Copyright CiviCRM LLC (c) 2004-2017 |
+---------------------------------------------------------------------+
| This file is a part of CiviCRM. |
| |
| CiviCRM is free software; you can copy, modify, and distribute it |
| under the terms of the GNU Affero General Public License |
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
| |
| CiviCRM is distributed in the hope that it will be useful, but |
| WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| See the GNU Affero General Public License for more details. |
| |
| You should have received a copy of the GNU Affero General Public |
| License and the CiviCRM Licensing Exception along |
| with this program; if not, contact CiviCRM LLC |
| at info[AT]civicrm[DOT]org. If you have questions about the |
| GNU Affero General Public License or the licensing of CiviCRM, |
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
+-------------------------------------------------------------------*/
use CRM_AdvancedEvents_ExtensionUtil as E;
class CRM_AdvancedEvents_Settings {
CONST TITLE = 'Advanced Events';
/**
* Get settings prefix name for this extension
* @return string
*/
public static function getPrefix() {
return 'advanced_events_';
}
/**
* Get filter of valid settings for this extension
* @return array
*/
public static function getFilter() {
return array('group' => 'advanced_events');
}
/**
* Get name of setting
* @param: setting name
* @prefix: Boolean
* @return: string
*/
public static function getName($name, $prefix = false) {
$ret = str_replace(self::getPrefix(),'',$name);
if ($prefix) {
$ret = self::getPrefix().$ret;
}
return $ret;
}
/**
* Save settings. Accepts an array of name=>value pairs. Name can be with or without prefix (it will be added if missing).
* @param array $values Array of settings and values with or without prefix (eg. array(smartdebit_username => 'test')) to save
*/
public static function save($settings) {
foreach ($settings as $name => $value) {
$prefixedSettings[self::getName($name, TRUE)] = $value;
}
civicrm_api3('setting', 'create', $prefixedSettings);
}
/**
* Read setting that has prefix in database and return single value
* @param $name
* @return mixed
*/
public static function getValue($name) {
$className = E::CLASS_PREFIX . '_Settings';
$settings = civicrm_api3('setting', 'get', array('return' => $className::getName($name,true)));
$domainID = CRM_Core_Config::domainID();
if (isset($settings['values'][$domainID][$className::getName($name,true)])) {
return $settings['values'][$domainID][$className::getName($name, true)];
}
return '';
}
/**
* Get settings
* @param array $settings of settings (eg. array(username, password))
*
* @return array
*/
public static function get($settings) {
if ((!is_array($settings) || empty($settings))) {
return array();
}
$domainID = CRM_Core_Config::domainID();
foreach ($settings as $name) {
$prefixedSettings[] = self::getName($name, TRUE);
}
$settingsResult = civicrm_api3('setting', 'get', array('return' => $prefixedSettings));
if (isset($settingsResult['values'][$domainID])) {
foreach ($settingsResult['values'][$domainID] as $name => $value) {
$unprefixedSettings[self::getName($name)] = $value;
}
return empty($unprefixedSettings) ? NULL : $unprefixedSettings;
}
return array();
}
}
This diff is collapsed.
# CiviCRM Advanced Events Extension
![Example Event Config](/docs/images/event_config_tab.png)
![Advanced Event Settings](/docs/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).
## Requirements
* PHP v5.6+
* CiviCRM 5.0+
## Installation (Web UI)
This extension has not yet been published for installation via the web UI.
## Installation (CLI, Zip)
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
```
## Usage
Navigate to Administer->CiviEvent->Advanced Events Configuration.
## Known Issues
This extension is under development.
<?php
// AUTO-GENERATED FILE -- Civix may overwrite any changes made to this file
/**
* The ExtensionUtil class provides small stubs for accessing resources of this
* extension.
*/
class CRM_AdvancedEvents_ExtensionUtil {
const SHORT_NAME = "advanced_events";
const LONG_NAME = "advanced-events";
const CLASS_PREFIX = "CRM_AdvancedEvents";
/**
* Translate a string using the extension's domain.
*
* If the extension doesn't have a specific translation
* for the string, fallback to the default translations.
*
* @param string $text
* Canonical message text (generally en_US).
* @param array $params
* @return string
* Translated text.
* @see ts
*/
public static function ts($text, $params = array()) {
if (!array_key_exists('domain', $params)) {
$params['domain'] = array(self::LONG_NAME, NULL);
}
return ts($text, $params);
}
/**
* Get the URL of a resource file (in this extension).
*
* @param string|NULL $file
* Ex: NULL.
* Ex: 'css/foo.css'.
* @return string
* Ex: 'http://example.org/sites/default/ext/org.example.foo'.
* Ex: 'http://example.org/sites/default/ext/org.example.foo/css/foo.css'.
*/
public static function url($file = NULL) {
if ($file === NULL) {
return rtrim(CRM_Core_Resources::singleton()->getUrl(self::LONG_NAME), '/');
}
return CRM_Core_Resources::singleton()->getUrl(self::LONG_NAME, $file);
}
/**
* Get the path of a resource file (in this extension).
*
* @param string|NULL $file
* Ex: NULL.
* Ex: 'css/foo.css'.
* @return string
* Ex: '/var/www/example.org/sites/default/ext/org.example.foo'.
* Ex: '/var/www/example.org/sites/default/ext/org.example.foo/css/foo.css'.
*/
public static function path($file = NULL) {
// return CRM_Core_Resources::singleton()->getPath(self::LONG_NAME, $file);
return __DIR__ . ($file === NULL ? '' : (DIRECTORY_SEPARATOR . $file));
}
/**
* Get the name of a class within this extension.
*
* @param string $suffix
* Ex: 'Page_HelloWorld' or 'Page\\HelloWorld'.
* @return string
* Ex: 'CRM_Foo_Page_HelloWorld'.
*/
public static function findClass($suffix) {
return self::CLASS_PREFIX . '_' . str_replace('\\', '_', $suffix);
}
}
use CRM_AdvancedEvents_ExtensionUtil as E;
/**
* (Delegated) Implements hook_civicrm_config().
*
* @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_config
*/
function _advanced_events_civix_civicrm_config(&$config = NULL) {
static $configured = FALSE;
if ($configured) {
return;
}
$configured = TRUE;
$template =& CRM_Core_Smarty::singleton();
$extRoot = dirname(__FILE__) . DIRECTORY_SEPARATOR;
$extDir = $extRoot . 'templates';
if (is_array($template->template_dir)) {
array_unshift($template->template_dir, $extDir);
}
else {
$template->template_dir = array($extDir, $template->template_dir);
}
$include_path = $extRoot . PATH_SEPARATOR . get_include_path();
set_include_path($include_path);
}
/**
* (Delegated) Implements hook_civicrm_xmlMenu().
*
* @param $files array(string)
*
* @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_xmlMenu
*/
function _advanced_events_civix_civicrm_xmlMenu(&$files) {
foreach (_advanced_events_civix_glob(__DIR__ . '/xml/Menu/*.xml') as $file) {
$files[] = $file;
}
}
/**
* Implements hook_civicrm_install().
*
* @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_install
*/
function _advanced_events_civix_civicrm_install() {
_advanced_events_civix_civicrm_config();
if ($upgrader = _advanced_events_civix_upgrader()) {
$upgrader->onInstall();
}
}
/**
* Implements hook_civicrm_postInstall().
*
* @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_postInstall
*/
function _advanced_events_civix_civicrm_postInstall() {
_advanced_events_civix_civicrm_config();
if ($upgrader = _advanced_events_civix_upgrader()) {
if (is_callable(array($upgrader, 'onPostInstall'))) {
$upgrader->onPostInstall();
}
}
}
/**
* Implements hook_civicrm_uninstall().
*
* @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_uninstall
*/
function _advanced_events_civix_civicrm_uninstall() {
_advanced_events_civix_civicrm_config();
if ($upgrader = _advanced_events_civix_upgrader()) {
$upgrader->onUninstall();
}
}
/**
* (Delegated) Implements hook_civicrm_enable().
*
* @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_enable
*/
function _advanced_events_civix_civicrm_enable() {
_advanced_events_civix_civicrm_config();
if ($upgrader = _advanced_events_civix_upgrader()) {
if (is_callable(array($upgrader, 'onEnable'))) {
$upgrader->onEnable();
}
}
}
/**
* (Delegated) Implements hook_civicrm_disable().
*
* @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_disable
* @return mixed
*/
function _advanced_events_civix_civicrm_disable() {
_advanced_events_civix_civicrm_config();
if ($upgrader = _advanced_events_civix_upgrader()) {
if (is_callable(array($upgrader, 'onDisable'))) {
$upgrader->onDisable();
}
}
}
/**
* (Delegated) Implements hook_civicrm_upgrade().
*
* @param $op string, the type of operation being performed; 'check' or 'enqueue'
* @param $queue CRM_Queue_Queue, (for 'enqueue') the modifiable list of pending up upgrade tasks
*
* @return mixed based on op. for 'check', returns array(boolean) (TRUE if upgrades are pending)
* for 'enqueue', returns void
*
* @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_upgrade
*/
function _advanced_events_civix_civicrm_upgrade($op, CRM_Queue_Queue $queue = NULL) {
if ($upgrader = _advanced_events_civix_upgrader()) {
return $upgrader->onUpgrade($op, $queue);
}
}
/**
* @return CRM_AdvancedEvents_Upgrader
*/
function _advanced_events_civix_upgrader() {
if (!file_exists(__DIR__ . '/CRM/AdvancedEvents/Upgrader.php')) {
return NULL;
}
else {
return CRM_AdvancedEvents_Upgrader_Base::instance();
}
}
/**
* Search directory tree for files which match a glob pattern
*
* Note: Dot-directories (like "..", ".git", or ".svn") will be ignored.
* Note: In Civi 4.3+, delegate to CRM_Utils_File::findFiles()
*
* @param $dir string, base dir
* @param $pattern string, glob pattern, eg "*.txt"
* @return array(string)
*/
function _advanced_events_civix_find_files($dir, $pattern) {
if (is_callable(array('CRM_Utils_File', 'findFiles'))) {
return CRM_Utils_File::findFiles($dir, $pattern);
}