Commit e468c7a2 authored by bgm's avatar bgm Committed by Aegir user

Update org.civicrm.module.cividiscount to 3.6

parent a7d9003d
......@@ -29,8 +29,6 @@
* @package CiviDiscount
*/
require_once 'CRM/CiviDiscount/DAO/Item.php';
class CRM_CiviDiscount_BAO_Item extends CRM_CiviDiscount_DAO_Item {
/**
......
......@@ -98,12 +98,6 @@ class CRM_CiviDiscount_BAO_Track extends CRM_CiviDiscount_DAO_Track {
}
static function getUsage($id = NULL, $cid = NULL, $orgid = NULL) {
require_once 'CRM/CiviDiscount/Utils.php';
require_once 'CRM/Member/BAO/Membership.php';
require_once 'CRM/Contact/BAO/Contact.php';
$where = '';
$sql = "
SELECT t.item_id as item_id,
t.contact_id as contact_id,
......
......@@ -27,8 +27,7 @@
/**
* @package CiviDiscount
*/
require_once 'CRM/Core/DAO.php';
require_once 'CRM/Utils/Type.php';
use CRM_CiviDiscount_ExtensionUtil as E;
class CRM_CiviDiscount_DAO_Track extends CRM_Core_DAO {
/**
......@@ -179,7 +178,7 @@ class CRM_CiviDiscount_DAO_Track extends CRM_Core_DAO {
'used_date' => array(
'name' => 'used_date',
'type' => CRM_Utils_Type::T_DATE + CRM_Utils_Type::T_TIME,
'title' => ts('Used Date'),
'title' => E::ts('Used Date'),
),
'contribution_id' => array(
'name' => 'contribution_id',
......@@ -189,7 +188,7 @@ class CRM_CiviDiscount_DAO_Track extends CRM_Core_DAO {
'entity_table' => array(
'name' => 'entity_table',
'type' => CRM_Utils_Type::T_STRING,
'title' => ts('Entity Table'),
'title' => E::ts('Entity Table'),
'required' => TRUE,
'maxlength' => 64,
'size' => CRM_Utils_Type::BIG,
......@@ -202,7 +201,7 @@ class CRM_CiviDiscount_DAO_Track extends CRM_Core_DAO {
'description' => array(
'name' => 'description',
'type' => CRM_Utils_Type::T_TEXT,
'title' => ts('Description'),
'title' => E::ts('Description'),
),
);
}
......
......@@ -56,17 +56,17 @@ class CRM_CiviDiscount_Form_Admin extends CRM_Admin_Form {
// check and ensure that update / delete have a valid id
if ($this->_action & (CRM_Core_Action::UPDATE | CRM_Core_Action::DELETE)) {
if (!CRM_Utils_Rule::positiveInteger($this->_id)) {
CRM_Core_Error::fatal(ts('We need a valid discount ID for update and/or delete'));
CRM_Core_Error::fatal('We need a valid discount ID for update and/or delete');
}
}
if ($this->_action & CRM_Core_Action::COPY) {
if (!CRM_Utils_Rule::positiveInteger($this->_cloneID)) {
CRM_Core_Error::fatal(ts('We need a valid discount ID for update and/or delete'));
CRM_Core_Error::fatal('We need a valid discount ID for update and/or delete');
}
}
CRM_Utils_System::setTitle(ts('Discounts'));
CRM_Utils_System::setTitle(E::ts('Discounts'));
$this->_multiValued = array(
'memberships' => NULL,
......@@ -211,7 +211,7 @@ class CRM_CiviDiscount_Form_Admin extends CRM_Admin_Form {
$events = CRM_CiviDiscount_Utils::getEvents();
if (!empty($events)) {
$events = array(ts('--any event--')) + $events;
$events = array(E::ts('--any event--')) + $events;
$this->_multiValued['events'] = $events;
$this->add('select',
'events',
......@@ -265,7 +265,7 @@ class CRM_CiviDiscount_Form_Admin extends CRM_Admin_Form {
);
$assignedAutoFilters[] = $autoFilter['form_field_name'];
if (!empty($autoFilter['rule_data_type'])) {
$this->addRule($autoFilter['form_field_name'], E::ts('Please re-enter ' . $autoFilter['title'] . ' you need to enter an ' . $autoFilter['rule_data_type']), $autoFilter['rule_data_type']);
$this->addRule($autoFilter['form_field_name'], E::ts('Please re-enter %1, a %2 is required.', [1 => $autoFilter['title'], 2 => $autoFilter['rule_data_type']]), $autoFilter['rule_data_type']);
}
}
}
......@@ -281,7 +281,7 @@ class CRM_CiviDiscount_Form_Admin extends CRM_Admin_Form {
public function postProcess() {
if ($this->_action & CRM_Core_Action::DELETE) {
CRM_CiviDiscount_BAO_Item::del($this->_id);
CRM_Core_Session::setStatus(ts('Selected Discount has been deleted.'), E::ts('Deleted'), 'success');
CRM_Core_Session::setStatus(E::ts('Selected Discount has been deleted.'), E::ts('Deleted'), 'success');
return;
}
......@@ -289,7 +289,7 @@ class CRM_CiviDiscount_Form_Admin extends CRM_Admin_Form {
$params = $this->exportValues();
$newCode = CRM_CiviDiscount_Utils::randomString('abcdefghjklmnpqrstwxyz23456789', 8);
CRM_CiviDiscount_BAO_Item::copy($this->_cloneID, $params, $newCode);
CRM_Core_Session::setStatus(ts('Selected Discount has been duplicated.'), E::ts('Copied'), 'success');
CRM_Core_Session::setStatus(E::ts('Selected Discount has been duplicated.'), E::ts('Saved'), 'success');
return;
}
......@@ -303,7 +303,7 @@ class CRM_CiviDiscount_Form_Admin extends CRM_Admin_Form {
$params['multi_valued'] = $this->_multiValued;
if (isset($params['events']) && in_array(0, $params['events']) && count($params['events']) > 1) {
CRM_Core_Session::setStatus(ts('You selected `any event` and specific events, specific events have been unset'));
CRM_Core_Session::setStatus(E::ts('The events you selected will be ignored because you also chose "any event."'));
$params['events'] = array(0);
}
if (!empty($params['autodiscount_membership_type_id']) && count($params['autodiscount_membership_status_id']) == 0) {
......@@ -316,8 +316,8 @@ class CRM_CiviDiscount_Form_Admin extends CRM_Admin_Form {
}
$item = CRM_CiviDiscount_BAO_Item::add($params);
CRM_Core_Session::setStatus(ts('The discount \'%1\' has been saved.',
array(1 => $item->description ? $item->description : $item->code)), E::ts('Saved'), 'success');
CRM_Core_Session::setStatus(E::ts('The discount "%1" has been saved.',
[1 => $item->description ?: $item->code]), E::ts('Saved'), 'success');
}
/**
......@@ -330,9 +330,10 @@ class CRM_CiviDiscount_Form_Admin extends CRM_Admin_Form {
* @throws \CRM_Core_Exception
*/
private function addAdvancedFilterToAutodiscount(&$params, $discountEntity, $discountString) {
$discounts = [];
if ($discountString) {
if (stristr($discountString, 'api.') || stristr($discountString, 'api_')) {
throw new CRM_Core_Exception(ts('You cannot nest apis in the advanced filter'));
throw new CRM_Core_Exception(E::ts('You cannot nest apis in the advanced filter'));
}
if (stristr($discountString, '{')) {
$discounts = json_decode($discountString, TRUE);
......@@ -341,7 +342,7 @@ class CRM_CiviDiscount_Form_Admin extends CRM_Admin_Form {
$discounts = explode(',', $discountString);
foreach ($discounts as $id => $discount) {
if (!stristr($discount, '=')) {
throw new CRM_Core_Exception(ts('You have a criteria without an = sign'));
throw new CRM_Core_Exception(E::ts('You have a criteria without an = sign'));
}
$parts = explode('=', $discount);
$discounts[$parts[0]] = $parts[1];
......@@ -405,7 +406,7 @@ class CRM_CiviDiscount_Form_Admin extends CRM_Admin_Form {
/**
* Convert handling of age fields to api-acceptable 'birth_date_high' & birth_date_low
* @param unknown $fields
* @param array $fields
*/
function adjustAgeFields(&$fields) {
if (!empty($fields['contact'])) {
......@@ -436,7 +437,7 @@ class CRM_CiviDiscount_Form_Admin extends CRM_Admin_Form {
if (empty($status)) {
$fields['membership']['active_only'] = 1;
if (count($fields['membership']['status_id']['IN']) > 1) {
CRM_Core_Session::setStatus(ts('You set "any current status" and specific statuses, specific statuses have been discarded'));
CRM_Core_Session::setStatus(E::ts('The statuses you selected will be ignored because you also chose "any current status."'));
}
unset($fields['membership']['status_id']);
continue;
......@@ -565,6 +566,7 @@ class CRM_CiviDiscount_Form_Admin extends CRM_Admin_Form {
* @param string $fieldName
* @param array $values
* @param null $spec
* @return string
*/
function setMembershipStatusDefaults(&$defaults, $fieldName, $values, $spec) {
if (!empty($values['membership']['active_only'])) {
......
......@@ -29,7 +29,6 @@
* @package CiviDiscount
*/
require_once 'CRM/CiviDiscount/DAO/Item.php';
use CRM_CiviDiscount_ExtensionUtil as E;
/**
......
......@@ -29,7 +29,7 @@
* @package CiviDiscount
*/
require_once 'CRM/CiviDiscount/DAO/Item.php';
use CRM_CiviDiscount_ExtensionUtil as E;
/**
* Page for displaying discount code details
......@@ -70,26 +70,26 @@ class CRM_CiviDiscount_Page_Report extends CRM_Core_Page {
if (!(self::$_links)) {
self::$_links = array(
CRM_Core_Action::UPDATE => array(
'name' => ts('Edit'),
'name' => E::ts('Edit'),
'url' => 'civicrm/cividiscount/discount/edit',
'qs' => '&id=%%id%%&reset=1',
'title' => ts('Edit Discount')
'title' => E::ts('Edit Discount')
),
CRM_Core_Action::DISABLE => array(
'name' => ts('Disable'),
'name' => E::ts('Disable'),
'class' => 'crm-enable-disable',
'title' => ts('Disable Discount')
'title' => E::ts('Disable Discount')
),
CRM_Core_Action::ENABLE => array(
'name' => ts('Enable'),
'name' => E::ts('Enable'),
'class' => 'crm-enable-disable',
'title' => ts('Enable Discount')
'title' => E::ts('Enable Discount')
),
CRM_Core_Action::DELETE => array(
'name' => ts('Delete'),
'name' => E::ts('Delete'),
'url' => 'civicrm/cividiscount/discount/delete',
'qs' => '&id=%%id%%',
'title' => ts('Delete Discount')
'title' => E::ts('Delete Discount')
)
);
}
......@@ -126,19 +126,16 @@ class CRM_CiviDiscount_Page_Report extends CRM_Core_Page {
function preProcess() {
$this->_id = CRM_Utils_Request::retrieve('id', 'Positive', $this, FALSE);
require_once 'CRM/Utils/Rule.php';
if (!CRM_Utils_Rule::positiveInteger($this->_id)) {
CRM_Core_Error::fatal(ts('We need a valid discount ID for view'));
CRM_Core_Error::fatal('We need a valid discount ID for view');
}
$this->assign('id', $this->_id);
$defaults = array();
$params = array('id' => $this->_id);
require_once 'CRM/CiviDiscount/BAO/Item.php';
CRM_CiviDiscount_BAO_Item::retrieve($params, $defaults);
require_once 'CRM/CiviDiscount/BAO/Track.php';
$rows = CRM_CiviDiscount_BAO_Track::getUsageByCode($this->_id);
$this->assign('rows', $rows);
......
......@@ -29,7 +29,6 @@
* @package CiviDiscount
*/
require_once 'CRM/CiviDiscount/DAO/Item.php';
/**
* Page for displaying discount code details
......@@ -63,10 +62,8 @@ class CRM_CiviDiscount_Page_Usage extends CRM_Core_Page {
$defaults = array();
$params = array('id' => $this->_id);
require_once 'CRM/CiviDiscount/BAO/Item.php';
CRM_CiviDiscount_BAO_Item::retrieve($params, $defaults);
require_once 'CRM/CiviDiscount/BAO/Track.php';
if ($cid) {
$rows = CRM_CiviDiscount_BAO_Track::getUsageByContact($this->_id);
}
......
......@@ -29,7 +29,6 @@
* @package CiviDiscount
*/
require_once 'CRM/CiviDiscount/DAO/Item.php';
use CRM_CiviDiscount_ExtensionUtil as E;
/**
......@@ -127,7 +126,6 @@ class CRM_CiviDiscount_Page_View extends CRM_Core_Page {
function preProcess() {
$this->_id = CRM_Utils_Request::retrieve('id', 'Positive', $this, FALSE);
require_once 'CRM/Utils/Rule.php';
if (!CRM_Utils_Rule::positiveInteger($this->_id)) {
CRM_Core_Error::fatal(ts('We need a valid discount ID for view'));
}
......@@ -136,7 +134,6 @@ class CRM_CiviDiscount_Page_View extends CRM_Core_Page {
$defaults = array();
$params = array('id' => $this->_id);
require_once 'CRM/CiviDiscount/BAO/Item.php';
CRM_CiviDiscount_BAO_Item::retrieve($params, $defaults);
$this->assign('code_id', $defaults['id']);
......@@ -158,7 +155,6 @@ class CRM_CiviDiscount_Page_View extends CRM_Core_Page {
if (array_key_exists('organization_id', $defaults)) {
$this->assign('organization_id', $defaults['organization_id']);
require_once 'CRM/Contact/BAO/Contact.php';
$orgname = CRM_Contact_BAO_Contact::displayName($defaults['organization_id']);
$this->assign('organization', $orgname);
}
......@@ -184,9 +180,6 @@ class CRM_CiviDiscount_Page_View extends CRM_Core_Page {
}
}
require_once 'CRM/CiviDiscount/Utils.php';
require_once 'CRM/Member/BAO/MembershipType.php';
if (array_key_exists('events', $defaults)) {
$events = CRM_CiviDiscount_Utils::getEvents();
$defaults['events'] = CRM_CiviDiscount_Utils::getIdsTitles($defaults['events'], $events);
......
......@@ -12,15 +12,31 @@ class CRM_CiviDiscount_Upgrader extends CRM_CiviDiscount_Upgrader_Base {
*
*/
public function upgrade_2201() {
$this->ctx->log->info('Applying update 2201');
CRM_Core_DAO::executeQuery('ALTER TABLE cividiscount_item ADD COLUMN discount_msg_enabled TINYINT(1) DEFAULT 0 AFTER is_active');
CRM_Core_DAO::executeQuery('ALTER TABLE cividiscount_item ADD COLUMN discount_msg VARCHAR(255) AFTER discount_msg_enabled');
if (CRM_Core_BAO_SchemaHandler::checkIfFieldExists('cividiscount_item', 'discount_msg_enabled')) {
$this->ctx->log->info('Skipped cividiscount update 2201. Column discount_msg_enabled already present on cividiscount_item table.');
}
else {
$this->ctx->log->info('Applying cividiscount update 2201. Adding discount_msg_enabled to the cividiscount_item table.');
CRM_Core_DAO::executeQuery('ALTER TABLE cividiscount_item ADD COLUMN discount_msg_enabled TINYINT(1) DEFAULT 0 AFTER is_active');
}
if (CRM_Core_BAO_SchemaHandler::checkIfFieldExists('cividiscount_item', 'discount_msg')) {
$this->ctx->log->info('Skipped cividiscount update 2201. Column discount_msg already present on cividiscount_item table.');
}
else {
$this->ctx->log->info('Applying cividiscount update 2201. Adding discount_msg to the cividiscount_item table.');
CRM_Core_DAO::executeQuery('ALTER TABLE cividiscount_item ADD COLUMN discount_msg VARCHAR(255) AFTER discount_msg_enabled');
}
return TRUE;
}
public function upgrade_2202() {
$this->ctx->log->info('Applying update 2202');
CRM_Core_DAO::executeQuery('ALTER TABLE cividiscount_item ADD COLUMN filters VARCHAR(255)');
if (CRM_Core_BAO_SchemaHandler::checkIfFieldExists('cividiscount_item', 'filters')) {
$this->ctx->log->info('Skipped cividiscount update 2202. Column filters already present on cividiscount_item table.');
}
else {
$this->ctx->log->info('Applying cividiscount update 2202. Adding filters to the cividiscount_item table.');
CRM_Core_DAO::executeQuery('ALTER TABLE cividiscount_item ADD COLUMN filters VARCHAR(255)');
}
return TRUE;
}
......@@ -36,4 +52,4 @@ class CRM_CiviDiscount_Upgrader extends CRM_CiviDiscount_Upgrader_Base {
}
return TRUE;
}
}
}
\ No newline at end of file
......@@ -88,7 +88,6 @@ class CRM_CiviDiscount_Upgrader_Base {
* @return bool
*/
protected static function executeCustomDataFileByAbsPath($xml_file) {
require_once 'CRM/Utils/Migrate/Import.php';
$import = new CRM_Utils_Migrate_Import();
$import->run($xml_file);
return TRUE;
......
......@@ -16,6 +16,11 @@ will get an automatic discount if they meet other criteria above - ie a minimum
<img src='https://github.com/dlobo/org.civicrm.module.cividiscount/blob/master/docs/images/advancedFilters.jpg'>
DOCUMENTATION
--
View the [CiviDiscount documentation](https://docs.civicrm.org/discount/en/latest/) on https://docs.civicrm.org.
NEEDED
--
......
......@@ -71,30 +71,31 @@ function cividiscount_civicrm_managed(&$entities) {
}
/**
* Implementation of hook_civicrm_tabs()
* Implementation of hook_civicrm_tabset()
*
* Display a discounts tab listing discount code usage for that contact.
*/
function cividiscount_civicrm_tabs(&$tabs, $cid) {
if (_cividiscount_is_org($cid)) {
$count = _cividiscount_get_tracking_count_by_org($cid);
function cividiscount_civicrm_tabset($path, &$tabs, $context) {
if ($path === 'civicrm/contact/view') {
$cid = $context['contact_id'];
if (_cividiscount_is_org($cid)) {
$tabs[] = array(
'id' => 'discounts_assigned',
'count' => _cividiscount_get_tracking_count_by_org($cid),
'title' => E::ts('Codes Assigned'),
'weight' => 115,
'url' => CRM_Utils_System::url('civicrm/cividiscount/usage', "reset=1&oid={$cid}", FALSE, NULL, FALSE),
);
}
$tabs[] = array(
'id' => 'discounts',
'count' => $count,
'title' => E::ts('Codes Assigned'),
'weight' => '98',
'url' => CRM_Utils_System::url('civicrm/cividiscount/usage', "reset=1&oid={$cid}", false, null, false),
'count' => _cividiscount_get_tracking_count($cid),
'title' => E::ts('Codes Redeemed'),
'weight' => 116,
'url' => CRM_Utils_System::url('civicrm/cividiscount/usage', "reset=1&cid={$cid}", FALSE, NULL, FALSE),
);
}
$count = _cividiscount_get_tracking_count($cid);
$tabs[] = array(
'id' => 'discounts',
'count' => $count,
'title' => E::ts('Codes Redeemed'),
'weight' => '99',
'url' => CRM_Utils_System::url('civicrm/cividiscount/usage', "reset=1&cid={$cid}", false, null, false),
);
}
/**
......@@ -1156,7 +1157,7 @@ function cividiscount_civicrm_navigationMenu( &$params ) {
}
foreach (array('Events', 'Contributions') as $header) {
_cividiscount_civix_insert_navigation_menu($params, $header, array(
'label' => ts('CiviDiscount', array('domain' => 'org.civicrm.module.cividiscount')),
'label' => E::ts('CiviDiscount'),
'name' => 'CiviDiscount',
'url' => 'civicrm/cividiscount',
'permission' => 'administer CiviCRM,administer CiviDiscount',
......@@ -1185,6 +1186,6 @@ function cividiscount_civicrm_entityTypes(&$entityTypes) {
function cividiscount_civicrm_permission(&$permissions) {
$permissions += array(
'administer CiviDiscount' => ts('administer CiviDiscount', array('domain' => 'org.civicrm.module.cividiscount')),
'administer CiviDiscount' => E::ts('administer CiviDiscount'),
);
}
# Installation
# Installation and Configuration
## Installation
Use the following steps to install CiviDiscount.
* **Administer > System Settings > Extensions**
* **Administer** > **System Settings** > **Extensions**
* **Add New**
* Find, download, and install CiviDiscount
To access the CiviDiscount dashboard to setup and manage codes go to **Administer > CiviDiscount**.
\ No newline at end of file
You can view this extension in the [Extension Directory](https://civicrm.org/extensions/cividiscount).
## Configuration
To access the CiviDiscount dashboard to set up and manage codes go to **Administer** > **CiviDiscount**.
......@@ -18,8 +18,8 @@
<author>CiviCRM LLC</author>
<email>info@civicrm.org</email>
</maintainer>
<releaseDate>2018-07-30</releaseDate>
<version>3.5</version>
<releaseDate>2018-10-21</releaseDate>
<version>3.6</version>
<compatibility>
<ver>5.3</ver>
</compatibility>
......
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