AnalyticsController.php 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. <?php
  2. namespace app\controllers;
  3. use Yii;
  4. use yii\filters\AccessControl;
  5. use yii\web\Controller;
  6. use yii\web\Response;
  7. use yii\filters\VerbFilter;
  8. use app\models\LoginForm;
  9. use app\models\ContactForm;
  10. use app\models\entity\Tasktypes;
  11. use app\models\entity\Tasks;
  12. use app\models\entity\Tasknotes;
  13. use app\models\entity\Accounts;
  14. use app\models\entity\AccountsJobtypes;
  15. use app\models\entity\Sections;
  16. use app\models\entity\Companies;
  17. use app\models\entity\Jobtypes;
  18. use app\models\entity\ProjectsLocotech;
  19. use app\models\entity\Projecttypes;
  20. class AnalyticsController extends MainController
  21. {
  22. private $threeWeeksAgo;
  23. public function beforeAction($action)
  24. {
  25. parent::beforeAction($action);
  26. $date = strtotime('-3 weeks');
  27. $this->threeWeeksAgo = date('Y-m-d', $date);
  28. $key = Yii::$app->request->headers->get('uuid-key');
  29. $this->checkAuth($key);
  30. $headerContent = Yii::$app->request->headers->get('content-type');
  31. \Yii::$app->response->format = \yii\web\Response::FORMAT_XML;
  32. if ( 'application/json' == $headerContent ) {
  33. \Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
  34. }
  35. return true;
  36. }
  37. public function actionCompanies()
  38. {
  39. $JobtypesAccountsEntity = Companies::find()->all();
  40. foreach( $JobtypesAccountsEntity as $jobtypeAccount ) {
  41. $value = [];
  42. $value['id'] = $jobtypeAccount->id;
  43. $value['name'] = $jobtypeAccount->name;
  44. $value['address'] = $jobtypeAccount->address;
  45. $arResult[] = $value;
  46. }
  47. return $arResult;
  48. }
  49. public function actionComands()
  50. {
  51. $tasksEntity = Tasks::find()->all();
  52. $arResult = [];
  53. foreach($tasksEntity as $task) {
  54. $value = [];
  55. $value['action'] = $task->project->action;
  56. $value['loco_type'] = $task->project->loco_type;
  57. $value['status'] = $task->project->status;
  58. $value['loco_number'] = $task->project->loco_number;
  59. $value['depo'] = $task->project->depo;
  60. $value['service'] = $task->project->depo_service;
  61. $value['created'] = $task->project->created;
  62. $value['section_id'] = $task->project->section_id;
  63. $value['id'] = $task->project->id;
  64. $value['created'] = $task->created;
  65. $value['finished_time'] = $task->finished_time;
  66. $value['accepted_time'] = $task->accepted_time;
  67. $value['expires'] = $task->expires;
  68. $value['type'] = $task->type;
  69. $value['account_id'] = $task->accounts->id;
  70. $value['accounts_name'] = $task->accounts->name;
  71. $value['task_status'] = $task->status;
  72. $value['task_id'] = $task->id;
  73. $arResult[] = $value;
  74. }
  75. return $arResult;
  76. }
  77. public function actionProjecttypes()
  78. {
  79. $projecttypesEntity = Projecttypes::find()->all();
  80. $arResult = [];
  81. foreach($projecttypesEntity as $projecttype){
  82. $value = [];
  83. $value['id'] = $projecttype->id;
  84. $value['name'] = $projecttype->name;
  85. $value['company'] = $projecttype->company;
  86. $arResult[] = $value;
  87. }
  88. return $arResult;
  89. }
  90. public function actionProjects()
  91. {
  92. $projectsEntity = ProjectsLocotech::find()
  93. // ->where(['>', 'created', $this->threeWeeksAgo])
  94. ->all();
  95. $arResult = [];
  96. foreach($projectsEntity as $projecttype) {
  97. $value['id'] = $projecttype->id;
  98. $value['action'] = $projecttype->action;
  99. $value['company'] = $projecttype->company;
  100. $value['status'] = $projecttype->status;
  101. $value['loco_type'] = $projecttype->loco_type;
  102. $value['loco_number'] = $projecttype->loco_number;
  103. $value['created'] = $projecttype->created;
  104. $value['tasks'] = $projecttype->tasks;
  105. $arResult[] = $value;
  106. }
  107. return $arResult;
  108. }
  109. public function actionTasktypes()
  110. {
  111. $arResult = [];
  112. $arrTaskstypes = Tasktypes::find()->all();
  113. foreach($arrTaskstypes as $taskstype){
  114. $value = [];
  115. $value['id'] = $taskstype->id;
  116. $value['name'] = $taskstype->name;
  117. $value['company'] = $taskstype->company;
  118. $value['main_task'] = $taskstype->main_task;
  119. $value['time_to_complete_minutes'] = $taskstype->time_to_complete_minutes;
  120. $arResult[] = $value;
  121. }
  122. return $arResult;
  123. }
  124. public function actionTasks()
  125. {
  126. $arResult = [];
  127. $arrTaskstypes = Tasks::find()
  128. // ->where(['>', 'created', $this->threeWeeksAgo])
  129. ->all();
  130. foreach($arrTaskstypes as $taskstype) {
  131. $value['id'] = $taskstype->id;
  132. $value['status'] = $taskstype->status;
  133. $value['parent_id'] = $taskstype->parent_id;
  134. $value['type'] = $taskstype->type;
  135. $value['assignees_arr'] = $taskstype->assignees_arr;
  136. $value['input_id'] = $taskstype->input_id;
  137. $value['created'] = $taskstype->created;
  138. $value['accepted_time'] = $taskstype->accepted_time;
  139. $value['finished_time'] = $taskstype->finished_time;
  140. $value['assigned'] = $taskstype->assigned;
  141. $value['text'] = $taskstype->text;
  142. $arResult[] = $value;
  143. }
  144. return $arResult;
  145. }
  146. public function actionAccounts()
  147. {
  148. $arrAccounts = Accounts::find()->all();
  149. foreach($arrAccounts as $accounts){
  150. $value = [];
  151. $value['id'] = $accounts->id;
  152. $value['name'] = $accounts->name;
  153. $value['cmdlevel'] = $accounts->cmdlevel;
  154. $value['company'] = $accounts->company;
  155. $value['last_seen_mobile'] = $accounts->last_seen_mobile;
  156. $value['overplan_mode'] = $accounts->overplan_mode;
  157. $arResult[] = $value;
  158. }
  159. return $arResult;
  160. }
  161. public function actionJobtypes()
  162. {
  163. $jobtypesModel = Jobtypes::find()->all();
  164. foreach($jobtypesModel as $jobtype){
  165. $value = [];
  166. $value['id'] = $jobtype->id;
  167. $value['name'] = $jobtype->name;
  168. $value['company'] = $jobtype->company;
  169. $arResult[] = $value;
  170. }
  171. return $arResult;
  172. }
  173. public function actionAccountsjobtypes()
  174. {
  175. $JobtypesAccountsEntity = AccountsJobtypes::find()->all();
  176. foreach( $JobtypesAccountsEntity as $jobtypeAccount ) {
  177. $value = [];
  178. $value['account_id'] = $jobtypeAccount->account_id;
  179. $value['jobtype_id'] = $jobtypeAccount->jobtype_id;
  180. $value['priority'] = $jobtypeAccount->priority;
  181. $arResult[] = $value;
  182. }
  183. return $arResult;
  184. }
  185. public function actionTasknotes()
  186. {
  187. $tasknotesEntity = Tasknotes::find()->all();
  188. foreach( $tasknotesEntity as $jobtypeAccount ) {
  189. $value = [];
  190. $value['id'] = $jobtypeAccount->id;
  191. $value['task_id'] = $jobtypeAccount->task_id;
  192. $value['checkpoint_id'] = $jobtypeAccount->checkpoint_id;
  193. $value['text'] = $jobtypeAccount->text;
  194. $value['date'] = $jobtypeAccount->date;
  195. $arResult[] = $value;
  196. }
  197. return $arResult;
  198. }
  199. public function actionSections()
  200. {
  201. $SectionsEntity = Sections::find()->all();
  202. foreach($SectionsEntity as $section){
  203. $value = [];
  204. $value['id'] = $section->id;
  205. $value['locomotive_series'] = $section->locomotive_series;
  206. $value['section_number'] = $section->section_number;
  207. $value['section_subnumber'] = $section->section_subnumber;
  208. $arResult[] = $value;
  209. }
  210. return $arResult;
  211. }
  212. }