Locotube.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php /** Created by Anton on 29.01.2020. */
  2. namespace app\models\entity;
  3. use yii\db\ActiveRecord;
  4. /**
  5. * This is the model class for table "locotube".
  6. *
  7. * @property int $id
  8. * @property int $user_id [int(10)]
  9. * @property int $task_id [int(10) unsigned]
  10. * @property string $start_time [datetime]
  11. * @property string $end_time [datetime]
  12. * @property string $url [varchar(255)]
  13. */
  14. class Locotube extends ActiveRecord
  15. {
  16. /**
  17. * {@inheritdoc}
  18. */
  19. public static function tableName()
  20. {
  21. return 'locotube';
  22. }
  23. /**
  24. * Возвращает массив ссылок на видеофайлы снятые во время выполнения задачи
  25. *
  26. * @param Tasks $task
  27. * @param int $userId
  28. * @return array
  29. */
  30. public static function getLinks($task, int $userId)
  31. {
  32. if (!('DateTime' == get_class($task->accepted_time) && 'DateTime' == get_class($task->finished_time))) return [];
  33. $videos = self::findAll([
  34. 'user_id' => $userId,
  35. // 'task_id' => $task->id
  36. ]);
  37. $result = [];
  38. $start = $task->accepted_time->format('Y-m-d H:i:s');
  39. $finish = $task->finished_time->format('Y-m-d H:i:s');
  40. foreach ($videos as $video) {
  41. if (
  42. $start < $video->start_time && $video->start_time < $finish ||
  43. $start < $video->end_time && $video->end_time < $finish
  44. ) {
  45. $result[] = $video->url;
  46. }
  47. }
  48. return $result;
  49. }
  50. }