123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319 |
- <?php
- namespace app\controllers;
- use Yii;
- use yii\filters\AccessControl;
- use yii\web\Controller;
- use yii\web\Response;
- use yii\filters\VerbFilter;
- use app\models\LoginForm;
- use app\models\ContactForm;
- use app\models\entity\Tasktypes;
- use app\models\entity\Tasks;
- use app\models\entity\Tasknotes;
- use app\models\entity\Accounts;
- use app\models\entity\AccountsJobtypes;
- use app\models\entity\Sections;
- use app\models\entity\Companies;
- use app\models\entity\Jobtypes;
- use app\models\entity\ProjectsLocotech;
- use app\models\entity\Projecttypes;
- class AnalyticsController extends MainController
- {
- public $path = '/uploads/xml_analitycs/';
- private $threeWeeksAgo;
-
-
- public function beforeAction($action)
- {
- parent::beforeAction($action);
- $date = strtotime('-3 weeks');
- $this->threeWeeksAgo = date('Y-m-d', $date);
- $key = Yii::$app->request->headers->get('uuid-key');
- $this->checkAuth($key);
- $headerContent = Yii::$app->request->headers->get('content-type');
- \Yii::$app->response->format = \yii\web\Response::FORMAT_XML;
- if ( 'application/json' == $headerContent ) {
- \Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
- }
- try {
- $dbh = new \PDO('mysql:host=localhost;dbname=promsystem', 'DB_Admin', 'SgRqm6f3Va');
- } catch (PDOException $e) {
- echo 'Connection failed: ' . $e->getMessage(); exit;
- }
-
- $dbh->setAttribute(\PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, false);
- return true;
- }
-
- public function actionCompanies()
- {
- $JobtypesAccountsEntity = Companies::find()->all();
- foreach( $JobtypesAccountsEntity as $jobtypeAccount ) {
- $value = [];
- $value['id'] = $jobtypeAccount->id;
- $value['name'] = $jobtypeAccount->name;
- $value['address'] = $jobtypeAccount->address;
- $arResult[] = $value;
- }
- return $arResult;
- }
-
- public function actionComands()
- {
-
-
-
- $tasksEntity = Tasks::find()->all();
- $arResult = [];
- foreach($tasksEntity as $task){
- $value = [];
- $value['action'] = $task->project->action;
- $value['loco_type'] = $task->project->loco_type;
- $value['status'] = $task->project->status;
- $value['loco_number'] = $task->project->loco_number;
- $value['depo'] = $task->project->depo;
- $value['service'] = $task->project->depo_service;
- $value['created'] = $task->project->created;
- $value['section_id'] = $task->project->section_id;
- $value['id'] = $task->project->id;
- $value['created'] = $task->created;
- $value['finished_time'] = $task->finished_time;
- $value['accepted_time'] = $task->accepted_time;
- $value['expires'] = $task->expires;
- $value['type'] = $task->type;
- $value['account_id'] = $task->accounts->id;
- $value['accounts_name'] = $task->accounts->name;
- $value['task_status'] = $task->status;
- $value['task_id'] = $task->id;
- $arResult[] = $value;
-
- }
-
- return $arResult;
- }
-
- public function actionProjecttypes()
- {
- $projecttypesEntity = Projecttypes::find()->all();
- $arResult = [];
- foreach($projecttypesEntity as $projecttype){
- $value = [];
- $value['id'] = $projecttype->id;
- $value['name'] = $projecttype->name;
- $value['company'] = $projecttype->company;
- $arResult[] = $value;
- }
- return $arResult;
- }
-
- public function actionProjects()
- {
- $projectsEntity = ProjectsLocotech::find()
- //->where(['>', 'created', $this->threeWeeksAgo])
- ->all();
- $arResult = [];
- foreach($projectsEntity as $projecttype){
- $value = [];
- $value['id'] = $projecttype->id;
- $value['action'] = $projecttype->action;
- $value['company'] = $projecttype->company;
- $value['status'] = $projecttype->status;
- $value['loco_type'] = $projecttype->loco_type;
- $value['loco_number'] = $projecttype->loco_number;
- $value['created'] = $projecttype->created;
- $value['tasks'] = $projecttype->tasks;
- $arResult[] = $value;
- }
- return $arResult;
- }
-
- public function actionTasktypes()
- {
- $arResult = [];
- $arrTaskstypes = Tasktypes::find()->all();
- foreach($arrTaskstypes as $taskstype){
- $value = [];
- $value['id'] = $taskstype->id;
- $value['name'] = $taskstype->name;
- $value['company'] = $taskstype->company;
- $value['main_task'] = $taskstype->main_task;
- $value['time_to_complete_minutes'] = $taskstype->time_to_complete_minutes;
- $arResult[] = $value;
- }
- return $arResult;
- }
-
- public function actionTasks()
- {
- $arResult = [];
- $arrTaskstypes = Tasks::find()
- //->where(['>', 'created_', $this->threeWeeksAgo])
- ->limit(10)
- ->all();
- foreach($arrTaskstypes as $taskstype){
- $value = [];
- $value['id'] = $taskstype->id;
- $value['status'] = $taskstype->status;
- $value['parent_id'] = $taskstype->parent_id;
- $value['type'] = $taskstype->type;
- $value['assignees_arr'] = $taskstype->assignees_arr;
- $value['input_id'] = $taskstype->input_id;
- $value['created'] = $taskstype->created;
- $value['accepted_time'] = $taskstype->accepted_time;
- $value['finished_time'] = $taskstype->finished_time;
- $value['assigned'] = $taskstype->assigned;
- $value['text'] = $taskstype->text;
- $arResult[] = $value;
- }
- return $arResult;
- // try {
- // $dbh = new \PDO('mysql:host=localhost;dbname=promsystem', 'DB_Admin', 'SgRqm6f3Va');
- // } catch (PDOException $e) {
- // echo 'Connection failed: ' . $e->getMessage(); exit;
- // }
-
- // $dbh->setAttribute(\PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, false);
-
- // $data = Tasks::find()->asArray();
-
- //$xmlWriter = new \XMLWriter();
- //$xmlWriter->openMemory();
- //$xmlWriter->startDocument('1.0', 'UTF-8');
- //$xmlWriter->startElement('response');
- //foreach ($data->batch(100) as $list) {
- //$query = 'SELECT `id`,`status`,`parent_id`,`type`,`assignees_arr`,`input_id`,`input_id`,`created`,`accepted_time`,`finished_time`,`assigned`,`text` FROM `tasks` ';
- //$list = \Yii::$app->db->createCommand($query)->queryAll();
- /* foreach ($list as $taskstype) {
- $value = [];
- $value['id'] = $taskstype['id'];
- $value['status'] = $taskstype['status'];
- $value['parent_id'] = $taskstype['parent_id'];
- $value['type'] = $taskstype['type'];
- $value['assignees_arr'] = $taskstype['assignees_arr'];
- $value['input_id'] = $taskstype['input_id'];
- $value['created'] = $taskstype['created'];
- $value['accepted_time'] = $taskstype['accepted_time'];
- $value['finished_time'] = $taskstype['finished_time'];
- $value['assigned'] = $taskstype['assigned'];
- $value['text'] = $taskstype['text'];
- $arResult[] = $value;
- }*/
- //$file = $this->writeXmlRows($xmlWriter,$arResult,$this->path);
- //$arResult = [];
- //}
- //$xmlWriter->endElement();
- //file_put_contents( $this->path, $xmlWriter->flush(true), FILE_APPEND);
- //if (file_exists($this->path)) {
- // return \Yii::$app->response->sendFile($this->path);
- //}
- // echo $_SERVER['DOCUMENT_ROOT'].$this->path .Yii::$app->controller->action->id . '.xml';
- //return \Yii::$app->response->sendFile($_SERVER['DOCUMENT_ROOT'].$this->path .Yii::$app->controller->action->id . '.xml');
- //return $arResult;
- }
-
- public function actionAccounts()
- {
- $arrAccounts = Accounts::find()->all();
- foreach($arrAccounts as $accounts){
- $value = [];
- $value['id'] = $accounts->id;
- $value['name'] = $accounts->name;
- $value['cmdlevel'] = $accounts->cmdlevel;
- $value['company'] = $accounts->company;
- $value['last_seen_mobile'] = $accounts->last_seen_mobile;
- $value['overplan_mode'] = $accounts->overplan_mode;
- $arResult[] = $value;
- }
-
- return $arResult;
- }
-
- public function actionJobtypes()
- {
- $jobtypesModel = Jobtypes::find()->all();
- foreach($jobtypesModel as $jobtype){
- $value = [];
- $value['id'] = $jobtype->id;
- $value['name'] = $jobtype->name;
- $value['company'] = $jobtype->company;
- $arResult[] = $value;
- }
- return $arResult;
- }
-
- public function actionAccountsjobtypes()
- {
- $JobtypesAccountsEntity = AccountsJobtypes::find()->all();
- foreach( $JobtypesAccountsEntity as $jobtypeAccount ) {
- $value = [];
- $value['account_id'] = $jobtypeAccount->account_id;
- $value['jobtype_id'] = $jobtypeAccount->jobtype_id;
- $value['priority'] = $jobtypeAccount->priority;
- $arResult[] = $value;
- }
- return $arResult;
- }
-
-
- public function actionTasknotes()
- {
- $tasknotesEntity = Tasknotes::find()->all();
- foreach( $tasknotesEntity as $jobtypeAccount ) {
- $value = [];
- $value['id'] = $jobtypeAccount->id;
- $value['task_id'] = $jobtypeAccount->task_id;
- $value['checkpoint_id'] = $jobtypeAccount->checkpoint_id;
- $value['text'] = $jobtypeAccount->text;
- $value['date'] = $jobtypeAccount->date;
- $arResult[] = $value;
- }
- return $arResult;
- }
-
- public function actionSections()
- {
- $SectionsEntity = Sections::find()->all();
- foreach($SectionsEntity as $section){
- $value = [];
- $value['id'] = $section->id;
- $value['locomotive_series'] = $section->locomotive_series;
- $value['section_number'] = $section->section_number;
- $value['section_subnumber'] = $section->section_subnumber;
- $arResult[] = $value;
- }
- return $arResult;
- }
- public function writeXmlRows($xmlWriter, $arr = [], $path = '' ){
- $i = 1;
- foreach ($arr as $r) {
- $xmlWriter->startElement('item');
- foreach($r as $key => $item){
- if ( null == $item ){$item = '_';}
- $xmlWriter->writeElement($key, $item);
- }
- $xmlWriter->endElement();
- if (0 == $i%100) {
- file_put_contents($path, $xmlWriter->flush(true), FILE_APPEND);
- }
- $i++;
- }
-
- }
- public function actionFoo() {
- //phpinfo();
- }
- }
|