leonsuke

models/Site.php

Nov 5th, 2019
289
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.40 KB | None | 0 0
  1. <?php
  2.  
  3. namespace app\models;
  4.  
  5. use Yii;
  6.  
  7. use yii\db\Query;
  8.  
  9. use yii\base\Model;
  10.  
  11. use app\modules\personnel\models\Employee;
  12.  
  13. class Site extends Model
  14. {
  15. private $query;
  16. private $employee_amount;
  17.  
  18. public function __construct()
  19. {
  20. $this->query = new Query;
  21. $this->employee_amount = Employee::find()->count();
  22. }
  23.  
  24. public function getDataGenderGrafik()
  25. {
  26. /* ##### GENDER ##### */
  27. // Get all employee with select field education_id
  28. $this->query->select('gender_id')->from('employees');
  29. $employee_gender_id = $this->query->all();
  30.  
  31. // Loop value from $employee_gender_id
  32. foreach ($employee_gender_id as $value) {
  33. if ($value['gender_id'] == 1177) {
  34. $gender_group['male'][] = $value;
  35. } else {
  36. $gender_group['female'][] = $value;
  37. }
  38. }
  39.  
  40. // Set $count_edu_group into array
  41. $count_gender_group = [];
  42.  
  43. // Loop again with use $gender_group
  44. foreach ($gender_group as $gender_groups => $gender_group_value) {
  45. $count_gender_group[$gender_groups] = count($gender_group_value);
  46. }
  47.  
  48. // Count
  49. $employee_gender['male'] = $count_gender_group['male'] / $this->employee_amount * 100;
  50. $employee_gender['female'] = $count_gender_group['female'] / $this->employee_amount * 100;
  51.  
  52. return $employee_gender;
  53. }
  54.  
  55. public function getDataEducationGrafik()
  56. {
  57. // Get all employee with select field education_id
  58. $this->query->select('education_id')->from('employees');
  59. $employee_education_id = $this->query->all();
  60.  
  61. // Loop value from $employee_education_id
  62. foreach ($employee_education_id as $value) {
  63. if ($value['education_id'] == 1219) {
  64. $edu_group['s1'][] = $value;
  65. } elseif ($value['education_id'] == 1220) {
  66. $edu_group['s2'][] = $value;
  67. } elseif ($value['education_id'] == 1221) {
  68. $edu_group['s3'][] = $value;
  69. } else {
  70. $edu_group['others'][] = $value;
  71. }
  72. }
  73.  
  74. // Set $count_edu_group into array
  75. $count_edu_group = [];
  76.  
  77. // Loop again with use $edu_group
  78. foreach ($edu_group as $edu_groups => $edu_group_value) {
  79. $count_edu_group[$edu_groups] = count($edu_group_value);
  80. }
  81.  
  82. // Count
  83. $employee_education['s1'] = $count_edu_group['s1'] / $this->employee_amount * 100;
  84. $employee_education['s2'] = $count_edu_group['s2'] / $this->employee_amount * 100;
  85. $employee_education['s3'] = $count_edu_group['s3'] / $this->employee_amount * 100;
  86. $employee_education['others'] = $count_edu_group['others'] / $this->employee_amount * 100;
  87.  
  88. return $employee_education;
  89. }
  90.  
  91. public function getDataDateBirthGrafik()
  92. {
  93. $formatter = \Yii::$app->formatter;
  94. $date_linux = Yii::$app->formatter->asdateTime('now', 'php:Y-m-d');
  95.  
  96. // Get array of birth_date and return record on query result
  97. $this->query->select('birth_date')->from('employees');
  98. $employee_birth_date = $this->query->all();
  99.  
  100. // Loop value from $employee_birth_date
  101. foreach ($employee_birth_date as $value) {
  102. // Set into normal format Date
  103. $cli_birth_date = Yii::$app->formatter->asDate($value['birth_date']);
  104.  
  105. // Set
  106. $cli_birth_year = date('Y', strtotime($cli_birth_date));
  107.  
  108. $age = date('Y', strtotime($date_linux)) - $cli_birth_year;
  109. if ($age < 35) {
  110. $age_group['below_35'][] = $age;
  111. } elseif ($age > 40) {
  112. $age_group['above_40'][] = $age;
  113. } else {
  114. $age_group['35_to_40'][] = $age;
  115. }
  116. }
  117.  
  118. // Set $count_datebirth_group into array
  119. $count_datebirth_group = [];
  120.  
  121. // Loop again with use $age_group
  122. foreach ($age_group as $age_groups => $age_group_value) {
  123. $count_datebirth_group[$age_groups] = count($age_group_value);
  124. // count_datebirth_group['below_35']
  125. // count_datebirth_group['above_40']
  126. // count_datebirth_group['35_to_40']
  127. }
  128. $date_birth['below_35'] = $count_datebirth_group['below_35'] / $this->employee_amount * 100;
  129. $date_birth['above_40'] = $count_datebirth_group['above_40'] / $this->employee_amount * 100;
  130. $date_birth['between_35_to_40'] = $count_datebirth_group['35_to_40'] / $this->employee_amount * 100;
  131.  
  132. return $date_birth;
  133. }
  134.  
  135. public function getDataEmployeeStatusGrafik()
  136. {
  137. // Get all employee with select field education_id
  138. $this->query->select('employment_status_id')->from('employees');
  139. $employment_status_id = $this->query->all();
  140.  
  141. // Loop value from $employee_education_id
  142. foreach ($employment_status_id as $value) {
  143. if ($value['employment_status_id'] == 1283) {
  144. $emp_stat_group['pns'][] = $value;
  145. } elseif ($value['employment_status_id'] == 232260) {
  146. $emp_stat_group['tetap'][] = $value;
  147. } elseif ($value['employment_status_id'] == 1284) {
  148. $emp_stat_group['tidak_tetap'][] = $value;
  149. } else {
  150. $emp_stat_group['outsrc'][] = $value;
  151. }
  152. }
  153.  
  154. // Set $count_employstatus_group into array
  155. $count_employstatus_group = [];
  156.  
  157. // Loop again with use $emp_stat_group
  158. foreach ($emp_stat_group as $emp_stat_groups => $emp_stat_groupval) {
  159. $count_employstatus_group[$emp_stat_groups] = count($emp_stat_groupval);
  160. }
  161.  
  162. // Count
  163. $employ_status['pegawai_negeri_sipil'] = $count_employstatus_group['pns'] / $this->employee_amount * 100;
  164. $employ_status['pegawai_tetap'] = $count_employstatus_group['tetap'] / $this->employee_amount * 100;
  165. $employ_status['pegawai_tidak_tetap'] = $count_employstatus_group['tidak_tetap'] / $this->employee_amount * 100;
  166. $employ_status['pegawai_outsourcing'] = $count_employstatus_group['outsrc'] / $this->employee_amount * 100;
  167.  
  168. return $employ_status;
  169. }
  170.  
  171. public function getDataEmployeeRankGrafik()
  172. {
  173.  
  174. }
  175. }
Advertisement
Add Comment
Please, Sign In to add comment