Skip to content

Commit

Permalink
enhancement: implemented validity period support for promotions and p…
Browse files Browse the repository at this point in the history
…romotion schemas (promotion and schema managament part) (LMS+ #1981)
  • Loading branch information
chilek committed Oct 19, 2021
1 parent 0ef997f commit 5c384c8
Show file tree
Hide file tree
Showing 20 changed files with 730 additions and 531 deletions.
4 changes: 3 additions & 1 deletion doc/lms.mysql
Original file line number Diff line number Diff line change
Expand Up @@ -1124,6 +1124,8 @@ CREATE TABLE promotionschemas (
disabled tinyint(1) DEFAULT '0' NOT NULL,
deleted tinyint(1) DEFAULT 0 NOT NULL,
length tinyint(1) DEFAULT NULL,
datefrom int(11) DEFAULT 0 NOT NULL,
dateto int(11) DEFAULT 0 NOT NULL,
PRIMARY KEY (id),
UNIQUE KEY promotionid (promotionid, name),
FOREIGN KEY (promotionid) REFERENCES promotions (id) ON DELETE CASCADE ON UPDATE CASCADE
Expand Down Expand Up @@ -4145,4 +4147,4 @@ INSERT INTO netdevicemodels (name, alternative_name, netdeviceproducerid) VALUES
('XR7', 'XR7 MINI PCI PCBA', 2),
('XR9', 'MINI PCI 600MW 900MHZ', 2);

INSERT INTO dbinfo (keytype, keyvalue) VALUES ('dbversion', '2021100500');
INSERT INTO dbinfo (keytype, keyvalue) VALUES ('dbversion', '2021101900');
4 changes: 3 additions & 1 deletion doc/lms.pgsql
Original file line number Diff line number Diff line change
Expand Up @@ -980,6 +980,8 @@ CREATE TABLE promotionschemas (
disabled smallint DEFAULT 0 NOT NULL,
deleted smallint DEFAULT 0 NOT NULL,
length smallint DEFAULT NULL,
datefrom integer DEFAULT 0 NOT NULL,
dateto integer DEFAULT 0 NOT NULL,
PRIMARY KEY (id),
CONSTRAINT promotionschemas_promotionid_key UNIQUE (promotionid, name)
);
Expand Down Expand Up @@ -4162,6 +4164,6 @@ INSERT INTO netdevicemodels (name, alternative_name, netdeviceproducerid) VALUES
('XR7', 'XR7 MINI PCI PCBA', 2),
('XR9', 'MINI PCI 600MW 900MHZ', 2);

INSERT INTO dbinfo (keytype, keyvalue) VALUES ('dbversion', '2021100500');
INSERT INTO dbinfo (keytype, keyvalue) VALUES ('dbversion', '2021101900');

COMMIT;
2 changes: 1 addition & 1 deletion lib/LMSDB_common.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
* $Id$
*/

define('DBVERSION', '2021100500'); // here should be always the newest version of database!
define('DBVERSION', '2021101900'); // here should be always the newest version of database!

/**
*
Expand Down
1 change: 1 addition & 0 deletions lib/locale/pl_PL/strings.php
Original file line number Diff line number Diff line change
Expand Up @@ -3301,6 +3301,7 @@
$_LANG['New Promotion'] = 'Nowa promocja';
$_LANG['New Schema'] = 'Nowy schemat';
$_LANG['Periods:'] = 'Okresy:';
$_LANG['Periods'] = 'Okresy';
$_LANG['Promotion:'] = 'Promocja:';
$_LANG['Promotions'] = 'Promocje';
$_LANG['Promotions:'] = 'Promocje:';
Expand Down
31 changes: 31 additions & 0 deletions lib/upgradedb/mysql.2021101900.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

/*
* LMS version 1.11-git
*
* (C) Copyright 2001-2021 LMS Developers
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License Version 2 as
* published by the Free Software Foundation.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
* USA.
*
*/

$this->BeginTrans();

$this->Execute("ALTER TABLE promotionschemas ADD COLUMN datefrom int(11) DEFAULT 0 NOT NULL");
$this->Execute("ALTER TABLE promotionschemas ADD COLUMN dateto int(11) DEFAULT 0 NOT NULL");

$this->Execute("UPDATE dbinfo SET keyvalue = ? WHERE keytype = ?", array('2021101900', 'dbversion'));

$this->CommitTrans();
33 changes: 33 additions & 0 deletions lib/upgradedb/postgres.2021101900.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

/*
* LMS version 1.11-git
*
* (C) Copyright 2001-2021 LMS Developers
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License Version 2 as
* published by the Free Software Foundation.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
* USA.
*
*/

$this->BeginTrans();

$this->Execute("
ALTER TABLE promotionschemas ADD COLUMN datefrom integer DEFAULT 0 NOT NULL;
ALTER TABLE promotionschemas ADD COLUMN dateto integer DEFAULT 0 NOT NULL
");

$this->Execute("UPDATE dbinfo SET keyvalue = ? WHERE keytype = ?", array('2021101900', 'dbversion'));

$this->CommitTrans();
28 changes: 5 additions & 23 deletions modules/promotionadd.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/*
* LMS version 1.11-git
*
* (C) Copyright 2001-2016 LMS Developers
* (C) Copyright 2001-2021 LMS Developers
*
* Please, see the doc/AUTHORS for more information about authors!
*
Expand Down Expand Up @@ -41,34 +41,16 @@
$error['name'] = trans('Specified name is in use!');
}

if (empty($promotion['datefrom'])) {
$promotion['from'] = 0;
} else {
$from = date_to_timestamp($promotion['datefrom']);
if (empty($from)) {
$error['datefrom'] = trans('Incorrect effective start time!');
}
}

if (empty($promotion['dateto'])) {
$promotion['to'] = 0;
} else {
$to = date_to_timestamp($promotion['dateto']);
if (empty($to)) {
$error['dateto'] = trans('Incorrect effective start time!');
}
}

if ($promotion['to'] != 0 && $promotion['from'] != 0 && $to < $from) {
$error['dateto'] = trans('Incorrect date range!');
if (!empty($promotion['dateto']) && !empty($promotion['datefrom']) && $promotion['dateto'] < $promotion['from']) {
$error['dateto'] = trans('Incorrect date range!');
}

if (!$error) {
$args = array(
'name' => $promotion['name'],
'description' => $promotion['description'],
'datefrom' => $promotion['from'],
'dateto' => $promotion['to'],
'datefrom' => $promotion['datefrom'] ?: 0,
'dateto' => $promotion['dateto'] ? strtotime('tomorrow', $promotion['dateto']) - 1 : 0,
);
$DB->Execute('INSERT INTO promotions (name, description, datefrom, dateto)
VALUES (?, ?, ?, ?)', array_values($args));
Expand Down
42 changes: 10 additions & 32 deletions modules/promotionedit.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/*
* LMS version 1.11-git
*
* (C) Copyright 2001-2016 LMS Developers
* (C) Copyright 2001-2021 LMS Developers
*
* Please, see the doc/AUTHORS for more information about authors!
*
Expand Down Expand Up @@ -88,38 +88,24 @@
$promotion['name'] = $oldpromotion['name'];
}

if (empty($promotion['datefrom'])) {
$promotion['from'] = 0;
} else {
$from = date_to_timestamp($promotion['datefrom']);
if (empty($from)) {
$error['datefrom'] = trans('Incorrect effective start time!');
}
}

if (empty($promotion['dateto'])) {
$promotion['to'] = 0;
} else {
$to = date_to_timestamp($promotion['dateto']);
if (empty($to)) {
$error['dateto'] = trans('Incorrect effective start time!');
}
}

if ($promotion['to'] != 0 && $promotion['from'] != 0 && $to < $from) {
if (!empty($promotion['dateto']) && !empty($promotion['datefrom']) && $promotion['dateto'] < $promotion['datefrom']) {
$error['dateto'] = trans('Incorrect date range!');
}

if (!$error && !$warning) {
$args = array(
'name' => $promotion['name'],
'description' => $promotion['description'],
'datefrom' => $promotion['from'],
'dateto' => $promotion['to'],
'datefrom' => $promotion['datefrom'] ?: 0,
'dateto' => $promotion['dateto'] ? strtotime('tomorrow', $promotion['dateto']) - 1 : 0,
SYSLOG::RES_PROMO => $promotion['id']
);
$DB->Execute('UPDATE promotions SET name = ?, description = ?, datefrom = ?, dateto = ?
WHERE id = ?', array_values($args));
$DB->Execute(
'UPDATE promotions
SET name = ?, description = ?, datefrom = ?, dateto = ?
WHERE id = ?',
array_values($args)
);

if ($SYSLOG) {
$SYSLOG->AddMessage(SYSLOG::RES_PROMO, SYSLOG::OPER_UPDATE, $args);
Expand All @@ -129,14 +115,6 @@
}
} else {
$promotion = $LMS->getPromotion($promotionid);

if ($promotion['datefrom']) {
$promotion['datefrom'] = date('Y/m/d', $promotion['datefrom']);
}

if ($promotion['dateto']) {
$promotion['dateto'] = date('Y/m/d', $promotion['dateto']);
}
}

$layout['pagetitle'] = trans('Promotion Edit: $a', $promotion['name']);
Expand Down
2 changes: 1 addition & 1 deletion modules/promotioninfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@

$promotion['schemas'] = $DB->GetAllByKey(
'SELECT
s.name, s.disabled, s.description, s.id, s.deleted,
s.name, s.disabled, s.description, s.id, s.deleted, s.datefrom, s.dateto,
COUNT(a.id) AS assignments
FROM promotionschemas s
LEFT JOIN assignments a ON a.promotionschemaid = s.id
Expand Down
12 changes: 9 additions & 3 deletions modules/promotionschemaadd.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/*
* LMS version 1.11-git
*
* (C) Copyright 2001-2016 LMS Developers
* (C) Copyright 2001-2021 LMS Developers
*
* Please, see the doc/AUTHORS for more information about authors!
*
Expand Down Expand Up @@ -46,6 +46,10 @@
$error['name'] = trans('Specified name is in use!');
}

if (!empty($schema['dateto']) && !empty($schema['datefrom']) && $schema['dateto'] < $schema['datefrom']) {
$error['dateto'] = trans('Incorrect date range!');
}

if (!$error) {
$length = 0;
$data = array();
Expand All @@ -65,10 +69,12 @@
'description' => $schema['description'],
'data' => $data,
'length' => $length,
'datefrom' => $schema['datefrom'] ?: 0,
'dateto' => $schema['dateto'] ? strtotime('tomorrow', $schema['dateto']) - 1 : 0,
);
$DB->Execute('INSERT INTO promotionschemas (promotionid, name,
description, data, length)
VALUES (?, ?, ?, ?, ?)', array_values($args));
description, data, length, datefrom, dateto)
VALUES (?, ?, ?, ?, ?, ?, ?)', array_values($args));

$sid = $DB->GetLastInsertId('promotionschemas');

Expand Down
16 changes: 13 additions & 3 deletions modules/promotionschemaedit.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/*
* LMS version 1.11-git
*
* (C) Copyright 2001-2020 LMS Developers
* (C) Copyright 2001-2021 LMS Developers
*
* Please, see the doc/AUTHORS for more information about authors!
*
Expand Down Expand Up @@ -291,6 +291,10 @@
}
}

if (!empty($schema['dateto']) && !empty($schema['datefrom']) && $schema['dateto'] < $schema['datefrom']) {
$error['dateto'] = trans('Incorrect date range!');
}

if (!$error && !$warning) {
$DB->BeginTrans();

Expand All @@ -299,10 +303,16 @@
'description' => $schema['description'],
'data' => empty($oldschema['assignmentcount']) || ConfigHelper::checkPrivilege('superuser') ? implode(';', $data) : $oldschema['data'],
'length' => $length,
'datefrom' => $schema['datefrom'] ?: 0,
'dateto' => $schema['dateto'] ? strtotime('tomorrow', $schema['dateto']) - 1 : 0,
SYSLOG::RES_PROMOSCHEMA => $schema['id'],
);
$DB->Execute('UPDATE promotionschemas SET name = ?, description = ?, data = ?, length = ?
WHERE id = ?', array_values($args));
$DB->Execute(
'UPDATE promotionschemas
SET name = ?, description = ?, data = ?, length = ?, datefrom = ?, dateto = ?
WHERE id = ?',
array_values($args)
);

if ($SYSLOG) {
$args[SYSLOG::RES_PROMO] = $oldschema['promotionid'];
Expand Down
2 changes: 1 addition & 1 deletion modules/promotionschemainfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

$schema = $DB->GetRow(
'SELECT
s.id, s.name, s.description, s.data, s.disabled, s.deleted, s.length,
s.id, s.name, s.description, s.data, s.disabled, s.deleted, s.length, s.datefrom, s.dateto,
p.id AS pid, p.name AS promotion,
COUNT(a.id) AS assignments
FROM promotionschemas s
Expand Down
Loading

0 comments on commit 5c384c8

Please sign in to comment.