diff --git a/library/Class/WebService/SIGB/Carthame/AccountResponseReader.php b/library/Class/WebService/SIGB/Carthame/AccountResponseReader.php index cabb376ea131fca1770d541225bfa9cdcb51fc27..da83c1c3b8357e71d4e9e992e5bb869b98f64833 100644 --- a/library/Class/WebService/SIGB/Carthame/AccountResponseReader.php +++ b/library/Class/WebService/SIGB/Carthame/AccountResponseReader.php @@ -38,14 +38,15 @@ class Class_WebService_SIGB_Carthame_AccountResponseReader { return new self(); } + /** * @param string $xml * @return Class_WebService_SIGB_Emprunteur */ public function getAccountFromXml($xml) { $this->_emprunteur = Class_WebService_SIGB_Emprunteur::newInstance() - ->empruntsAddAll(array()) - ->reservationsAddAll(array()); + ->empruntsAddAll([]) + ->reservationsAddAll([]); $this->_xml_parser = Class_WebService_XMLParser::newInstance(); $this->_xml_parser @@ -53,83 +54,85 @@ class Class_WebService_SIGB_Carthame_AccountResponseReader { ->parse($xml); return $this->_emprunteur; - } + public function startF400() { $this->_current_emprunt = Class_WebService_SIGB_Emprunt::newInstanceWithEmptyExemplaire(); } + public function endF400() { $this->_emprunteur->empruntsAdd($this->_current_emprunt); } + public function startF500() { $this->_current_reservation = Class_WebService_SIGB_Reservation::newInstanceWithEmptyExemplaire(); } + public function endF500() { $this->_emprunteur->reservationsAdd($this->_current_reservation); } + public function endSFa($data) { $data = (string)$data; if ($this->_xml_parser->inParents('F100')) { $parts = explode(',', $data); - $this->_emprunteur->setNom(trim($parts[0])) - ->setPrenom(trim($parts[1])) - ; + ->setPrenom(trim($parts[1])); + return; } if ($this->_xml_parser->inParents('F400')) { $this->_current_emprunt->getExemplaire()->setNoNotice($data); + return; } - if ($this->_xml_parser->inParents('F500')) { + if ($this->_xml_parser->inParents('F500')) $this->_current_reservation->getExemplaire()->setNoNotice($data); - } - } + public function endSFc($data) { + if (!$this->_xml_parser->inParents('F400')) + return; + $data = (string)$data; + $date = substr($data, strlen($data)-2) . '/' . substr($data, 4, 2). '/' . substr($data, 0, 4); + $this->_current_emprunt->setDateRetour($date); + } - if ($this->_xml_parser->inParents('F400')) { - $date = substr($data, strlen($data)-2) . '/' . substr($data, 4, 2). '/' . substr($data, 0, 4); - $this->_current_emprunt->setDateRetour($date); - } + public function endSFd($data) { + if (!$this->_xml_parser->inParents('F500')) + return; - } + $mapping = ['A' => 'En attente', + 'D' => 'Disponible', + 'T' => 'En transfert']; - public function endSFd($data) { - if ($this->_xml_parser->inParents('F500')) { - $status = ''; - switch ((string)$data) { - case 'A': $status = 'En attente'; break; - case 'D': $status = 'Disponible'; break; - case 'T': $status = 'En transfert'; break; - } - - $this->_current_reservation->setEtat($status); - } + $data = (string)$data; + $this->_current_reservation->setEtat(isset($mapping[$data]) ? $mapping[$data] : ''); } + public function endSFh($data) { - if ($this->_xml_parser->inParents('F500')) { + if ($this->_xml_parser->inParents('F500')) $this->_current_reservation->setId((string)$data); - } } + public function endSFk($data) { - if ($this->_xml_parser->inParents('F400')) { - $id = (string)$data; - $this->_current_emprunt->setId($id); - $this->_current_emprunt->getExemplaire()->setId($id); - } - } + if (!$this->_xml_parser->inParents('F400')) + return; + $id = (string)$data; + $this->_current_emprunt->setId($id); + $this->_current_emprunt->getExemplaire()->setId($id); + } } ?> \ No newline at end of file diff --git a/library/Class/WebService/SIGB/Carthame/RecordResponseReader.php b/library/Class/WebService/SIGB/Carthame/RecordResponseReader.php index 683b6f34fdc5f0b97d176820f337e96565741f14..8d97582d6e4e5db9cf4b54f0b7fe64c3262969ef 100644 --- a/library/Class/WebService/SIGB/Carthame/RecordResponseReader.php +++ b/library/Class/WebService/SIGB/Carthame/RecordResponseReader.php @@ -40,6 +40,7 @@ class Class_WebService_SIGB_Carthame_RecordResponseReader { return new self(); } + /** * @param string $xml * @return type @@ -53,35 +54,37 @@ class Class_WebService_SIGB_Carthame_RecordResponseReader { return $this->_notice; } + public function endNoticeid($data) { $this->_notice = new Class_WebService_SIGB_Notice((string)$data); } + public function endSFh($data) { $this->_current_exemplaire = new Class_WebService_SIGB_Exemplaire((string)$data); $this->_current_exemplaire->setNotice($this->_notice); } + public function endSFa($data) { $this->_current_exemplaire->setCodeBarre((string)$data); } + public function endSFo($data) { $data = (int)$data; - $this->_current_exemplaire->setReservable(in_array($data, array(self::STATUT_RESERVE, - self::STATUT_PRETE))); + $this->_current_exemplaire->setReservable(in_array($data, [self::STATUT_RESERVE, + self::STATUT_PRETE])); - if (self::STATUT_DISPO === $data) { - $this->_current_exemplaire->setDisponibiliteLibre(); - } else { - $this->_current_exemplaire->setDisponibiliteIndisponible(); - } + (self::STATUT_DISPO === $data) + ? $this->_current_exemplaire->setDisponibiliteLibre() + : $this->_current_exemplaire->setDisponibiliteIndisponible(); } + public function endSFq($data) { $data = (string)$data; $date = substr($data, strlen($data)-2) . '/' . substr($data, 4, 2). '/' . substr($data, 0, 4); - $this->_current_exemplaire->setDateRetour($date); } @@ -89,6 +92,5 @@ class Class_WebService_SIGB_Carthame_RecordResponseReader { public function endF941($data) { $this->_notice->addExemplaire($this->_current_exemplaire); } - } ?> \ No newline at end of file diff --git a/library/Class/WebService/SIGB/Carthame/ReserveInfoResponseReader.php b/library/Class/WebService/SIGB/Carthame/ReserveInfoResponseReader.php index 92a0439d07af716decb3277c38ddf959aca7ef2e..4d9a47f5e62ca3f2fe09c7b26671b9d2f9e56295 100644 --- a/library/Class/WebService/SIGB/Carthame/ReserveInfoResponseReader.php +++ b/library/Class/WebService/SIGB/Carthame/ReserveInfoResponseReader.php @@ -26,10 +26,10 @@ class Class_WebService_SIGB_Carthame_ReserveInfoResponseReader { protected $_sites; protected $_current_site_id; - protected $_codif_site_ifr = array('Institut F' => 1, - 'Cluj-Napoc' => 2, - 'Iasi' => 3, - 'Timisoara' => 4); + protected $_codif_site_ifr = ['Institut F' => 1, + 'Cluj-Napoc' => 2, + 'Iasi' => 3, + 'Timisoara' => 4]; /** * @return Class_WebService_SIGB_Carthame_AccountResponseReader @@ -38,13 +38,13 @@ class Class_WebService_SIGB_Carthame_ReserveInfoResponseReader { return new self(); } + /** * @param string $xml * @return Class_WebService_SIGB_Emprunteur */ public function readXml($xml) { - $this->_sites = array(); - + $this->_sites = []; $this->_xml_parser = Class_WebService_XMLParser::newInstance(); $this->_xml_parser ->setElementHandler($this) @@ -57,10 +57,12 @@ class Class_WebService_SIGB_Carthame_ReserveInfoResponseReader { return $this->_codif_site_ifr[$code]; } + public function getSites() { return $this->_sites; } + public function isSiteAllowed($code) { return array_key_exists($this->getId($code), $this->_sites); } @@ -75,5 +77,4 @@ class Class_WebService_SIGB_Carthame_ReserveInfoResponseReader { $this->_sites[$this->_current_site_id] = $data; } } - ?> \ No newline at end of file diff --git a/library/Class/WebService/SIGB/Carthame/Service.php b/library/Class/WebService/SIGB/Carthame/Service.php index 2c80f6c5e9c359c30e28f30683ef4df24487cc82..c7a89262a840d1acde66e0882f42f2d964412526 100644 --- a/library/Class/WebService/SIGB/Carthame/Service.php +++ b/library/Class/WebService/SIGB/Carthame/Service.php @@ -18,6 +18,7 @@ * along with AFI-OPAC 2.0; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ + class Class_WebService_SIGB_Carthame_Service extends Class_WebService_SIGB_AbstractRESTService { protected function _getReserveDocumentErrorMessage($code) { $messages = $this->_getReserveDocumentErrors(); @@ -28,30 +29,30 @@ class Class_WebService_SIGB_Carthame_Service extends Class_WebService_SIGB_Abstr protected function _getReserveDocumentErrors() { $t = $this->translate = Zend_Registry::get('translate'); - return array( - '101' => $t->_('Reservation not allowed to public'), - '102' => $t->_('No copies allowed for this document'), - '103' => $t->_('Maximum amount of reservation for this document'), - '104' => $t->_('No copy or copy cannot be reserved, none on order'), - '106' => $t->_('This document does not belong to any document family'), - '107' => $t->_('No copy, on order but cannot be reserved'), - '108' => $t->_('All copies are on loan to a customer whose loans are not reserved'), - '109' => $t->_('No copies available to reserve because of the availability of copies'), - '201' => $t->_('Customer has overdue loans'), - '202' => $t->_('Customer has reached maximum number of reservations'), - '203' => $t->_('Already exists at least one reservation for this customer for this notice'), - '204' => $t->_('This notice is already on loan to this customer'), - '304' => $t->_('No withdrawal possible : subscription problem, no available copy to reserve'), - '401' => $t->_('Customer has no valid subscription'), - '403' => $t->_('Customer has overdue payments'), - '501' => $t->_('The notice\'s document type for reservation does not belong to any document family'), - '502' => $t->_('Reservation limit reached'), - '503' => $t->_('Reservation limit reached for this document type'), - '504' => $t->_('Reservation limit reached for this annexe'), - '505' => $t->_('No valid customer subscription or payments overdue'), - '506' => $t->_('Notice\'s document family cannot be reserved')); + return ['101' => $t->_('Reservation not allowed to public'), + '102' => $t->_('No copies allowed for this document'), + '103' => $t->_('Maximum amount of reservation for this document'), + '104' => $t->_('No copy or copy cannot be reserved, none on order'), + '106' => $t->_('This document does not belong to any document family'), + '107' => $t->_('No copy, on order but cannot be reserved'), + '108' => $t->_('All copies are on loan to a customer whose loans are not reserved'), + '109' => $t->_('No copies available to reserve because of the availability of copies'), + '201' => $t->_('Customer has overdue loans'), + '202' => $t->_('Customer has reached maximum number of reservations'), + '203' => $t->_('Already exists at least one reservation for this customer for this notice'), + '204' => $t->_('This notice is already on loan to this customer'), + '304' => $t->_('No withdrawal possible : subscription problem, no available copy to reserve'), + '401' => $t->_('Customer has no valid subscription'), + '403' => $t->_('Customer has overdue payments'), + '501' => $t->_('The notice\'s document type for reservation does not belong to any document family'), + '502' => $t->_('Reservation limit reached'), + '503' => $t->_('Reservation limit reached for $this->is document type'), + '504' => $t->_('Reservation limit reached for this annexe'), + '505' => $t->_('No valid customer subscription or payments overdue'), + '506' => $t->_('Notice\'s document family cannot be reserved')]; } + /** * @return Class_WebService_SIGB_Carthame_Service */ @@ -59,6 +60,7 @@ class Class_WebService_SIGB_Carthame_Service extends Class_WebService_SIGB_Abstr return new self(); } + /** * @param string $server_root * @return Class_WebService_SIGB_Carthame_Service @@ -67,25 +69,26 @@ class Class_WebService_SIGB_Carthame_Service extends Class_WebService_SIGB_Abstr return self::newInstance()->setServerRoot($server_root); } + /** * @param Class_Users $user * @return Class_WebService_SIGB_Emprunteur */ public function getEmprunteur($user) { $userId = $this->_authenticate($user); - $xml = $this->httpGet(array( - 'sigb' => 'ktm', - 'version' => 'standalone', - 'action' => 'accountDetails', - 'userid' => $userId)); + $xml = $this->httpGet(['sigb' => 'ktm', + 'version'=> 'standalone', + 'action' => 'accountDetails', + 'userid' => $userId]); + $account = Class_WebService_SIGB_Carthame_AccountResponseReader::newInstance() ->getAccountFromXml($xml); return $account->setId($userId) ->setService($this); - } + /** * @param Class_Users $user * @param Class_Exemplaire exemplaire @@ -96,13 +99,11 @@ class Class_WebService_SIGB_Carthame_Service extends Class_WebService_SIGB_Abstr $userId = $this->_authenticate($user); $notice_id = $exemplaire->getIdOrigine(); - $xml = $this->httpGet(array( - 'sigb' => 'ktm', - 'version' => 'standalone', - 'action' => 'reserveInfo', - 'userid' => $userId, - 'nn' => $notice_id - )); + $xml = $this->httpGet(['sigb' => 'ktm', + 'version'=> 'standalone', + 'action' => 'reserveInfo', + 'userid' => $userId, + 'nn' => $notice_id]); if (1 <= (int)$this->_getTagData($xml, 'error')) { $error_code = (string)$this->_getTagData($xml, 'code'); @@ -116,14 +117,12 @@ class Class_WebService_SIGB_Carthame_Service extends Class_WebService_SIGB_Abstr implode(',' , $reserveInfoReader->getSites()))); } - $xml = $this->httpGet(array( - 'sigb' => 'ktm', - 'version' => 'standalone', - 'action' => 'reserveDocument', - 'userid' => $userId, - 'nn' => $notice_id, - 'site' => $reserveInfoReader->getId($code_annexe), - )); + $xml = $this->httpGet(['sigb' => 'ktm', + 'version'=> 'standalone', + 'action' => 'reserveDocument', + 'userid' => $userId, + 'nn' => $notice_id, + 'site' => $reserveInfoReader->getId($code_annexe)]); if (1 === (int)$this->_getTagData($xml, 'error')) return $this->_success(); @@ -133,18 +132,17 @@ class Class_WebService_SIGB_Carthame_Service extends Class_WebService_SIGB_Abstr return $this->_error($error_message); } + /** * @param Class_Users $user * @param string $reservation_id * @return array */ public function supprimerReservation($user, $reservation_id) { - $xml = $this->httpGet(array( - 'sigb' => 'ktm', - 'version' => 'standalone', - 'action' => 'reserveCancel', - 'resid' => $reservation_id, - )); + $xml = $this->httpGet(['sigb' => 'ktm', + 'version'=> 'standalone', + 'action' => 'reserveCancel', + 'resid' => $reservation_id]); if (0 === (int)$this->_getTagData($xml, 'error')) return $this->_success(); @@ -152,18 +150,17 @@ class Class_WebService_SIGB_Carthame_Service extends Class_WebService_SIGB_Abstr return $this->_error((string)$this->_getTagData($xml, 'code')); } + /** * @param Class_Users $user * @param string $pret_id * @return array */ public function prolongerPret($user, $pret_id) { - $xml = $this->httpGet(array( - 'sigb' => 'ktm', - 'version' => 'standalone', - 'action' => 'prolongLoan', - 'loanid' => $pret_id, - )); + $xml = $this->httpGet(['sigb' => 'ktm', + 'version'=> 'standalone', + 'action' => 'prolongLoan', + 'loanid' => $pret_id]); if (0 === (int)$this->_getTagData($xml, 'error')) return $this->_success(); @@ -171,33 +168,32 @@ class Class_WebService_SIGB_Carthame_Service extends Class_WebService_SIGB_Abstr return $this->_error((string)$this->_getTagData($xml, 'code')); } + /** * @param string $id * @return Class_WebService_SIGB_Notice */ public function getNotice($id) { - $xml = $this->httpGet(array( - 'sigb' => 'ktm', - 'version' => 'standalone', - 'action' => 'copyDetails', - 'nn' => (string)$id)); + $xml = $this->httpGet(['sigb' => 'ktm', + 'version'=> 'standalone', + 'action' => 'copyDetails', + 'nn' => (string)$id]); + return Class_WebService_SIGB_Carthame_RecordResponseReader::newInstance() ->getNoticeFromXML($xml); - } + /** * @param Class_Users $user * @return string */ protected function _authenticate($user) { - $response = $this->httpGet(array( - 'sigb' => 'ktm', - 'version' => 'standalone', - 'action' => 'login', - 'username'=> (string)$user->getLogin(), - 'password'=> (string)$user->getPassword(), - )); + $response = $this->httpGet(['sigb' => 'ktm', + 'version' => 'standalone', + 'action' => 'login', + 'username'=> (string)$user->getLogin(), + 'password'=> (string)$user->getPassword()]); return $this->_getTagData($response, 'id'); }