/common/components/ActualTimeline1.php

https://gitlab.com/abigabaw/dptt · PHP · 181 lines · 129 code · 31 blank · 21 comment · 0 complexity · db50d2b89e90981464c9e5e62386cd16 MD5 · raw file

  1. <?php
  2. namespace common\components;
  3. use Yii;
  4. use yii\base\Widget;
  5. use backend\models\Queries;
  6. use backend\models\IterationType;
  7. use backend\models\PipelineStage;
  8. use backend\models\VProject;
  9. /*
  10. How to run the widget:
  11. use backend\components\DPTTInfo;
  12. <?=DPTTInfo::widget(['message' => ' Yii2.0']) ?>
  13. */
  14. class ActualTimeline1 extends Widget{
  15. public $id;
  16. public $elementid;
  17. public $normal_color;
  18. public $repeat_color;
  19. public $iteration_color;
  20. //Data for normal progress
  21. public $dataset_normal;
  22. public $dataset_data_normal;
  23. //Data for extension of normal progress
  24. public $dataset_normal_extension;
  25. public $dataset_data_normal_extension;
  26. //Data for repeat of milestone
  27. public $dataset_repeat;
  28. public $dataset_data_repeat;
  29. //Data for extension of repeat of milestone
  30. public $dataset_repeat_extension;
  31. public $dataset_data_repeat_extension;
  32. //Data for iteration of milestone
  33. public $dataset_iteration;
  34. public $dataset_data_iteration;
  35. //Data for extension of iteration of milestone
  36. public $dataset_iteration_extension;
  37. public $dataset_data_iteration_extension;
  38. public function init(){
  39. $series=[];
  40. $mstone =[];
  41. $mstone2 =[];
  42. $ct=$ctr=0;
  43. //Scale 1: Distinct Milestones Achieved
  44. $m=Yii::$app->db->createCommand("SELECT distinct milestone_id from v_milestone_submission where project_id=".$this->id." order by start_date asc")->queryAll();
  45. foreach($m as $ms)
  46. $mstone[$ms['milestone_id']]=++$ct;
  47. //Scale 2: Milestones of pipeline
  48. $pipeline=Yii::$app->session['pipeline'] ? Yii::$app->session['pipeline'] : VProject::find()->where(['id'=>$this->id])->one()->pipeline_id;
  49. //die(print_r($this->id));
  50. $st=PipelineStage::find()->where(['pipeline'=>$pipeline])->orderBy(['ordering'=>SORT_ASC])->All();
  51. //print_r($st);
  52. foreach($st as $stage) {
  53. //echo $stage;
  54. $ms=Yii::$app->db->createCommand("select milestone from milestone_stage where stage=".$stage->stage." order by ordering asc")->queryAll();
  55. foreach ($ms as $mst) {
  56. $mstone2[$mst['milestone']]=++$ctr;
  57. }
  58. }
  59. $scale=$mstone2;
  60. $qry = Yii::$app->db->createCommand(Queries::qryMilestoneSubmission($this->id))->queryAll();
  61. $this->normal_color = IterationType::findOne(1)->color_code;
  62. $this->repeat_color = IterationType::findOne(3)->color_code;
  63. $this->iteration_color = IterationType::findOne(5)->color_code;
  64. // echo "<pre>";die(print_r($qry));
  65. foreach($qry as $key => $ar){
  66. switch($ar['iteration_type_id']){
  67. case 1:
  68. $this->dataset_normal .= '{ x: '.strtotime($ar['start_date']).'000, y: '.$scale[$ar['milestone_id']].' },';
  69. $this->dataset_data_normal .='{ x: '.strtotime($ar['start_date']).'000, text: \'<b>Started milestone:</b> <br/>'.str_replace('\'', '', $ar['milestone']).'<br/>\' },';
  70. $this->dataset_normal .= '{ x: '.strtotime($ar['end_date']).'000, y: '.$scale[$ar['milestone_id']].' },';
  71. $this->dataset_data_normal .='{ x: '.strtotime($ar['end_date']).'000, text: \'<b>Submitted milestone:</b> <br/>'.str_replace('\'', '', $ar['milestone']).'<br/>\' },';
  72. //set other values to null
  73. break;
  74. case 2:
  75. $this->dataset_normal_extension .= '{ x: '.strtotime($ar['start_date']).'000, y: '.$scale[$ar['milestone_id']].' },';
  76. $this->dataset_data_normal_extension .='{ x: '.strtotime($ar['start_date']).'000, text: \'<b>Extended milestone:</b> <br/>'.str_replace('\'', '', $ar['milestone']).'<br/>\' },';
  77. $this->dataset_normal_extension .= '{ x: '.strtotime($ar['end_date']).'000, y: '.$scale[$ar['milestone_id']].' },';
  78. $this->dataset_data_normal_extension .='{ x: '.strtotime($ar['end_date']).'000, text: \'<b>Submitted milestone:</b> <br/>'.str_replace('\'', '', $ar['milestone']).'<br/>\' },';
  79. //set other values to null
  80. $this->dataset_normal .= '{ x: '.strtotime($ar['start_date']).'000, y: null },';
  81. $this->dataset_normal .= '{ x: '.strtotime($ar['end_date']).'000, y: '.$scale[$ar['milestone_id']].' },';
  82. break;
  83. case 3:
  84. $this->dataset_repeat .= '{ x: '.strtotime($ar['start_date']).'000, y: '.$scale[$ar['milestone_id']].' },';
  85. $this->dataset_data_repeat .='{ x: '.strtotime($ar['start_date']).'000, text: \'<b>Started repeat of milestone:</b> <br/>'.str_replace('\'', '', $ar['milestone']).'<br/>\' },';
  86. $this->dataset_repeat .= '{ x: '.strtotime($ar['end_date']).'000, y: '.$scale[$ar['milestone_id']].' },';
  87. $this->dataset_data_repeat .='{ x: '.strtotime($ar['end_date']).'000, text: \'<b>Submitted repeat of milestone:</b> <br/>'.str_replace('\'', '', $ar['milestone']).'<br/>\' },';
  88. break;
  89. case 4:
  90. $this->dataset_repeat_extension .= '{ x: '.strtotime($ar['start_date']).'000, y: '.$scale[$ar['milestone_id']].' },';
  91. $this->dataset_data_repeat_extension .='{ x: '.strtotime($ar['start_date']).'000, text: \'<b>Extended milestone:</b> <br/>'.str_replace('\'', '', $ar['milestone']).'<br/>\' },';
  92. $this->dataset_repeat_extension .= '{ x: '.strtotime($ar['end_date']).'000, y: '.$scale[$ar['milestone_id']].' },';
  93. $this->dataset_data_repeat_extension .='{ x: '.strtotime($ar['end_date']).'000, text: \'<b>Submitted of milestone:</b> <br/>'.str_replace('\'', '', $ar['milestone']).'<br/>\' },';
  94. $this->dataset_repeat .= '{ x: '.strtotime($ar['start_date']).'000, y: null },';
  95. $this->dataset_repeat .= '{ x: '.strtotime($ar['end_date']).'000, y: '.$scale[$ar['milestone_id']].' },';
  96. break;
  97. case 5:
  98. $this->dataset_iteration .= '{ x: '.strtotime($ar['start_date']).'000, y: '.$scale[$ar['milestone_id']].' },';
  99. $this->dataset_data_iteration .='{ x: '.strtotime($ar['start_date']).'000, text: \'<b>Started iteration of milestone:</b> <br/>'.str_replace('\'', '', $ar['milestone']).'<br/>\' },';
  100. $this->dataset_iteration .= '{ x: '.strtotime($ar['end_date']).'000, y: '.$scale[$ar['milestone_id']].' },';
  101. $this->dataset_data_iteration .='{ x: '.strtotime($ar['end_date']).'000, text: \'<b>Submitted iteration of milestone:</b> <br/>'.str_replace('\'', '', $ar['milestone']).'<br/>\' },';
  102. break;
  103. case 6:
  104. $this->dataset_iteration_extension .= '{ x: '.strtotime($ar['start_date']).'000, y: '.$scale[$ar['milestone_id']].' },';
  105. $this->dataset_data_iteration_extension .='{ x: '.strtotime($ar['start_date']).'000, text: \'<b>Extended milestone:</b> <br/>'.str_replace('\'', '', $ar['milestone']).'<br/>\' },';
  106. $this->dataset_iteration_extension .= '{ x: '.strtotime($ar['end_date']).'000, y: '.$scale[$ar['milestone_id']].' },';
  107. $this->dataset_data_iteration_extension .='{ x: '.strtotime($ar['end_date']).'000, text: \'<b>Submitted milestone:</b> <br/>'.str_replace('\'', '', $ar['milestone']).'<br/>\' },';
  108. $this->dataset_iteration .='{ x: '.strtotime($ar['start_date']).'000, y: null },';
  109. $this->dataset_iteration .='{ x: '.strtotime($ar['end_date']).'000, y: '.$ar['milestone_id'].' },';
  110. break;
  111. }
  112. }
  113. $this->dataset_normal = rtrim($this->dataset_normal);
  114. $this->dataset_data_normal = rtrim($this->dataset_data_normal);
  115. $this->dataset_normal_extension = rtrim($this->dataset_normal_extension);
  116. $this->dataset_data_normal_extension = rtrim($this->dataset_data_normal_extension);
  117. $this->dataset_repeat = rtrim($this->dataset_repeat);
  118. $this->dataset_data_repeat = rtrim($this->dataset_data_repeat);
  119. $this->dataset_repeat_extension = rtrim($this->dataset_repeat_extension);
  120. $this->dataset_data_repeat_extension = rtrim($this->dataset_data_repeat_extension);
  121. $this->dataset_iteration = rtrim($this->dataset_iteration);
  122. $this->dataset_data_iteration = rtrim($this->dataset_data_iteration);
  123. $this->dataset_iteration_extension = rtrim($this->dataset_iteration_extension);
  124. $this->dataset_data_iteration_extension = rtrim($this->dataset_data_iteration_extension);
  125. }
  126. public function run(){
  127. return $this->render('/widget/actualtimeline1',
  128. [
  129. 'normal_color' => $this->normal_color,
  130. 'repeat_color' => $this->repeat_color,
  131. 'iteration_color' => $this->iteration_color,
  132. 'dataset_normal' => $this->dataset_normal,
  133. 'dataset_data_normal' => $this->dataset_data_normal,
  134. 'dataset_normal_extension' => $this->dataset_normal_extension,
  135. 'dataset_data_normal_extension' => $this->dataset_data_normal_extension,
  136. 'dataset_repeat' => $this->dataset_repeat,
  137. 'dataset_data_repeat' => $this->dataset_data_repeat,
  138. 'dataset_repeat_extension' => $this->dataset_repeat_extension,
  139. 'dataset_data_repeat_extension' => $this->dataset_data_repeat_extension,
  140. 'dataset_iteration' => $this->dataset_iteration,
  141. 'dataset_data_iteration' => $this->dataset_data_iteration,
  142. 'dataset_iteration_extension' => $this->dataset_iteration_extension,
  143. 'dataset_data_iteration_extension' => $this->dataset_data_iteration,
  144. 'elementid' => $this->elementid,
  145. ]);
  146. }
  147. }
  148. ?>