Completed
Push — master ( 03cde8...21f90a )
by Paul
02:45
created

PatronInformationRequest::getMessageString()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 32
Code Lines 20

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 20
dl 0
loc 32
ccs 0
cts 22
cp 0
rs 9.6
c 0
b 0
f 0
cc 1
nc 1
nop 2
crap 2
1
<?php
2
3
namespace lordelph\SIP2\Request;
4
5
/**
6
 * PatronInformationRequest is a superset of the Patron Status Request message. It should be used to request patron
7
 * information. The ACS should respond with the Patron Information Response message.
8
 *
9
 * The setType() method accepts one of none, hold, overdue, charged, fine, recall and unavail
10
 *
11
 * @method setLanguage(string $languageCode)
12
 * @method setType(string $informationType)
13
 * @method setInstitutionId(string $institutionId)
14
 * @method setPatronIdentifier(string $patron)
15
 * @method setTerminalPassword(string $terminalPassword)
16
 * @method setPatronPassword(string $patronPassword)
17
 * @method setStart(string $start)
18
 * @method setEnd(string $end)
19
 *
20
 * @licence    https://opensource.org/licenses/MIT
21
 * @copyright  John Wohlers <[email protected]>
22
 * @copyright  Paul Dixon <[email protected]>
23
 */
24
class PatronInformationRequest extends SIP2Request
25
{
26
    protected $var = [
27
        'Language' => ['type' => 'nnn', 'default' => '001'],
28
        'Type' => ['default' => 'none'],
29
        'InstitutionId' => [],
30
        'PatronIdentifier' => [],
31
        'TerminalPassword' => ['default' => ''],
32
        'PatronPassword' => ['default' => ''],
33
        'Start' => ['default' => '1'],
34
        'End' => ['default' => '5'],
35
    ];
36
37
    public function getMessageString($withSeq = true, $withCrc = true): string
38
    {
39
        /*
40
        * According to the specification:
41
        * Only one category of items should be  requested at a time, i.e. it would take 6 of these messages,
42
        * each with a different position set to Y, to get all the detailed information about a patron's items.
43
        */
44
        $summary = [];
45
        $summary['none'] = '      ';
46
        $summary['hold'] = 'Y     ';
47
        $summary['overdue'] = ' Y    ';
48
        $summary['charged'] = '  Y   ';
49
        $summary['fine'] = '   Y  ';
50
        $summary['recall'] = '    Y ';
51
        $summary['unavail'] = '     Y';
52
53
        $type = $this->getVariable('Type');
54
55
        $this->newMessage('63');
56
        $this->addFixedOption($this->getVariable('Language'), 3);
57
        $this->addFixedOption($this->datestamp(), 18);
58
        $this->addFixedOption(sprintf("%-10s", $summary[$type]), 10);
59
        $this->addVarOption('AO', $this->getVariable('InstitutionId'));
60
        $this->addVarOption('AA', $this->getVariable('PatronIdentifier'));
61
        $this->addVarOption('AC', $this->getVariable('TerminalPassword'));
62
        $this->addVarOption('AD', $this->getVariable('PatronPassword'), true);
63
        /* old function version used padded 5 digits, not sure why */
64
        $this->addVarOption('BP', $this->getVariable('Start'), true);
65
        /* old function version used padded 5 digits, not sure why */
66
        $this->addVarOption('BQ', $this->getVariable('End'), true);
67
68
        return $this->returnMessage($withSeq, $withCrc);
69
    }
70
}
71