Newer
Older
<?php
/**
* Copyright Maarch since 2008 under licence GPLv3.
* See LICENCE.txt file at the root folder for more details.
* This file is part of Maarch software.
* @brief ActionController
* @author dev <dev@maarch.org>
* @ingroup core
*/
namespace Action\controllers;
use History\controllers\HistoryController;
use Resource\models\ResModel;
use Action\models\ActionModel;
use SrcCore\models\ValidatorModel;
class ActionMethodController
{
const COMPONENTS_ACTIONS = [
'confirmAction' => null,
'closeMailAction' => 'closeMailAction',
'updateDepartureDateAction' => 'updateDepartureDateAction',
];
public static function terminateAction(array $aArgs)
{
ValidatorModel::notEmpty($aArgs, ['id', 'resources', 'basketName']);
ValidatorModel::intVal($aArgs, ['id']);
ValidatorModel::arrayType($aArgs, ['resources']);
ValidatorModel::stringType($aArgs, ['basketName', 'note']);
$set = ['locker_user_id' => null, 'locker_time' => null, 'modification_date' => 'CURRENT_TIMESTAMP'];
$action = ActionModel::getById(['id' => $aArgs['id'], 'select' => ['label_action', 'id_status', 'history']]);
if (!empty($action['id_status']) && $action['id_status'] != '_NOSTATUS_') {
$set['status'] = $action['id_status'];
}
ResModel::update([
'set' => $set,
'where' => ['res_id in (?)'],
'data' => [$aArgs['resources']]
if (!empty($aArgs['note'])) {
foreach ($aArgs['resources'] as $resource) {
NoteModel::create([
'resId' => $resource,
'login' => $GLOBALS['userId'],
'note_text' => $aArgs['note']
]);
}
}
foreach ($aArgs['resources'] as $resource) {
HistoryController::add([
'recordId' => $resource,
'eventType' => 'ACTION#' . $resource,
'eventId' => $aArgs['id'],
'info' => "{$aArgs['basketName']} : {$action['label_action']}"
public static function closeMailAction(array $aArgs)
{
ValidatorModel::notEmpty($aArgs, ['resId']);
ValidatorModel::intVal($aArgs, ['resId']);
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
ResModel::updateExt(['set' => ['closing_date' => 'CURRENT_TIMESTAMP'], 'where' => ['res_id = ?'], 'data' => [$aArgs['resId']]]);
if (CurlModel::isEnabled(['curlCallId' => 'closeResource'])) {
$bodyData = [];
$config = CurlModel::getConfigByCallId(['curlCallId' => 'closeResource']);
$configResource = CurlModel::getConfigByCallId(['curlCallId' => 'sendResourceToExternalApplication']);
$resource = ResModel::getOnView(['select' => ['doc_' . $configResource['return']['value']], 'where' => ['res_id = ?'], 'data' => [$aArgs['resId']]]);
if (!empty($resource[0]['doc_' . $configResource['return']['value']])) {
if (!empty($config['inObject'])) {
$multipleObject = true;
foreach ($config['objects'] as $object) {
$select = [];
$tmpBodyData = [];
foreach ($object['rawData'] as $value) {
if ($value == $configResource['return']['value']) {
$select[] = 'doc_' . $configResource['return']['value'];
} elseif ($value != 'note') {
$select[] = $value;
}
}
$document = ResModel::getOnView(['select' => $select, 'where' => ['res_id = ?'], 'data' => [$aArgs['resId']]]);
if (!empty($document[0])) {
foreach ($object['rawData'] as $key => $value) {
if ($value == 'note') {
$tmpBodyData[$key] = $formValues['note_content_to_users'];
} elseif ($value == $configResource['return']['value']) {
$tmpBodyData[$key] = $document[0]['doc_' . $value];
} else {
$tmpBodyData[$key] = $document[0][$value];
}
}
}
if (!empty($object['data'])) {
$tmpBodyData = array_merge($tmpBodyData, $object['data']);
}
$bodyData[$object['name']] = $tmpBodyData;
}
} else {
$multipleObject = false;
$select = [];
foreach ($config['rawData'] as $value) {
if ($value != 'note') {
$select[] = $value;
}
}
$document = ResModel::getOnView(['select' => $select, 'where' => ['res_id = ?'], 'data' => [$aArgs['resId']]]);
if (!empty($document[0])) {
foreach ($config['rawData'] as $key => $value) {
if ($value == 'note') {
$bodyData[$key] = $formValues['note_content_to_users'];
} else {
$bodyData[$key] = $document[0][$value];
}
}
}
if (!empty($config['data'])) {
$bodyData = array_merge($bodyData, $config['data']);
}
}
CurlModel::exec(['curlCallId' => 'closeResource', 'bodyData' => $bodyData, 'multipleObject' => $multipleObject, 'noAuth' => true]);
}
}
return true;
}
public static function updateDepartureDateAction(array $aArgs)
{
ValidatorModel::notEmpty($aArgs, ['resId']);
ValidatorModel::intVal($aArgs, ['resId']);
ResModel::update(['set' => ['departure_date' => 'CURRENT_TIMESTAMP'], 'where' => ['res_id = ?', 'departure_date is null'], 'data' => [$aArgs['resId']]]);
return true;
}