ArealitysController.php 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. <?php
  2. namespace app\controllers;
  3. use app\models\entity\Companies;
  4. use Yii;
  5. use app\models\entity\Accounts;
  6. use app\models\entity\FaceFeature;
  7. use app\models\entity\Objects;
  8. use app\models\entity\Tasks;
  9. use yii\web\UnauthorizedHttpException;
  10. class ArealitysController extends MainController
  11. {
  12. private $isAdmin = false;
  13. private $response = ['login' => '','response' => [],'error' => []];
  14. public function beforeAction($action)
  15. {
  16. parent::beforeAction($action);
  17. $key = Yii::$app->request->headers->get('uuid-key');
  18. $this->checkAuth($key);
  19. \Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
  20. return true;
  21. }
  22. //todo: Перенести на corp
  23. /**
  24. * Получение данных
  25. *
  26. * @param $login
  27. * @param $password
  28. * @return string (список объектов)
  29. */
  30. public function actionGetardata()
  31. {
  32. $post = Yii::$app->request->post();
  33. $this->response['login'] = $post['login'];
  34. $checkAdmin = $this->checkAdmin($post);
  35. if(!empty($checkAdmin)){
  36. return $this->response['error'] = $checkAdmin;
  37. }
  38. $objectsEntity = Objects::find()->all();
  39. $tempArray = [];
  40. $tempArray2 = [];
  41. $tempArray3 = [];
  42. //var_dump($post['login']); die();
  43. foreach( $objectsEntity as $object) {
  44. $tempArray = [];
  45. $tempArray['id'] = $object->id;
  46. $tempArray['name'] = $object->name;
  47. $tempArray['name_display'] = $object->name_display;
  48. $tempArray['x'] = $object->x;
  49. $tempArray['y'] = $object->y;
  50. $tempArray['z'] = $object->z;
  51. $tempArray['imageA'] = $object->imageA;
  52. $tempArray['imageB'] = $object->imageB;
  53. $tempArray['imageC'] = $object->imageC;
  54. foreach( $object->tasks as $task) {
  55. $tempArray2 = [];
  56. $tempArray2['id'] = $task->id;
  57. $tempArray2['name'] = $task->tasktypes->name;
  58. foreach( $task->phase as $phase) {
  59. $tempArray3 = [];
  60. $tempArray3['id'] = $phase->id;
  61. $tempArray3['phase_number'] = $phase->phase_number;
  62. $tempArray3['message'] = $phase->message;
  63. $tempArray3['CoordX'] = $phase->x;
  64. $tempArray3['CoordY'] = $phase->y;
  65. $tempArray3['CoordZ'] = $phase->z;
  66. $tempArray2['phase'][] = $tempArray3;
  67. }
  68. $tempArray['comands'][] = $tempArray2;
  69. }
  70. $this->response['response'][] = $tempArray;
  71. }
  72. return $this->response;
  73. }
  74. /**
  75. * Добавление объекта.
  76. *
  77. * @param $login
  78. * @param $password
  79. * @param $params
  80. * @return ?
  81. */
  82. public function actionAddobject()
  83. {
  84. $post = Yii::$app->request->post();
  85. $checkAdmin = $this->checkAdmin($post);
  86. if(!empty($checkAdmin)){
  87. return $this->response['error'] = $checkAdmin;
  88. }
  89. $post['params'] = json_decode($post['params'],true);
  90. $objectsEntity = new Objects();
  91. /*
  92. $objectsEntity->name = $post['params']['name'];
  93. $objectsEntity->name_display = $post['params']['name_display'];
  94. $objectsEntity->x = $post['params']['SizeX'];
  95. $objectsEntity->y = $post['params']['SizeY'];
  96. $objectsEntity->z = $post['params']['SizeZ'];
  97. $objectsEntity->imageA = $post['params']['imageA'];
  98. $objectsEntity->imageB = $post['params']['imageB'];
  99. $objectsEntity->imageC = $post['params']['imageC'];
  100. */
  101. if ( $objectsEntity->load($post['params'], '') and $objectsEntity->save() ) {
  102. $this->response['response'] = $objectsEntity->id;
  103. } else {
  104. $this->response['error'] = $objectsEntity->errors;
  105. }
  106. if ( isset($post['params']['command'])
  107. and !empty( $post['params']['command'] )
  108. and isset( $objectsEntity->id )
  109. ) {
  110. foreach( $post['params']['command'] as $command){
  111. $tasksEntity = Tasks::findOne($command['id']);
  112. $tasksEntity->objects_id = $objectsEntity->id;
  113. $tasksEntity->save();
  114. if ( !empty($tasksEntity->errors) ) {
  115. $this->response['error'] = $tasksEntity->errors;
  116. }
  117. }
  118. }
  119. //$this->response[''];
  120. //$objectsEntity->load($post['params'], '');
  121. return $this->response;//$return;
  122. }
  123. /**
  124. * Удаление объекта.
  125. *
  126. * @param $login
  127. * @param $password
  128. * @param $id
  129. * @return ?
  130. */
  131. public function actionRemoveobject()
  132. {
  133. $post = Yii::$app->request->post();
  134. $return = [];
  135. return $return;
  136. }
  137. /**
  138. * Добавление этапа.
  139. *
  140. * @param $login
  141. * @param $password
  142. * @param $obj_params
  143. * @return ?
  144. */
  145. public function actionAddphase()
  146. {
  147. $post = Yii::$app->request->post();
  148. $return = [];
  149. return $return;
  150. }
  151. /**
  152. * Удаление этапа.
  153. *
  154. * @param $login
  155. * @param $password
  156. * @param $obj_params
  157. * @return ?
  158. */
  159. public function actionRemovephase()
  160. {
  161. $post = Yii::$app->request->post();
  162. $return = [];
  163. return $return;
  164. }
  165. }