diff --git a/.gitattributes b/.gitattributes index fd5da2846c0f94dadc5a3e64b458c9af700d4c46..e1e943cb361487293167fa17fb6427efe0a0b33b 100644 --- a/.gitattributes +++ b/.gitattributes @@ -2200,6 +2200,7 @@ cosmogramme/sql/patch/patch_171.sql -text cosmogramme/sql/patch/patch_172.sql -text cosmogramme/sql/patch/patch_173.sql -text cosmogramme/sql/patch/patch_174.sql -text +cosmogramme/sql/patch/patch_175.sql -text cosmogramme/storm_init.php -text cosmogramme/tests/bootstrap.php -text cosmogramme/tests/php/classes/AbonneIntegrationTest.php -text @@ -2484,6 +2485,7 @@ library/Class/UploadMover/Abstract.php -text library/Class/UploadMover/HttpPost.php -text library/Class/UploadMover/LocalFile.php -text library/Class/UserGroup.php -text +library/Class/UserGroupCategorie.php -text library/Class/UserGroupMembership.php -text library/Class/Users.php -text library/Class/Video.php -text @@ -6084,6 +6086,7 @@ tests/library/Class/TimeSourceForTest.php -text tests/library/Class/ToutApprendreLinkTest.php -text tests/library/Class/TypeDocTest.php -text tests/library/Class/UploadTest.php -text +tests/library/Class/UserGroupCategorieTest.php -text tests/library/Class/UserGroupTest.php -text tests/library/Class/UsersTest.php -text tests/library/Class/VodeclicLinkTest.php -text diff --git a/cosmogramme/php/_init.php b/cosmogramme/php/_init.php index c3b4dcc701cca7e48b7e9c49959851c83a54a0ef..b35d36cb8d8378c7b5480b830a7ead56fce6fd01 100644 --- a/cosmogramme/php/_init.php +++ b/cosmogramme/php/_init.php @@ -1,7 +1,7 @@ <?PHP // Constantes define("VERSION_COSMOGRAMME","6.38"); -define("PATCH_LEVEL","174"); +define("PATCH_LEVEL","175"); define("APPLI","cosmogramme"); define("COSMOPATH", "/var/www/html/vhosts/opac2/www/htdocs"); define("CRLF", chr(13) . chr(10)); diff --git a/cosmogramme/sql/patch/patch_175.sql b/cosmogramme/sql/patch/patch_175.sql new file mode 100644 index 0000000000000000000000000000000000000000..5c5649626a45330c91e610dd14e0e66c8f308372 --- /dev/null +++ b/cosmogramme/sql/patch/patch_175.sql @@ -0,0 +1,10 @@ +CREATE TABLE IF NOT EXISTS `user_group_categorie` ( + `id` int( 11 ) NOT NULL AUTO_INCREMENT , + `parent_id` int( 11 ) NOT NULL default '0', + `libelle` varchar( 100 ) default NULL , + PRIMARY KEY ( `id` ) +) ENGINE = MYISAM DEFAULT CHARSET = utf8; + +alter table user_groups add column id_cat int(11) not null; + + diff --git a/library/Class/UserGroup.php b/library/Class/UserGroup.php index f8ec38e3f581a827a0bace38164df79ec36b0cd3..ec252a10bcfa7f33f09edac36502236ff324801b 100644 --- a/library/Class/UserGroup.php +++ b/library/Class/UserGroup.php @@ -26,7 +26,8 @@ class Class_UserGroup extends Storm_Model_Abstract { 'dependent' => 'delete' ], 'users' => [ 'through' => 'user_group_memberships', 'unique' => true ] ]; - + protected $_belongs_to = ['categorie' => ['model' => 'Class_UserGroupCategorie', + 'referenced_in' => 'ID_CAT']]; // Les droits doivent être une puissance de 2 (ce sont des masques) const RIGHT_SUIVRE_FORMATION = 1; const RIGHT_DIRIGER_FORMATION = 2; diff --git a/library/Class/UserGroupCategorie.php b/library/Class/UserGroupCategorie.php new file mode 100644 index 0000000000000000000000000000000000000000..7ad7bb321e9c533ed0096f715760506a12c21879 --- /dev/null +++ b/library/Class/UserGroupCategorie.php @@ -0,0 +1,43 @@ +<?php +/** + * Copyright (c) 2012, 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 Class_UserGroupCategorie extends Storm_Model_Abstract { + protected $_table_name = 'user_group_categorie'; + protected $_has_many = [ 'user_group' => [ 'model' => 'Class_UserGroup', + 'role' => 'categorie', + 'dependent' => 'delete' ], + 'sous_categories' => ['model' => 'Class_UserGroupCategorie', + 'role' => 'parent', + 'dependents' => 'delete'], + + ]; + + protected $_belongs_to = ['parent_categorie' => ['model' => 'Class_UserGroupCategorie', + 'referenced_in' => 'parent_id']]; + + + public static function getLoader() { + return self::getLoaderFor(__CLASS__); + } + + + +} \ No newline at end of file diff --git a/tests/library/Class/UserGroupCategorieTest.php b/tests/library/Class/UserGroupCategorieTest.php new file mode 100644 index 0000000000000000000000000000000000000000..ec28e541399a77d57a64d19d6f2f06759828dd5a --- /dev/null +++ b/tests/library/Class/UserGroupCategorieTest.php @@ -0,0 +1,62 @@ +<?php +/** + * Copyright (c) 2012, 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 UserGroupCategorieWithNoGroupTest extends Storm_Test_ModelTestCase { + + protected $_association; + protected $_etablissement; + + public function setup() { + parent::setup(); + $this->_etablissement = Class_UserGroupCategorie::newInstanceWithId(1,['libelle'=>'Etablissement']); + $this->_association = + Class_UserGroupCategorie::newInstanceWithId(2,['libelle'=>'Association', + 'parent_categorie' => $this->_etablissement]); + $this->_etablissement->setSousCategories([$this->_association]); + } + + + /** @test **/ + public function associationShouldNotHaveUserGroup() { + $this->assertEmpty($this->_association->getUserGroup()); + + } + + + /** @test **/ + public function associationShouldHaveParentCategorieEtablissement() { + $this->assertEquals($this->_association->getParentCategorie(), $this->_etablissement); + } + + + /** @test **/ + public function etablissementShouldHaveSousCategorieAssociation() { + $this->assertEquals([$this->_association], $this->_etablissement->getSousCategories()); + } + + + /** @test **/ + public function associationShouldNotHaveSousCategorie() { + $this->assertEmpty($this->_association->getSousCategories()); + } +} + +?> \ No newline at end of file diff --git a/tests/library/Class/UserGroupTest.php b/tests/library/Class/UserGroupTest.php index 564488af17e1731efaa23b9b704468b254dfe8f6..57b7e3551f260daa62704958d916f833971e0de1 100644 --- a/tests/library/Class/UserGroupTest.php +++ b/tests/library/Class/UserGroupTest.php @@ -215,4 +215,21 @@ class UserGroupWithNoUsersTest extends UserGroupTestCase { } +class UserGroupWithCategorieUserGroupTest extends UserGroupTestCase { + protected $_zork_group; + + public function setUp() { + parent::setUp(); + $this->_categorie = Class_UserGroupCategorie::newInstanceWithId(10, ['libelle' => 'Association']); + + $this->_zork_group = Class_UserGroup::newInstanceWithId(999999, ['categorie' => $this->_categorie]); + } + + /** @test */ + public function zorkGroupShouldBelongsToCategorieAssociation() { + $this->assertEquals('Association' , $this->_zork_group->getCategorie()->getLibelle()); + } +} + + ?> \ No newline at end of file