From acafbea62427a3c2f144fc40c6fc156cbcc25354 Mon Sep 17 00:00:00 2001
From: efalcy <efalcy@git-test.afi-sa.fr>
Date: Tue, 1 Oct 2013 16:24:08 +0000
Subject: [PATCH] Groupes de formation : ajout de la notion de categorie de
 groupe

---
 .gitattributes                                |  3 +
 cosmogramme/php/_init.php                     |  2 +-
 cosmogramme/sql/patch/patch_175.sql           | 10 +++
 library/Class/UserGroup.php                   |  3 +-
 library/Class/UserGroupCategorie.php          | 43 +++++++++++++
 .../library/Class/UserGroupCategorieTest.php  | 62 +++++++++++++++++++
 tests/library/Class/UserGroupTest.php         | 17 +++++
 7 files changed, 138 insertions(+), 2 deletions(-)
 create mode 100644 cosmogramme/sql/patch/patch_175.sql
 create mode 100644 library/Class/UserGroupCategorie.php
 create mode 100644 tests/library/Class/UserGroupCategorieTest.php

diff --git a/.gitattributes b/.gitattributes
index fd5da2846c0..e1e943cb361 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 c3b4dcc701c..b35d36cb8d8 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 00000000000..5c5649626a4
--- /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 f8ec38e3f58..ec252a10bcf 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 00000000000..7ad7bb321e9
--- /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 00000000000..ec28e541399
--- /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 564488af17e..57b7e3551f2 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
-- 
GitLab