View camera archive list. Stub for archive record page

This commit is contained in:
ftc
2023-07-02 17:18:17 +03:00
parent b19e70b005
commit 477afbecd1
6 changed files with 93 additions and 4 deletions
+8 -1
View File
@@ -9,7 +9,14 @@ class TestController extends Controller
{ {
public function actionIndex() public function actionIndex()
{ {
$client = new \app\components\ApiClient(Yii::$app->params['zmUrl'].'/zm/api'); $client = new \app\components\ApiClient(Yii::$app->params['zmUrl'].'zm/api');
print_r($client->getVersion()); print_r($client->getVersion());
} }
public function actionEvents($id)
{
$client = new \app\components\ApiClient(Yii::$app->params['zmUrl'].'zm/api');
//print_r($client->getAllEvents($id));
print_r($client->getEvents($id, date("Y-m-d H:i:s", strtotime('-10 days'))));
}
} }
+11 -1
View File
@@ -29,7 +29,6 @@ class ApiClient
{ {
$this->http_client->setOption(CURLOPT_POSTFIELDS, $json); $this->http_client->setOption(CURLOPT_POSTFIELDS, $json);
} }
$result = $this->http_client->$method($url); $result = $this->http_client->$method($url);
if ($this->http_client->responseCode !== 200) if ($this->http_client->responseCode !== 200)
{ {
@@ -44,4 +43,15 @@ class ApiClient
return $this->sendRequest('host/getVersion.json'); return $this->sendRequest('host/getVersion.json');
} }
public function getAllEvents($id)
{
return $this->sendRequest('events/index/MonitorId:'.$id.'.json');
}
public function getEvents($id, $start_time, $page = 1)
{
return $this->sendRequest('events/index/MonitorId:'.$id.'/'.
urlencode('StartTime >=:'.$start_time).'.json?page='.$page);
}
} }
+35 -1
View File
@@ -41,9 +41,43 @@ class CameraController extends Controller
{ {
throw new NotFoundHttpException(); throw new NotFoundHttpException();
} }
$archive = $this->getArchive($cms[$id]);
return $this->render('view', return $this->render('view',
[ [
'id' => $id 'id' => $id,
'archive' => array_reverse($archive),
]);
}
private function getArchive($zm_id) : array
{
$client = new \app\components\ApiClient(Yii::$app->params['zmUrl'].'zm/api');
$json = $client->getEvents($zm_id, date("Y-m-d H:i:s", time() - 7 * 24 * 3600));
$r = json_decode($json, true);
$result = [];
foreach ($r['events'] as $e)
{
$result[] = new \app\models\zm\Event($e['Event']);
}
$pages_count = $r['pagination']['pageCount'];
for ($i = 2; $i <= $pages_count; $i++)
{
$json = $client->getEvents($zm_id, date("Y-m-d H:i:s", time() - 7 * 24 * 3600), $i);
$r = json_decode($json, true);
foreach ($r['events'] as $e)
{
$result[] = new \app\models\zm\Event($e['Event']);
}
}
return $result;
}
public function actionViewArchive($event_id)
{
return $this->render('view_archive',
[
'id' => $event_id,
]); ]);
} }
} }
+19
View File
@@ -0,0 +1,19 @@
<?php
namespace app\models\zm;
class Event
{
public $id;
public $monitor_id;
public $start_time;
public $end_time;
public function __construct($json)
{
$this->id = $json['Id'];
$this->monitor_id = $json['MonitorId'];
$this->start_time = $json['StartDateTime'];
$this->end_time = $json['EndDateTime'];
}
}
+7 -1
View File
@@ -2,6 +2,7 @@
/** @var yii\web\View $this */ /** @var yii\web\View $this */
use yii\helpers\Url; use yii\helpers\Url;
use yii\helpers\Html;
$this->title = 'Камера '.$id; $this->title = 'Камера '.$id;
?> ?>
@@ -12,7 +13,12 @@ $this->title = 'Камера '.$id;
<img style="max-width:100%;" src='<?= Url::to(['camera/stream', 'id' => $id]); ?>'> <img style="max-width:100%;" src='<?= Url::to(['camera/stream', 'id' => $id]); ?>'>
</div> </div>
<div class="col-lg-8"> <div class="col-lg-8">
Архив записей: Архив записей:<br/>
<ul>
<?php foreach ($archive as $e): ?>
<li><?= Html::a($e->start_time." - ".$e->end_time, ['camera/view-archive', 'event_id' => $e->id]); ?></li>
<?php endforeach; ?>
</ul>
</div> </div>
</div> </div>
</div> </div>
+13
View File
@@ -0,0 +1,13 @@
<?php
/** @var yii\web\View $this */
use yii\helpers\Url;
$this->title = 'Архив, запись #'.$id;
?>
<div class="site-index">
<div class="body-content">
<div class="row">
TODO!
</div>
</div>