示例#1
0
 public function executeUpdateTimesheetItemComment($request)
 {
     $this->backAction = $this->getContext()->getUser()->getFlash('actionName');
     $this->getContext()->getUser()->setFlash('actionName', $this->backAction);
     $timesheetId = $request->getParameter('timesheetId');
     $activityId = $request->getParameter('activityId');
     $projectId = $this->getProjectId($activityId);
     $date = $request->getParameter('date');
     $comment = $request->getParameter('comment');
     $employeeId = $request->getParameter('employeeId');
     $dao = new TimesheetDao();
     $timesheetItem = $dao->getTimesheetItemByDateProjectId($timesheetId, $employeeId, $projectId, $activityId, $date);
     if ($timesheetItem[0]->getTimesheetItemId() == null) {
         $newTimesheetItem = new TimesheetItem();
         $newTimesheetItem->setTimesheetId($timesheetId);
         $newTimesheetItem->setDate($date);
         $newTimesheetItem->setComment(trim($comment));
         $newTimesheetItem->setProjectId($projectId);
         $newTimesheetItem->setEmployeeId($employeeId);
         $newTimesheetItem->setActivityId($activityId);
         $dao->saveTimesheetItem($newTimesheetItem);
     } else {
         $timesheetItem[0]->setComment(trim($comment));
         $dao->saveTimesheetItem($timesheetItem[0]);
     }
 }
示例#2
0
 public function executeUpdateTimesheetItemComment($request)
 {
     $this->backAction = $this->getContext()->getUser()->getFlash('actionName');
     $this->getContext()->getUser()->setFlash('actionName', $this->backAction);
     $timesheetId = $request->getParameter('timesheetId');
     $activityId = $request->getParameter('activityId');
     $projectId = $this->getProjectId($activityId);
     $date = $request->getParameter('date');
     $comment = $request->getParameter('comment');
     $csrfToken = $request->getParameter('csrfToken');
     $form = new TimesheetFormToImplementCsrfTokens();
     if ($form->getCSRFToken() != $csrfToken) {
         return sfView::NONE;
     }
     $employeeId = $request->getParameter('employeeId');
     $dao = new TimesheetDao();
     $timesheetItem = $dao->getTimesheetItemByDateProjectId($timesheetId, $employeeId, $projectId, $activityId, $date);
     if ($timesheetItem[0]->getTimesheetItemId() == null) {
         $newTimesheetItem = new TimesheetItem();
         $newTimesheetItem->setTimesheetId($timesheetId);
         $newTimesheetItem->setDate($date);
         $newTimesheetItem->setComment(trim($comment));
         $newTimesheetItem->setProjectId($projectId);
         $newTimesheetItem->setEmployeeId($employeeId);
         $newTimesheetItem->setActivityId($activityId);
         $resultItem = $dao->saveTimesheetItem($newTimesheetItem);
     } else {
         $timesheetItem[0]->setComment(trim($comment));
         $resultItem = $dao->saveTimesheetItem($timesheetItem[0]);
     }
     return $this->renderText($resultItem->getTimesheetItemId());
 }
示例#3
0
 /**
  * Add or Save TimesheetItem
  * @param $timesheetItem
  * @return $timesheetItem
  */
 public function saveTimesheetItem(TimesheetItem $timesheetItem)
 {
     try {
         if ($timesheetItem->getTimesheetItemId() == '') {
             $idGenService = new IDGeneratorService();
             $idGenService->setEntity($timesheetItem);
             $timesheetItem->setTimesheetItemId($idGenService->getNextID());
         }
         $timesheetItem->save();
         return $timesheetItem;
     } catch (Exception $ex) {
         throw new DaoException($ex->getMessage());
     }
 }
示例#4
0
 public function getTimesheet($date, $employeeId, $timesheetId)
 {
     $timesheetItems = $this->getTimesheetDao()->getTimesheetItem($timesheetId, $employeeId);
     $startDate = $date;
     $timesheet = $this->getTimesheetDao()->getTimesheetByStartDateAndEmployeeId($startDate, $employeeId);
     $endDate = $timesheet->getEndDate();
     $dates = $this->getDatesOfTheTimesheetPeriod($startDate, $endDate);
     if (!empty($timesheetItems)) {
         $temp = current($timesheetItems);
         $projectId = $temp["projectId"];
         $activityId = $temp["activityId"];
         $i = 0;
         foreach ($timesheetItems as $timesheetItem) {
             if ($timesheetItem["projectId"] == $projectId && $timesheetItem["activityId"] == $activityId) {
                 $rows[$i][] = $timesheetItem;
             } else {
                 $projectId = $timesheetItem["projectId"];
                 $activityId = $timesheetItem["activityId"];
                 $i++;
                 $rows[$i][] = $timesheetItem;
             }
         }
         foreach ($rows as $row) {
             $rowArray['projectId'] = $row[0]["projectId"];
             $rowArray['projectName'] = $row[0]->getProject()->getCustomer()->getName() . " - ##" . $row[0]->getProject()->getName();
             $rowArray['isProjectDeleted'] = $row[0]->getProject()->getIsDeleted();
             $rowArray['activityId'] = $row[0]["activityId"];
             $rowArray['activityName'] = $row[0]->getProjectActivity()->getName();
             $rowArray['isActivityDeleted'] = $row[0]->getProjectActivity()->getIsDeleted();
             foreach ($dates as $date) {
                 $current = current($row);
                 if ($date == $current["date"]) {
                     $timesheetItemsArray[$date] = array_shift($row);
                     continue;
                 }
                 $newTimesheetItem = new TimesheetItem();
                 $newTimesheetItem->setDate($date);
                 $timesheetItemsArray[$date] = $newTimesheetItem;
             }
             $rowArray['timesheetItems'] = $timesheetItemsArray;
             $printableArray[] = $rowArray;
         }
         return $printableArray;
     } else {
         return null;
     }
 }
示例#5
0
 /**
  * Testing saveTimesheetItem method for the newly made timesheet Items
  */
 public function testSaveTimesheetItemWithNewTimesheetItem()
 {
     TestDataService::truncateTables(array('TimesheetItem'));
     $timesheetItem = new TimesheetItem();
     $timesheetItem->setTimesheetId(1);
     $timesheetItem->setDate("2011-04-23");
     $timesheetItem->setDuration("5700");
     $timesheetItem->setComment("New Timesheet Item");
     $timesheetItem->setProjectId(1);
     $timesheetItem->setEmployeeId(1);
     $timesheetItem->setActivityId(4);
     $savedNewTimesheetItem = $this->timesheetDao->saveTimesheetItem($timesheetItem);
     $this->assertTrue($savedNewTimesheetItem instanceof TimesheetItem);
     $this->assertEquals('001', $savedNewTimesheetItem->getTimesheetItemId());
     $this->assertEquals($timesheetItem->getTimesheetId(), $savedNewTimesheetItem->getTimesheetId());
     $this->assertEquals($timesheetItem->getDate(), $savedNewTimesheetItem->getDate());
     $this->assertEquals($timesheetItem->getDuration(), $savedNewTimesheetItem->getDuration());
     $this->assertEquals($timesheetItem->getComment(), $savedNewTimesheetItem->getComment());
     $this->assertEquals($timesheetItem->getProjectId(), $savedNewTimesheetItem->getProjectId());
     $this->assertEquals($timesheetItem->getEmployeeId(), $savedNewTimesheetItem->getEmployeeId());
     $this->assertEquals($timesheetItem->getActivityId(), $savedNewTimesheetItem->getActivityId());
 }
 public function saveTimesheetItems($inputTimesheetItems, $employeeId, $timesheetId, $keysArray, $initialRows)
 {
     foreach ($inputTimesheetItems as $inputTimesheetItem) {
         $activityId = $inputTimesheetItem['projectActivityName'];
         if ($activityId != null) {
             $activity = $this->getTimesheetDao()->getProjectActivityByActivityId($activityId);
             $projectId = $activity->getProjectId();
             $tempArray = array_slice($inputTimesheetItem, 3);
             for ($i = 0; $i < sizeof($keysArray); $i++) {
                 $date = $keysArray[$i];
                 $timesheetItemId = $inputTimesheetItem['TimesheetItemId' . $i];
                 $timesheetItemDuration = $inputTimesheetItem[$i];
                 if ($timesheetItemId != null) {
                     $existingTimesheetItem = $this->getTimesheetDao()->getTimesheetItemById($timesheetItemId);
                     $existingTimesheetItem->setProjectId($projectId);
                     $existingTimesheetItem->setActivityId($activityId);
                     if ($timesheetItemDuration == null) {
                         $timesheetItemDuration = 0;
                     }
                     $existingTimesheetItem->setDuration($this->convertDurationToSeconds($timesheetItemDuration));
                     $existingTimesheetItem->save();
                 } else {
                     if ($timesheetItemDuration != null) {
                         $existingTimesheetItem = $this->getTimesheetDao()->getTimesheetItemByDateProjectId($timesheetId, $employeeId, $projectId, $activityId, $date);
                         if ($existingTimesheetItem[0]->getProjectId() != null) {
                             $existingTimesheetItem[0]->setProjectId($projectId);
                             $existingTimesheetItem[0]->setActivityId($activityId);
                             $existingTimesheetItem[0]->setDuration($this->convertDurationToSeconds($timesheetItemDuration));
                             $existingTimesheetItem[0]->save();
                         } else {
                             $newTimesheetItem = new TimesheetItem();
                             $newTimesheetItem->setProjectId($projectId);
                             $newTimesheetItem->setActivityId($activityId);
                             $newTimesheetItem->setDate($date);
                             $newTimesheetItem->setDuration($this->convertDurationToSeconds($timesheetItemDuration));
                             $newTimesheetItem->setTimesheetId($timesheetId);
                             $newTimesheetItem->setEmployeeId($employeeId);
                             $this->getTimesheetDao()->saveTimesheetItem($newTimesheetItem);
                         }
                     }
                 }
             }
         }
     }
 }