From 737d840c3106e750d8d911112db6f9e04113fa93 Mon Sep 17 00:00:00 2001 From: jhaniot Date: Thu, 26 Oct 2017 10:29:10 +0300 Subject: [PATCH] Admin view denials - Points addition - Sorting (#45) * Removed Deletion button and Request deny application * RemoveDeletionButton & DenyApplication * PHP_CS_FIXER * View Denials in Admin Panel * Added First&Lastname in View Denials * First-Lastname added in admin view applications * Applicants Sorted by specialty and points * Checked returned value in deny application transaction" * Removed redundant if in user's index.php * Sorting corrections/additions * Fix exception --- controllers/AdminController.php | 21 ++++- controllers/ApplicationController.php | 49 ++++++++++- controllers/SiteController.php | 5 ++ migrations/m171024_104206_DenyToApply.php | 16 ++++ .../m171025_092922_ApplicantsPoints.php | 16 ++++ models/Applicant.php | 2 + views/admin/index.php | 59 +++++++------ views/admin/view-applications.php | 16 +++- views/admin/view-denials.php | 34 ++++++++ .../application/confirm-deny-application.php | 16 ++++ views/application/view.php | 2 +- views/site/denied-application.php | 20 +++++ views/site/index.php | 85 ++++++++----------- 13 files changed, 256 insertions(+), 85 deletions(-) create mode 100644 migrations/m171024_104206_DenyToApply.php create mode 100644 migrations/m171025_092922_ApplicantsPoints.php create mode 100644 views/admin/view-denials.php create mode 100644 views/application/confirm-deny-application.php create mode 100644 views/site/denied-application.php diff --git a/controllers/AdminController.php b/controllers/AdminController.php index 8733aca..c0b0d2e 100644 --- a/controllers/AdminController.php +++ b/controllers/AdminController.php @@ -173,10 +173,25 @@ public function actionViewApplications() 'applications' => function (\yii\db\ActiveQuery $query) { $query->andWhere(['deleted' => 0])->count() > 0; } - ])->all()]); + ])->orderBy(['specialty' => SORT_ASC, 'points' => SORT_DESC])->all(), + 'pagination' => ['pageSize' => 100], + 'sort' => ['attributes' => [ + 'points'=> [ + 'asc' => ['specialty' => SORT_DESC, 'points' => SORT_ASC], + 'desc' => ['specialty' => SORT_ASC, 'points' => SORT_DESC]], + 'lastname', 'firstname', 'vat', 'identity', 'specialty']]]); + + return $this->render('view-applications', ['users' => $dataProvider]); + } + - return $this->render('view-applications', ['users' => $dataProvider, + public function actionViewDenials() + { + $dataProvider = new ArrayDataProvider(['allModels' => Applicant::find()->where(['state' => 1])->all(), 'pagination' => ['pageSize' => 100], + 'sort' => ['attributes' => ['lastname', 'firstname', 'vat', 'identity', 'specialty']] + ]); + return $this->render('view-denials', ['users' => $dataProvider, 'sort' => ['attributes' => ['vat', 'identity', 'specialty']], ]); } @@ -190,7 +205,7 @@ public function actionPrintApplications($applicantId = null) } else { $users = Applicant::find()->joinWith(['applications' => function (\yii\db\ActiveQuery $query) { $query->andWhere(['deleted' => 0])->count() > 0; - }])->all(); + }])->orderBy(['specialty' => SORT_ASC, 'points' => SORT_DESC])->all(); } $data = []; diff --git a/controllers/ApplicationController.php b/controllers/ApplicationController.php index 1a38526..722bdc5 100644 --- a/controllers/ApplicationController.php +++ b/controllers/ApplicationController.php @@ -13,6 +13,8 @@ use app\models\Prefecture; use app\models\PrefecturesPreference; use app\models\Choice; +use yii\web\ForbiddenHttpException; +use yii\web\GoneHttpException; use kartik\mpdf\Pdf; use app\models\AuditLog; @@ -46,7 +48,7 @@ public function behaviors() } ], [ - 'actions' => ['apply', 'delete-my-application', 'my-delete'], + 'actions' => ['apply', 'request-deny', 'deny'],// 'delete-my-application', 'my-delete'], 'allow' => true, 'roles' => ['@'], 'matchCallback' => function ($rule, $action) { @@ -93,6 +95,10 @@ public function actionMyApplication($printMode = 0) { $user = Applicant::findOne(['vat' => \Yii::$app->user->getIdentity()->vat, 'specialty' => \Yii::$app->user->getIdentity()->specialty]); + if ($user->state == Applicant::DENIED_TO_APPLY) { + return $this->redirect(['site/index']); + } + $choices = $user->applications; // if no application exists, forward to create @@ -124,7 +130,9 @@ public function actionMyApplication($printMode = 0) $data[0]['user'] = $user; $data[0]['provider'] = $provider; $data[0]['last_submit_model'] = $last_submit_model; - $content = $this->renderPartial('print', compact('data')); + $content = $this->renderPartial('print', [ + 'data' => $data, + ]); $actionlogo = "file:///" . realpath(dirname(__FILE__). '/../web/images/logo.jpg'); $pdelogo = "file:///" . realpath(dirname(__FILE__). '/../web/images/pdelogo.jpg'); @@ -167,6 +175,9 @@ public function actionMyApplication($printMode = 0) public function actionApply() { $user = Applicant::findOne(['vat' => \Yii::$app->user->getIdentity()->vat, 'specialty' => \Yii::$app->user->getIdentity()->specialty]); + if ($user->state == Applicant::DENIED_TO_APPLY) { + return $this->redirect(['site/index']); + } $prefectrs_prefrnc_model = PrefecturesPreference::find()->where(['applicant_id' => $user->id])->orderBy('order')->all(); if (count($prefectrs_prefrnc_model) == 0) { Yii::$app->session->addFlash('info', "Δεν υπάρχουν νομοί προτιμήσης."); @@ -277,6 +288,7 @@ public function actionApply() public function actionDeleteMyApplication() { + throw new GoneHttpException(); $user = Applicant::findOne(['vat' => \Yii::$app->user->getIdentity()->vat, 'specialty' => \Yii::$app->user->getIdentity()->specialty]); // if user has made no choices, forward to index if (count($user->applications) == 0) { @@ -289,6 +301,7 @@ public function actionDeleteMyApplication() public function actionMyDelete() { + throw new GoneHttpException(); $user = Applicant::findOne(['vat' => \Yii::$app->user->getIdentity()->vat, 'specialty' => \Yii::$app->user->getIdentity()->specialty]); Application::updateAll(['deleted' => 1], ['applicant_id' => $user->id]); @@ -304,11 +317,41 @@ public function actionMyDelete() */ public function actionDelete($id) { + throw new GoneHttpException(); $this->findModel($id)->delete(); - return $this->redirect(['my-application']); } + public function actionRequestDeny() + { + $user = Applicant::findOne(\Yii::$app->user->getIdentity()->id); + if (count($user->applications) > 0) { + throw new ForbiddenHttpException(); + } + return $this->render('confirm-deny-application'); + } + + public function actionDeny() + { + $user = Applicant::findOne(\Yii::$app->user->getIdentity()->id); + if (count($user->applications) > 0) { + throw new ForbiddenHttpException(); + } + $user->setAttribute('state', 1); + try { + $rowsAffected = $user->updateAll(['state' => 1], ['id' => $user->id]); + if ($rowsAffected != 1) { + throw new \Exception(); + } + } catch (\Exception $nse) { + Yii::$app->session->addFlash('danger', "Προέκυψε σφάλμα κατά την αποθήκευση της επιλογής σας. Παρακαλώ προσπαθήστε ξανά."); + return $this->redirect(['site/index']); + } + Yii::$app->session->addFlash('info', "Η δήλωση άρνησης αίτησης έχει καταχωριστεί."); + return $this->redirect(['site/index']); + } + + /** * Finds the Application model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. diff --git a/controllers/SiteController.php b/controllers/SiteController.php index 30dc9ef..172b899 100644 --- a/controllers/SiteController.php +++ b/controllers/SiteController.php @@ -9,6 +9,7 @@ use app\models\LoginForm; // use app\models\ContactForm; use yii\web\GoneHttpException; +use app\models\Applicant; class SiteController extends Controller { @@ -69,6 +70,10 @@ public function actionIndex() if (\Yii::$app->user->identity->isAdmin()) { return $this->redirect(['admin/index']); } else { + $user = Applicant::findOne(['vat' => \Yii::$app->user->getIdentity()->vat, 'specialty' => \Yii::$app->user->getIdentity()->specialty]); + if ($user->state == Applicant::DENIED_TO_APPLY) { + return $this->render('denied-application'); + } return $this->render('index', [ 'enable_applications' => (\app\models\Config::getConfig('enable_applications') === 1) ]); diff --git a/migrations/m171024_104206_DenyToApply.php b/migrations/m171024_104206_DenyToApply.php new file mode 100644 index 0000000..b5138d9 --- /dev/null +++ b/migrations/m171024_104206_DenyToApply.php @@ -0,0 +1,16 @@ +addColumn('{{%applicant}}', 'state', $this->integer()->defaultValue(0)); + } + + public function safeDown() + { + $this->dropColumn('{{%applicant}}', 'state'); + } +} diff --git a/migrations/m171025_092922_ApplicantsPoints.php b/migrations/m171025_092922_ApplicantsPoints.php new file mode 100644 index 0000000..843db08 --- /dev/null +++ b/migrations/m171025_092922_ApplicantsPoints.php @@ -0,0 +1,16 @@ +addColumn('{{%applicant}}', 'points', $this->decimal(9, 3)); + } + + public function safeDown() + { + $this->dropColumn('{{%applicant}}', 'points'); + } +} diff --git a/models/Applicant.php b/models/Applicant.php index 61c7570..65677cd 100644 --- a/models/Applicant.php +++ b/models/Applicant.php @@ -13,6 +13,8 @@ */ class Applicant extends \yii\db\ActiveRecord { + const DENIED_TO_APPLY = "1"; + public $last_submit_str; /* the following properties should be separated from the model in th final version */ public $firstname; diff --git a/views/admin/index.php b/views/admin/index.php index ccbe596..1107377 100644 --- a/views/admin/index.php +++ b/views/admin/index.php @@ -15,44 +15,49 @@
-
-

Ενεργοποίηση αιτήσεων

- -

Η υποβολή των αιτήσεων είναι ενεργοποιημένη..

-

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

- -

Η υποβολή των αιτήσεων είναι απενεργοποιημένη.

-

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

- +
+

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

+

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

+

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

-
-

Εξαγωγή αιτήσεων

+
+

Εξαγωγή αιτήσεων

Η λειτουργία αυτή εξάγει όλες τις μη διεγραμμένες αιτήσεις σε μορφή CSV.

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

-
-

Επισκόπηση στοιχείων

-

Εμφάνιση συνοπτικών στατιστικών.

-

'btn btn-primary']) ?>

+
+

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

+

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

+

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

+
+
+

Δηλώσεις Άρνησης

+

Προβολή εκπαιδευτικών που έχουν δηλώσει άρνηση πρόσληψης.

+

'btn btn-primary']) ?>

-
-

Εκκαθάριση στοιχείων

+
+

Επισκόπηση στοιχείων

+

Εμφάνιση συνοπτικών στατιστικών.

+

'btn btn-primary']) ?>

+
+
+

Εκκαθάριση στοιχείων

Η επιλογή αυτή θα διαγράψει όλα τα δεδομένα που αφορούν αιτήσεις, αιτούντες, κενά και περιφερειακές ενότητες.

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

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

-
-
-

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

-

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

-

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

-
-
-

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

-

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

-

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

+
+
+

Ενεργοποίηση αιτήσεων

+ +

Η υποβολή των αιτήσεων είναι ενεργοποιημένη..

+

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

+ +

Η υποβολή των αιτήσεων είναι απενεργοποιημένη.

+

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

+
diff --git a/views/admin/view-applications.php b/views/admin/view-applications.php index 3d5e040..90a0a8e 100644 --- a/views/admin/view-applications.php +++ b/views/admin/view-applications.php @@ -11,6 +11,14 @@ 'dataProvider' => $users, 'columns' => [ ['class' => 'yii\grid\SerialColumn'], + [ + 'label' => 'Επώνυμο', + 'attribute' => 'lastname' + ], + [ + 'label' => 'Όνομα', + 'attribute' => 'firstname' + ], [ 'label' => 'Α.Φ.Μ.', 'attribute' => 'vat' @@ -23,6 +31,10 @@ 'label' => 'Ειδικότητα', 'attribute' => 'specialty' ], + [ + 'label' => 'Μόρια', + 'attribute' => 'points' + ], [ 'attribute' => 'last_submit_str', 'format' => 'html' @@ -32,8 +44,8 @@ 'header' => 'Προβολή', 'template' => '{printButton}', 'buttons' => ['printButton' => function ($url, $model, $key) { - return Html::a(Html::icon('print'), ['admin/print-applications', 'applicantId' => $model->id]); - } + return Html::a(Html::icon('print'), ['admin/print-applications', 'applicantId' => $model->id]); + } ] ] ] diff --git a/views/admin/view-denials.php b/views/admin/view-denials.php new file mode 100644 index 0000000..cf0882c --- /dev/null +++ b/views/admin/view-denials.php @@ -0,0 +1,34 @@ +title = 'Προβολή δηλώσεων άρνησης'; +$this->params['breadcrumbs'][] = ['label' => 'Διαχειριστικές λειτουργίες', 'url' => ['index']]; +$this->params['breadcrumbs'][] = $this->title; + +echo GridView::widget([ + 'dataProvider' => $users, + 'columns' => [ + ['class' => 'yii\grid\SerialColumn'], + [ + 'label' => 'Επώνυμο', + 'attribute' => 'lastname' + ], + [ + 'label' => 'Όνομα', + 'attribute' => 'firstname' + ], + [ + 'label' => 'Α.Φ.Μ.', + 'attribute' => 'vat' + ], + [ + 'label' => 'Α.Δ.Τ.', + 'attribute' => 'identity' + ], + [ + 'label' => 'Ειδικότητα', + 'attribute' => 'specialty' + ] + ] +]); diff --git a/views/application/confirm-deny-application.php b/views/application/confirm-deny-application.php new file mode 100644 index 0000000..9240351 --- /dev/null +++ b/views/application/confirm-deny-application.php @@ -0,0 +1,16 @@ +title = 'Επιβεβαίωση δήλωσης άρνησης αίτησης'; +$this->params['breadcrumbs'][] = $this->title; + +?> +
+

Επιβεβαίωση άρνησης αίτησης

+

Είστε βέβαιοι ότι επιθυμείτε να δηλώσετε άρνηση υποβολής αίτησης;

+

'btn btn-danger', 'data-method' => 'POST', 'data-confirm' => 'Η δήλωση άρνησης είναι μη αναστρέψιμη ενέργεια. Είστε απόλυτα βέβαιοι;']) ?>

+

'btn btn-default']) ?>

+
diff --git a/views/application/view.php b/views/application/view.php index b86b635..e06685a 100644 --- a/views/application/view.php +++ b/views/application/view.php @@ -14,7 +14,7 @@
- 'pull-right btn btn-danger']); ?> + 'pull-right btn btn-danger']);?> '1'], ['class' => 'pull-right btn btn-primary']) ?>
diff --git a/views/site/denied-application.php b/views/site/denied-application.php new file mode 100644 index 0000000..50c0909 --- /dev/null +++ b/views/site/denied-application.php @@ -0,0 +1,20 @@ +title = 'Αιτήσεις'; + +?> +
+
+

Διαχείριση αιτήσεων

+
+
+
+
+

Έχετε δηλώσει άρνηση δήλωσης τοποθέτησης

+
+
+
+
diff --git a/views/site/index.php b/views/site/index.php index 45fad78..c242807 100644 --- a/views/site/index.php +++ b/views/site/index.php @@ -15,56 +15,43 @@
-
- user->isGuest || (!Yii::$app->user->isGuest && !Yii::$app->user->identity->isAdmin())) : ?> - \Yii::$app->user->getIdentity()->vat, 'specialty' => \Yii::$app->user->getIdentity()->specialty]); - if($user->applications): ?> -
-

Επεξεργασία

-

Επεξεργαστείτε την αίτηση που έχετε υποβάλλει

- -

'btn btn-success']) ?>

- -

'btn btn-success disabled', 'disabled' => 'disabled']) ?>

-

Η υποβολή αιτήσεων δεν είναι διαθέσιμη.

- -
- -
-

Καταχώρηση

-

Υποβάλλετε την αίτησή σας εδώ.

- -

'btn btn-success']) ?>

- -

'btn btn-success disabled', 'disabled' => 'disabled']) ?>

-

Η υποβολή αιτήσεων δεν είναι διαθέσιμη.

- -
- -
-

Προβολή

-

Προβάλλετε την αίτηση σας εδώ.

-

'btn btn-primary']) ?>

-
- - user->isGuest && Yii::$app->user->identity->isAdmin()) : ?> -
-

Ενεργοποίηση αιτήσεων

- -

Η υποβολή των αιτήσεων είναι ενεργοποιημένη..

-

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

- -

Η υποβολή των αιτήσεων είναι απενεργοποιημένη.

-

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

- -
-
-

Εξαγωγή

-

Η εξαγωγή είναι διαθέσιμη μόνο στους διαχειριστές.

-

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

-
- + \Yii::$app->user->getIdentity()->vat, 'specialty' => \Yii::$app->user->getIdentity()->specialty]); + if ($user->applications): ?> +
+

Επεξεργασία

+

Επεξεργαστείτε την αίτηση που έχετε υποβάλλει

+ +

'btn btn-success']) ?>

+ +

'btn btn-success disabled', 'disabled' => 'disabled']) ?>

+

Η υποβολή αιτήσεων δεν είναι διαθέσιμη.

+ +
+ +
+

Καταχώρηση

+

Υποβάλλετε την αίτησή σας εδώ.

+ +

'btn btn-success']) ?>

+ +

'btn btn-success disabled', 'disabled' => 'disabled']) ?>

+

Η υποβολή αιτήσεων δεν είναι διαθέσιμη.

+ +
+ +
+

Προβολή

+

Προβάλλετε την αίτηση σας εδώ.

+

'btn btn-primary']) ?>

+
+ applications) === 0): ?> +
+

Άρνηση Δήλωσης

+

Δηλώστε άρνηση υποβολής αίτησης εδώ.

+

'btn btn-primary']) ?>

+
+