Commit 6cff00c8 authored by Laurent's avatar Laurent

hotline #107991 user groups : fix age criteria

parent c3134f6f
Pipeline #9694 passed with stage
in 63 minutes and 48 seconds
- ticket #107991 : Groupes d'utilisateurs : correction du calcul de l'appartenance pouvant apparaître sur le critère "âge".
\ No newline at end of file
......@@ -79,7 +79,7 @@ class Class_User_SearchCriteria_Age extends Class_SearchCriteria_Abstract {
if ($this->_hasFrom()
&& ($date = $this->substractYearsToCurrentDate((int)$this->_from))
&& $user->getNaissance() < $date) {
&& $user->getNaissance() > $date) {
return false;
}
......@@ -87,7 +87,7 @@ class Class_User_SearchCriteria_Age extends Class_SearchCriteria_Abstract {
return true;
$date = $this->substractYearsToCurrentDate((int)$this->_to);
return $user->getNaissance() <= $date;
return $user->getNaissance() >= $date;
}
......
......@@ -28,7 +28,7 @@ class UserGroupLoader extends Storm_Model_Loader {
public function save($model) {
$result = parent::save($model);
if ($model->isDynamic())
$this->_dynamics_of_user_cache = [];
$this->resetDynamicsOfUserCache();
return $result;
}
......@@ -123,9 +123,18 @@ class UserGroupLoader extends Storm_Model_Loader {
}
public function resetDynamicsOfUserCache() {
$this->_dynamics_of_user_cache = [];
return $this;
}
protected function _realFindAllDynamicsOf($user) {
return array_filter(Class_UserGroup::findAllDynamics(),
function($group) use($user) { return $group->hasUser($user); });
function($group) use($user)
{
return $group->hasUser($user);
});
}
}
......
......@@ -109,6 +109,8 @@ class DynamicUserGroupModoBibTest extends DynamicUserGroupTestCase {
public function setUp() {
parent::setUp();
Class_AdminVar::set('ENABLED_SEARCH_USER_AGE', 1);
$this->_marseillais = $this
->fixture('Class_UserGroup',
['id' => 3,
......@@ -136,7 +138,9 @@ class DynamicUserGroupModoBibTest extends DynamicUserGroupTestCase {
->beModoBib()
->assertSave();
Class_User_ILSSubscription::setTimeSource(new TimeSourceForTest('2020-01-15 15:00'));
$time_source = new TimeSourceForTest('2020-01-15 15:00');
Class_User_ILSSubscription::setTimeSource($time_source);
Class_User_SearchCriteria_Age::setTimeSource($time_source);
$this->_gontran = $this->fixture('Class_Users',
['id' => 22,
'login' => 'gontran',
......@@ -144,6 +148,7 @@ class DynamicUserGroupModoBibTest extends DynamicUserGroupTestCase {
'id_site' => 1,
'idabon' => '111',
'statut' => 1,
'naissance' => '2000-01-01',
'role_level' => ZendAfi_Acl_AdminControllerRoles::ABONNE_SIGB,
'date_fin' => '2050-01-01'
]);
......@@ -232,6 +237,35 @@ class DynamicUserGroupModoBibTest extends DynamicUserGroupTestCase {
'search_role_level' => ZendAfi_Acl_AdminControllerRoles::ABONNE_SIGB,
'search_end_subscription_days'=> 10
])]);
$this->_minors = $this
->fixture('Class_UserGroup',
['id' => 20,
'libelle' => 'Mineurs',
'group_type' => Class_UserGroup::TYPE_DYNAMIC,
'filters' => json_encode([
'search_age_debut' => 0,
'search_age_fin'=> 17
])]);
$this->_adults = $this
->fixture('Class_UserGroup',
['id' => 21,
'libelle' => 'Adultes',
'group_type' => Class_UserGroup::TYPE_DYNAMIC,
'filters' => json_encode([
'search_age_debut' => 18
])]);
Class_UserGroup::resetDynamicsOfUserCache();
}
public function tearDown() {
Class_User_ILSSubscription::setTimeSource(null);
Class_User_SearchCriteria_Age::setTimeSource(null);
parent::tearDown();
}
......@@ -246,6 +280,8 @@ class DynamicUserGroupModoBibTest extends DynamicUserGroupTestCase {
['_baptiste', '_basketers'],
['_gontran', '_searchers'],
['_shella', '_subscription_ended'],
['_shella', '_minors'],
['_gontran', '_adults'],
];
}
......@@ -273,6 +309,8 @@ class DynamicUserGroupModoBibTest extends DynamicUserGroupTestCase {
['_baptiste', '_marseillais'],
['_xavier', '_anneciens'],
['_gontran', '_subscription_ended'],
['_shella', '_adults'],
['_gontran', '_minors'],
];
}
......
Markdown is supported
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