PageRenderTime 54ms CodeModel.GetById 24ms RepoModel.GetById 1ms app.codeStats 0ms

/application/plugins/reports/models/Reports.class.php

https://github.com/fb83/Project-Pier
PHP | 402 lines | 262 code | 33 blank | 107 comment | 47 complexity | 6d89659771f59c26fa90c41adec61efa MD5 | raw file
Possible License(s): AGPL-1.0, GPL-2.0, AGPL-3.0, LGPL-2.1, GPL-3.0
  1. <?php
  2. /**
  3. * @author ALBATROS INFORMATIQUE SARL - CARQUEFOU FRANCE - Damien HENRY
  4. * @licence Honest Public License
  5. * @package ProjectPier Gantt
  6. * @version $Id$
  7. * @access public
  8. */
  9. class Reports {
  10. public function __construct(){
  11. }
  12. /**
  13. *Make Gantt
  14. *@return image png & die
  15. */
  16. function MakeGanttChart(){
  17. // is logged ?
  18. if (!logged_user()->isProjectUser(active_project())) {
  19. die;
  20. } // if
  21. // is user can view this project ??
  22. if (!ProjectFile::canView(logged_user(), active_project())) {
  23. die;
  24. } //if
  25. /*
  26. * Init gantt graph
  27. */
  28. $width = 850;
  29. $graph = new GanttGraph($width);
  30. /*
  31. * here header must be set at end and during process catch all date to determine the difference max between start and end
  32. * to present HDAY or not depend on information volume
  33. */
  34. //graph header
  35. $graph->ShowHeaders(GANTT_HYEAR | GANTT_HMONTH | GANTT_HWEEK | GANTT_HDAY);
  36. // Instead of week number show the date for the first day in the week
  37. // on the week scale
  38. $graph->scale->week->SetStyle(WEEKSTYLE_FIRSTDAY);
  39. $graph->SetMarginColor('blue:1.7');
  40. $graph->SetColor('white');
  41. $graph->SetBackgroundGradient('#60A2BA','white',GRAD_HOR,BGRAD_MARGIN);
  42. //$graph->SetBackgroundGradient('#A01010','white',GRAD_HOR,BGRAD_MARGIN);
  43. $graph->title->SetColor('white');
  44. $graph->title->SetFont(FF_FONT2,FS_BOLD,18);
  45. //$graph->scale->actinfo->SetColTitles(array('Act','Duration','Start','Finish','Resp'));
  46. $graph->scale->actinfo->SetStyle(ACTINFO_3D);
  47. $graph->scale->actinfo->SetFont(FF_ARIAL,FS_NORMAL,10);
  48. $graph->scale->actinfo->vgrid->SetColor('gray');
  49. $graph->scale->actinfo->SetColor('darkgray');
  50. $locale_char_set = 'utf-8';
  51. //For french support
  52. //Localization::instance()->getLocale();
  53. //if (preg_match('/' . Localization::instance()->getLocale() . '/i', 'fr_fr')) $graph->scale->SetDateLocale("fr_FR.utf8");
  54. /*
  55. * data jpgraph construction gantt type for project
  56. */
  57. $project = active_project();
  58. //Project title
  59. $project_name = $project->getName();
  60. $graph->title->Set(lang('project') . ': ' . substr(utf8_decode($project_name),0,40) );
  61. $rows = $this->displayProjectGantt($project, $graph, 0);
  62. $subprojects = $project->getSubprojects();
  63. if (is_array($subprojects)) {
  64. foreach($subprojects as $subproject) {
  65. $rows = $this->displayProjectGantt($subproject, $graph, $rows++);
  66. }
  67. }
  68. //send data
  69. $type = "image/png";
  70. $name = "projectpiergantt.png";
  71. header("Content-Type: $type");
  72. header("pragma: no-cache");
  73. header("Content-Disposition: attachment; filename=\"$name\"");
  74. $graph->Stroke();
  75. die(); //end process do not send other informations
  76. } //MakeGantt
  77. function displayProjectGantt(&$project, &$graph, $start_row) {
  78. /*
  79. * There is no start date in project i take the created date project
  80. * fields "created_on"
  81. */
  82. //start date project
  83. $start_date = Localization::instance()->formatDate($project->getCreatedOn(),0,"Y-m-d");
  84. //line number jpgraph
  85. $rows = $start_row;
  86. $project_name = $project->getName();
  87. $label = lang('project') . ': ' . substr(utf8_decode($project_name),0,40);
  88. $mydate = date('Y-m-d');
  89. $data = array(
  90. array($rows++,ACTYPE_GROUP,$label,$start_date,$mydate,'')
  91. );
  92. $graph->SetSimpleFont(FF_FONT1,FS_BOLD,18);
  93. $graph->CreateSimple($data);
  94. /*
  95. * Milestone
  96. */
  97. $milestonehidden = array();
  98. $milestones = $project->getMilestones();
  99. $mymilestone = array();
  100. if (is_array($milestones)) {
  101. foreach($milestones as $milestone){
  102. if (!in_array($milestone->getId(),$milestonehidden)){
  103. $ms_date = $milestone->getDueDate();
  104. if (is_null($ms_date)) {
  105. $ms_date = Localization::instance()->formatDate($project->getCreatedOn(),0,"Y-m-d");
  106. } else {
  107. $ms_date = Localization::instance()->formatDate($ms_date,0,'Y-m-d');
  108. }
  109. $mymilestone[] = array($rows++, ACTYPE_MILESTONE, " " . utf8_decode($milestone->getName()), $ms_date, $ms_date);
  110. } //if
  111. } //foreach
  112. } //if
  113. // add many diamond on graph
  114. if (count($mymilestone)>0) $graph->CreateSimple($mymilestone);
  115. $task_lists = $project->getTaskLists();
  116. /*
  117. * We took only task because we can just compute execution % on task_list, there is no notion in task
  118. */
  119. //milestone which dont appear => link to task_list
  120. $milestonehidden = array();
  121. if (is_array($task_lists)) {
  122. // Tasks lists
  123. foreach ($task_lists as $task_list) {
  124. //security access User can view this task_list ?
  125. if (!ProjectTaskList::canView(logged_user(), $task_list->getId())) continue;
  126. // task list name
  127. $task_list_name=$task_list->getName();
  128. //due to migration to 0.8.6 it s possible task_list due_date isnull
  129. $start_date = $task_list->getStartDate();
  130. if (is_null($start_date)) {
  131. $start_date = Localization::instance()->formatDate($project->getCreatedOn(),0,"Y-m-d");
  132. //$start_date = date('Y-m-d');
  133. } else {
  134. $start_date = Localization::instance()->formatDate($start_date,0,'Y-m-d');
  135. }
  136. $mydate = $task_list->getDueDate();
  137. if ($mydate == ''){
  138. $mydate = date('Y-m-d');
  139. }else{
  140. $mydate = Localization::instance()->formatDate($mydate,0,'Y-m-d');
  141. }
  142. $progress = $this->progress($task_list);
  143. $progressgantt = array(
  144. array($rows,$progress[0]/100)
  145. );
  146. /*
  147. * detect if task_list is linked to milestone ?
  148. */
  149. $istasklistlinktomilestone = $task_list->getMilestone();
  150. //This task list have a milestone it due_date is milestone now
  151. $typebar = ACTYPE_GROUP;
  152. $milestonename = '';
  153. if ($istasklistlinktomilestone != '' && $istasklistlinktomilestone != null){
  154. $mydatemilestone = $istasklistlinktomilestone->getDueDate();
  155. if ($mydatemilestone != ''){
  156. $mydate = Localization::instance()->formatDate($mydatemilestone,0,'Y-m-d');
  157. }
  158. $milestonehidden[] = $istasklistlinktomilestone->getId();
  159. $typebar = ACTYPE_MILESTONE;
  160. $milestonename = "\n " . lang('milestone') . ": " . substr(utf8_decode($istasklistlinktomilestone->getName()),0,20);
  161. }//if
  162. $datasgantt = array(
  163. array($rows++,$typebar," " . substr(utf8_decode($task_list_name),0,35) . " [" . $progress[1] . '/' . $progress[2] . "]" . $this->epure($milestonename),$start_date,$mydate,'[' . $progress[0] ."%]",'','')
  164. );
  165. //task for this task_list
  166. $tasks = $task_list->getTasks();
  167. if (is_array($tasks)) {
  168. foreach($tasks as $task) {
  169. /*
  170. * security access
  171. */
  172. //security access User can view this task ?
  173. if (!ProjectTask::canView(logged_user(), $task->getId())) continue;
  174. // icon freeming ok | cancel
  175. if ($task->isCompleted()) {
  176. //complete
  177. $progressgantt[] = array($rows,1);
  178. } else {
  179. $progressgantt[] = array($rows,0);
  180. }//if
  181. //task name
  182. $task_text = '[' . $task->getId() . '] ' . $task->getText();
  183. $this->epure($task_text);
  184. $task_text = " $task_text";
  185. if (strlen($task_text) > 35) $task_text = substr($task_text,0,35) . "...";
  186. $start_date = $task->getStartDate();
  187. if (is_null($start_date)) {
  188. $start_date = Localization::instance()->formatDate($project->getCreatedOn(),0,"Y-m-d");
  189. //$start_date = date('Y-m-d');
  190. } else {
  191. $start_date = Localization::instance()->formatDate($start_date,0,'Y-m-d');
  192. }
  193. $mydate = $task->getDueDate();
  194. if ($mydate == ''){
  195. $mydate = date('Y-m-d');
  196. } else {
  197. $mydate = Localization::instance()->formatDate($mydate,0,'Y-m-d');
  198. }
  199. $datasgantt[] = array($rows++,ACTYPE_NORMAL,utf8_decode($task_text),$start_date,$mydate,$mydate,'','');
  200. }
  201. }
  202. if (count($datasgantt)> 0) $graph->CreateSimple($datasgantt,null,$progressgantt);
  203. } // foreach
  204. } // if
  205. return $rows;
  206. } // displayProjectGantt
  207. /**
  208. *Make Mn
  209. *@return string
  210. */
  211. function MakeMindMap(){
  212. // header xml data freemind
  213. $content = "<map version=\"0.9.0\">\n";
  214. $content .= "<!-- To view this file, download free mind mapping software FreeMind from http://freemind.sourceforge.net -->\n";
  215. $mytime = time();
  216. // is logged ?
  217. if (!logged_user()->isProjectUser(active_project())) {
  218. echo $content;
  219. echo "<node CREATED=\"$mytime\" ID=\"Freemind_Link_558888646\" MODIFIED=\"$mytime\" STYLE=\"bubble\" TEXT=\"Disconnected\">\n";
  220. echo "</node>\n";
  221. echo "</map>\n";
  222. die;
  223. } // if
  224. // is user can view this project ??
  225. if (!ProjectFile::canView(logged_user(), active_project())) {
  226. echo $content;
  227. echo "<node CREATED=\"$mytime\" ID=\"Freemind_Link_558888646\" MODIFIED=\"$mytime\" STYLE=\"bubble\" TEXT=\"Not Allowed\">\n";
  228. echo "</node>\n";
  229. echo "</map>\n";
  230. die;
  231. } //if
  232. /*
  233. * xml data construction freemind for project
  234. */
  235. $project = active_project();
  236. $project_name = $project->getName();
  237. $this->epure($project_name);
  238. //Project title
  239. $url = externalUrl(get_url('task','index'));
  240. $content .= "<node CREATED=\"$mytime\" LINK=\"$url\" MODIFIED=\"$mytime\" STYLE=\"bubble\" TEXT=\"$project_name\">\n";
  241. //milestones
  242. $milestones = $project->getMilestones();
  243. $mymilestone = array();
  244. if (is_array($milestones)) {
  245. foreach($milestones as $milestone){
  246. $url = externalUrl(get_url('milestone','view',array('id' => $milestone->getId())));
  247. $content .= "<node CREATED=\"$mytime\" LINK=\"$url\" POSITION=\"right\" MODIFIED=\"$mytime\" TEXT=\" [" . $milestone->getName() . ' ' . Localization::instance()->formatDate($milestone->getDueDate()) . "]\">\n";
  248. $content .= "<font NAME=\"SansSerif\" BOLD=\"true\" SIZE=\"12\"/>";
  249. $content .= "<icon BUILTIN=\"messagebox_warning\"/>\n";
  250. $content .= "<icon BUILTIN=\"messagebox_warning\"/>\n";
  251. $content .= "</node>\n";
  252. }
  253. }
  254. $task_lists = $project->getTaskLists();
  255. if (is_array($task_lists)) {
  256. //Tasks lists
  257. $positions = array('right','left');
  258. $actualpos = 0;
  259. foreach ($task_lists as $task_list) {
  260. /*
  261. * security access
  262. */
  263. //security access User can view this task_list ?
  264. if (!ProjectTaskList::canView(logged_user(), $task_list->getId())) continue;
  265. // task list name
  266. $task_list_name=$task_list->getName();
  267. //Complete or not complete
  268. $progress = $this->progress($task_list);
  269. $icon = null;
  270. $tasklistComplete = false;
  271. if ($progress[0] == '100'){
  272. $icon .= "<icon BUILTIN=\"button_ok\"/>\n";
  273. $tasklistComplete = true;
  274. }
  275. $kt_tl_var = 'tl:' . $task_list_name;
  276. $this->epure($kt_tl_var);
  277. if (strlen($task_list_name) > 40) $task_list_name = substr($task_list_name,0,40) . "...";
  278. $position = $positions[$actualpos];
  279. $url = externalUrl(get_url('task','view_list',array('id' => $task_list->getId())));
  280. $content .= "<node CREATED=\"$mytime\" LINK=\"$url\" MODIFIED=\"$mytime\" POSITION=\"$position\" TEXT=\"$task_list_name\">\n";
  281. $content .= "$icon";
  282. if ($actualpos == 0){
  283. $actualpos =1;
  284. }else{
  285. $actualpos =0;
  286. } //if
  287. //tasks
  288. $tasks = $task_list->getTasks();
  289. if (is_array($tasks)) {
  290. foreach($tasks as $task) {
  291. /*
  292. * security access
  293. */
  294. //security access User can view this task ?
  295. if (!ProjectTask::canView(logged_user(), $task->getId())) continue;
  296. // icon freeming ok | cancel
  297. $icon = null;
  298. if (!$tasklistComplete){
  299. if ($task->isCompleted()) {
  300. //complete : icon ok
  301. $icon .= "<icon BUILTIN=\"button_ok\"/>\n";
  302. $dateclose = " []";
  303. }else{
  304. //incomplete : icon cancel
  305. $icon .= "<icon BUILTIN=\"button_cancel\"/>\n";
  306. $dateclose = " []";
  307. } //if
  308. } //if
  309. //task name
  310. $task_text = $task->getText();
  311. $this->epure($task_text);
  312. if (strlen($task_text) > 40) $task_text = substr($task_text,0,40) . "...";
  313. $url = externalUrl(get_url('task','view_task',array('id' => $task->getId())));
  314. $content .= "<node CREATED=\"$mytime\" LINK=\"$url\" MODIFIED=\"$mytime\" TEXT=\"" . $task_text . "\">\n";
  315. $content .= $icon;
  316. $content .= "</node>\n";
  317. }
  318. }
  319. $content .= "</node>\n";
  320. } // if
  321. } // if
  322. //footer xml data freemind
  323. $content .= "</node>\n";
  324. $content .= "</map>";
  325. //send data
  326. $type = "x-freemind/mm";
  327. $name = "projectpier.mm";
  328. $size = strlen($content);
  329. header("Content-Type: $type");
  330. header("Content-Disposition: attachment; filename=\"$name\"");
  331. header("Content-Length: " . (string) $size);
  332. echo $content;
  333. die; //end process do not send other informations
  334. } //MakeMm
  335. /*
  336. * Necessary call by line : if (!ProjectTaskList::canView(logged_user(), $task_list->getId())) continue;
  337. */
  338. public function isPrivate(){
  339. return false;
  340. } //isPrivate
  341. /*
  342. * Necessary : call by line : if (!ProjectTask::canView(logged_user(), $task->getId())) continue;
  343. */
  344. public function getProject(){
  345. return active_project();
  346. } //getProject
  347. private function progress($task_list){
  348. /*
  349. * return string[]
  350. */
  351. $totalTasks = $task_list->countAllTasks();
  352. $openTasks = $task_list->countOpenTasks();
  353. $completedTasks = $task_list->countCompletedTasks();
  354. $percentTasks = 0;
  355. if ($totalTasks>0) {
  356. $percentTasks = round($completedTasks / $totalTasks * 100);
  357. }
  358. return array($percentTasks,$completedTasks,$totalTasks);
  359. }
  360. private function epure(&$value){
  361. /*
  362. * for epure char include <> not compatible with xml datas
  363. */
  364. $value = preg_replace('/\>|\</','',$value);
  365. $value = preg_replace('/\"/','\'',$value);
  366. $value = preg_replace('/\n|\r/','',$value);
  367. }
  368. }
  369. ?>