示例#1
0
 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));
 }
示例#2
0
 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;
 }
示例#3
0
 private function compileCams($cam)
 {
     $camName = explode('_', $cam);
     $camName = $this->double ? Shared::model()->findByPK($camName[1])->cam : Cams::model()->findByPK(Cams::model()->getRealId($camName[1]));
     if (!$camName) {
         throw new CHttpException(404, Yii::t('errors', 'There is no such cam'));
     }
     $this->buff[$cam] = $camName->getSessionId();
     return $camName->name;
 }
示例#4
0
文件: Cams.php 项目: mrtos/OpenNVR
 public static function getAvailableCams()
 {
     $id = Yii::app()->user->getId();
     $public = array();
     $publicAll = Cams::model()->findAllByAttributes(array('is_public' => 1));
     $shared = Shared::model()->findAllByAttributes(array('user_id' => $id, 'is_public' => 0));
     foreach ($shared as $key => $value) {
         if (!isset($value->cam->id)) {
             $value->delete();
             unset($shared[$key]);
         }
     }
     $publicEdited = Shared::model()->findAllByAttributes(array('user_id' => $id, 'is_public' => 1), array('index' => 'cam_id'));
     foreach ($publicAll as $cam) {
         if (isset($publicEdited[$cam->id])) {
             $public[] = $publicEdited[$cam->id];
         } else {
             $public[] = $cam;
         }
     }
     $myCams = Cams::model()->findAllByAttributes(array('user_id' => $id));
     $myPublicCams = $public;
     $mySharedCams = $shared;
     $allMyCams = array();
     foreach ($myCams as $key => $cam) {
         $allMyCams[$cam->id] = $cam;
     }
     foreach ($myPublicCams as $key => $cam) {
         if (isset($cam->cam)) {
             $allMyCams[$cam->id] = $cam->cam;
         } else {
             $allMyCams[$cam->id] = $cam;
         }
     }
     foreach ($mySharedCams as $key => $cam) {
         $allMyCams[$cam->cam_id] = $cam->cam;
     }
     return $allMyCams;
 }