message.php 40 KB
Newer Older
Prosper De Laure's avatar
Prosper De Laure committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
<?php

/*
 * Copyright (C) 2015 Maarch
 *
 * This file is part of bundle medona.
 *
 * Bundle medona is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * Bundle medona 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 bundle medona.  If not, see <http://www.gnu.org/licenses/>.
 */

namespace ext\thirdPartyArchiving\presentation\maarchRM\Presenter\medona;

/**
 * Serializer html retentionRule
 *
 * @package RecordsManagement
 * @author  Maarch Prosper DE LAURE <prosper.delaure@maarch.com>
 */
class message
{

    use archiveDeliveryTrait,
        archiveDestructionTrait,
        archiveTransferTrait,
36
        archiveOutgoingTransferTrait,
Prosper De Laure's avatar
Prosper De Laure committed
37
38
39
40
41
42
43
44
45
46
        archiveAuthorizationTrait,
        archiveNotificationTrait,
        archiveRestitutionTrait,
        \presentation\maarchRM\Presenter\exceptions\exceptionTrait;

    public $view;
    public $sdoFactory;
    protected $json;
    protected $translator;

47
    protected $dashboardPresenter;
Cyril Vazquez's avatar
Cyril Vazquez committed
48
    protected $menu;
49

Prosper De Laure's avatar
Prosper De Laure committed
50
51
52
53
54
55
56
57
58
59
60
    /**
     * Constuctor of message html serializer
     * @param \dependency\html\Document                    $view       The view
     * @param \dependency\sdo\Factory                      $sdoFactory The SDO dependency
     * @param \dependency\json\JsonObject                  $json       The JSON dependency
     * @param \dependency\localisation\TranslatorInterface $translator The localisation dependency
     */
    public function __construct(
        \dependency\html\Document $view,
        \dependency\sdo\Factory $sdoFactory,
        \dependency\json\JsonObject $json,
61
        \dependency\localisation\TranslatorInterface $translator
Prosper De Laure's avatar
Prosper De Laure committed
62
63
64
65
66
67
68
69
70
    ) {
        $this->view = $view;
        $this->sdoFactory = $sdoFactory;

        $this->json = $json;
        $this->json->status = true;

        $this->translator = $translator;
        $this->translator->setCatalog('medona/messages');
Cyril Vazquez's avatar
Cyril Vazquez committed
71
        $this->menu = \laabs::configuration()['medona']['menu'];
72
73
74
75
76
77
78
79
80
81

        $this->dashboardPresenter = \laabs::newService('presentation/dashboard');
    }

    /**
     * Dashobord for messages
     */
    public function index()
    {
        $this->view->addContentFile("medona/message/menu.html");
82

83
84
85
86
87
88
89
90
91
        $menu = $this->dashboardPresenter->filterMenuAuth($this->menu);

        $this->view->translate();

        $this->view->setSource('medonaMenu', $menu);

        $this->view->merge();

        return $this->view->saveHtml();
Prosper De Laure's avatar
Prosper De Laure committed
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
    }

    /**
     * View message description
     * @param thirdPartyArchiving/message $message The message object
     *
     * @return string
     */
    public function read($message)
    {
        $this->view->addContentFile("medona/message/message.table.html");
        $this->view->translate();

        $this->view->setSource("message", $message);

        $this->view->merge();

        return $this->view->saveHtml();
    }

    /**
     * Initialise the history form
     */
    public function initHistoryForm()
    {
        $archivalAgreements = \laabs::callService('medona/archivalAgreement/readIndex');
        $currentService = \laabs::getToken("ORGANIZATION");
        $ownerOriginatorOrgs = [];
        $ownerDepositorOrgs = [];
        $ownerArchiverOrgs = [];

        if ($currentService) {
            $originators = \laabs::callService('organization/organization/readByrole_role_', 'originator');
            $depositors = \laabs::callService('organization/organization/readByrole_role_', 'depositor');
            $archivers = \laabs::callService('organization/organization/readByrole_role_', 'archiver');


Cyril Vazquez's avatar
Cyril Vazquez committed
129
            $owner = is_array($currentService->orgRoleCodes) && in_array('owner', $currentService->orgRoleCodes);
Prosper De Laure's avatar
Prosper De Laure committed
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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197

            foreach ($originators as $originator) {
                if (!isset($ownerOriginatorOrgs[(string) $originator->ownerOrgId])) {
                    $orgObject = \laabs::callService('organization/organization/read_orgId_', (string) $originator->ownerOrgId);

                    $ownerOriginatorOrgs[(string) $orgObject->orgId] = new \stdClass();
                    $ownerOriginatorOrgs[(string) $orgObject->orgId]->displayName = $orgObject->displayName;
                    $ownerOriginatorOrgs[(string) $orgObject->orgId]->originators = [];
                }

                $ownerOriginatorOrgs[(string) $orgObject->orgId]->originators[] = $originator;
            }
            foreach ($depositors as $depositor) {
                if (!isset($ownerDepositorOrgs[(string) $depositor->ownerOrgId])) {
                    $orgObject = \laabs::callService('organization/organization/read_orgId_', (string) $depositor->ownerOrgId);
                    $ownerDepositorOrgs[(string) $orgObject->orgId] = new \stdClass();
                    $ownerDepositorOrgs[(string) $orgObject->orgId]->displayName = $orgObject->displayName;
                    $ownerDepositorOrgs[(string) $orgObject->orgId]->depositors = [];
                }

                $ownerDepositorOrgs[(string) $orgObject->orgId]->depositors[] = $depositor ;
            }
            foreach ($archivers as $archiver) {
                if (!isset($ownerArchiverOrgs[(string) $archiver->ownerOrgId])) {
                    $orgObject = \laabs::callService('organization/organization/read_orgId_', (string) $archiver->ownerOrgId);
                    $ownerArchiverOrgs[(string) $orgObject->orgId] = new \stdClass();
                    $ownerArchiverOrgs[(string) $orgObject->orgId]->displayName = $orgObject->displayName;
                    $ownerArchiverOrgs[(string) $orgObject->orgId]->archivers = [];
                }

                $ownerArchiverOrgs[(string) $orgObject->orgId]->archivers[] = $archiver ;
            }
        }

        $this->view->setSource('archivalAgreements', $archivalAgreements);
        $this->view->setSource('ownerOriginatorOrgs', $ownerOriginatorOrgs);
        $this->view->setSource('ownerDepositorOrgs', $ownerDepositorOrgs);
        $this->view->setSource('ownerArchiverOrgs', $ownerArchiverOrgs);
    }

    /**
     * get a message's information for history view
     * @param medona/message $message The message objects
     *
     * @return string
     */
    public function displayInHistory($message)
    {
        return $this->display($message, $withActionsButtons = false);
    }

    /**
     * get a message's information
     * @param medona/message $message            The message objects
     * @param boolean        $withActionsButtons Set the action buttons up on screen
     *
     * @return string
     */
    public function display($message, $withActionsButtons = true)
    {
        if (isset(\laabs::configuration('medona')['parentsDerogation']) && \laabs::configuration('medona')['parentsDerogation']) {
            $registrationNumber = \laabs::callService('organization/userPosition/readDescendantservices');
        } else {
            $organization = \laabs::getToken("ORGANIZATION");
            $registrationNumber = array($organization->registrationNumber);
        }

        $messageObjects = [];
198

Prosper De Laure's avatar
Prosper De Laure committed
199
        $messages = array($message);
Alexandre Morin's avatar
Alexandre Morin committed
200
        $baseMessage = reset($messages);
201
202
203
        if (isset($message->acknowledgement)) {
            $messages = array_merge($messages, [$message->acknowledgement]);
        }
Prosper De Laure's avatar
Prosper De Laure committed
204
205
206
207
208
209
210
211
212
213
214
215

        if (isset($message->authorizationMessages)) {
            $messages = array_merge($messages, $message->authorizationMessages);
        }

        if (isset($message->replyMessage)) {
            $messages[] = $message->replyMessage;
        }

        foreach ($messages as $message) {
            $messageObject = $message->object;
            $messageObject->type = $message->type;
216
            $messageObject->schema = $message->schema;
Prosper De Laure's avatar
Prosper De Laure committed
217
218
219
            $messageObject->messageId = $message->messageId;
            $messageObject->xml = isset($message->xml);
            $messageObject->archived = $message->archived;
220
221
222
223
224
            $messageObject->status = $message->status;
            $messageObject->archivalAgreement = $message->archivalAgreementReference;
            $messageObject->reference = $message->reference;
            $messageObject->size = number_format($message->size, 0, '', ' ');

225
226
227
            $user = \laabs::callService('auth/userAccount/read_userAccountId_', $message->accountId);
            $messageObject->accountDisplayName = $user->displayName;
            $messageObject->accountName = $user->accountName;
228

229
230
231
            if (isset($message->lifeCycleEvent)) {
                $messageObject->lifeCycleEvent = $message->lifeCycleEvent;
            }
232

Prosper De Laure's avatar
Prosper De Laure committed
233
234
            // Load the organizations names
            if (isset($messageObject->archivalAgency)) {
Alexandre Morin's avatar
Alexandre Morin committed
235
                $messageObject->archivalAgency->name = $this->loadOrganizationName($messageObject->archivalAgency, $message);
Prosper De Laure's avatar
Prosper De Laure committed
236
237
            }
            if (isset($messageObject->transferringAgency)) {
Alexandre Morin's avatar
Alexandre Morin committed
238
                $messageObject->transferringAgency->name = $this->loadOrganizationName($messageObject->transferringAgency, $message);
Prosper De Laure's avatar
Prosper De Laure committed
239
240
            }
            if (isset($messageObject->controlAuthority)) {
Alexandre Morin's avatar
Alexandre Morin committed
241
                $messageObject->controlAuthority->name = $this->loadOrganizationName($messageObject->controlAuthority, $message);
Prosper De Laure's avatar
Prosper De Laure committed
242
243
            }
            if (isset($messageObject->originatingAgency)) {
Alexandre Morin's avatar
Alexandre Morin committed
244
                $messageObject->originatingAgency->name = $this->loadOrganizationName($messageObject->originatingAgency, $message);
Prosper De Laure's avatar
Prosper De Laure committed
245
246
            }
            if (isset($messageObject->requester)) {
Alexandre Morin's avatar
Alexandre Morin committed
247
                $messageObject->requester->name = $this->loadOrganizationName($messageObject->requester, $message);
Prosper De Laure's avatar
Prosper De Laure committed
248
            }
249
            if (isset($messageObject->sender)) {
Alexandre Morin's avatar
Alexandre Morin committed
250
                $messageObject->sender->name = $this->loadOrganizationName($messageObject->sender, $message);
251
252
            }
            if (isset($messageObject->receiver)) {
Alexandre Morin's avatar
Alexandre Morin committed
253
                $messageObject->receiver->name = $this->loadOrganizationName($messageObject->receiver, $message);
254
            }
Prosper De Laure's avatar
Prosper De Laure committed
255
256
257
258
259
260

            // Set messages action buttons
            if ($withActionsButtons) {
                $this->setMessageActions($message, $messages, $messageObject, $registrationNumber);
            }

261
262
263
264
            if ($message->status === 'error') {
                $messageObject->retryButton = "/medona/message/". $message->messageId . "/retry";
            }

265
            if ($baseMessage->schema == 'seda2' && isset($messageObject->dataObjectPackage)) {
Alexandre Morin's avatar
Alexandre Morin committed
266
267
268
269
                foreach ($messageObject->dataObjectPackage->descriptiveMetadata->archiveUnit as $archive) {
                    if ($archive->content->originatingAgency) {
                        $archive->content->originatingAgency->name = $this->loadOrganizationName($archive->content->originatingAgency, $message);
                    }
Alexandre Morin's avatar
Alexandre Morin committed
270
271
272
273
274
275
276
277

                    if ($archive->archiveUnit) {
                        foreach ($archive->archiveUnit as $archiveChildren) {
                            if ($archiveChildren->content->originatingAgency) {
                                $archiveChildren->content->originatingAgency->name = $this->loadOrganizationName($archiveChildren->content->originatingAgency, $message);
                            }
                        }
                    }
Alexandre Morin's avatar
Alexandre Morin committed
278
                }
Alexandre Morin's avatar
Alexandre Morin committed
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
            } elseif ($baseMessage->schema == 'recordsManagement') {
                if (!isset($descriptionField)) {
                    $descriptionFields = \laabs::callService('recordsManagement/descriptionField/readIndex');
                }

                $messageObject->sender = $message->senderOrg;
                $messageObject->receiver = $message->recipientOrg;

                if (isset($messageObject->binaryDataObject)) {
                    $messageObject->binaryDataObject = (array) $messageObject->binaryDataObject;
                }

                if (isset($messageObject->descriptiveMetadata)) {
                    $messageObject->descriptiveMetadata = (array) $messageObject->descriptiveMetadata;

                    foreach ($messageObject->descriptiveMetadata as $descriptiveMetadata) {
                        if (isset($descriptiveMetadata->descriptionObject)) {
                            $descriptionObjects = $descriptiveMetadata->descriptionObject;
                            $descriptiveMetadata->descriptionObject = [];

                            foreach($descriptionObjects as $key => $value) {
                                $object = new \stdClass();
                                $object->key = $key;

                                foreach ($descriptionFields as $descriptionField) {
                                    if ($descriptionField->name === $key) {
                                        $object->label = $descriptionField->label;
                                    }
                                }

                                $object->value = $value;

                                $descriptiveMetadata->descriptionObject[] = $object;
                            }
                        }
                    }
                }
Alexandre Morin's avatar
Alexandre Morin committed
316
            }
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
            
            foreach ($messageObject->archive as $archive) {
                if (isset($archive->appraisalRule)) {
                    $dateInter = new \DateInterval($archive->appraisalRule->duration);
                    $numberDuration = 0;
                    $toDisplay = '';
                    if ($dateInter->y != 0) {
                        $numberDuration = $dateInter->y;
                        $toDisplay = "Year(s)";
                    } elseif ($dateInter->m != 0) {
                        $numberDuration = $dateInter->m;
                        $toDisplay = "Month(s)";
                    } elseif ($dateInter->d != 0) {
                        $numberDuration = $dateInter->d;
                        $toDisplay = "Day(s)";
                    }
                    $archive->appraisalRule->durationNumber = $numberDuration;
                    $archive->appraisalRule->durationToDisplay = $toDisplay;
                }
            }
Prosper De Laure's avatar
Prosper De Laure committed
337
338
339
340
            $messageObjects[] = $messageObject;
        }

        end($messageObjects)->last = true;
341
        $this->view->addContentFile($baseMessage->schema."/message/messageModal.html");
342
343

        $messageDiv = $this->view->getElementById('[?merge .messageId ?]');
Prosper De Laure's avatar
Prosper De Laure committed
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
        if ($baseMessage->schema == 'medona') {
            $this->view->addContentFile('medona/message/message.html', $messageDiv);

            // Append description specific form
            $descriptionMetadataDiv = $this->view->getElementById('descriptiveMetadata');
            if (isset($messageObjects[0]->dataObjectPackage)) {
                $this->view->addContentFile($messageObjects[0]->dataObjectPackage->descriptiveMetadataClass.'.html', $descriptionMetadataDiv);
                if ($messageObjects[0]->dataObjectPackage->descriptiveMetadataClass == 'medona/archivePackage') {
                    foreach ($messageObjects[0]->dataObjectPackage->descriptiveMetadata->archive as $archive) {
                        if (isset($archive->descriptionObject)) {
                            $archive->descriptionObject->json = json_encode($archive->descriptionObject);
                        }
                    }
                }
            }
359
360
361
        } /**else {
    $this->view->addContentFile($baseMessage->schema.'/message/message.html', $messageDiv);
    }*/
362

363
364
        if ($this->view->getElementsByClass("dataTable")->item(2)) {
            $dataTable = $this->view->getElementsByClass("dataTable")->item(2)->plugin['dataTable'];
Alexandre Morin's avatar
Alexandre Morin committed
365
366
367
            $dataTable->setPaginationType("full_numbers");
            $dataTable->setSorting(array(array(0, 'desc')));
        }
368
369
        // var_dump($messageObjects[0]->archive[0]->appraisalRule);
        
Prosper De Laure's avatar
Prosper De Laure committed
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
        $this->view->setSource('messages', $messageObjects);
        $this->view->merge();

        $this->view->translate();

        return $this->view->saveHtml();
    }

    /**
     * Get a message as a certificate
     * @param medona/message $message The message objects
     *
     * @return string
     */
    public function getCertificate($message)
    {
        $message->last = true;
        $messages = array($message);

        $this->view->addContentFile("medona/message/messageModal.html");
        $this->view->setSource('messages', $messages);
        $this->view->merge();

        $messageSerializer = $this->getMessageTypeSerializer($message);
        $html = $messageSerializer->display($message);
        $html = utf8_decode($html);
        if ($html) {
            $messageContent = $this->view->createDocumentFragment();
            $messageContent->appendHTML($html);

            $messageDiv = $this->view->getElementById($message->messageId);
            $messageDiv->appendChild($messageContent);
        }
        $this->view->translate();

        return $this->view->saveHtml();
    }

    /**
     * Get a form to search resource
     * @param recordsManagement/digitalResource $digitalResource The digital resouce
     *
     * @return string
     */
    public function getDataObjectAttachment($digitalResource)
    {
        $contents = $digitalResource->getContents();
        $mimetype = $digitalResource->mimetype;
        \laabs::setResponseType($mimetype);

        switch ($mimetype) {
            case 'application/xml':
            case 'text/xml':
                $dom = new \DOMDocument();
                $dom->formatOutput = true;

                $dom->loadXml($contents);

                $contents = "<pre>".htmlentities(preg_replace('#\>\n(\s*\n)*#', ">\n", $dom->saveXml()))."</pre>";
                \laabs::setResponseType("text/html");
                break;

            default:
                break;
        }

        return $contents;
    }

    /**
     * Get a form to search resource
     * @param string $mimetype The mime type
     *
     * @return string
     */
    public function showDataObjectAttachmentsContent($mimetype)
    {
        $this->view->addContentFile("recordsManagement/archive/modalViewDocument.html");
        $this->view->translate();

        //$this->view->setSource('url', $url);
        $this->view->setSource('mimetype', $mimetype);
        $this->view->merge();

        return $this->view->saveHtml();
    }

    /**
     * List archive conversion request
     *
     * @param array $archivesConversionRequest Array of medona/message object
     *
     * @return string
     */
    public function listConversionRequest($archivesConversionRequest)
    {
        $this->view->addContentFile("medona/message/conversionRequestList.html");

        $dataTable = $this->view->getElementsByClass("dataTable")->item(0)->plugin['dataTable'];
        $dataTable->setPaginationType("full_numbers");
        $dataTable->setUnsortableColumns(3);

        $this->view->translate();

        $this->view->setSource('archivesConversionRequest', $archivesConversionRequest);
        $this->view->merge();

        return $this->view->saveHtml();
    }

    /**
     * Get the message import form
     * @param string $messageZip The message zip
     *
     * @return string
     */
    public function messageExport($messageZip)
    {
        \laabs::setResponseType("application/zip");

        return $messageZip;
    }

    //JSON

    /**
     * Get messages numbers
     * @param array $messagesCount Array of number for each message type
     *
     * @return array
     */
    public function countMessages($messagesCount)
    {
        return json_encode($this->count($messagesCount));
    }

    /**
     * Serializer JSON for acceptArchiveTransfer method
     *
     * @return type
     */
    public function acceptArchiveTransfer()
    {
        $this->json->message = $this->translator->getText("Message accepted");

        return $this->json->save();
    }

    /**
     * Serializer JSON for rejectArchiveTransfer method
     *
     * @return type
     */
    public function rejectArchiveTransfer()
    {
        $this->json->message = $this->translator->getText("Message rejected");

        return $this->json->save();
    }

    /**
     * Serializer JSON for validateArchiveTransfer method
     *
     * @return type
     */
    public function validateArchiveTransfer()
    {
        $this->json->message = $this->translator->getText("Message validated");

        return $this->json->save();
    }
541

Prosper De Laure's avatar
Prosper De Laure committed
542
543
544
545
546
547
548
549
550
551
552
553
554
    /**
     * Serializer JSON for processBash method
     *
     * @return type
     */
    public function processArchiveTransfer()
    {
        $this->json->message = $this->translator->getText("Message processed");

        return $this->json->save();
    }

    /**
Alexandre Morin's avatar
Alexandre Morin committed
555
     * Serializer JSON for derogationDeliveryRequest method
Prosper De Laure's avatar
Prosper De Laure committed
556
557
558
     *
     * @return type
     */
Alexandre Morin's avatar
Alexandre Morin committed
559
    public function derogationDeliveryRequest()
Prosper De Laure's avatar
Prosper De Laure committed
560
    {
Alexandre Morin's avatar
Alexandre Morin committed
561
        $this->json->message = $this->translator->getText("Message sent to derogation");
Prosper De Laure's avatar
Prosper De Laure committed
562
563
564
565
566
567
568
569
570

        return $this->json->save();
    }

    /**
     * Serializer JSON for rejectArchiveTransfer method
     *
     * @return type
     */
Alexandre Morin's avatar
Alexandre Morin committed
571
    public function rejectDeliveryRequest()
Prosper De Laure's avatar
Prosper De Laure committed
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
    {
        $this->json->message = $this->translator->getText("Message rejected");

        return $this->json->save();
    }

    /**
     * Serializer JSON for rejectArchiveTransfer method
     *
     * @return type
     */
    public function rejectArchiveDestructionRequest()
    {
        $this->json->message = $this->translator->getText("Message rejected");

        return $this->json->save();
    }

    /**
     * Serializer JSON for rejectArchiveTransfer method
     *
     * @return type
     */
    public function validateArchiveDestructionRequest()
    {
        $this->json->message = $this->translator->getText("Message accepted");

        return $this->json->save();
    }


    /**
     * Serializer JSON for sendAuthorizationOriginatingAgencyRequest method
     *
     * @return type
     */
    public function sendAuthorizationOriginatingAgencyRequest()
    {
        $this->json->message = $this->translator->getText("Authorization request send to originator agency");

        return $this->json->save();
    }

    /**
     * Serializer JSON for sendAuthorizationControlAuthorityRequest method
     *
     * @return type
     */
    public function sendAuthorizationControlAuthorityRequest()
    {
        $this->json->message = $this->translator->getText("Authorization request send to control authority");

        return $this->json->save();
    }

    /**
     * Serializer JSON for acceptAuthorizationOriginatingAgencyRequest method
     *
     * @return type
     */
    public function acceptAuthorizationOriginatingAgencyRequest()
    {
        $this->json->message = $this->translator->getText("Authorization accepted");

        return $this->json->save();
    }

    /**
     * Serializer JSON for rejectAuthorizationOriginatingAgencyRequest method
     *
     * @return type
     */
    public function rejectAuthorizationOriginatingAgencyRequest()
    {
        $this->json->message = $this->translator->getText("Authorization rejected");

        return $this->json->save();
    }

    /**
     * Serializer JSON for acceptAuthorizationControlAuthorityRequest method
     *
     * @return type
     */
    public function acceptAuthorizationControlAuthorityRequest()
    {
        $this->json->message = $this->translator->getText("Authorization accepted");

        return $this->json->save();
    }

    /**
     * Serializer JSON for rejectAuthorizationControlAuthorityRequest method
     *
     * @return type
     */
    public function rejectAuthorizationControlAuthorityRequest()
    {
        $this->json->message = $this->translator->getText("Authorization rejected");

        return $this->json->save();
    }

675
676
677
678
679
680
681
682
683
684
685
686
    /**
     * Serializer JSON for acceptArchiveTransfer method
     *
     * @return type
     */
    public function retry()
    {
        $this->json->message = $this->translator->getText("Message restarted");

        return $this->json->save();
    }

Prosper De Laure's avatar
Prosper De Laure committed
687
688
689
690
691
692
693
694
695
696
697
698
699
700
    /**
     * Serializer JSON for invalid message exception
     * @param Exception $exception The exception
     *
     * @return object JSON object with a status
     */
    public function invalidMessageException($exception)
    {
        $this->json->status = false;
        $this->json->message = $this->translator->getText($exception->getFormat());
        $this->json->message = vsprintf($this->json->message, $exception->getVariables());

        if (count($exception->errors)) {
            foreach ($exception->errors as $error) {
Alexandre Morin's avatar
Alexandre Morin committed
701
702
703
704
                if (method_exists($error,'getFormat')) {
                    $format = $this->translator->getText($error->getFormat());
                    $error->setMessage(vsprintf($format, $error->getVariables()));
                }
Prosper De Laure's avatar
Prosper De Laure committed
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
            }
        }
        $this->json->errors = $exception->errors;

        return $this->json->save();
    }

    /**
     * Serializer JSON for invalid status exception
     * @param Exception $exception The exception
     *
     * @return object JSON object with a status
     */
    public function invalidStatusException(\Exception $exception)
    {
        $this->json->status = false;
        $this->json->message = $this->translator->getText($exception->getMessage());

        return $this->json->save();
    }

    /**
     * Serializer JSON for receive method
728
     * @param medona/message $ack The ack message object
Prosper De Laure's avatar
Prosper De Laure committed
729
730
731
     *
     * @return object JSON object with a status
     */
732
    public function receive($ack)
Prosper De Laure's avatar
Prosper De Laure committed
733
734
735
    {
        $this->json->status = true;
        $this->json->message = $this->translator->getText("Message received");
736
737
738
739
        $this->json->messageId = (string) $ack->receivedMessageId;
        if (isset($ack->xml)) {
            $this->json->acknowledgement = $ack->xml->saveXML();
        }
Prosper De Laure's avatar
Prosper De Laure committed
740
741
742
743

        return $this->json->save();
    }

744
    /**
Prosper De Laure's avatar
Prosper De Laure committed
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
     * Serializer JSON for validate method
     *
     * @return object JSON object with a status
     */
    public function validate()
    {
        $this->json->status = true;
        $this->json->message = $this->translator->getText("Message received");

        return $this->json->save();
    }

    /**
     * Load organization name
     * @param object $message            The message
     * @param object $messages           The message list
     * @param object $messageObject      The message object
     * @param string $registrationNumber The current user registration number
     */
    protected function setMessageActions($message, $messages, $messageObject, $registrationNumber)
    {
766

Prosper De Laure's avatar
Prosper De Laure committed
767
768
769
770
771
        if (in_array($message->recipientOrgRegNumber, $registrationNumber)) {
            $messageId = (string) $messageObject->messageId;

            switch ($messageObject->type) {
                case 'ArchiveTransfer':
772
                    if ($message->status == "received" || $message->status == "modified") {
773
                        if (!$message->isIncoming) {
774
                            $messageObject->acknowledgeButton = "/restitution/".$messageId."/Acknowledge";
775
776
                        }
                        $messageObject->validateButton = "/transferValidate/" . $messageId;
Alexandre Morin's avatar
Alexandre Morin committed
777
                        $messageObject->exportButton = "/medona/message/".$messageId."/Export";
Prosper De Laure's avatar
Prosper De Laure committed
778
779
780
                    } elseif ($message->status == "valid") {
                        $messageObject->acceptButton = "/transferAcceptance/".$messageId;
                        $messageObject->rejectButton = "/transferRejection/".$messageId;
Alexandre Morin's avatar
Alexandre Morin committed
781
                        $messageObject->exportButton = "/medona/message/".$messageId."/Export";
782
783
784
785
                    } elseif ($message->status == "toBeModified") {
                        $messageObject->rejectButton = "/transferRejection/".$messageId;
                        $messageObject->retryButton = "/medona/message/". $message->messageId . "/retry";
                        $messageObject->modifyButton = "/transferModify/". $message->messageId;
Prosper De Laure's avatar
Prosper De Laure committed
786
787
                    } elseif ($message->status == "accepted") {
                        $messageObject->processButton = "/transferProcess/".$messageId;
Alexandre Morin's avatar
Alexandre Morin committed
788
                        $messageObject->exportButton = "/medona/message/".$messageId."/Export";
789
790
791
792
793
                    } elseif ($message->status == "sent") {
                        $messageObject->exportButton = "/outgoingTransfer/".$messageId."/Export";
                    } elseif ($message->status == "downloaded") {
                        $messageObject->acknowledgeButton = "/outgoingTransfer/".$messageId."/Acknowledge";
                        $messageObject->rejectButton = "/outgoingTransfer/".$messageId."/Reject";
Alexandre Morin's avatar
Alexandre Morin committed
794
                        $messageObject->exportButton = "/medona/message/".$messageId."/Export";
795
796
                    } elseif ($message->status == "processing") {
                        $messageObject->retryButton = "/medona/message/". $message->messageId . "/retry";
Prosper De Laure's avatar
Prosper De Laure committed
797
798
799
                    }
                    break;

800
801
802
803
                case 'Acknowledgement':
                    $messageObject->exportButton = "/medona/message/".$messageId."/Export";
                    break;

Prosper De Laure's avatar
Prosper De Laure committed
804
805
                case 'ArchiveDeliveryRequest':
                    if (count($messages) == 1) {
Alexandre Morin's avatar
Alexandre Morin committed
806
                        if ($message->status === "sent") {
807
                            $messageObject->rejectButton = "/delivery/".$messageId."/Reject";
Alexandre Morin's avatar
Alexandre Morin committed
808
                            $messageObject->derogationButton = "/delivery/".$messageId."/Derogation";
Prosper De Laure's avatar
Prosper De Laure committed
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
                        }
                    }
                    break;

                case 'ArchiveDeliveryRequestReply':
                    if (count($messages) == 1) {
                        if ($message->status == "sent") {
                            $messageObject->exportButton = "/delivery/".$messageId."/Export";
                        }
                    }
                    break;

                case 'ArchiveRestitutionRequest':
                    if (count($messages) == 1) {
                        if ($message->status == "sent") {
                            $messageObject->rejectButton = "/restitutionRequest/".$messageId."/Reject";
825
                            $messageObject->acceptWarningButton = "/restitutionRequest/".$messageId."/Accept";
Prosper De Laure's avatar
Prosper De Laure committed
826
827
828
829
830
831
832
833
834
835
                        }
                    } elseif ($message->status == "accepted") {
                        $messageObject->processButton = "/restitutionRequest/".$messageId."/process";
                    }
                    break;

                case 'ArchiveRestitution':
                    if ($message->status == "sent") {
                        $messageObject->exportButton = "/restitution/".$messageId."/Export";
                    } elseif ($message->status == "received") {
836
                        $messageObject->rejectButton = "/restitution/".$messageId."/Reject";
Alexandre Morin's avatar
Alexandre Morin committed
837
                        $messageObject->acknowledgeButton = "/restitution/".$messageId."/Acknowledge";
838
839
                    } elseif ($message->status == "acknowledge") {
                        $messageObject->validationButton = "/restitution/".$messageId."/process";
Alexandre Morin's avatar
Alexandre Morin committed
840
                        $messageObject->exportButton = "/medona/message/".$messageId."/Export";
Prosper De Laure's avatar
Prosper De Laure committed
841
842
843
844
845
                    }
                    break;

                case 'ArchiveDestructionRequest':
                    if ($message->status == "accepted") {
846
847
                        $messageObject->validationButton = "/destructionRequest/".$messageId."/Accept";
                        //$messageObject->rejectButton = "/destructionRequest/".(string) $message->messageId."/Reject";
Prosper De Laure's avatar
Prosper De Laure committed
848
849
850
851
852
853
854
855
856
                    }
                    break;

                case 'AuthorizationOriginatingAgencyRequest':
                    $messageObject->acceptButton = "/authorizationOriginatingAgencyRequest/".(string) $message->messageId."/Accept";
                    $messageObject->rejectButton = "/authorizationOriginatingAgencyRequest/".(string) $message->messageId."/Reject";
                    break;

                case 'AuthorizationOriginatingAgencyRequestReply':
857
                    if (($messages[0]->status != "originator_authorization_wait" && $messages[0]->status != "control_authorization_wait") || ($message != end($messages))) {
Prosper De Laure's avatar
Prosper De Laure committed
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
                        break;
                    }

                    if (strtoupper($message->replyCode) == "000") {
                        if ($messages[0]->type == "ArchiveDeliveryRequest") {
                            $messageObject->acceptButton = "/deliveryRequest/".(string) $messages[0]->messageId."/Accept";
                            $messageObject->sendRequestAuth = "/authorizationControlAuthorityRequest/".(string) $messages[0]->messageId;
                        }

                        if ($messageObject[0]->type == "ArchiveDestructionRequest") {
                            $messageObject->acceptButton = "/destructionRequest/".(string) $messages[0]->messageId."/Accept";
                            $messageObject->sendRequestAuth = "/authorizationControlAuthorityRequest/".(string) $messages[0]->messageId;
                        }
                    } else {
                        if ($messages[0]->type == "ArchiveDeliveryRequest") {
                            $messageObject->rejectButton = "/deliveryRequest/".$messageId."/Reject";
                        }

                        if ($messages[0]->type == "ArchiveDestructionRequest") {
                            $messageObject->rejectButton = "/destructionRequest/".(string) $messages[0]->messageId."/Reject";
                        }
                    }
                    break;

                case 'AuthorizationControlAuthorityRequest':
                    $messageObject->acceptButton = "/authorizationControlAuthorityRequest/".(string) $message->messageId."/Accept";
                    $messageObject->rejectButton = "/authorizationControlAuthorityRequest/".(string) $message->messageId."/Reject";
                    break;

                case 'AuthorizationControlAuthorityRequestReply':
                    if (strtoupper($message->replyCode) == "000") {
                        if ($messages[0]->type == "ArchiveDeliveryRequest") {
                            $messageObject->acceptButton = "/deliveryRequest/".(string) $messages[0]->messageId."/Accept";
                        }
                    } else {
                        if ($messages[0]->type == "ArchiveDeliveryRequest") {
                            $messageObject->rejectButton = "/deliveryRequest/".(string) $messages[0]->messageId."/Reject";
                        }
                    }
                    break;
898
899
                /*
                */
Prosper De Laure's avatar
Prosper De Laure committed
900
901
902
903
904
905
906
907
908
909
            }
        } elseif (in_array($message->senderOrgRegNumber, $registrationNumber)) {
            $messageId = (string) $messageObject->messageId;

            switch ($messageObject->type) {
                case 'ArchiveRestitution':
                    if ($message->status == "acknowledge") {
                        $messageObject->validationButton = "/restitution/".$messageId."/process";
                    }
                    break;
910
911
912
913
914
                case 'ArchiveTransfer' :
                    if ($message->status == "acknowledge") {
                        $messageObject->validationButton = "/outgoingTransfer/".$messageId."/process";
                    }
                    break;
Prosper De Laure's avatar
Prosper De Laure committed
915
916
917
918
            }
        }
    }

919
    /**
Prosper De Laure's avatar
Prosper De Laure committed
920
921
922
923
924
925
926
927
     * Load organization name
     * @param object         $object
     * @param medona/message $message
     */
    protected function loadOrganizationName($object, $message)
    {
        $organization = null;

Alexandre Morin's avatar
Alexandre Morin committed
928
        if (!isset($object->identifier) && !isset($object->identification->value)) {
Prosper De Laure's avatar
Prosper De Laure committed
929
930
            return;
        }
931

932
933
934
935
        if (isset($object->identifier)) {
            $name = 'identifier';
        } else {
            $name = 'identification';
936
937
        }

938
939
940
941
942
943
944
945
946
947
        if ($object->{$name}->value == $message->recipientOrg->registrationNumber) {
            $organization = $message->recipientOrg;
        } elseif ($object->{$name}->value == $message->senderOrg->registrationNumber) {
            $organization = $message->senderOrg;
        } else {
            try {
                $organization = \laabs::callService('organization/organization/readByregnumber', $object->{$name}->value)->orgName;
            } catch (\Exception $e) {
                $organization = "Organisation inconnue (" . $object->{$name}->value . ")";
            }
948
        }
949

Alexandre Morin's avatar
Alexandre Morin committed
950
        return $organization;
Prosper De Laure's avatar
Prosper De Laure committed
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
    }

    /**
     * Get the message type and schema specific serializer
     * @param medona/message $message The message object
     * @param string         $format  The implementation format
     *
     * @return The parser
     */
    protected function getMessageTypeSerializer($message, $format = "html")
    {
        if (!isset($message->type)) {
            $message->type = $message->xml->documentElement->nodeName;
        }

        if (!isset($message->schema)) {
            $messageNamespace = $message->xml->documentElement->namespaceURI;
            if (!$messageSchema = \laabs::resolveXmlNamespace($messageNamespace)) {
                throw new \Exception('Unknown message namespace'.$messageNamespace);
            }
            $message->schema = $messageSchema;
        }

        $this->messageTypeSerializer = \laabs::newSerializer($message->schema.LAABS_URI_SEPARATOR.$message->type, $format);

        return $this->messageTypeSerializer;
    }

    /**
     * Show message list
981
982
     * @param array     $messages Array of message object
     * @param boolean   $history  Type of table (true => history and false => other)
Prosper De Laure's avatar
Prosper De Laure committed
983
984
985
     *
     * @return string The view
     */
986
    protected function prepareMesageList($messages, $history = null)
Prosper De Laure's avatar
Prosper De Laure committed
987
988
989
990
    {

        $dataTable = $this->view->getElementsByClass("dataTable")->item(0)->plugin['dataTable'];
        $dataTable->setPaginationType("full_numbers");
991
992
993
994
995
996
997
998

        if ($history) {
            $dataTable->setUnsortableColumns(6);
            $dataTable->setSorting(array(array(4, 'desc')));
        } else {
            $dataTable->setUnsortableColumns(5);
            $dataTable->setSorting(array(array(3, 'desc')));
        }
Prosper De Laure's avatar
Prosper De Laure committed
999
1000

        $this->view->translate();
For faster browsing, not all history is shown. View entire blame