Skip to content
Snippets Groups Projects
Commit f1d156e9 authored by Laurent's avatar Laurent
Browse files

rd #14085 pnb

usage constraints properties stored as serialized json
parent bea67a5a
6 merge requests!780Master,!767Master,!764Dev#21988 consultation pnb,!753Dev#21988 consultation pnb,!744Dev #21987 register ip pnb,!733Rd #14085 pnb
......@@ -2,7 +2,7 @@
// Constantes
error_reporting(E_ERROR | E_PARSE);
define("PATCH_LEVEL","234");
define("PATCH_LEVEL","235");
define("APPLI","cosmogramme");
define("COSMOPATH", "/var/www/html/vhosts/opac2/www/htdocs");
......
<?php
$adapter = Zend_Registry::get('sql');
$adapter->query('CREATE TABLE `album_usage_constraints` ( '
. 'id int(11) unsigned not null auto_increment,'
. 'album_id int(11) unsigned not null,'
. 'usage_type varchar(4) not null,'
. 'serialized_datas text not null,'
. 'primary key (id),'
. 'key (`value`)'
. ') engine=MyISAM default charset=utf8');
$adapter->query('ALTER TABLE album_usage_constraints ADD INDEX (album_id)');
\ No newline at end of file
......@@ -21,13 +21,49 @@
class Class_Album_UsageConstraint extends Storm_Model_Abstract {
const LOAN_CONSTRAINT = '06';
const
DEVICE_SHARE_CONSTRAINT = '04',
LOAN_CONSTRAINT = '06';
protected
$_table_name = 'album_usage_constraints',
$_belongs_to = ['album' => ['model' => 'Class_Album']],
$_default_attribute_values = ['serialized_datas' => ''],
$_datas;
public function beforeSave() {
$this->setSerializedDatas($this->getDatas()->serialized());
}
protected $_belongs_to = ['album' => ['model' => 'Class_Album']];
public function isLoanConstraint() {
return $this->getUsageType() == self::LOAN_CONSTRAINT;
}
public function getDatas() {
if (!isset($this->_datas))
$this->_datas = (new Class_JSONSerializedDatas($this->getSerializedDatas()));
return $this->_datas;
}
public function getLoanDuration() {
return (int)$this->getDatas()->get('loan_duration');
}
public function setLoanDuration($value) {
$this->getDatas()->set('loan_duration', $value);
return $this;
}
public function setQuantity($value) {
$this->getDatas()->set('quantity', $value);
return $this;
}
}
?>
\ No newline at end of file
<?php
/**
* Copyright (c) 2012-2014, Agence Française Informatique (AFI). All rights reserved.
*
* BOKEH 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).
*
* BOKEH 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 BOKEH; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
class Class_JSONSerializedDatas {
protected $_datas;
public function __construct($datas) {
if (!$this->_datas = json_decode($datas, true))
$this->_datas = [];
}
public function get($name) {
return isset($this->_datas[$name]) ? $this->_datas[$name] : null;
}
public function set($name, $value) {
$this->_datas[$name] = $value;
return $this;
}
public function serialized() {
return json_encode($this->_datas);
}
}
?>
\ No newline at end of file
<?php
/**
* Copyright (c) 2012-2014, Agence Française Informatique (AFI). All rights reserved.
*
* BOKEH 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).
*
* BOKEH 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 BOKEH; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
class Class_WebService_BibNumerique_Dilicom_UsageConstraint {
}
?>
\ No newline at end of file
<?php
/**
* Copyright (c) 2012-2014, Agence Française Informatique (AFI). All rights reserved.
*
* BOKEH 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).
*
* BOKEH 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 BOKEH; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
class Class_Album_UsageConstraintTest extends Storm_Test_ModelTestCase {
public function setUp() {
parent::setUp();
Storm_Model_Loader::defaultToVolatile();
$this->fixture('Class_Album',
['id' => 23]);
$this->fixture('Class_Album_UsageConstraint',
['id' => 2,
'album_id' => 23,
'usage_type' => Class_Album_UsageConstraint::LOAN_CONSTRAINT,
'serialized_datas' => json_encode(['loan_duration' => 45,
'max_number_of_loans' => 30,
'max_number_of_users' => 15])]);
Class_Album::clearCache();
Class_Album_UsageConstraint::clearCache();
}
public function tearDown() {
Storm_Model_Loader::defaultToDb();
parent::tearDown();
}
/** @test */
public function albumGetCounstraintsLoanDurationShouldAnswers45() {
$this->assertEquals(45, Class_Album::find(23)->getUsageConstraints()->getLoanDuration());
}
/** @test */
public function savedConstraintShouldSerializeItsDatas() {
$constraint = Class_Album_UsageConstraint::newInstance(['usage_type' => Class_Album_Usageconstraint::DEVICE_SHARE_CONSTRAINT,
'quantity' => 4]);
Class_Album::find(23)
->addUsageConstraint($constraint)
->save();
Class_Album_UsageConstraint::clearCache();
$this->assertEquals(['quantity' => 4],
json_decode(Class_Album_UsageConstraint::find(3)->getSerializedDatas(),
true));
}
}
?>
\ 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