/frontend/components/ActualTimeline.php

https://gitlab.com/abigabaw/dptt · PHP · 155 lines · 111 code · 29 blank · 15 comment · 0 complexity · 55107e656131ad0b211d0baeaafaf19d MD5 · raw file

  1. <?php
  2. namespace frontend\components;
  3. use Yii;
  4. use yii\base\Widget;
  5. use frontend\models\Queries;
  6. use frontend\models\IterationType;
  7. /*
  8. How to run the widget:
  9. use frontend\components\DPTTInfo;
  10. <?=DPTTInfo::widget(['message' => ' Yii2.0']) ?>
  11. */
  12. class ActualTimeline extends Widget{
  13. public $id;
  14. public $elementid;
  15. public $normal_color;
  16. public $repeat_color;
  17. public $iteration_color;
  18. //Data for normal progress
  19. public $dataset_normal;
  20. public $dataset_data_normal;
  21. //Data for extension of normal progress
  22. public $dataset_normal_extension;
  23. public $dataset_data_normal_extension;
  24. //Data for repeat of milestone
  25. public $dataset_repeat;
  26. public $dataset_data_repeat;
  27. //Data for extension of repeat of milestone
  28. public $dataset_repeat_extension;
  29. public $dataset_data_repeat_extension;
  30. //Data for iteration of milestone
  31. public $dataset_iteration;
  32. public $dataset_data_iteration;
  33. //Data for extension of iteration of milestone
  34. public $dataset_iteration_extension;
  35. public $dataset_data_iteration_extension;
  36. public function init(){
  37. $qry = Yii::$app->db->createCommand(Queries::qryMilestoneSubmission($this->id))->queryAll();
  38. $this->normal_color = IterationType::findOne(1)->color_code;
  39. $this->repeat_color = IterationType::findOne(3)->color_code;
  40. $this->iteration_color = IterationType::findOne(5)->color_code;
  41. foreach($qry as $key => $ar){
  42. switch($ar['iteration_type']){
  43. case 1:
  44. $this->dataset_normal .= '{ x: '.strtotime($ar['start_date']).'000, y: '.$ar['milestone_id'].' },';
  45. $this->dataset_data_normal .='{ x: '.strtotime($ar['start_date']).'000, text: \'<b>Started milestone:</b> <br/>'.str_replace('\'', '', $ar['milestone']).'<br/>\' },';
  46. $this->dataset_normal .= '{ x: '.strtotime($ar['end_date']).'000, y: '.$ar['milestone_id'].' },';
  47. $this->dataset_data_normal .='{ x: '.strtotime($ar['end_date']).'000, text: \'<b>Submitted milestone:</b> <br/>'.str_replace('\'', '', $ar['milestone']).'<br/>\' },';
  48. //set other values to null
  49. break;
  50. case 2:
  51. $this->dataset_normal_extension .= '{ x: '.strtotime($ar['start_date']).'000, y: '.$ar['milestone_id'].' },';
  52. $this->dataset_data_normal_extension .='{ x: '.strtotime($ar['start_date']).'000, text: \'<b>Extended milestone:</b> <br/>'.str_replace('\'', '', $ar['milestone']).'<br/>\' },';
  53. $this->dataset_normal_extension .= '{ x: '.strtotime($ar['end_date']).'000, y: '.$ar['milestone_id'].' },';
  54. $this->dataset_data_normal_extension .='{ x: '.strtotime($ar['end_date']).'000, text: \'<b>Submitted milestone:</b> <br/>'.str_replace('\'', '', $ar['milestone']).'<br/>\' },';
  55. //set other values to null
  56. $this->dataset_normal .= '{ x: '.strtotime($ar['start_date']).'000, y: null },';
  57. $this->dataset_normal .= '{ x: '.strtotime($ar['end_date']).'000, y: '.$ar['milestone_id'].' },';
  58. break;
  59. case 3:
  60. $this->dataset_repeat .= '{ x: '.strtotime($ar['start_date']).'000, y: '.$ar['milestone_id'].' },';
  61. $this->dataset_data_repeat .='{ x: '.strtotime($ar['start_date']).'000, text: \'<b>Started repeat of milestone:</b> <br/>'.str_replace('\'', '', $ar['milestone']).'<br/>\' },';
  62. $this->dataset_repeat .= '{ x: '.strtotime($ar['end_date']).'000, y: '.$ar['milestone_id'].' },';
  63. $this->dataset_data_repeat .='{ x: '.strtotime($ar['end_date']).'000, text: \'<b>Submitted repeat of milestone:</b> <br/>'.str_replace('\'', '', $ar['milestone']).'<br/>\' },';
  64. break;
  65. case 4:
  66. $this->dataset_repeat_extension .= '{ x: '.strtotime($ar['start_date']).'000, y: '.$ar['milestone_id'].' },';
  67. $this->dataset_data_repeat_extension .='{ x: '.strtotime($ar['start_date']).'000, text: \'<b>Extended milestone:</b> <br/>'.str_replace('\'', '', $ar['milestone']).'<br/>\' },';
  68. $this->dataset_repeat_extension .= '{ x: '.strtotime($ar['end_date']).'000, y: '.$ar['milestone_id'].' },';
  69. $this->dataset_data_repeat_extension .='{ x: '.strtotime($ar['end_date']).'000, text: \'<b>Submitted of milestone:</b> <br/>'.str_replace('\'', '', $ar['milestone']).'<br/>\' },';
  70. $this->dataset_repeat .= '{ x: '.strtotime($ar['start_date']).'000, y: null },';
  71. $this->dataset_repeat .= '{ x: '.strtotime($ar['end_date']).'000, y: '.$ar['milestone_id'].' },';
  72. break;
  73. case 5:
  74. $this->dataset_iteration .= '{ x: '.strtotime($ar['start_date']).'000, y: '.$ar['milestone_id'].' },';
  75. $this->dataset_data_iteration .='{ x: '.strtotime($ar['start_date']).'000, text: \'<b>Started iteration of milestone:</b> <br/>'.str_replace('\'', '', $ar['milestone']).'<br/>\' },';
  76. $this->dataset_iteration .= '{ x: '.strtotime($ar['end_date']).'000, y: '.$ar['milestone_id'].' },';
  77. $this->dataset_data_iteration .='{ x: '.strtotime($ar['end_date']).'000, text: \'<b>Submitted iteration of milestone:</b> <br/>'.str_replace('\'', '', $ar['milestone']).'<br/>\' },';
  78. break;
  79. case 6:
  80. $this->dataset_iteration_extension .= '{ x: '.strtotime($ar['start_date']).'000, y: '.$ar['milestone_id'].' },';
  81. $this->dataset_data_iteration_extension .='{ x: '.strtotime($ar['start_date']).'000, text: \'<b>Extended milestone:</b> <br/>'.str_replace('\'', '', $ar['milestone']).'<br/>\' },';
  82. $this->dataset_iteration_extension .= '{ x: '.strtotime($ar['end_date']).'000, y: '.$ar['milestone_id'].' },';
  83. $this->dataset_data_iteration_extension .='{ x: '.strtotime($ar['end_date']).'000, text: \'<b>Submitted milestone:</b> <br/>'.str_replace('\'', '', $ar['milestone']).'<br/>\' },';
  84. $this->dataset_iteration .= '{ x: '.strtotime($ar['start_date']).'000, y: null },';
  85. $this->dataset_iteration .= '{ x: '.strtotime($ar['end_date']).'000, y: '.$ar['milestone_id'].' },';
  86. break;
  87. }
  88. }
  89. $this->dataset_normal = rtrim($this->dataset_normal);
  90. $this->dataset_data_normal = rtrim($this->dataset_data_normal);
  91. $this->dataset_normal_extension = rtrim($this->dataset_normal_extension);
  92. $this->dataset_data_normal_extension = rtrim($this->dataset_data_normal_extension);
  93. $this->dataset_repeat = rtrim($this->dataset_repeat);
  94. $this->dataset_data_repeat = rtrim($this->dataset_data_repeat);
  95. $this->dataset_repeat_extension = rtrim($this->dataset_repeat_extension);
  96. $this->dataset_data_repeat_extension = rtrim($this->dataset_data_repeat_extension);
  97. $this->dataset_iteration = rtrim($this->dataset_iteration);
  98. $this->dataset_data_iteration = rtrim($this->dataset_data_iteration);
  99. $this->dataset_iteration_extension = rtrim($this->dataset_iteration_extension);
  100. $this->dataset_data_iteration_extension = rtrim($this->dataset_data_iteration_extension);
  101. }
  102. public function run(){
  103. return $this->render('/widget/actualtimeline',
  104. [
  105. 'normal_color' => $this->normal_color,
  106. 'repeat_color' => $this->repeat_color,
  107. 'iteration_color' => $this->iteration_color,
  108. 'dataset_normal' => $this->dataset_normal,
  109. 'dataset_data_normal' => $this->dataset_data_normal,
  110. 'dataset_normal_extension' => $this->dataset_normal_extension,
  111. 'dataset_data_normal_extension' => $this->dataset_data_normal_extension,
  112. 'dataset_repeat' => $this->dataset_repeat,
  113. 'dataset_data_repeat' => $this->dataset_data_repeat,
  114. 'dataset_repeat_extension' => $this->dataset_repeat_extension,
  115. 'dataset_data_repeat_extension' => $this->dataset_data_repeat_extension,
  116. 'dataset_iteration' => $this->dataset_iteration,
  117. 'dataset_data_iteration' => $this->dataset_data_iteration,
  118. 'dataset_iteration_extension' => $this->dataset_iteration,
  119. 'dataset_data_iteration_extension' => $this->dataset_data_iteration,
  120. 'elementid' => $this->elementid,
  121. ]);
  122. }
  123. }
  124. ?>