public function actionNotifications($id = 0, $action = '') { if ($id) { $notify = Notify::model()->findByPK($id); if (!$notify) { throw new CHttpException(404, Yii::t('errors', 'Wrong notify')); } elseif ($action) { if ($notify->status == 2 || $notify->status == 3) { throw new CHttpException(404, Yii::t('errors', 'Status already set')); } if ($notify->shared_id) { $cam = Shared::model()->findByPK($notify->shared_id); if (!$cam) { $notify->delete(); throw new CHttpException(404, Yii::t('errors', 'Wrong cam')); } } else { $notify->delete(); throw new CHttpException(404, Yii::t('errors', 'Wrong cam')); } $n = new Notify(); $id = Yii::app()->user->getId(); if ($action == 'approve') { //TODO specify user and cam $n->note(Yii::t('user', 'User approve shared cam'), array($id, $notify->creator_id, 0)); $cam->is_approved = 1; $cam->save(); $notify->status = 2; $notify->save(); } elseif ($action == 'disapprove') { $n->note(Yii::t('user', 'User decline shared cam'), array($id, $notify->creator_id, 0)); $cam->is_approved = 0; $cam->save(); $notify->status = 3; $notify->save(); } else { throw new CHttpException(404, Yii::t('errors', 'Wrong action')); } } else { throw new CHttpException(404, Yii::t('errors', 'Wrong action')); } } $new = Notify::model()->findAllByAttributes(array('dest_id' => Yii::app()->user->getId(), 'status' => 1)); $old = Notify::model()->findAllByAttributes(array('dest_id' => Yii::app()->user->getId(), 'status' => array(0, 2, 3)), array('order' => 'time DESC')); foreach ($new as $notify) { if ($notify->shared_id == 0) { $notify->status = 0; $notify->save(); } } $this->render('notify', array('new' => $new, 'old' => $old)); }
public function unixtime() { $result = $this->moment->unixtime(); if (!$result) { Notify::note(Yii::t('errors', 'Unixtime get fail, problem with nvr')); } return $result; }
public function delete($id) { Notify::note("{$this->options['protocol']}://{$this->options['server_ip']}/admin/remove_channel?conf_file={$id}"); $result = $this->http->get("{$this->options['protocol']}://{$this->options['server_ip']}/admin/remove_channel?conf_file={$id}"); return trim($result) == 'OK' ? true : $result; }
public function save() { $id = Yii::app()->user->getId(); foreach ($this->camBuff as $cam) { foreach ($this->emailBuff as $user) { $n = new Notify(); $shared = Shared::model()->findByAttributes(array('owner_id' => $id, 'user_id' => $user->id, 'cam_id' => $cam->id, 'is_public' => 0)); if (!$shared) { $shared = new Shared(); $shared->owner_id = $id; $shared->user_id = $user->id; $shared->cam_id = $cam->id; } if ($this->type == 'assign') { $shared->is_approved = 1; } $shared->save(); $n->note(Yii::t('cams', 'You granted access to camera {cam}', array('{cam}' => $cam->name)), array($id, $user->id, $shared->id), intval($this->type == 'assign') * 2); } } return true; }