public function actionList() { $limit = 20; $q = new CDbCriteria(array('select' => array('*', '(SELECT COUNT(*) FROM log WHERE qr.id = log.qr_id) AS hitCount'), 'alias' => 'qr', 'with' => array('user' => array('select' => 'username', 'alias', 'user')))); $this->addDefaultCriteria($q, array('limit' => $limit, 'order' => 'qr.created_at', 'sort' => 'DESC')); $qrs = Qr::model()->findAll($q); $count = Qr::model()->count($q); $pages = new CPagination($count); // results per page $pages->pageSize = $limit; $pages->applyLimit($q); $this->render('list', array('qrs' => $qrs, 'pages' => $pages)); }
protected function _associateQrsInSession($user = null) { $qrs = Qr::getInSession(); if ($qrs) { if ($user instanceof User) { $userId = $user->id; } else { $userId = Yii::app()->user->getId(); } foreach ($qrs as $id) { if ($qr = Qr::model()->findByPk($id)) { $qr->user_id = $userId; $qr->save(); } } } }
public function checkAccess($operation, $params = array()) { // if(Yii::app()->user->getState('role') === 'admin') { // return true; // } // else if($operation == 'ownQr') { // $id = Yii::app()->request->getParam('id'); // // if(Qr::isInSession($id)) { // return true; // } // else if($qr = Qr::model()->findByPk($id)) { // return Yii::app()->user->getId() == Qr::model()->findByPk($id)->user_id; // } // else { // return false; // } // } // // return false; if (empty($this->id)) { // Not identified => no rights return false; } $role = $this->getState("role"); if ($role === 'admin') { return true; // admin role has access to everything } if ($operation == 'ownQr') { $id = Yii::app()->request->getParam('id'); if (Qr::isInSession($id)) { return true; } else { if ($qr = Qr::model()->findByPk($id)) { return Yii::app()->user->getId() == Qr::model()->findByPk($id)->user_id; } else { return false; } } } // allow access if the operation request is the current user's role return $operation === $role; }
public function loadModel($id) { $model = Qr::model()->findByPk($id); if ($model === null) { throw new CHttpException(404, 'The QR Code does not exists.'); } return $model; }
<?php echo $form->textField($model, 'last_name', array('class' => 'form-control')); ?> <?php echo $form->error($model, 'last_name'); ?> </div> </div> <div class="form-group"> <?php echo $form->labelEx($model, 'company', array('class' => 'col-sm-2 control-label', 'for' => 'company')); ?> <div class="col-sm-6"> <?php echo $form->dropDownList($model, 'company', CHtml::listData(Qr::model()->findAll(array('condition' => "company!=''", 'distinct' => true, 'order' => 'company ASC')), 'company', 'company'), array('empty' => 'Select Company', 'class' => 'form-control')); ?> <?php echo $form->error($model, 'company'); ?> </div> </div> <div class="form-group"> <?php echo $form->labelEx($model, 'is_companyadmin', array('class' => 'col-sm-2 control-label', 'for' => 'is_companyadmin')); ?> <div class="col-sm-6"> <label style="padding-top: 5px;"> <?php echo $form->checkBox($model, 'is_companyadmin', array('value' => '1'));
/** * This is the default 'index' action that is invoked * when an action is not explicitly requested by users. */ public function actionIndex() { $gallery = Qr::model()->findAll(array('condition' => 't.show_in_gallery = 1 AND t.user_id > 0', 'limit' => Yii::app()->params['home_gallery_count'], 'order' => 't.id DESC')); $this->render('index', array('gallery' => $gallery)); }
<div class="panel panel-default" style="margin-top:20px;"> <div class="panel-heading"> <h3 class="panel-title">Reporting Kunde iklinik</h3> </div> <div class="panel-body"> <?php $this->widget('zii.widgets.grid.CGridView', array('id' => 'scans_list', 'enableSorting' => true, 'dataProvider' => $model->search(), 'filter' => $model, 'columns' => array(array('header' => 'ID', 'value' => '$data->id', 'name' => 'id', 'sortable' => true, 'filter' => false), array('header' => 'Title', 'name' => 'qrtitle', 'value' => '$data->qrtitle', 'filter' => CHtml::dropDownList('Scans[qrtitle]', $model->qrtitle, CHtml::listData(Qr::model()->findAll(array('order' => 'id desc', 'condition' => "company LIKE'%" . Yii::app()->user->getState('company') . "%'", 'distinct' => true)), 'title', 'title'), array('empty' => 'select title')), 'sortable' => false), array('header' => 'IP', 'value' => '$data->ip', 'name' => 'ip', 'sortable' => true, 'filter' => false), array('header' => 'Scan', 'value' => 'Yii::app()->dateFormatter->format("d.M.y hh:mm a",$data->scan)', 'name' => 'scan', 'sortable' => true, 'filter' => false), array('header' => 'Browser', 'value' => '$data->browser'), array('header' => 'Platform', 'value' => '$data->platform'), array('header' => 'Enjoyer', 'value' => '$data->counter', 'name' => 'counter', 'sortable' => true, 'filter' => false), array('class' => 'CButtonColumn', 'header' => 'Actions', 'template' => '{delete}')))); ?> </div> </div>