コード例 #1
0
ファイル: TimeTest.php プロジェクト: RainyBlueSky/PHProjekt
 /**
  * Test convertMinutesToHours
  */
 public function testConvertMinutesToHours()
 {
     $converter = new Phprojekt_Converter_Time();
     $this->assertEquals('00:20', $converter->convertMinutesToHours(20));
     $this->assertEquals('01:20', $converter->convertMinutesToHours(80));
     $this->assertEquals('10:05', $converter->convertMinutesToHours(605));
 }
コード例 #2
0
 /**
  * Returns the statistics data.
  *
  * Also return the Total per rows.
  *
  * OPTIONAL request parameters:
  * <pre>
  *  - date    <b>startDate</b> ISO start date for filter.
  *  - date    <b>endDate</b>   ISO end date for filter.
  *  - integer <b>nodeId</b>    List all the projects under nodeId.
  * </pre>
  *
  * The return is in CSV format.
  *
  * @return void
  */
 public function csvListAction()
 {
     $startDate = Cleaner::sanitize('date', $this->getRequest()->getParam('startDate', date("Y-m-d")));
     $endDate = Cleaner::sanitize('date', $this->getRequest()->getParam('endDate', date("Y-m-d")));
     $projectId = (int) $this->getRequest()->getParam('nodeId', null);
     $this->setCurrentProjectId();
     $data = $this->getModelObject()->getStatistics($startDate, $endDate, $projectId);
     $data = $data['data'];
     $rows = array();
     $sumPerUser = array();
     $index = 0;
     $rows[$index][] = 'Project';
     foreach ($data['users'] as $name) {
         $rows[$index][] = $name;
     }
     $rows[$index][] = 'Total';
     $index++;
     $converter = new Phprojekt_Converter_Time();
     foreach ($data['projects'] as $projectId => $title) {
         $sumPerProject = 0;
         $rows[$index][] = $title;
         foreach (array_keys($data['users']) as $userId) {
             if (!isset($data['rows'][$projectId][$userId])) {
                 $rows[$index][] = $converter->convertMinutesToHours(0);
             } else {
                 $rows[$index][] = $converter->convertMinutesToHours($data['rows'][$projectId][$userId]);
                 $sumPerProject = $sumPerProject + $data['rows'][$projectId][$userId];
                 if (!isset($sumPerUser[$userId])) {
                     $sumPerUser[$userId] = 0;
                 }
                 $sumPerUser[$userId] = $sumPerUser[$userId] + $data['rows'][$projectId][$userId];
             }
         }
         $rows[$index][] = $converter->convertMinutesToHours($sumPerProject);
         $index++;
     }
     $rows[$index][] = 'Total';
     $total = 0;
     foreach (array_keys($data['users']) as $userId) {
         if (!isset($sumPerUser[$userId])) {
             $rows[$index][] = $converter->convertMinutesToHours(0);
         } else {
             $rows[$index][] = $converter->convertMinutesToHours($sumPerUser[$userId]);
             $total = $total + $sumPerUser[$userId];
         }
     }
     $rows[$index][] = $converter->convertMinutesToHours($total);
     Phprojekt_Converter_Csv::echoConvert($rows);
 }