Skip to content

Commit

Permalink
Admin view denials - Points addition - Sorting (#45)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
jhaniot authored and spapad committed Oct 26, 2017
1 parent 928f6cd commit 737d840
Show file tree
Hide file tree
Showing 13 changed files with 256 additions and 85 deletions.
21 changes: 18 additions & 3 deletions controllers/AdminController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']],
]);
}
Expand All @@ -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 = [];
Expand Down
49 changes: 46 additions & 3 deletions controllers/ApplicationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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');
Expand Down Expand Up @@ -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', "Δεν υπάρχουν νομοί προτιμήσης.");
Expand Down Expand Up @@ -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) {
Expand All @@ -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]);

Expand All @@ -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.
Expand Down
5 changes: 5 additions & 0 deletions controllers/SiteController.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use app\models\LoginForm;
// use app\models\ContactForm;
use yii\web\GoneHttpException;
use app\models\Applicant;

class SiteController extends Controller
{
Expand Down Expand Up @@ -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)
]);
Expand Down
16 changes: 16 additions & 0 deletions migrations/m171024_104206_DenyToApply.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

use yii\db\Migration;

class m171024_104206_DenyToApply extends Migration
{
public function safeUp()
{
$this->addColumn('{{%applicant}}', 'state', $this->integer()->defaultValue(0));
}

public function safeDown()
{
$this->dropColumn('{{%applicant}}', 'state');
}
}
16 changes: 16 additions & 0 deletions migrations/m171025_092922_ApplicantsPoints.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

use yii\db\Migration;

class m171025_092922_ApplicantsPoints extends Migration
{
public function safeUp()
{
$this->addColumn('{{%applicant}}', 'points', $this->decimal(9, 3));
}

public function safeDown()
{
$this->dropColumn('{{%applicant}}', 'points');
}
}
2 changes: 2 additions & 0 deletions models/Applicant.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
59 changes: 32 additions & 27 deletions views/admin/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,44 +15,49 @@
<div class="body-content">

<div class="row">
<div class="col-lg-4">
<h2>Ενεργοποίηση αιτήσεων</h2>
<?php if ($enable_applications === true) : ?>
<p>Η υποβολή των αιτήσεων είναι <strong><span class="text-success">ενεργοποιημένη.</span></strong>.</p>
<p><?= Html::a('Απενεργοποίηση', Url::to(['enable-applications/confirm-enable']), ['class' => 'btn btn-danger', 'data-method' => 'POST']) ?></p>
<?php else: ?>
<p>Η υποβολή των αιτήσεων είναι <strong><span class="text-danger">απενεργοποιημένη.</span></strong></p>
<p><?= Html::a('Ενεργοποίηση', Url::to(['enable-applications/confirm-enable']), ['class' => 'btn btn-primary', 'data-method' => 'POST']) ?></p>
<?php endif; ?>
<div class="col-lg-3">
<h3>Προβολή Αιτήσεων</h3>
<p>Προβολή αιτήσεων που έχουν υποβληθεί.</p>
<p><?= Html::a('Προβολή', Url::to(['admin/view-applications']), ['class' => 'btn btn-primary', 'data-method' => 'post']) ?></p>
</div>
<div class="col-lg-4">
<h2>Εξαγωγή αιτήσεων</h2>
<div class="col-lg-3">
<h3>Εξαγωγή αιτήσεων</h3>
<p>Η λειτουργία αυτή εξάγει όλες τις μη διεγραμμένες αιτήσεις σε μορφή CSV.</p>
<p><?= Html::a(Html::icon('save') . ' Εξαγωγή σε CSV', Url::to(['admin/export-csv']), ['class' => 'btn btn-primary', 'data-method' => 'POST']) ?></p>
</div>
<div class="col-lg-4">
<h2>Επισκόπηση στοιχείων</h2>
<p>Εμφάνιση συνοπτικών στατιστικών.</p>
<p><?= Html::a('Προβολή', Url::to(['admin/overview']), ['class' => 'btn btn-primary']) ?></p>
<div class="col-lg-3">
<h3>Εκτύπωση αιτήσεων</h3>
<p>Η λειτουργία αυτή εκτυπώνει όλες τις υποβληθείσες αιτήσεις.</p>
<p><?= Html::a(Html::icon('print') . ' Εκτύπωση', Url::to(['admin/print-applications']), ['class' => 'btn btn-primary', 'data-method' => 'POST']) ?></p>
</div>
<div class="col-lg-3">
<h3>Δηλώσεις Άρνησης</h3>
<p>Προβολή εκπαιδευτικών που έχουν δηλώσει άρνηση πρόσληψης.</p>
<p><?= Html::a('Προβολή', Url::to(['view-denials']), ['class' => 'btn btn-primary']) ?></p>
</div>
</div>

<div class="row">
<div class="col-lg-4">
<h2>Εκκαθάριση στοιχείων</h2>
<div class="col-lg-3">
<h3>Επισκόπηση στοιχείων</h3>
<p>Εμφάνιση συνοπτικών στατιστικών.</p>
<p><?= Html::a('Προβολή', Url::to(['admin/overview']), ['class' => 'btn btn-primary']) ?></p>
</div>
<div class="col-lg-3">
<h3>Εκκαθάριση στοιχείων</h3>
<p>Η επιλογή αυτή θα διαγράψει όλα τα δεδομένα που αφορούν <strong>αιτήσεις</strong>, <strong>αιτούντες</strong>, <strong>κενά</strong> και <strong>περιφερειακές ενότητες</strong>.</p>
<p class="text-danger">Προσοχή! Η ενέργεια αυτή είναι <strong>μή αναστρέψιμη</strong>!</p>
<p><?= Html::a(Html::icon('trash') . ' Εκκαθάριση', Url::to(['admin/clear-data']), ['class' => 'btn btn-danger', 'data-method' => 'post', 'data-confirm' => 'Η ενέργεια αυτή είναι μη αναστρέψιμη! Είστε βέβαιοι;']) ?></p>
</div>
<div class="col-lg-4">
<h2>Εκτύπωση αιτήσεων</h2>
<p>Η λειτουργία αυτή εκτυπώνει όλες τις υποβληθείσες αιτήσεις.</p>
<p><?= Html::a(Html::icon('print') . ' Εκτύπωση', Url::to(['admin/print-applications']), ['class' => 'btn btn-primary', 'data-method' => 'POST']) ?></p>
</div>
<div class="col-lg-4">
<h2>Προβολή Αιτήσεων</h2>
<p>Προβολή αιτήσεων που έχουν υποβληθεί.</p>
<p><?= Html::a('Προβολή', Url::to(['admin/view-applications']), ['class' => 'btn btn-primary', 'data-method' => 'post']) ?></p>
</div>
<div class="col-lg-3">
<h3>Ενεργοποίηση αιτήσεων</h3>
<?php if ($enable_applications === true) : ?>
<p>Η υποβολή των αιτήσεων είναι <strong><span class="text-success">ενεργοποιημένη.</span></strong>.</p>
<p><?= Html::a('Απενεργοποίηση', Url::to(['enable-applications/confirm-enable']), ['class' => 'btn btn-danger', 'data-method' => 'POST']) ?></p>
<?php else: ?>
<p>Η υποβολή των αιτήσεων είναι <strong><span class="text-danger">απενεργοποιημένη.</span></strong></p>
<p><?= Html::a('Ενεργοποίηση', Url::to(['enable-applications/confirm-enable']), ['class' => 'btn btn-primary', 'data-method' => 'POST']) ?></p>
<?php endif; ?>
</div>
</div>

Expand Down
16 changes: 14 additions & 2 deletions views/admin/view-applications.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,14 @@
'dataProvider' => $users,
'columns' => [
['class' => 'yii\grid\SerialColumn'],
[
'label' => 'Επώνυμο',
'attribute' => 'lastname'
],
[
'label' => 'Όνομα',
'attribute' => 'firstname'
],
[
'label' => 'Α.Φ.Μ.',
'attribute' => 'vat'
Expand All @@ -23,6 +31,10 @@
'label' => 'Ειδικότητα',
'attribute' => 'specialty'
],
[
'label' => 'Μόρια',
'attribute' => 'points'
],
[
'attribute' => 'last_submit_str',
'format' => 'html'
Expand All @@ -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]);
}
]
]
]
Expand Down
34 changes: 34 additions & 0 deletions views/admin/view-denials.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

use yii\grid\GridView;

$this->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'
]
]
]);
16 changes: 16 additions & 0 deletions views/application/confirm-deny-application.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

use yii\helpers\Html;

/* @var $this yii\web\View */

$this->title = 'Επιβεβαίωση δήλωσης άρνησης αίτησης';
$this->params['breadcrumbs'][] = $this->title;

?>
<div class="jumbotron">
<h1>Επιβεβαίωση άρνησης αίτησης</h1>
<p>Είστε βέβαιοι ότι επιθυμείτε να δηλώσετε άρνηση υποβολής αίτησης;</p>
<p><?= Html::a('Eίμαι βέβαιος / βέβαιη', ['deny'], ['class' => 'btn btn-danger', 'data-method' => 'POST', 'data-confirm' => 'Η δήλωση άρνησης είναι μη αναστρέψιμη ενέργεια. Είστε απόλυτα βέβαιοι;']) ?></p>
<p><?= Html::a('Άκυρο', ['/site/index'], ['class' => 'btn btn-default']) ?></p>
</div>
2 changes: 1 addition & 1 deletion views/application/view.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

<div class="btn-toolbar">
<?php if ($enable_applications === true) : ?>
<?= Html::a('Διαγραφή', ['delete-my-application'], ['class' => 'pull-right btn btn-danger']); ?>
<?php //= Html::a('Διαγραφή', ['delete-my-application'], ['class' => 'pull-right btn btn-danger']);?>
<?php endif; ?>
<?= Html::a('Εκτύπωση', ['my-application', 'printMode' => '1'], ['class' => 'pull-right btn btn-primary']) ?>
</div>
Expand Down
Loading

0 comments on commit 737d840

Please sign in to comment.