/** * Test csv convertion of array */ public function testConvertArray() { $data = array('first entry', 'second entry'); $converted = "\"\n\"\n"; $result = Phprojekt_Converter_Csv::convert($data); $this->assertEquals($converted, $result); $data = array(); $data[0][] = 'Title 1'; $data[0][] = 'Title 2'; $data[1][] = 'Data 1'; $data[1][] = 'Data 2'; $convertedFields = '"Title 1","Title 2"'; $convertedValues = '"Data 1","Data 2"'; $result = Phprojekt_Converter_Csv::convert($data); $this->assertContains($convertedFields, $result); $this->assertContains($convertedValues, $result); }
/** * 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); }
/** * Returns the list of requested ids items. * * The function use Phprojekt_ModelInformation_Default::ORDERING_LIST for get and sort the fields. * * OPTIONAL request parameters: * <pre> * - string <b>ids</b> Comma separated ids of the item to list. * </pre> * * The return is in CSV format. * * @return void */ public function csvExportMultipleAction() { $ids = $this->getRequest()->getParam('ids', null); $this->setCurrentProjectId(); if (!empty($ids)) { $idsArray = explode(",", $ids); $where = "id IN ("; $i = 0; foreach ($idsArray as $id) { $i++; $where .= (int) $id; if ($i < count($idsArray)) { $where .= ", "; } } $where .= ")"; $records = $this->getModelObject()->fetchAll($where, null, 0, 0); Phprojekt_Converter_Csv::echoConvert($records, Phprojekt_ModelInformation_Default::ORDERING_LIST); } }
/** * Returns the list of the bookings in the month. * * The function use Phprojekt_ModelInformation_Default::ORDERING_LIST for get and sort the fields. * * OPTIONAL request parameters: * <pre> * - integer <b>year</b> Year to consult. * - integer <b>month</b> Month to consult. * </pre> * * The return is in CSV format. * * @return void */ public function csvListAction() { $db = Phprojekt::getInstance()->getDb(); $userId = Phprojekt_Auth::getUserId(); $year = (int) $this->getRequest()->getParam('year', date("Y")); $month = (int) $this->getRequest()->getParam('month', date("m")); if (strlen($month) == 1) { $month = '0' . $month; } $where = sprintf('(owner_id = %d AND DATE(start_datetime) LIKE %s)', (int) $userId, $db->quote($year . '-' . $month . '-%')); $this->setCurrentProjectId(); $records = $this->getModelObject()->fetchAll($where, 'start_datetime ASC'); Phprojekt_Converter_Csv::echoConvert($records); }
/** * Returns the list of events where the logged user is involved, * for a specific period (like week or month). * * The function use Phprojekt_ModelInformation_Default::ORDERING_LIST for get and sort the fields. * * OPTIONAL request parameters: * <pre> * - date <b>dateStart</b> Start date for filter. * - date <b>dateEnd</b> End date for filter. * - integer <b>count</b> Use for SQL LIMIT count. * - integer <b>offset</b> Use for SQL LIMIT offset. * </pre> * * The return is in CSV format. * * @return void */ public function csvPeriodListAction() { $count = (int) $this->getRequest()->getParam('count', null); $offset = (int) $this->getRequest()->getParam('start', null); $db = Phprojekt::getInstance()->getDb(); $dateStart = $db->quote(Cleaner::sanitize('date', $this->getRequest()->getParam('dateStart', date("Y-m-d")))); $dateEnd = $db->quote(Cleaner::sanitize('date', $this->getRequest()->getParam('dateEnd', date("Y-m-d")))); $this->setCurrentProjectId(); $where = sprintf('participant_id = %d AND DATE(start_datetime) <= %s AND DATE(end_datetime) >= %s', (int) PHprojekt_Auth::getUserId(), $dateEnd, $dateStart); $records = $this->getModelObject()->fetchAll($where, "start_datetime", $count, $offset); Phprojekt_Converter_Csv::echoConvert($records, Phprojekt_ModelInformation_Default::ORDERING_FORM); }