/** * @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; } }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Proyecto::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to return any records when validation fails // $query->where('0=1'); return $dataProvider; } $query->andFilterWhere(['id' => $this->id, 'fecha_inicio' => $this->fecha_inicio, 'fecha_fin' => $this->fecha_fin, 'estatus_proyecto' => $this->estatus_proyecto, 'situacion_presupuestaria' => $this->situacion_presupuestaria, 'monto_proyecto' => $this->monto_proyecto, 'sub_sector' => $this->sub_sector, 'plan_operativo' => $this->plan_operativo, 'objetivo_general' => $this->objetivo_general]); $query->andFilterWhere(['like', 'codigo_proyecto', $this->codigo_proyecto])->andFilterWhere(['like', 'codigo_sne', $this->codigo_sne])->andFilterWhere(['like', 'nombre', $this->nombre])->andFilterWhere(['like', 'descripcion', $this->descripcion]); $query->andFilterWhere(['estatus' => $this->nombreEstatus]); return $dataProvider; }
/** * @return \yii\db\ActiveQuery */ public function getProyecto() { return $this->hasOne(Proyecto::className(), ['id' => 'proyecto_id']); }
/** * 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.'); } }
/** * Updates an existing ProyectoAsignar model. * For ajax request will return json object * and for non-ajax request if update is successful, the browser will be redirected to the 'view' page. * @param integer $id * @return mixed */ public function actionUpdate($id) { $request = Yii::$app->request; $model = $this->findModel($id); //Listas desplegables $proyectos = Proyecto::find(['estatus' => 1])->all(); if ($request->isAjax) { /* * Process for ajax request */ Yii::$app->response->format = Response::FORMAT_JSON; if ($request->isGet) { return ['title' => "Asignar", 'content' => $this->renderPartial('update', ['model' => $model, 'proyectos' => $proyectos]), 'footer' => Html::button('Cerrar', ['class' => 'btn btn-default pull-left', 'data-dismiss' => "modal"]) . Html::button('Guardar', ['class' => 'btn btn-primary', 'type' => "submit"])]; } else { if ($model->load($request->post()) && $model->save()) { return ['forceReload' => 'true', 'title' => "Asignado", 'content' => $this->renderPartial('view', ['model' => $model]), 'footer' => Html::button('Cerrar', ['class' => 'btn btn-default pull-left', 'data-dismiss' => "modal"]) . Html::a('Editar', ['update', 'id' => $id], ['class' => 'btn btn-primary', 'role' => 'modal-remote'])]; } else { return ['title' => "Asignar", 'content' => $this->renderPartial('update', ['model' => $model, 'proyectos' => $proyectos]), 'footer' => Html::button('Cerrar', ['class' => 'btn btn-default pull-left', 'data-dismiss' => "modal"]) . Html::button('Guardar', ['class' => 'btn btn-primary', 'type' => "submit"])]; } } } else { /* * Process for non-ajax request */ if ($model->load($request->post()) && $model->save()) { return $this->redirect(['view', 'id' => $model->id]); } else { return $this->render('update', ['model' => $model, 'proyectos' => $proyectos]); } } }
protected function findAmbito($proyecto) { $proyecto = Proyecto::findOne($proyecto); return $proyecto->nombreAmbito; }