ArchiveNotification.php 3.5 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
<?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\bundle\medona\Controller;

/**
 * Class for ArchiveNotification
 *
 * @author Prosper DE LAURE <prosper.delaure@maarch.org>
 */
class ArchiveNotification extends abstractMessage
{
     /**
     * Get received notification messages
Dylan's avatar
#6982    
Dylan committed
33
34
35
36
37
38
39
     * @param string $reference
     * @param string $archiver
     * @param string $originator
     * @param string $depositor
     * @param string $archivalAgreement
     * @param date   $fromDate
     * @param date   $toDate
Prosper De Laure's avatar
Prosper De Laure committed
40
41
42
     *
     * @return array Array of medona/message object
     */
Dylan's avatar
#6982    
Dylan committed
43
    public function listReception($reference = null, $archiver = null, $originator = null, $depositor = null, $archivalAgreement = null, $fromDate = null, $toDate = null)
Prosper De Laure's avatar
Prosper De Laure committed
44
45
46
47
    {
        $registrationNumber = $this->getCurrentRegistrationNumber();

        $queryParts = [];
48
        $queryParts[] = "recipientOrgRegNumber=$registrationNumber OR senderOrgRegNumber=$registrationNumber";
49
        $queryParts[] = "type='ArchiveModificationNotification' OR type='ArchiveDestructionNotification' OR type='ArchivalProfileModificationNotification'";
Prosper De Laure's avatar
Prosper De Laure committed
50
51
        $queryParts[] = "active=true";

52
        return $this->sdoFactory->find('medona/message', '('.implode(') and (', $queryParts).')', null, false, false, 300);
Prosper De Laure's avatar
Prosper De Laure committed
53
54
    }

Dylan's avatar
#6982    
Dylan committed
55
56
    /**
     * Get transfer history
Alexandre Morin's avatar
Alexandre Morin committed
57
58
59
60
61
62
63
64
65
     *
     * @param string $reference         Reference
     * @param string $archiver          Archiver
     * @param string $originator        Originator
     * @param string $depositor         Depositor
     * @param string $archivalAgreement Archival agreement
     * @param date   $fromDate          From date
     * @param date   $toDate            To date
     * @param string $status            Status
Dylan's avatar
#6982    
Dylan committed
66
67
68
     *
     * @return array Array of medona/message object
     */
Alexandre Morin's avatar
Alexandre Morin committed
69
    public function history($reference = null, $archiver = null, $originator = null, $depositor = null, $archivalAgreement = null, $fromDate = null, $toDate = null, $status = null)
Dylan's avatar
#6982    
Dylan committed
70
    {
Alexandre Morin's avatar
Alexandre Morin committed
71
        return $this->search("ArchiveNotification", $reference, $archiver, $originator, $depositor, $archivalAgreement, $fromDate, $toDate, $status, false);
Dylan's avatar
#6982    
Dylan committed
72
73
    }

Prosper De Laure's avatar
Prosper De Laure committed
74
75
76
77
78
79
80
81
82
83
84
85
    /**
     * Count notification message
     *
     * @return array Number of notification messages
     */
    public function count()
    {
        $registrationNumber = $this->getCurrentRegistrationNumber();

        $res = array();
        $queryParts = array();
        $queryParts[] = "(type='ArchiveModificationNotification' OR type='ArchiveDestructionNotification' OR type='ArchivalProfileModificationNotification')";
86
        $queryParts[] = "recipientOrgRegNumber=$registrationNumber OR senderOrgRegNumber=$registrationNumber";
Prosper De Laure's avatar
Prosper De Laure committed
87
88
89
90
91
92
        $queryParts[] = "active=true";
        $res['received'] = $this->sdoFactory->count('medona/message', implode(' and ', $queryParts));

        return $res;
    }
}