Example #1
0
 /**
  * Tests the deleteActivities() method.
  */
 public function testDeleteActivities()
 {
     $projId = 1;
     $ids = array(1, 2, 3, 4);
     // Verify that invalid project ids throw exceptions
     try {
         ProjectActivity::deleteActivities($ids, "Test");
         $this->fail("Exception not thrown");
     } catch (ProjectActivityException $e) {
         // Expected
     }
     // Verify that invalid project ids throw exceptions
     try {
         ProjectActivity::deleteActivities($ids, "");
         $this->fail("Exception not thrown");
     } catch (ProjectActivityException $e) {
         // Expected
     }
     // Verify that invalid activity ids throw exceptions
     try {
         ProjectActivity::deleteActivities(null, 1);
         $this->fail("Exception not thrown");
     } catch (ProjectActivityException $e) {
         // Expected
     }
     // Verify that invalid activity ids throw exceptions
     try {
         ProjectActivity::deleteActivities(array(1, ""), 1);
         $this->fail("Exception not thrown");
     } catch (ProjectActivityException $e) {
         // Expected
     }
     // Verify that invalid activity ids throw exceptions
     try {
         ProjectActivity::deleteActivities(array(1, "ew"), 1);
         $this->fail("Exception not thrown");
     } catch (ProjectActivityException $e) {
         // Expected
     }
     // try deleting unavailable ids.
     $numDeleted = ProjectActivity::deleteActivities($ids, $projId);
     $this->assertEquals(0, $numDeleted);
     $numDeleted = ProjectActivity::deleteActivities($ids);
     $this->assertEquals(0, $numDeleted);
     // create some activites
     $actList = $this->_getTestActivities();
     $this->_createActivites($actList);
     mysql_query("UPDATE ohrm_project_activity SET is_deleted = 0");
     // delete one and check
     $ids = array(1);
     $numDeleted = ProjectActivity::deleteActivities($ids);
     $this->assertEquals(1, $numDeleted);
     $num = $this->_getNumActivities("activity_id = 1 AND deleted = 1");
     $this->assertEquals(1, $num);
     $num = $this->_getNumActivities("deleted = 1");
     $this->assertEquals(1, $num);
     $num = $this->_getNumActivities("deleted = 0");
     $this->assertEquals(3, $num);
     // delete already deleted activity, verify no change
     $numDeleted = ProjectActivity::deleteActivities($ids);
     $this->assertEquals(0, $numDeleted);
     $num = $this->_getNumActivities("activity_id = 1 AND deleted = 1");
     $this->assertEquals(1, $num);
     $num = $this->_getNumActivities("deleted = 1");
     $this->assertEquals(1, $num);
     mysql_query("UPDATE ohrm_project_activity SET is_deleted = 0");
     // verify that only activies in given project are deleted.
     // NOTE: 1,2,3 belong to projId 1, 4 to projId 2
     $projId = 2;
     $ids = array(1, 2, 3);
     $numDeleted = ProjectActivity::deleteActivities($ids, $projId);
     $this->assertEquals(0, $numDeleted);
     $num = $this->_getNumActivities("deleted = 1");
     $this->assertEquals(0, $num);
     $ids = array(1, 2, 3, 4);
     $numDeleted = ProjectActivity::deleteActivities($ids, $projId);
     $this->assertEquals(1, $numDeleted);
     $num = $this->_getNumActivities("deleted = 1");
     $this->assertEquals(1, $num);
     $num = $this->_getNumActivities("activity_id = 4 AND deleted = 1");
     $this->assertEquals(1, $num);
     // delete multiple activities
     $ids = array(1, 2, 3);
     $numDeleted = ProjectActivity::deleteActivities($ids);
     $this->assertEquals(3, $numDeleted);
     $num = $this->_getNumActivities("deleted = 1");
     $this->assertEquals(4, $num);
 }
 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';
     }
 }