/** * @return string|\yii\web\Response * @throws \yii\base\Exception */ public function actionProjectManagerRequest() { $projectManager = new ProjectManager(); $user = new User(); $person = new Person(); if (Yii::$app->request->post()) { $params = Yii::$app->request->post(); $person->load($params); $user->load($params); $projectManager->load($params); if ($person->validate() && $user->validate() && $projectManager->validate()) { $user->password_hash = Yii::$app->getSecurity()->generatePasswordHash($params['User']['password_hash']); $person->save(false); $user->person_id = $person->id; $user->register(); $projectManager->user_id = $user->id; $projectManager->save(); Yii::$app->session->setFlash('success', 'Se envío un correo de confirmación. Por favor verifique su correo electrónico'); return $this->refresh(); } else { Yii::$app->session->setFlash('danger', 'Ocurrió un error al guardar. Vuelve a intentar'); } } return $this->render('project-manager-request', ['projectManager' => $projectManager, 'user' => $user, 'person' => $person]); }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = ProjectManager::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, 'user_id' => $this->user_id]); $query->andFilterWhere(['like', 'organization', $this->organization]); return $dataProvider; }
/** * @return \yii\db\ActiveQuery */ public function getProjectManager() { return $this->hasOne(ProjectManager::className(), ['id' => 'manager_id']); }
/** * Figure it out the person role and returns an * object of that type. */ public function getUserRole() { $rol = null; if (Yii::$app->user->can('projectManager')) { return $rol = ProjectManager::findOne(['user_id' => $this->id]); } if (Yii::$app->user->can('socialServiceManager')) { return $rol = SocialServiceManager::findOne(['user_id' => $this->id]); } if (Yii::$app->user->can('student')) { return $rol = Student::findOne(['user_id' => $this->id]); } return $rol; }
/** * Finds the ProjectManager model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return ProjectManager the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = ProjectManager::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
<?php echo $form->field($model, 'name')->textInput(['maxlength' => true]); ?> <?php echo $form->field($model, 'description')->textarea(['rows' => 6]); ?> <?php echo $form->field($model, 'delivery_date')->widget(\yii\jui\DatePicker::classname(), ['dateFormat' => 'yyyy-MM-dd']); ?> <?php $user = User::find()->where("id=" . Yii::$app->user->id)->one(); $userId = $user->id; $manager = ProjectManager::find()->where("user_id=" . $userId)->one(); $managerId = $manager->id; $students = Yii::$app->db->createCommand('Select registration.student_id, student.id, person.name, person.lastname From registration Inner Join student On registration.student_id = student.id Inner Join user On student.user_id = user.id Inner Join person On user.person_id = person.id where registration.project_id=' . $projectId)->queryAll();
/** * @return mixed|\yii\web\Response */ public function actionPrintEvidenceReport() { $student = Student::findOne(['user_id' => Yii::$app->user->id]); date_default_timezone_set("America/Mexico_City"); try { $searchModel = new StudentEvidenceSearch(); $dataProviderAccepted = $searchModel->search(Yii::$app->request->queryParams, StudentEvidence::$ACCEPTED); $registration = Registration::findOne(['student_id' => $student->id]); $person = Person::findOne(User::findOne(Yii::$app->user->id)->person_id); $project = Project::findOne($registration->project_id); $projectM = ProjectManager::findOne($project->manager_id); // get your HTML raw content without any layouts or scripts $content = $this->render('studentEvidencePDF', ['registration' => $registration, 'student' => $student, 'person' => $person, 'project' => $project, 'projectM' => $projectM, 'searchModel' => $searchModel, 'dataProviderAccepted' => $dataProviderAccepted]); $formatter = \Yii::$app->formatter; // setup kartik\mpdf\Pdf component $pdf = new Pdf(['mode' => Pdf::MODE_UTF8, 'format' => Pdf::FORMAT_LETTER, 'orientation' => Pdf::ORIENT_PORTRAIT, 'destination' => Pdf::DEST_BROWSER, 'content' => $content, 'cssFile' => '@vendor/kartik-v/yii2-mpdf/assets/kv-mpdf-bootstrap.min.css', 'cssInline' => '.kv-heading-1{font-size:18px}', 'options' => ['title' => 'Reporte de avances'], 'methods' => ['SetFooter' => ['Fecha de expedición: ' . $formatter->asDate(date('d-F-Y'))]]]); // return the pdf output as per the destination setting return $pdf->render(); } catch (InvalidConfigException $e) { Yii::$app->getSession()->setFlash('danger', 'No tienes proyectos asignados'); return $this->redirect(Url::home()); } }
/** * Updates an existing Project model. * If update is successful, the browser will be redirected to the 'view' page. * @param integer $id * @return mixed */ public function actionUpdate($id) { $model = $this->findModel($id); $user_id = User::find()->where("id=" . Yii::$app->user->id)->one()->id; $manager_id = ProjectManager::find()->where("user_id=" . $user_id)->one()->id; $model->manager_id = $manager_id; $degreeIds = StudentProfile::find()->where("project_id=" . $model->id)->all(); $cupoValor = ProjectVacancy::find()->where("project_id=" . $model->id)->all(); $ids = ArrayHelper::getColumn($degreeIds, 'degree_id'); $cupo = ArrayHelper::getColumn($cupoValor, 'vacancy')[0]; $model->degrees1 = $ids; $model->vacancy = $cupo; if ($model->load(Yii::$app->request->post()) && $model->save()) { StudentProfile::deleteAll('project_id=' . $model->id); ProjectVacancy::deleteAll('project_id=' . $model->id); $vacancyValue = $_POST['Project']['vacancy']; $newVacancy = new ProjectVacancy(); $newVacancy->project_id = $model->id; $newVacancy->vacancy = $vacancyValue; $newVacancy->save(); $degreesList = $_POST['Project']['degrees1']; foreach ($degreesList as $value) { $this->createStudentProfile($model->id, $value); } Yii::$app->getSession()->setFlash('success', 'Los cambios se han guardado exitosamente'); return $this->redirect(['view', 'id' => $model->id]); } else { return $this->render('update', ['model' => $model]); } }