/**
  * markUnreadForProjectMembers() is only intended to be called from a child class such as UnreadActivityModel
  * @param string $itemId
  * @param ProjectModel $project
  * @throws \Exception
  */
 public static function markUnreadForProjectMembers($itemId, $project, $questionId = '', $exceptThisUserId = '')
 {
     $className = get_called_class();
     if ($className == 'Api\\Model\\UserUnreadModel') {
         throw new \Exception("static method markUnreadForProject cannot be called from base class UserUnreadModel");
     }
     $userList = $project->listUsers();
     foreach ($userList->entries as $user) {
         if ($user['id'] == $exceptThisUserId) {
             continue;
         }
         // TODO: Review: This code is getting cumbersome with if statements for specific child classes.  Maybe it's time to move this method to the child classes - cjh 2013/10
         if ($questionId != '') {
             $unreadModel = new $className($user['id'], $project->id->asString(), $questionId);
         } else {
             $unreadModel = new $className($user['id'], $project->id->asString());
         }
         $unreadModel->markUnread($itemId);
         $unreadModel->write();
     }
 }
 public function testCreateSimple_CreateUser_PasswordAndJoinProject()
 {
     $this->environ->clean();
     // setup parameters: username and project
     $userName = '******';
     $project = $this->environ->createProject(SF_TESTPROJECT, SF_TESTPROJECTCODE);
     $projectId = $project->id->asString();
     $currentUserId = $this->environ->createUser('test1', 'test1', '*****@*****.**');
     // create user
     $dto = UserCommands::createSimple($userName, $projectId, $currentUserId, $this->environ->website);
     // read from disk
     $user = new UserModel($dto['id']);
     $sameProject = new ProjectModel($projectId);
     // user created and password created, user joined to project
     $this->assertEqual($user->username, "username");
     $this->assertEqual(strlen($dto['password']), 4);
     $projectUser = $sameProject->listUsers()->entries[0];
     $this->assertEqual($projectUser['username'], "username");
     $userProject = $user->listProjects($this->environ->website->domain)->entries[0];
     $this->assertEqual($userProject['projectName'], SF_TESTPROJECT);
 }
 public function testRemoveUsers_ProjectOwner_NotRemovedFromProject_RestoreErrorDisplay()
 {
     // restore error display after last test
     $this->environ->restoreErrorDisplay();
     // read from disk
     $sameProject = new ProjectModel($this->save['projectId']);
     $sameUser1 = new UserModel($this->save['user1Id']);
     $sameUser2 = new UserModel($this->save['user2Id']);
     // project still has project owner
     $this->assertEqual($sameProject->listUsers()->count, 1);
     $this->assertEqual($sameUser1->listProjects($this->environ->website->domain)->count, 0);
     $this->assertEqual($sameUser2->listProjects($this->environ->website->domain)->count, 1);
 }
 public function testProjectListUsers_TwoUsers_ListHasDetails()
 {
     $e = new MongoTestEnvironment();
     $userId1 = $e->createUser('user1', 'User One', '*****@*****.**');
     $um1 = new UserModel($userId1);
     $userId2 = $e->createUser('user2', 'User Two', '*****@*****.**');
     $um2 = new UserModel($userId2);
     $project = $e->createProject(SF_TESTPROJECT, SF_TESTPROJECTCODE);
     $projectId = $project->id->asString();
     // Check the list users is empty
     $result = $project->listUsers();
     $this->assertEqual(0, $result->count);
     $this->assertEqual(array(), $result->entries);
     // Add our two users
     $project->addUser($userId1, ProjectRoles::CONTRIBUTOR);
     $um1->addProject($projectId);
     $um1->write();
     $project->addUser($userId2, ProjectRoles::CONTRIBUTOR);
     $um2->addProject($projectId);
     $um2->write();
     $project->write();
     $otherProject = new ProjectModel($projectId);
     $result = $otherProject->listUsers();
     $this->assertEqual(2, $result->count);
     $this->assertEqual(array(array('email' => '*****@*****.**', 'name' => 'User One', 'username' => 'user1', 'id' => $userId1, 'role' => ProjectRoles::CONTRIBUTOR), array('email' => '*****@*****.**', 'name' => 'User Two', 'username' => 'user2', 'id' => $userId2, 'role' => ProjectRoles::CONTRIBUTOR)), $result->entries);
 }