diff --git a/application/modules/opac/controllers/DatasController.php b/application/modules/opac/controllers/DatasController.php new file mode 100644 index 0000000000000000000000000000000000000000..4b520a76a03ac5e9f16eba3d640cca08d5a5b313 --- /dev/null +++ b/application/modules/opac/controllers/DatasController.php @@ -0,0 +1,41 @@ +<?php +/** + * Copyright (c) 2012-2014, Agence Française Informatique (AFI). All rights reserved. + * + * AFI-OPAC 2.0 is free software; you can redistribute it and/or modify + * it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE as published by + * the Free Software Foundation. + * + * There are special exceptions to the terms and conditions of the AGPL as it + * is applied to this software (see README file). + * + * AFI-OPAC 2.0 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 AFFERO GENERAL PUBLIC LICENSE for more details. + * + * You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE + * 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 DatasController extends Zend_Controller_Action { + public function fieldsAction() { + $this->_json(Class_CustomField::findAllBy(['model' => $this->_getParam('model', '')])); + } + + + public function valuesAction() { + $this->_json(Class_CustomField_Value::findAllBy(['custom_field_id' => $this->_getParam('field', 0)])); + } + + + protected function _json($values) { + $response = []; + foreach ($values as $value) + $response[] = $value->toArray(); + $this->_helper->json($response); + } +} +?> \ No newline at end of file diff --git a/tests/application/modules/opac/controllers/DatasControllerTest.php b/tests/application/modules/opac/controllers/DatasControllerTest.php new file mode 100644 index 0000000000000000000000000000000000000000..99838ce497d46bfe3ee0cb997d57d71b2a2114a9 --- /dev/null +++ b/tests/application/modules/opac/controllers/DatasControllerTest.php @@ -0,0 +1,56 @@ +<?php +/** + * Copyright (c) 2012-2014, Agence Française Informatique (AFI). All rights reserved. + * + * AFI-OPAC 2.0 is free software; you can redistribute it and/or modify + * it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE as published by + * the Free Software Foundation. + * + * There are special exceptions to the terms and conditions of the AGPL as it + * is applied to this software (see README file). + * + * AFI-OPAC 2.0 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 AFFERO GENERAL PUBLIC LICENSE for more details. + * + * You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE + * 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 DatasControllerTest extends AbstractControllerTestCase { + public function setUp() { + parent::setUp(); + $this->fixture('Class_CustomField', [ + 'id' => 19, + 'model' => 'SessionFormation', + 'meta' => $this->fixture('Class_CustomField_Meta', ['id' => 1, 'label' => 'thématique'])]); + + $this->fixture('Class_CustomField_Value', [ + 'id' => 23, + 'custom_field_id' => 19, + 'value' => 'Macramé' + ]); + } + + + /** @test */ + public function fieldsOfSessionFormationShouldReturnJson() { + $this->dispatch('/opac/datas/fields/model/SessionFormation'); + $this->assertEquals( + '[{"priority":0,"id":19,"model":"SessionFormation","meta_id":1,"label":"th\u00e9matique","field_type":"text","options_list":""}]', + $this->_response->getBody()); + } + + + /** @test */ + public function valuesOfFieldThematiqueShouldReturnJson() { + $this->dispatch('/opac/datas/values/field/19'); + $this->assertEquals( + '[{"value":"Macram\u00e9","id":23,"custom_field_id":19}]', + $this->_response->getBody()); + } +} +?> \ No newline at end of file