Analytics2Controller.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319
  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. public $path = '/uploads/xml_analitycs/';
  23. private $threeWeeksAgo;
  24. public function beforeAction($action)
  25. {
  26. parent::beforeAction($action);
  27. $date = strtotime('-3 weeks');
  28. $this->threeWeeksAgo = date('Y-m-d', $date);
  29. $key = Yii::$app->request->headers->get('uuid-key');
  30. $this->checkAuth($key);
  31. $headerContent = Yii::$app->request->headers->get('content-type');
  32. \Yii::$app->response->format = \yii\web\Response::FORMAT_XML;
  33. if ( 'application/json' == $headerContent ) {
  34. \Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
  35. }
  36. try {
  37. $dbh = new \PDO('mysql:host=localhost;dbname=promsystem', 'DB_Admin', 'SgRqm6f3Va');
  38. } catch (PDOException $e) {
  39. echo 'Connection failed: ' . $e->getMessage(); exit;
  40. }
  41. $dbh->setAttribute(\PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, false);
  42. return true;
  43. }
  44. public function actionCompanies()
  45. {
  46. $JobtypesAccountsEntity = Companies::find()->all();
  47. foreach( $JobtypesAccountsEntity as $jobtypeAccount ) {
  48. $value = [];
  49. $value['id'] = $jobtypeAccount->id;
  50. $value['name'] = $jobtypeAccount->name;
  51. $value['address'] = $jobtypeAccount->address;
  52. $arResult[] = $value;
  53. }
  54. return $arResult;
  55. }
  56. public function actionComands()
  57. {
  58. $tasksEntity = Tasks::find()->all();
  59. $arResult = [];
  60. foreach($tasksEntity as $task){
  61. $value = [];
  62. $value['action'] = $task->project->action;
  63. $value['loco_type'] = $task->project->loco_type;
  64. $value['status'] = $task->project->status;
  65. $value['loco_number'] = $task->project->loco_number;
  66. $value['depo'] = $task->project->depo;
  67. $value['service'] = $task->project->depo_service;
  68. $value['created'] = $task->project->created;
  69. $value['section_id'] = $task->project->section_id;
  70. $value['id'] = $task->project->id;
  71. $value['created'] = $task->created;
  72. $value['finished_time'] = $task->finished_time;
  73. $value['accepted_time'] = $task->accepted_time;
  74. $value['expires'] = $task->expires;
  75. $value['type'] = $task->type;
  76. $value['account_id'] = $task->accounts->id;
  77. $value['accounts_name'] = $task->accounts->name;
  78. $value['task_status'] = $task->status;
  79. $value['task_id'] = $task->id;
  80. $arResult[] = $value;
  81. }
  82. return $arResult;
  83. }
  84. public function actionProjecttypes()
  85. {
  86. $projecttypesEntity = Projecttypes::find()->all();
  87. $arResult = [];
  88. foreach($projecttypesEntity as $projecttype){
  89. $value = [];
  90. $value['id'] = $projecttype->id;
  91. $value['name'] = $projecttype->name;
  92. $value['company'] = $projecttype->company;
  93. $arResult[] = $value;
  94. }
  95. return $arResult;
  96. }
  97. public function actionProjects()
  98. {
  99. $projectsEntity = ProjectsLocotech::find()
  100. //->where(['>', 'created', $this->threeWeeksAgo])
  101. ->all();
  102. $arResult = [];
  103. foreach($projectsEntity as $projecttype){
  104. $value = [];
  105. $value['id'] = $projecttype->id;
  106. $value['action'] = $projecttype->action;
  107. $value['company'] = $projecttype->company;
  108. $value['status'] = $projecttype->status;
  109. $value['loco_type'] = $projecttype->loco_type;
  110. $value['loco_number'] = $projecttype->loco_number;
  111. $value['created'] = $projecttype->created;
  112. $value['tasks'] = $projecttype->tasks;
  113. $arResult[] = $value;
  114. }
  115. return $arResult;
  116. }
  117. public function actionTasktypes()
  118. {
  119. $arResult = [];
  120. $arrTaskstypes = Tasktypes::find()->all();
  121. foreach($arrTaskstypes as $taskstype){
  122. $value = [];
  123. $value['id'] = $taskstype->id;
  124. $value['name'] = $taskstype->name;
  125. $value['company'] = $taskstype->company;
  126. $value['main_task'] = $taskstype->main_task;
  127. $value['time_to_complete_minutes'] = $taskstype->time_to_complete_minutes;
  128. $arResult[] = $value;
  129. }
  130. return $arResult;
  131. }
  132. public function actionTasks()
  133. {
  134. $arResult = [];
  135. $arrTaskstypes = Tasks::find()
  136. //->where(['>', 'created_', $this->threeWeeksAgo])
  137. ->limit(10)
  138. ->all();
  139. foreach($arrTaskstypes as $taskstype){
  140. $value = [];
  141. $value['id'] = $taskstype->id;
  142. $value['status'] = $taskstype->status;
  143. $value['parent_id'] = $taskstype->parent_id;
  144. $value['type'] = $taskstype->type;
  145. $value['assignees_arr'] = $taskstype->assignees_arr;
  146. $value['input_id'] = $taskstype->input_id;
  147. $value['created'] = $taskstype->created;
  148. $value['accepted_time'] = $taskstype->accepted_time;
  149. $value['finished_time'] = $taskstype->finished_time;
  150. $value['assigned'] = $taskstype->assigned;
  151. $value['text'] = $taskstype->text;
  152. $arResult[] = $value;
  153. }
  154. return $arResult;
  155. // try {
  156. // $dbh = new \PDO('mysql:host=localhost;dbname=promsystem', 'DB_Admin', 'SgRqm6f3Va');
  157. // } catch (PDOException $e) {
  158. // echo 'Connection failed: ' . $e->getMessage(); exit;
  159. // }
  160. // $dbh->setAttribute(\PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, false);
  161. // $data = Tasks::find()->asArray();
  162. //$xmlWriter = new \XMLWriter();
  163. //$xmlWriter->openMemory();
  164. //$xmlWriter->startDocument('1.0', 'UTF-8');
  165. //$xmlWriter->startElement('response');
  166. //foreach ($data->batch(100) as $list) {
  167. //$query = 'SELECT `id`,`status`,`parent_id`,`type`,`assignees_arr`,`input_id`,`input_id`,`created`,`accepted_time`,`finished_time`,`assigned`,`text` FROM `tasks` ';
  168. //$list = \Yii::$app->db->createCommand($query)->queryAll();
  169. /* foreach ($list as $taskstype) {
  170. $value = [];
  171. $value['id'] = $taskstype['id'];
  172. $value['status'] = $taskstype['status'];
  173. $value['parent_id'] = $taskstype['parent_id'];
  174. $value['type'] = $taskstype['type'];
  175. $value['assignees_arr'] = $taskstype['assignees_arr'];
  176. $value['input_id'] = $taskstype['input_id'];
  177. $value['created'] = $taskstype['created'];
  178. $value['accepted_time'] = $taskstype['accepted_time'];
  179. $value['finished_time'] = $taskstype['finished_time'];
  180. $value['assigned'] = $taskstype['assigned'];
  181. $value['text'] = $taskstype['text'];
  182. $arResult[] = $value;
  183. }*/
  184. //$file = $this->writeXmlRows($xmlWriter,$arResult,$this->path);
  185. //$arResult = [];
  186. //}
  187. //$xmlWriter->endElement();
  188. //file_put_contents( $this->path, $xmlWriter->flush(true), FILE_APPEND);
  189. //if (file_exists($this->path)) {
  190. // return \Yii::$app->response->sendFile($this->path);
  191. //}
  192. // echo $_SERVER['DOCUMENT_ROOT'].$this->path .Yii::$app->controller->action->id . '.xml';
  193. //return \Yii::$app->response->sendFile($_SERVER['DOCUMENT_ROOT'].$this->path .Yii::$app->controller->action->id . '.xml');
  194. //return $arResult;
  195. }
  196. public function actionAccounts()
  197. {
  198. $arrAccounts = Accounts::find()->all();
  199. foreach($arrAccounts as $accounts){
  200. $value = [];
  201. $value['id'] = $accounts->id;
  202. $value['name'] = $accounts->name;
  203. $value['cmdlevel'] = $accounts->cmdlevel;
  204. $value['company'] = $accounts->company;
  205. $value['last_seen_mobile'] = $accounts->last_seen_mobile;
  206. $value['overplan_mode'] = $accounts->overplan_mode;
  207. $arResult[] = $value;
  208. }
  209. return $arResult;
  210. }
  211. public function actionJobtypes()
  212. {
  213. $jobtypesModel = Jobtypes::find()->all();
  214. foreach($jobtypesModel as $jobtype){
  215. $value = [];
  216. $value['id'] = $jobtype->id;
  217. $value['name'] = $jobtype->name;
  218. $value['company'] = $jobtype->company;
  219. $arResult[] = $value;
  220. }
  221. return $arResult;
  222. }
  223. public function actionAccountsjobtypes()
  224. {
  225. $JobtypesAccountsEntity = AccountsJobtypes::find()->all();
  226. foreach( $JobtypesAccountsEntity as $jobtypeAccount ) {
  227. $value = [];
  228. $value['account_id'] = $jobtypeAccount->account_id;
  229. $value['jobtype_id'] = $jobtypeAccount->jobtype_id;
  230. $value['priority'] = $jobtypeAccount->priority;
  231. $arResult[] = $value;
  232. }
  233. return $arResult;
  234. }
  235. public function actionTasknotes()
  236. {
  237. $tasknotesEntity = Tasknotes::find()->all();
  238. foreach( $tasknotesEntity as $jobtypeAccount ) {
  239. $value = [];
  240. $value['id'] = $jobtypeAccount->id;
  241. $value['task_id'] = $jobtypeAccount->task_id;
  242. $value['checkpoint_id'] = $jobtypeAccount->checkpoint_id;
  243. $value['text'] = $jobtypeAccount->text;
  244. $value['date'] = $jobtypeAccount->date;
  245. $arResult[] = $value;
  246. }
  247. return $arResult;
  248. }
  249. public function actionSections()
  250. {
  251. $SectionsEntity = Sections::find()->all();
  252. foreach($SectionsEntity as $section){
  253. $value = [];
  254. $value['id'] = $section->id;
  255. $value['locomotive_series'] = $section->locomotive_series;
  256. $value['section_number'] = $section->section_number;
  257. $value['section_subnumber'] = $section->section_subnumber;
  258. $arResult[] = $value;
  259. }
  260. return $arResult;
  261. }
  262. public function writeXmlRows($xmlWriter, $arr = [], $path = '' ){
  263. $i = 1;
  264. foreach ($arr as $r) {
  265. $xmlWriter->startElement('item');
  266. foreach($r as $key => $item){
  267. if ( null == $item ){$item = '_';}
  268. $xmlWriter->writeElement($key, $item);
  269. }
  270. $xmlWriter->endElement();
  271. if (0 == $i%100) {
  272. file_put_contents($path, $xmlWriter->flush(true), FILE_APPEND);
  273. }
  274. $i++;
  275. }
  276. }
  277. public function actionFoo() {
  278. //phpinfo();
  279. }
  280. }