PatronInformationRequest   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 1
eloc 30
c 1
b 0
f 0
dl 0
loc 45
ccs 21
cts 21
cp 1
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A getMessageString() 0 32 1
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 1
    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 1
        $summary = [];
45 1
        $summary['none'] = '      ';
46 1
        $summary['hold'] = 'Y     ';
47 1
        $summary['overdue'] = ' Y    ';
48 1
        $summary['charged'] = '  Y   ';
49 1
        $summary['fine'] = '   Y  ';
50 1
        $summary['recall'] = '    Y ';
51 1
        $summary['unavail'] = '     Y';
52
53 1
        $type = $this->getVariable('Type');
54
55 1
        $this->newMessage('63');
56 1
        $this->addFixedOption($this->getVariable('Language'), 3);
57 1
        $this->addFixedOption($this->datestamp(), 18);
58 1
        $this->addFixedOption(sprintf("%-10s", $summary[$type]), 10);
59 1
        $this->addVarOption('AO', $this->getVariable('InstitutionId'));
60 1
        $this->addVarOption('AA', $this->getVariable('PatronIdentifier'));
61 1
        $this->addVarOption('AC', $this->getVariable('TerminalPassword'));
62 1
        $this->addVarOption('AD', $this->getVariable('PatronPassword'), true);
63
        /* old function version used padded 5 digits, not sure why */
64 1
        $this->addVarOption('BP', $this->getVariable('Start'), true);
65
        /* old function version used padded 5 digits, not sure why */
66 1
        $this->addVarOption('BQ', $this->getVariable('End'), true);
67
68 1
        return $this->returnMessage($withSeq, $withCrc);
69
    }
70
}
71