/** * Check if an user is in the group * * @param USVN_Db_Table_Row_User User * @return boolean */ public function isInGroup($group) { if ($this->_cleanData === array()) { return false; } $user_groups = new USVN_Db_Table_UsersToGroups(); $res = $user_groups->fetchRow(array("groups_id = ?" => $group->groups_id, "users_id = ?" => $this->id)); if ($res === NULL) { return false; } return true; }
public function test_noleaderFindByGroupId() { $this->db->query("INSERT INTO usvn_users (users_id, users_login, users_password, users_is_admin) VALUES (1,'noplay', 'xxx', 0);"); $this->db->query("INSERT INTO usvn_users (users_id, users_login, users_password, users_is_admin) VALUES (2,'stem', 'xxx', 0);"); $this->db->query("INSERT INTO usvn_users (users_id, users_login, users_password, users_is_admin) VALUES (3,'eozine', 'xxx', 0);"); $this->db->query("INSERT INTO usvn_groups (groups_id, groups_name) VALUES (1,'epitech');"); $this->db->query("INSERT INTO usvn_groups (groups_id, groups_name) VALUES (2,'etna');"); $table = new USVN_Db_Table_UsersToGroups(); $table->insert(array('users_id' => 1, 'groups_id' => 1, 'is_leader' => false)); $table->insert(array('users_id' => 2, 'groups_id' => 1, 'is_leader' => '')); $table->insert(array('users_id' => 2, 'groups_id' => 2, 'is_leader' => true)); $table->insert(array('users_id' => 3, 'groups_id' => 1, 'is_leader' => true)); $this->assertEquals(2, count($table->noleaderFindByGroupId(1))); }
public function isLeaderOrAdmin($user) { if ($user) { $user_groups = new USVN_Db_Table_UsersToGroups(); $res = $user_groups->fetchRow(array("groups_id = ?" => $this->id, "users_id = ?" => $user->id)); if ($res) { if ($res->is_leader == 1) { return 1; } } if ($user->is_admin == 1) { return 1; } return 0; } }
public function completionAction() { echo "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"; $table = "<table width=100%>"; $nb = 0; echo "<files>\n"; if ($_GET['idx'] == 1) { if (isset($_GET['grp']) && $_GET['grp'] != "") { $table_groups = new USVN_Db_Table_Groups(); $res_groups = $table_groups->findByGroupsName($_GET['grp']); $table_userstogroups = new USVN_Db_Table_UsersToGroups(); $res_usersspe = $table_userstogroups->findByGroupId($res_groups->groups_id); } else { if (isset($_GET['prj']) && $_GET['prj'] != "") { $table_project = new USVN_Db_Table_Projects(); $res_project = $table_project->findByName($_GET['prj']); $table_userstoprojects = new USVN_Db_Table_UsersToProjects(); $res_usersspe = $table_userstoprojects->findByProjectId($res_project->projects_id); } } $table_users = new USVN_Db_Table_Users(); $res_users = $table_users->allUsersLike($_GET['txt']); foreach ($res_users as $user) { $find = false; foreach ($res_usersspe as $tmpuser) { if ($tmpuser->users_id == $user->users_id) { $find = true; } } if ($find == false) { $table .= "<tr id='user" . $nb . "' class='comp'>"; $table .= "<td align=left onclick='javascript:dumpInput(" . "\"" . $user->users_login . "\"" . "," . "\"" . $_GET['input'] . "\"" . ", \"completion\")'>"; $table .= "<label id='luser" . $nb . "'>" . $user->users_login . "</label>"; $table .= "</td></tr>"; $nb++; } } } if ($_GET['idx'] == 2) { $table_project = new USVN_Db_Table_Projects(); $res_project = $table_project->findByName($_GET['prj']); $table_groupstoprojects = new USVN_Db_Table_GroupsToProjects(); $res_groupstoprojects = $table_groupstoprojects->findByProjectId($res_project->projects_id); $table_groups = new USVN_Db_Table_Groups(); $res_groups = $table_groups->allGroupsLike($_GET['txt']); foreach ($res_groups as $group) { $find = false; foreach ($res_groupstoprojects as $tmpgrp) { if ($tmpgrp->groups_id == $group->groups_id) { $find = true; } } if ($find == false) { $table .= "<tr id='grp" . $nb . "' class='comp'>"; $table .= "<td align=left onclick='javascript:dumpInput(" . "\"" . $group->groups_name . "\"" . "," . "\"" . $_GET['input'] . "\"" . ", \"completion1\")'>"; $table .= "<label id='lgrp" . $nb . "'>" . $group->groups_name . "</label>"; $table .= "</td></tr>"; $nb++; } } } if ($_GET['idx'] == 3) { $table_users = new USVN_Db_Table_Users(); $res_users = $table_users->allUsersLike($_GET['txt']); $table_groups = new USVN_Db_Table_Groups(); $res_groups = $table_groups->findByGroupsName($_GET['grp']); $res_usersspe = $table_users->allLeader($res_groups->groups_id); foreach ($res_users as $user) { $find = false; foreach ($res_usersspe as $tmpuser) { if ($tmpuser->users_id == $user->users_id) { $find = true; } } if ($find == false) { $table .= "<tr id='user" . $nb . "' class='comp'>"; $table .= "<td align=left onclick='javascript:dumpInput(" . "\"" . $user->users_login . "\"" . "," . "\"" . $_GET['input'] . "\"" . ", \"completionleader\")'>"; $table .= "<label id='luser" . $nb . "'>" . $user->users_login . "</label>"; $table .= "</td></tr>"; $nb++; } } } if ($_GET['idx'] == 4) { $table_groups = new USVN_Db_Table_Groups(); $res_groups = $table_groups->findByGroupsName($_GET['grp']); $table_userstogroups = new USVN_Db_Table_UsersToGroups(); $res_usersspe = $table_userstogroups->noleaderFindByGroupId($res_groups->groups_id); $table_users = new USVN_Db_Table_Users(); $res_users = $table_users->allUsersLike($_GET['txt']); foreach ($res_users as $user) { $find = false; foreach ($res_usersspe as $tmpuser) { if ($tmpuser->users_id == $user->users_id) { $find = true; } } if ($find == false) { $table .= "<tr id='user" . $nb . "' class='comp'>"; $table .= "<td align=left onclick='javascript:dumpInput(" . "\"" . $user->users_login . "\"" . "," . "\"" . $_GET['input'] . "\"" . ", \"completion\")'>"; $table .= "<label id='luser" . $nb . "'>" . $user->users_login . "</label>"; $table .= "</td></tr>"; $nb++; } } } $table .= "</table>"; echo "<nbcomp>" . $nb . "</nbcomp>\n"; echo "<tableau><![CDATA[" . $table . "]]></tableau>\n"; echo "</files>\n"; }
public function testFindUserInGroup() { $test = $this->createUser("test"); $babar = $this->createUser("babar"); $john = $this->createUser("john"); $group = $this->createGroup("toto"); $user_groups = new USVN_Db_Table_UsersToGroups(); $user_groups->insert(array("groups_id" => $group->id, "users_id" => $test->id, "is_leader" => false)); $user_groups->insert(array("groups_id" => $group->id, "users_id" => $babar->id, "is_leader" => false)); $group_table = new USVN_Db_Table_Groups(); $group = $group_table->find($test->id)->current(); $users = $group->findManyToManyRowset('USVN_Db_Table_Users', 'USVN_Db_Table_UsersToGroups'); $res = array(); foreach ($users as $user) { array_push($res, $user->users_login); } $this->assertContains("test", $res); $this->assertContains("babar", $res); $this->assertNotContains("john", $res); }
public function testUserIsGroupLeader() { $user2 = $this->users["test"]; $user3 = $this->users["babar"]; $user4 = $this->users["john"]; $user_groups = new USVN_Db_Table_UsersToGroups(); $user_groups->insert(array("groups_id" => $this->group1->id, "users_id" => $user3->id, "is_leader" => 0)); $user_groups->insert(array("groups_id" => $this->group1->id, "users_id" => $user4->id, "is_leader" => 1)); $this->assertFalse($this->group1->userIsGroupLeader($user2)); $this->assertFalse($this->group1->userIsGroupLeader($user3)); $this->assertTrue($this->group1->userIsGroupLeader($user4)); }