예제 #1
0
 /**
  * Tests removeAdmins() method.
  */
 public function testRemoveAdmins()
 {
     $gw = new ProjectAdminGateway();
     $this->_insertAdmins();
     // Verify that invalid project id's emp numbers throw exceptions
     try {
         $gw->removeAdmins($projectId = "", array(12));
         $this->fail("Exception not thrown");
     } catch (ProjectAdminException $e) {
         // Expected
     }
     try {
         $gw->removeAdmins($projectId = "test", array(12));
         $this->fail("Exception not thrown");
     } catch (ProjectAdminException $e) {
         // Expected
     }
     try {
         $gw->removeAdmins($projectId = null, array(12));
         $this->fail("Exception not thrown");
     } catch (ProjectAdminException $e) {
         // Expected
     }
     try {
         $gw->removeAdmins($projectId = 1, array(12, ""));
         $this->fail("Exception not thrown");
     } catch (ProjectAdminException $e) {
         // Expected
     }
     try {
         $gw->removeAdmins($projectId = 1, array(1, "xyz"));
         $this->fail("Exception not thrown");
     } catch (ProjectAdminException $e) {
         // Expected
     }
     try {
         $gw->removeAdmins($projectId = 1, null);
         $this->fail("Exception not thrown");
     } catch (ProjectAdminException $e) {
         // Expected
     }
     // Pass empty array, valid project Id
     $this->assertEquals(0, $gw->removeAdmins($projectId = 1, $empList = array()));
     $this->assertEquals(3, $this->_countAdmins());
     // Remove one admin, invalid empNumber
     $this->assertEquals(0, $gw->removeAdmins($projectId = 1, $empList = array(12)));
     $this->assertEquals(3, $this->_countAdmins());
     // Remove one admin, valid empNumber but not admin
     $this->assertEquals(0, $gw->removeAdmins($projectId = 1, $empList = array(3)));
     $this->assertEquals(3, $this->_countAdmins());
     // Remove one admin, valid empNumber and admin but wrong project
     $this->assertEquals(0, $gw->removeAdmins($projectId = 2, $empList = array(1)));
     $this->assertEquals(3, $this->_countAdmins());
     // Remove one admin, valid empNumber and admin for given project
     $this->assertEquals(1, $gw->removeAdmins($projectId = 1, $empList = array(1)));
     $this->assertEquals(2, $this->_countAdmins());
     $this->assertEquals(0, $this->_countAdmins("emp_number = 1"));
     $this->_deleteAllAdmins();
     $this->_insertAdmins();
     // Remove two admins, one valid, the other invalid
     $this->assertEquals(1, $gw->removeAdmins($projectId = 1, $empList = array(2, 12)));
     $this->assertEquals(2, $this->_countAdmins());
     $this->assertEquals(1, $this->_countAdmins("emp_number = 2"));
     $this->_deleteAllAdmins();
     $this->_insertAdmins();
     // Remove two admins, both valid admins but invalid project Id
     $this->assertEquals(0, $gw->removeAdmins($projectId = 14, $empList = array(2, 1)));
     $this->assertEquals(3, $this->_countAdmins());
     $this->assertTrue(mysql_query("INSERT INTO hs_hr_project_admin(emp_number, project_id) " . "VALUES(3, 1)"));
     $this->assertEquals(1, mysql_affected_rows());
     // Remove three admins, both valid admins
     $this->assertEquals(3, $gw->removeAdmins($projectId = 1, $empList = array(1, 2, 3)));
     $this->assertEquals(1, $this->_countAdmins());
     $this->assertEquals(1, $this->_countAdmins("emp_number = 2 AND project_id = 2"));
 }
 function delParser($indexCode, $arrList)
 {
     $this->indexCode = $indexCode;
     switch ($this->indexCode) {
         case 'EST':
             $this->empstat = new EmploymentStatus();
             $res = $this->empstat->delEmpStat($arrList);
             break;
         case 'JEM':
             $this->jobtit_empstat = new JobTitEmpStat();
             $res = $this->jobtit_empstat->delJobTitEmpStat($arrList);
             break;
         case 'JOB':
             $this->jobtit = new JobTitle();
             $res = $this->jobtit->delJobTitles($arrList);
             break;
         case 'SPC':
             if (isset($arrList[0])) {
                 try {
                     $res = JobSpec::delete($arrList[0]);
                 } catch (JobSpecException $e) {
                     $res = false;
                 }
             }
             break;
         case 'CST':
             $this->compstruct = new CompStruct();
             $res = $this->compstruct->delCompStruct($arrList);
             break;
         case 'LOC':
             $this->location = new models_eimadmin_Location();
             $res = $this->location->delLocation($arrList);
             break;
         case 'SKI':
             $this->skills = new Skills();
             $res = $this->skills->delSkills($arrList);
             break;
         case 'ETH':
             $this->ethnicrace = new EthnicRace();
             $res = $this->ethnicrace->delEthnicRace($arrList);
             break;
         case 'MEM':
             $this->membershiptype = new MembershipType();
             $res = $this->membershiptype->delMembershipType($arrList);
             break;
         case 'NAT':
             $this->nationalityinfo = new NationalityInfo();
             $res = $this->nationalityinfo->delNationalityInfo($arrList);
             break;
         case 'LAN':
             $this->languageinfo = new LanguageInfo();
             $res = $this->languageinfo->delLanguageInfo($arrList);
             break;
         case 'MME':
             $this->membershipinformation = new MembershipInfo();
             $res = $this->membershipinformation->delMembershipInfo($arrList);
             break;
         case 'SGR':
             $this->salarygrade = new SalaryGrades();
             $res = $this->salarygrade->delSalaryGrades($arrList);
             break;
         case 'EDU':
             $this->qual = new Education();
             $res = $this->qual->delEducation($arrList);
             break;
         case 'EEC':
             $this->EEOJobCat = new EEOJobCat();
             $res = $this->EEOJobCat->delEEOJobCat($arrList);
             break;
         case 'LIC':
             $this->Licenses = new Licenses();
             $res = $this->Licenses->delLicenses($arrList);
             break;
         case 'CUS':
             $this->customers = new Customer();
             $res = $this->customers->deletewrapperCustomer($arrList);
             break;
         case 'CTM':
             $this->customFields = new CustomFields();
             if (isset($arrList[0])) {
                 try {
                     $this->customFields->deleteFields($arrList[0]);
                     $res = true;
                     if (is_array($arrList) && count($arrList) > 0) {
                         $mediator = EventMediator::instance();
                         $mediator->notify(EventMediator::POST_CUSTOM_FIELD_DELETE_EVENT, array('customFieldIds' => $arrList[0]));
                     }
                 } catch (CustomFieldsException $e) {
                     $res = false;
                 }
             } else {
                 $res = false;
             }
             break;
         case 'CEX':
             if (isset($arrList[0])) {
                 try {
                     CustomExport::deleteExports($arrList[0]);
                     $res = true;
                 } catch (CustomExportException $e) {
                     $res = false;
                 }
             } else {
                 $res = false;
             }
             break;
         case 'CIM':
             if (isset($arrList[0])) {
                 try {
                     CustomImport::deleteImports($arrList[0]);
                     $res = true;
                 } catch (CustomImportException $e) {
                     $res = false;
                 }
             } else {
                 $res = false;
             }
             break;
         case 'PRJ':
             $this->Projects = new Projects();
             $res = $this->Projects->deletewrapperProjects($arrList);
             break;
         case 'PAD':
             // Project admins
             $gw = new ProjectAdminGateway();
             $projectId = $_GET['id'];
             $res = $gw->removeAdmins($projectId, $arrList[0]);
             break;
         case 'PAC':
             // Project activity
             $authorizeObj = new authorize($_SESSION['empID'], $_SESSION['isAdmin']);
             $projectId = $_GET['projectId'];
             if ($authorizeObj->isAdmin() || $authorizeObj->isProjectAdminOf($projectId)) {
                 $res = ProjectActivity::deleteActivities($arrList[0], $projectId);
             }
             break;
         case 'USR':
             $this->users = new Users();
             $res = $this->users->delUsers($arrList);
             break;
         case 'USG':
             $this->usergroups = new UserGroups();
             $res = $this->usergroups->delUserGroups($arrList);
             break;
     }
     if ($res) {
         $_GET['message'] = 'DELETE_SUCCESS';
     } else {
         $_GET['message'] = 'DELETE_FAILURE';
     }
 }