Start working on adding locations to service messages
This commit is contained in:
parent
f5ff322c33
commit
d04b40c925
@ -30,4 +30,7 @@ class ServiceMessage extends \BaseClass {
|
||||
|
||||
/* @var $icon string */
|
||||
public $icon;
|
||||
|
||||
/* @var $locations string[] */
|
||||
public $locations;
|
||||
}
|
||||
@ -130,6 +130,17 @@ class ServiceMessageHandler extends \BaseClass {
|
||||
} catch (\Exception $e) {
|
||||
$validationModel->errorKeys[] = 'INVALID_STYLE';
|
||||
}
|
||||
if ($serviceMessage->locations === null || count($serviceMessage->locations) === 0) {
|
||||
$validationModel->errorKeys[] = 'MISSING_LOCATIONS';
|
||||
} else {
|
||||
$locations = ServiceMessageLocation::getAll();
|
||||
foreach ($serviceMessage->locations as $location) {
|
||||
if (!in_array($location, $locations)) {
|
||||
$validationModel->errorKeys[] = 'INVALID_LOCATION';
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (count($validationModel->errorKeys) > 0) {
|
||||
// Validation failed
|
||||
|
||||
34
api/BusinessLogic/ServiceMessages/ServiceMessageLocation.php
Normal file
34
api/BusinessLogic/ServiceMessages/ServiceMessageLocation.php
Normal file
@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace BusinessLogic\ServiceMessages;
|
||||
|
||||
|
||||
class ServiceMessageLocation {
|
||||
const CUSTOMER_HOME = 'CUSTOMER_HOME';
|
||||
const CUSTOMER_KB_HOME = 'CUSTOMER_KB_HOME';
|
||||
const CUSTOMER_VIEW_KB_ARTICLE = 'CUSTOMER_VIEW_KB_ARTICLE';
|
||||
const CUSTOMER_SUBMIT_TICKET = 'CUSTOMER_SUBMIT_TICKET';
|
||||
const CUSTOMER_VIEW_TICKET = 'CUSTOMER_VIEW_TICKET';
|
||||
const STAFF_LOGIN = 'STAFF_LOGIN';
|
||||
const STAFF_HOME = 'STAFF_HOME';
|
||||
const STAFF_KB_HOME = 'STAFF_KB_HOME';
|
||||
const STAFF_VIEW_KB_ARTICLE = 'STAFF_VIEW_KB_ARTICLE';
|
||||
const STAFF_SUBMIT_TICKET = 'STAFF_SUBMIT_TICKET';
|
||||
const STAFF_VIEW_TICKET = 'STAFF_VIEW_TICKET';
|
||||
|
||||
static function getAll() {
|
||||
return array(
|
||||
self::CUSTOMER_HOME,
|
||||
self::CUSTOMER_KB_HOME,
|
||||
self::CUSTOMER_VIEW_KB_ARTICLE,
|
||||
self::CUSTOMER_SUBMIT_TICKET,
|
||||
self::CUSTOMER_VIEW_TICKET,
|
||||
self::STAFF_LOGIN,
|
||||
self::STAFF_HOME,
|
||||
self::STAFF_KB_HOME,
|
||||
self::STAFF_VIEW_KB_ARTICLE,
|
||||
self::STAFF_SUBMIT_TICKET,
|
||||
self::STAFF_VIEW_TICKET,
|
||||
);
|
||||
}
|
||||
}
|
||||
@ -2,6 +2,7 @@
|
||||
|
||||
namespace Controllers\ServiceMessages;
|
||||
|
||||
use BusinessLogic\Helpers;
|
||||
use BusinessLogic\Security\UserContext;
|
||||
use BusinessLogic\ServiceMessages\ServiceMessage;
|
||||
use BusinessLogic\ServiceMessages\ServiceMessageHandler;
|
||||
@ -70,11 +71,19 @@ class ServiceMessagesController extends \BaseClass {
|
||||
$serviceMessage->createdBy = $userContext->id;
|
||||
}
|
||||
|
||||
$serviceMessage->title = $data['title'];
|
||||
$serviceMessage->icon = $data['icon'];
|
||||
$serviceMessage->message = $data['message'];
|
||||
$serviceMessage->published = $data['published'];
|
||||
$serviceMessage->style = $data['style'];
|
||||
$serviceMessage->title = Helpers::safeArrayGet($data, 'title');
|
||||
$serviceMessage->icon = Helpers::safeArrayGet($data, 'icon');
|
||||
$serviceMessage->message = Helpers::safeArrayGet($data, 'message');
|
||||
$serviceMessage->published = Helpers::safeArrayGet($data, 'published');
|
||||
$serviceMessage->style = Helpers::safeArrayGet($data, 'style');
|
||||
|
||||
$jsonLocations = Helpers::safeArrayGet($data, 'locations');
|
||||
|
||||
if ($jsonLocations !== null && !empty($jsonLocations)) {
|
||||
foreach ($jsonLocations as $key => $value) {
|
||||
$serviceMessage->locations[] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
return $serviceMessage;
|
||||
}
|
||||
|
||||
@ -36,6 +36,11 @@ class ServiceMessagesGateway extends CommonDao {
|
||||
|
||||
$serviceMessage->id = hesk_dbInsertID();
|
||||
|
||||
foreach ($serviceMessage->locations as $location) {
|
||||
hesk_dbQuery("INSERT INTO `" . hesk_dbEscape($heskSettings['db_pfix']) . "mfh_service_message_to_location`
|
||||
(`service_message_id`, `location`) VALUES (" . intval($serviceMessage->id) . ", '" . hesk_dbEscape($location) . "')");
|
||||
}
|
||||
|
||||
// Get the autogenerated fields
|
||||
$rs = hesk_dbQuery("SELECT `dt`, `order` FROM `" . hesk_dbEscape($heskSettings['db_pfix']) . "service_messages`
|
||||
WHERE `id` = " . intval($serviceMessage->id));
|
||||
@ -69,6 +74,14 @@ class ServiceMessagesGateway extends CommonDao {
|
||||
$serviceMessage->message = $row['message'];
|
||||
$serviceMessage->style = ServiceMessageStyle::getStyleById($row['style']);
|
||||
$serviceMessage->icon = $row['icon'];
|
||||
$serviceMessage->locations = array();
|
||||
|
||||
$locationsRs = hesk_dbQuery("SELECT `location` FROM `" . hesk_dbEscape($heskSettings['db_pfix']) . "mfh_service_message_to_location`
|
||||
WHERE `service_message_id` = " . intval($serviceMessage->id));
|
||||
while ($innerRow = hesk_dbFetchAssoc($locationsRs)) {
|
||||
$serviceMessage->locations[] = $innerRow['location'];
|
||||
}
|
||||
|
||||
$serviceMessages[] = $serviceMessage;
|
||||
}
|
||||
|
||||
@ -92,6 +105,13 @@ class ServiceMessagesGateway extends CommonDao {
|
||||
`order` = " . intval($serviceMessage->order) . "
|
||||
WHERE `id` = " . intval($serviceMessage->id));
|
||||
|
||||
hesk_dbQuery("DELETE FROM `" . hesk_dbEscape($heskSettings['db_pfix']) . "mfh_service_message_to_location`
|
||||
WHERE `service_message_id` = " . intval($serviceMessage->id));
|
||||
foreach ($serviceMessage->locations as $location) {
|
||||
hesk_dbQuery("INSERT INTO `" . hesk_dbEscape($heskSettings['db_pfix']) . "mfh_service_message_to_location`
|
||||
(`service_message_id`, `location`) VALUES (" . intval($serviceMessage->id) . ", '" . hesk_dbEscape($location) . "')");
|
||||
}
|
||||
|
||||
$otherFieldsRs = hesk_dbQuery("SELECT `dt`, `author`, `order` FROM `" . hesk_dbEscape($heskSettings['db_pfix']) . "service_messages`
|
||||
WHERE `id` = " . intval($serviceMessage->id));
|
||||
$otherFields = hesk_dbFetchAssoc($otherFieldsRs);
|
||||
@ -107,6 +127,9 @@ class ServiceMessagesGateway extends CommonDao {
|
||||
function deleteServiceMessage($id, $heskSettings) {
|
||||
$this->init();
|
||||
|
||||
hesk_dbQuery("DELETE FROM `" . hesk_dbEscape($heskSettings['db_pfix']) . "mfh_service_message_to_location`
|
||||
WHERE `service_message_id` = " . intval($id));
|
||||
|
||||
hesk_dbQuery("DELETE FROM `" . hesk_dbEscape($heskSettings['db_pfix']) . "service_messages`
|
||||
WHERE `id` = " . intval($id));
|
||||
|
||||
|
||||
@ -216,5 +216,7 @@ function getAllMigrations() {
|
||||
//3.2.1 - 3.2.2
|
||||
160 => new UpdateMigration('3.2.1', '3.2.0', 160),
|
||||
161 => new UpdateMigration('3.2.2', '3.2.1', 161),
|
||||
// 3.3.0
|
||||
162 => new \v330\CreateServiceMessageToLocationTable(162),
|
||||
);
|
||||
}
|
||||
@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
namespace v330;
|
||||
|
||||
|
||||
class CreateServiceMessageToLocationTable extends \AbstractUpdatableMigration {
|
||||
|
||||
function innerUp($hesk_settings) {
|
||||
$this->executeQuery("CREATE TABLE `" . hesk_dbEscape($hesk_settings['db_pfix']) . "mfh_service_message_to_location`
|
||||
(`service_message_id` INT NOT NULL, `location` VARCHAR(100) NOT NULL)");
|
||||
}
|
||||
|
||||
function innerDown($hesk_settings) {
|
||||
$this->executeQuery("DROP TABLE `" . hesk_dbEscape($hesk_settings['db_pfix']) . "mfh_service_message_to_location`");
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user