/** * @param string|integer $user the user ID. * @param Item $item the role or permission that this rule is associated with * @param array $params parameters passed to ManagerInterface::checkAccess(). * @return boolean a value indicating whether the rule permits the role or permission it is associated with. */ public function execute($user, $item, $params) { //admin no deberia ser afectado por la regla if (Yii::$app->user->can('sysadmin')) { return true; } else { $proyecto = Proyecto::findOne(Yii::$app->request->get('id')); return $proyecto->usuario_creacion == $user ? true : false; } }
/** * save Feedback model and trigger event notifications. * @param integer $id proyecto * @return Json Feedbaack */ public function actionFeedback($id) { // ajax validation if (Yii::$app->request->isAjax) { $data = json_decode($_POST['feedback']); //search proyecto creaction user $model_proyecto = Proyecto::findOne($id); $model = new Feedback(); $model->id_usuario = Yii::$app->user->identity->id; $model->id_usuario_destino = $model_proyecto->usuario_creacion; $model->mensaje = $data->note; $model->img = $data->img; if ($model->save()) { $model->trigger(Feedback::EVENT_NUEVO_PEDIDO); //Notificacion Yii::$app->response->format = Response::FORMAT_JSON; return true; } else { return false; } } }
/** * Finds the Proyecto model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Proyecto the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Proyecto::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
protected function findAmbito($proyecto) { $proyecto = Proyecto::findOne($proyecto); return $proyecto->nombreAmbito; }