123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- <?php /** Created by Anton on 29.01.2020. */
- namespace app\models\entity;
- use yii\db\ActiveRecord;
- /**
- * This is the model class for table "locotube".
- *
- * @property int $id
- * @property int $user_id [int(10)]
- * @property int $task_id [int(10) unsigned]
- * @property string $start_time [datetime]
- * @property string $end_time [datetime]
- * @property string $url [varchar(255)]
- */
- class Locotube extends ActiveRecord
- {
- /**
- * {@inheritdoc}
- */
- public static function tableName()
- {
- return 'locotube';
- }
- /**
- * Возвращает массив ссылок на видеофайлы снятые во время выполнения задачи
- *
- * @param Tasks $task
- * @param int $userId
- * @return array
- */
- public static function getLinks($task, int $userId)
- {
- if (!('DateTime' == get_class($task->accepted_time) && 'DateTime' == get_class($task->finished_time))) return [];
- $videos = self::findAll([
- 'user_id' => $userId,
- // 'task_id' => $task->id
- ]);
- $result = [];
- $start = $task->accepted_time->format('Y-m-d H:i:s');
- $finish = $task->finished_time->format('Y-m-d H:i:s');
- foreach ($videos as $video) {
- if (
- $start < $video->start_time && $video->start_time < $finish ||
- $start < $video->end_time && $video->end_time < $finish
- ) {
- $result[] = $video->url;
- }
- }
- return $result;
- }
- }
|