Skip to content
Snippets Groups Projects
Commit a0b94176 authored by Patrick Barroca's avatar Patrick Barroca :grin:
Browse files

rel #15273 : added specific controller for custom fields data retreival

parent 7c3be206
Branches
Tags
2 merge requests!321Dev#12992 custom fields,!305Dev#12992 custom fields
<?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
<?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
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment