From 7d31bf39b268be654b9dd0eae7ec370c90229281 Mon Sep 17 00:00:00 2001 From: jhaniot Date: Thu, 19 Oct 2017 11:35:22 +0300 Subject: [PATCH] Print Applications Admin and User panel --- controllers/AdminController.php | 80 ++++++++++++++++++++++++++- controllers/ApplicationController.php | 26 ++++----- views/admin/index.php | 10 ++++ views/admin/view-applications.php | 35 ++++++++++++ views/application/print.php | 16 ++++-- views/application/view.php | 13 +++-- 6 files changed, 153 insertions(+), 27 deletions(-) create mode 100644 views/admin/view-applications.php diff --git a/controllers/AdminController.php b/controllers/AdminController.php index 0365513..e9a0846 100644 --- a/controllers/AdminController.php +++ b/controllers/AdminController.php @@ -7,7 +7,10 @@ use app\models\Application; use app\models\Applicant; use app\models\Choice; +use app\models\Prefecture; use League\Csv\Writer; +use yii\data\ArrayDataProvider; +use kartik\mpdf\Pdf; class AdminController extends \yii\web\Controller { @@ -101,7 +104,7 @@ public function actionOverview() $choices = Choice::find() ->count(); - + return $this->render('overview', compact(['dataProvider', 'applicants', 'applications', 'choices'])); } @@ -152,4 +155,79 @@ public function actionExportCsv() $csv->output('ΑΙΤΗΣΕΙΣ-' . date('Y-m-d') . '.csv'); \Yii::$app->end(); } + + public function actionViewApplications() + { + $dataProvider = new ArrayDataProvider(['allModels' => Applicant::find()->joinWith([ + 'applications' => function (\yii\db\ActiveQuery $query) { + $query->andWhere(['deleted' => 0])->count() >0; + } + ])->all()]); + + return $this->render('view-applications', ['users' => $dataProvider, + 'pagination' => ['pageSize' => 100], + 'sort' => ['attributes' => ['vat', 'identity', 'specialty']], + ]); + } + + public function actionPrintApplications($applicantId = null) + { + if(isset($applicantId) && is_numeric($applicantId) && intval($applicantId)) + $users[0] = Applicant::findOne(['id' => $applicantId]); + else + $users = Applicant::find()->joinWith(['applications' => function (\yii\db\ActiveQuery $query) { + $query->andWhere(['deleted' => 0])->count() >0;}])->all(); + + for($j = 0; $j < count($users); $j++){ + $choices = $users[$j]->applications; + + // if no application exists, forward to create + if (count($choices) == 0) { + Yii::$app->session->addFlash('info', "Δεν υπάρχει αποθηκευμένη αίτηση. Μπορείτε να υποβάλλετε νέα αίτηση."); + return $this->redirect(['apply']); + } + + $choicesArray = \yii\helpers\ArrayHelper::toArray($choices); + + for($i = 0; $i < count($choicesArray); $i++){ + $choiceActRec = Choice::findOne(['id' => $choicesArray[$i]['choice_id']]); + $prefectureId = $choiceActRec->prefecture_id; + $choicesArray[$i]['Position'] = $choiceActRec->position; + $choicesArray[$i]['PrefectureName'] = Prefecture::findOne(['id' => $prefectureId])->prefecture; + $choicesArray[$i]['RegionName'] = Prefecture::findOne(['id' => $prefectureId])->region; + } + + $provider = new \yii\data\ArrayDataProvider([ + 'allModels' => $choicesArray + ]); + + + $data[$j]['user'] = $users[$j]; + $data[$j]['provider'] = $provider; + } + + $content = $this->renderPartial('../application/print', ['data' => $data]); + // setup kartik\mpdf\Pdf component + $pdf = new Pdf([ + 'mode' => Pdf::MODE_UTF8, + 'format' => Pdf::FORMAT_A4, + 'orientation' => Pdf::ORIENT_PORTRAIT, + 'filename' => 'aitisi.pdf', + 'destination' => Pdf::DEST_DOWNLOAD, + 'content' => $content, + 'cssFile' => '@vendor/kartik-v/yii2-mpdf/assets/kv-mpdf-bootstrap.min.css', + 'cssInline' => '.kv-heading-1{font-size:18px}', + 'options' => ['title' => 'Περιφερειακή Διεύθυνση Πρωτοβάθμιας και Δευτεροβάθμιας Εκπαίδευσης Κρήτης'], + 'methods' => [ + 'SetHeader'=>['Περιφερειακή Διεύθυνση Πρωτοβάθμιας και Δευτεροβάθμιας Εκπαίδευσης Κρήτης'], + 'SetFooter'=>['Σελίδα: {PAGENO} από {nb}'], + ] + ]); + + return $pdf->render(); + } + + private function printApplications($applicants) + { + } } diff --git a/controllers/ApplicationController.php b/controllers/ApplicationController.php index 87f42e9..247fdfa 100644 --- a/controllers/ApplicationController.php +++ b/controllers/ApplicationController.php @@ -40,7 +40,7 @@ public function behaviors() [ 'actions' => ['my-application'], 'allow' => true, - 'roles' => ['@'], + 'roles' => ['@'], 'matchCallback' => function ($rule, $action) { return false === \Yii::$app->user->identity->isAdmin(); } @@ -89,10 +89,9 @@ public function actionIndex() */ public function actionMyApplication($printMode = 0) { - $user = Applicant::findOne(['vat' => \Yii::$app->user->getIdentity()->vat, 'specialty' => \Yii::$app->user->getIdentity()->specialty]); + $user = Applicant::findOne(['vat' => \Yii::$app->user->getIdentity()->vat, 'specialty' => \Yii::$app->user->getIdentity()->specialty]); + $choices = $user->applications; - //$prefectrs_prefrnc_model = PrefecturesPreference::find()->where(['applicant_id' => $user->id])->orderBy('order')->all(); - //$prefectrs_choices_model = Choice::classname(); // if no application exists, forward to create if (count($choices) == 0) { @@ -109,20 +108,16 @@ public function actionMyApplication($printMode = 0) $choicesArray[$i]['PrefectureName'] = Prefecture::findOne(['id' => $prefectureId])->prefecture; $choicesArray[$i]['RegionName'] = Prefecture::findOne(['id' => $prefectureId])->region; } - //echo "
"; print_r($choicesArray); echo "
"; die(); $provider = new \yii\data\ArrayDataProvider([ - 'allModels' => $choicesArray, - 'pagination' => [ - 'pageSize' => 100, - ], + 'allModels' => $choicesArray ]); if($printMode == 1){ + $data[0]['user'] = $user; + $data[0]['provider'] = $provider; $content = $this->renderPartial('print', [ - 'user' => $user, - 'dataProvider' => $provider, - 'enable_applications' => (\app\models\Config::getConfig('enable_applications') === 1) + 'data' => $data, ]); // setup kartik\mpdf\Pdf component @@ -141,8 +136,7 @@ public function actionMyApplication($printMode = 0) 'SetFooter'=>['Σελίδα: {PAGENO} από {nb}'], ] ]); - - // return the pdf output as per the destination setting + return $pdf->render(); } @@ -173,7 +167,7 @@ public function actionApply() $prefectures_choices = []; $counter = 1; - if($user->applications){ + if($user->applications){ // Edit, if the user has already applied foreach ($prefectrs_prefrnc_model as $preference) { $userChoices = $user->getApplications()->all(); $prefectures_choices[$preference->getPrefectureName()] = $preference->prefect_id; @@ -186,7 +180,7 @@ public function actionApply() } } } - else{ + else{ // Make new application, if the user has not already applied foreach ($prefectrs_prefrnc_model as $preference) { $choices = Choice::getChoices($preference->prefect_id, $user->specialty); $prefectures_choices[$preference->getPrefectureName()] = $preference->prefect_id; diff --git a/views/admin/index.php b/views/admin/index.php index 708f9be..28099e6 100644 --- a/views/admin/index.php +++ b/views/admin/index.php @@ -44,6 +44,16 @@

Προσοχή! Η ενέργεια αυτή είναι μή αναστρέψιμη!

'btn btn-danger', 'data-method' => 'post', 'data-confirm' => 'Η ενέργεια αυτή είναι μη αναστρέψιμη! Είστε βέβαιοι;']) ?>

+
+

Εκτύπωση αιτήσεων

+

Η λειτουργία αυτή εκτυπώνει όλες τις υποβληθείσες αιτήσεις.

+

'btn btn-primary', 'data-method' => 'POST']) ?>

+
+
+

Προβολή Αιτήσεων

+

Προβολή αιτήσεων που έχουν υποβληθεί.

+

'btn btn-primary', 'data-method' => 'post']) ?>

+
diff --git a/views/admin/view-applications.php b/views/admin/view-applications.php new file mode 100644 index 0000000..f8a0ad4 --- /dev/null +++ b/views/admin/view-applications.php @@ -0,0 +1,35 @@ +title = 'Προβολή αιτήσεων'; +$this->params['breadcrumbs'][] = ['label' => 'Διαχειριστικές λειτουργίες', 'url' => ['index']]; +$this->params['breadcrumbs'][] = $this->title; +//echo "
"; print_r($users); echo "
"; die(); +echo GridView::widget([ + 'dataProvider' => $users, + 'columns' => [ + ['class' => 'yii\grid\SerialColumn'], + [ + 'label' => 'Α.Φ.Μ.', + 'attribute' => 'vat' + ], + [ + 'label' => 'Α.Δ.Τ.', + 'attribute' => 'identity' + ], + [ + 'label' => 'Ειδικότητα', + 'attribute' => 'specialty' + ], + ['class' => 'yii\grid\ActionColumn', + 'header' => 'Προβολή', + 'template' => '{printButton}', + 'buttons' => ['printButton' => function($url, $model, $key){ + return Html::a(Html::icon('print'), ['admin/print-applications', 'applicantId' => $model->id]);} + ] + ] + ] + ]); + +?> diff --git a/views/application/print.php b/views/application/print.php index e6d7464..0b4bcc3 100644 --- a/views/application/print.php +++ b/views/application/print.php @@ -9,15 +9,21 @@ $this->params['breadcrumbs'][] = $this->title; ?> + "; + $putpagebreak = true; + ?>

title) ?>

- + - - + + @@ -28,7 +34,6 @@

Ονοματεπώνυμο:

Ειδικότητα: specialty ?>

Ειδικότητα: specialty ?>

Α.Φ.Μ.: vat ?>

Ταυτότητα: identity ?>

Α.Φ.Μ.: vat ?>

Ταυτότητα: identity ?>

Τηλ:

..................., .... /.... /

- "; var_dump($dataProvider); echo ""; ?>

Προτιμήσεις

@@ -41,7 +46,7 @@ $dataProvider, + 'dataProvider' => $userdata['provider'],//$dataProvider, 'itemView' => '_myapplication_item', 'summary' => '

{totalCount} προτιμήσεις

' ]); @@ -52,3 +57,4 @@
 Ο αιτών / Η αιτούσα


(υπογραφή)
+ diff --git a/views/application/view.php b/views/application/view.php index 7f04fd2..c33df60 100644 --- a/views/application/view.php +++ b/views/application/view.php @@ -5,16 +5,19 @@ /* @var $this yii\web\View */ /* @var $model app\models\Application */ -$this->title = 'Η αίτηση μου'; +$this->title = 'Η αίτησή μου'; $this->params['breadcrumbs'][] = $this->title; ?>
- - 'pull-right btn btn-danger']) ?> - '1'], ['class' => 'pull-right btn btn-primary']) ?> - +
+ + 'pull-right btn btn-danger']);?> + + '1', 'userId' => $user->id], ['class' => 'pull-right btn btn-primary']) ?> +
+

title) ?>