예제 #1
0
 function testDeleteKPI()
 {
     global $dd;
     $kpi_group_ids[] = $this->createKPIGroup($this->company_id, 10);
     $kpi_group_ids[] = $this->createKPIGroup($this->company_id, 20);
     // Create a KPI( Rating Type )
     $kpi_ids[10] = $this->createKPI($this->company_id, 10, 10, $kpi_group_ids[0], 1, 10);
     // Create another KPI( Text Type )
     $kpi_ids[30] = $this->createKPI($this->company_id, 70, 70, $kpi_group_ids[1]);
     // Create reviews
     $user_ids[] = $dd->createUser($this->company_id, 12);
     $user_ids[] = $dd->createUser($this->company_id, 13);
     $user_ids[] = $dd->createUser($this->company_id, 14);
     $user_ids[] = $dd->createUser($this->company_id, 15);
     foreach ($kpi_ids as $type => $kpi_id) {
         $user_key = rand(0, 2);
         $reviewer_user_key = $user_key + 1;
         $user_review_control_ids[] = $user_review_control_id = $this->createUserReviewControl($user_ids[$user_key], $user_ids[$reviewer_user_key]);
         if ($user_review_control_id != '') {
             $urf = TTnew('UserReviewFactory');
             $urf->setUserReviewControl($user_review_control_id);
             $urf->setKPI($kpi_id);
             switch ($type) {
                 case 10:
                     $urf->setRating(7);
                     break;
                 case 30:
                     $urf->setNote('');
                     break;
             }
             if ($urf->isValid()) {
                 $user_review_ids[] = $urf->Save();
             }
         }
     }
     // Delete the KPI which is in use, it will fail to delete
     foreach ($kpi_ids as $kpi_id) {
         $lf = new KPIListFactory();
         $lf->getById($kpi_id);
         if ($lf->getRecordCount() == 1) {
             $lf = $lf->getCurrent();
             $lf->setDeleted(TRUE);
             $is_valid = $lf->isValid();
             if ($is_valid == TRUE) {
                 $lf->Save();
             }
         }
     }
     $kpi_arr = $this->getKPIArrayByControlId($user_review_control_ids[0]);
     $this->assertEquals($kpi_arr[0]['type_id'], 10);
     $this->assertEquals($kpi_arr[0]['minimum_rate'], 1);
     $this->assertEquals($kpi_arr[0]['maximum_rate'], 10);
     $this->assertEquals($kpi_arr[0]['group_id'][0], $kpi_group_ids[0]);
     $this->assertEquals($kpi_arr[0]['rating'], 7);
     $kpi_arr = $this->getKPIArrayByControlId($user_review_control_ids[1]);
     $this->assertEquals($kpi_arr[0]['type_id'], 30);
     $this->assertEquals($kpi_arr[0]['minimum_rate'], FALSE);
     $this->assertEquals($kpi_arr[0]['maximum_rate'], FALSE);
     $this->assertEquals($kpi_arr[0]['group_id'][0], $kpi_group_ids[1]);
     $this->assertEquals($kpi_arr[0]['rating'], FALSE);
     // Delete reviews first and then delete KPIs
     foreach ($user_review_ids as $user_review_id) {
         $lf = new UserReviewListFactory();
         $lf->getById($user_review_id);
         if ($lf->getRecordCount() == 1) {
             $lf = $lf->getCurrent();
             $lf->setDeleted(TRUE);
             $is_valid = $lf->isValid();
             if ($is_valid == TRUE) {
                 $lf->Save();
             }
         }
     }
     foreach ($kpi_ids as $kpi_id) {
         $lf = new KPIListFactory();
         $lf->getById($kpi_id);
         if ($lf->getRecordCount() == 1) {
             $lf = $lf->getCurrent();
             $lf->setDeleted(TRUE);
             $is_valid = $lf->isValid();
             if ($is_valid == TRUE) {
                 $lf->Save();
             }
         }
     }
     $kpi_arr = $this->getKPIArrayByControlId($user_review_control_ids[0]);
     $this->assertEquals($kpi_arr, FALSE);
     $kpi_arr = $this->getKPIArrayByControlId($user_review_control_ids[1]);
     $this->assertEquals($kpi_arr, FALSE);
     return TRUE;
 }
예제 #2
0
 function getByCompanyIdArray($company_id, $include_blank = TRUE)
 {
     $klf = new KPIListFactory();
     $klf->getByCompanyId($company_id);
     if ($include_blank == TRUE) {
         $list[0] = '--';
     }
     foreach ($klf as $kpi_obj) {
         $list[$kpi_obj->getID()] = $kpi_obj->getName();
     }
     if (isset($list)) {
         return $list;
     }
     return FALSE;
 }