diff --git a/application/modules/opac/controllers/NoticeajaxController.php b/application/modules/opac/controllers/NoticeajaxController.php index 58400410752c71c6d9102981e01dd55f60e29689..5d0efe3f36179b47e2074bfa5fb6cc35f414b84c 100644 --- a/application/modules/opac/controllers/NoticeajaxController.php +++ b/application/modules/opac/controllers/NoticeajaxController.php @@ -153,12 +153,16 @@ class NoticeAjaxController extends Zend_Controller_Action { public function localisationAction() { $id_bib=$this->_request->getParam("id_bib"); + + $cote=$this->_request->getParam("cote"); $code_barres=$this->_request->getParam("code_barres"); // Recup des donnees $cls_loc=new Class_Localisation(); - $data=$cls_loc->getLocFromExemplaire($id_bib,$cote,$code_barres); + $data = []; + if ($bib=Class_Bib::find($id_bib)) + $data=$cls_loc->getLocFromExemplaire($bib,$cote,$code_barres); // Retour $ret =json_encode($data); diff --git a/library/Class/Localisation.php b/library/Class/Localisation.php index 54cbf4484e1eb533b0c9c2e263a95c98d88c96cc..071b946c33736c1fcd8dd49c087a7db57c4fab89 100644 --- a/library/Class/Localisation.php +++ b/library/Class/Localisation.php @@ -104,19 +104,38 @@ class Class_Localisation extends Storm_Model_Abstract { } + // ---------------------------------------------------------------- + // Rend les caracteristiques de l'image pour un plan + // ---------------------------------------------------------------- + public function getImagePlan() + { + xdebug_break(); + if (!$plan=$this->getPlan()) + return []; + + $image=$plan->getImage(); + $img = "/userfiles/photobib/plans/".$image; + if ($image == "" or (self::getFileSystem()->file_exists(getcwd().$img)==false)) + return false; + $ret=getimagesize(getcwd().$img); + $ret["url"]=BASE_URL.$img; + return $ret; + } + // ---------------------------------------------------------------- // Rend les données de localisation pour 1 exemplaire // ---------------------------------------------------------------- - public function getLocFromExemplaire($id_bib, $cote, $code_barres) { - if(!$localisations = Class_Localisation::getLoader()->getLocalisations($id_bib)) + public function getLocFromExemplaire($bib, $cote, $code_barres) { + + if(!$localisations = $bib->getLocalisations()) return $this->localisationErrorAsArray(); $exemplaire = (!$code_barres) ? Class_Exemplaire::findFirstBy(['cote' => $cote, - 'id_bib' => $id_bib]) + 'id_bib' => $bib->getId()]) : Class_Exemplaire::findFirstBy(['code_barres' => $code_barres, - 'id_bib' => $id_bib]); + 'id_bib' => $bib->getId()]); if(!$exemplaire) return $this->localisationErrorAsArray(); @@ -144,7 +163,7 @@ class Class_Localisation extends Storm_Model_Abstract { protected function asArrayForJson() { - return ['url' => $this->getImagePlan($this->getIdPlan()), + return ['url' => $this->getImagePlan(), 'posX' => $this->getPosX(), 'posY' => $this->getPosY(), 'description' => (trim($this->getDescription()) diff --git a/tests/application/modules/opac/controllers/NoticeAjaxControllerTest.php b/tests/application/modules/opac/controllers/NoticeAjaxControllerTest.php index d1995c20f5c2e4c3502eb50a42cb677dfa84eccc..6ddf4efcf3a26120d8c9cb597084c04016536643 100644 --- a/tests/application/modules/opac/controllers/NoticeAjaxControllerTest.php +++ b/tests/application/modules/opac/controllers/NoticeAjaxControllerTest.php @@ -1398,7 +1398,8 @@ abstract class NoticeAjaxControllerLocalisationTestCase extends AbstractControll 'genre' => 'Doc']); $this->fixture('Class_bib', - ['id' => 1]); + ['id' => 1, + ]); $this->fixture('Class_Plan', ['id' => 1, @@ -1511,6 +1512,14 @@ class NoticeAjaxControllerWithMultipleSelectorLocalisationTest extends NoticeAja 'id_plan' => '1', 'genre' => 'Doc', 'emplacement' => '7']); + $file_system = Storm_Test_ObjectWrapper::mock() + ->whenCalled('file_exists') + ->answers(true) + ->whenCalled('rename') + ->answers(true); + + Class_Plan::setFileSystem($file_system); + Class_Localisation::setFileSystem($file_system); $this->dispatch('noticeajax/localisation/id_bib/1/cote/123789', true); $this->_json = json_decode($this->_response->getBody());