Esempio n. 1
0
<?php

use app\models\Project;
use app\models\Registration;
use app\models\student;
use app\models\StudentEvidenceSearch;
/* @var $this yii\web\View */
/* @var $searchModel app\models\StudentSearch */
/* @var $dataProvider yii\data\ActiveDataProvider */
$this->title = 'Página principal';
Yii::$app->formatter->locale = 'es_ES';
$student = Student::findOne(['user_id' => Yii::$app->user->id]);
if ($registration = Registration::findOne(['student_id' => $student->id])) {
    $project = Project::findOne($registration->project_id);
    $textProject = 'Avances de proyecto: ' . $project->name;
    $searchModel = new StudentEvidenceSearch();
    $dataProviderNews = $searchModel->search(Yii::$app->request->queryParams, \app\models\StudentEvidence::$NEW);
    $dataProviderPending = $searchModel->search(Yii::$app->request->queryParams, \app\models\StudentEvidence::$PENDING);
    $countNews = $dataProviderNews->getTotalCount();
    $countPending = $dataProviderPending->getTotalCount();
    if ($countNews == 1) {
        $textDetails = 'Tienes ' . $countNews . ' avance nuevo.';
    } else {
        $textDetails = 'Tienes ' . $countNews . ' avances nuevos.';
    }
    if ($countPending == 1) {
        $textDetails .= '<br>Tienes ' . $countPending . ' avance pendiente.';
    } else {
        $textDetails .= '<br>Tienes ' . $countPending . ' avances pendientes.';
    }
    $textFooter = "<div class = 'panel-footer'><h4>Da click en el menú <i>Avances</i> para ver los detalles.</h4></div>";
 /**
  * @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());
     }
 }
 /**
  * Finds the Registration model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Registration the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Registration::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
 /**
  * @throws BadRequestHttpException
  */
 public function actionSetBeginningAndEndingDates()
 {
     $beginningDate = new \DateTime(Yii::$app->request->post('Registration')['beginning_date']);
     $endingDate = new \DateTime(Yii::$app->request->post('Registration')['ending_date']);
     $interval = $beginningDate->diff($endingDate);
     $daysBetweenDates = $interval->format('%a');
     if ($daysBetweenDates > 180) {
         try {
             $student = Student::findOne(['user_id' => Yii::$app->user->id]);
             $registration = Registration::findOne(['student_id' => $student->id]);
             $registration->beginning_date = Yii::$app->request->post('Registration')['beginning_date'];
             $registration->ending_date = Yii::$app->request->post('Registration')['ending_date'];
             $registration->save(false);
             $this->actionPrintProjectAssignmentPDF();
         } catch (InvalidConfigException $e) {
             throw new BadRequestHttpException('No se tiene asignado ningún proyecto');
         }
     } else {
         throw new BadRequestHttpException('Las fechas ingresadas no son válidas,
         deben tener una diferencia de al menos 6 meses');
     }
 }