/** * Exports time records * * @param void * @return null */ function export() { $object_visibility = array_var($_GET, 'visibility', VISIBILITY_NORMAL); $exportable_modules = explode(',', array_var($_GET, 'modules', null)); if (!is_foreachable($exportable_modules)) { $exportable_modules = null; } // if require_once PROJECT_EXPORTER_MODULE_PATH . '/models/ProjectExporterOutputBuilder.class.php'; $output_builder = new ProjectExporterOutputBuilder($this->active_project, $this->smarty, $this->active_module, $exportable_modules); if (!$output_builder->createOutputFolder()) { $this->serveData($output_builder->execution_log, 'execution_log', null, FORMAT_JSON); } // if $output_builder->createAttachmentsFolder(); $timerecords = TimeRecords::findByProject($this->active_project, STATE_VISIBLE, $object_visibility); $distinct_months = array(); foreach ($timerecords as $timerecord) { $date = $timerecord->getRecordDate(); $exists = false; for ($x = 0; $x < count($distinct_months); $x++) { if ($distinct_months[$x]['month'] == $date->getMonth() && $distinct_months[$x]['year'] == $date->getYear()) { $exists = true; } // if } // for if (!$exists) { $distinct_months[] = array("year" => $date->getYear(), "month" => $date->getMonth(), "month_string" => $date->date_data['month'], "beginning_of_month" => DateTimeValue::beginningOfMonth($date->getMonth(), $date->getYear()), "end_of_month" => DateTimeValue::endOfMonth($date->getMonth(), $date->getYear())); } // if } // foreach $people = ProjectUsers::findUsersByProject($this->active_project); $companies = Companies::findByProject($this->active_project); $total_times = array(); foreach ($people as $person) { $person->temp_total_time = TimeRecords::getTotalUserTimeOnProject($this->active_project, $person); } // foreach $output_builder->setFileTemplate($this->active_module, $this->controller_name, 'index'); $output_builder->smarty->assign(array("distinct_months" => $distinct_months, "people" => $people, "companies" => $companies, "total_times" => $total_times, "timerecords" => $timerecords)); $output_builder->outputToFile('index'); // export monthly report if (is_foreachable($distinct_months)) { $output_builder->setFileTemplate($this->active_module, $this->controller_name, 'monthly'); foreach ($distinct_months as $distinct_month) { $output_builder->smarty->assign(array('current_month' => $distinct_month, 'start_date' => DateTimeValue::beginningOfMonth($distinct_month[month], $distinct_month['year']), 'end_date' => DateTimeValue::endOfMonth($distinct_month['month'], $distinct_month['year']))); $output_builder->outputToFile('monthly_' . $distinct_month['month'] . '_' . $distinct_month['year']); } // foreach } // if // export report for persons if (is_foreachable($people)) { $output_builder->setFileTemplate($this->active_module, $this->controller_name, 'person'); foreach ($people as $person) { $output_builder->smarty->assign(array('current_person' => $person)); $output_builder->outputToFile('user_' . $person->getId()); } // foreach } // if $this->serveData($output_builder->execution_log, 'execution_log', null, FORMAT_JSON); }
/** * Returns array of companies that are involved in project * @param Project $project * @return array */ function findByProject($project) { $people = ProjectUsers::findUsersByProject($project); if (is_foreachable($people)) { $company_ids = array(); foreach ($people as $person) { if (!in_array($person->getCompanyId(), $company_ids)) { $company_ids[] = $person->getCompanyId(); } // if } // foreach return Companies::findByIds($company_ids); } else { return null; } // if }
/** * Return users that are assigned to this project * * @param void * @return array */ function getUsers() { if ($this->users === false) { $this->users = ProjectUsers::findUsersByProject($this); } // if return $this->users; }