Commit fa6e5a72 authored by Νίκος Κατσαούνος's avatar Νίκος Κατσαούνος

applicationSubmitted Controller updated

parents 86c98190 f248fded
......@@ -30,23 +30,11 @@ class Client
$this->_settings = array_merge($this->_settings, $settings);
$this->_settings['ws_endpoint_token'] = "{$this->_settings['ws_endpoint']}/oauth2/token";
$this->_settings['ws_endpoint_token_granttype'] = 'password';
$this->_settings['ws_endpoint_studentepalinfo'] = "{$this->_settings['ws_endpoint']}/api/epal/GetStudentEpalInfo";
$this->_settings['ws_endpoint_studentepalcertification'] = "{$this->_settings['ws_endpoint']}/api/epal/GetStudentEpalCertification";
$this->_settings['ws_endpoint_studentepalpromotion'] = "{$this->_settings['ws_endpoint']}/api/epal/GetStudentEpalPromotion";
$this->_settings['ws_endpoint_alldidactiyear'] = "{$this->_settings['ws_endpoint']}/api/general/GetAllDidactiYear";
}
/**
* Επιστρέφει πίνακα με κλειδιά τα property names των πεδίων που επιστρέφει η GetStudentEpalInfo
* και τιμές λεκτικά - ετικέτες τους.
*
* @return array
*/
public function getStudentInfoFields()
{
return $this->studentInfoFields;
}
/**
* Λαμβάνει το authentication token
*
......
<?php
namespace Drupal\epal;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Drupal\Core\Logger\LoggerChannelFactoryInterface;
use Drupal\epal\Client;
class ClientConsumer
{
protected $entityTypeManager;
protected $logger;
protected $client;
protected $settings;
protected $cached_didactic_years = [
"1" => "2008 - 2009",
"2" => "2011 - 2012",
"3" => "1999 - 2000",
"4" => "2000 - 2001",
"5" => "2009 - 2010",
"6" => "2010 - 2011",
"7" => "2001 - 2002",
"8" => "2002 - 2003",
"9" => "2003 - 2004",
"10" => "2004 - 2005",
"11" => "2005 - 2006",
"12" => "2006 - 2007",
"13" => "2007 - 2008",
"17" => "2012 - 2013",
"18" => "2013 - 2014",
"22" => "2014 - 2015",
"23" => "2015 - 2016",
"24" => "2016 - 2017"
];
protected $cached_level_names = [
"1" => "Α",
"2" => "Β",
"3" => "Γ",
"4" => "Δ"
];
public function __construct($settings, EntityTypeManagerInterface $entityTypeManager, LoggerChannelFactoryInterface $loggerChannel)
{
$this->settings = $settings;
$this->entityTypeManager = $entityTypeManager;
$this->logger = $loggerChannel->get('epal-school');
$this->client = new Client($this->settings, $this->logger);
}
public function getAllDidactiYear()
{
$ts_start = microtime(true);
// try {
// $catalog = $this->client->getAllDidactiYear();
// } catch (\Exception $e) {
// $catalog = [];
// }
$catalog = $this->cached_didactic_years;
$duration = microtime(true) - $ts_start;
$this->logger->info(__METHOD__ . " :: timed [{$duration}]");
return $catalog;
}
public function getStudentEpalPromotion($didactic_year_id, $lastname, $firstname, $father_firstname, $mother_firstname, $birthdate, $registry_no, $level_name)
{
$ts_start = microtime(true);
try {
$result = $this->client->getStudentEpalPromotion($didactic_year_id, $lastname, $firstname, $father_firstname, $mother_firstname, $birthdate, $registry_no, $level_name);
} catch (\Exception $e) {
$result = -1;
}
$duration = microtime(true) - $ts_start;
$this->logger->info(__METHOD__ . " :: timed [{$duration}]");
return $result;
}
public function getStudentEpalCertification($didactic_year_id, $lastname, $firstname, $father_firstname, $mother_firstname, $birthdate, $registry_no, $level_name)
{
$ts_start = microtime(true);
try {
$result = $this->client->getStudentEpalCertification($didactic_year_id, $lastname, $firstname, $father_firstname, $mother_firstname, $birthdate, $registry_no, $level_name);
} catch (\Exception $e) {
$result = -1;
}
$duration = microtime(true) - $ts_start;
$this->logger->info(__METHOD__ . " :: timed [{$duration}]");
return $result;
}
/**
* If $ending is provided
* it is assumed as the second part of the academic-year (i.e. 2017 for 2016-2017),
* the function returns the corresponding id to match first;
* If $id is provided, return the corresponding label.
* $id has priority over $ending, if both are supplied.
*
* @return null|string null if no input or no info located
*/
public function getDidacticYear($ending = null, $id = null)
{
$value = null;
if ($id !== null) {
if (array_key_exists($id, $this->cached_didactic_years)) {
$value = $this->cached_didactic_years[$id];
}
} elseif ($ending !== null) {
$remain = array_filter($this->cached_didactic_years, function ($v) use ($ending) {
$pos = strpos($v, "$ending");
return ($pos !== false && $pos > 4);
});
if (count($remain) > 0) {
$values = array_keys($remain);
$value = $values[0];
}
}
return $value;
}
/**
* Get the level name of the denoted class level
*
* @return string|mixed The level name of the provided failsafe value if not found
*/
public function getLevelName($id, $failsafe_value = 'X')
{
$value = $failsafe_value;
if (array_key_exists($id, $this->cached_level_names)) {
$value = $this->cached_level_names["$id"];
}
return $value;
}
private function generateRandomString($length)
{
$characters = ['Α','Β','Γ','Δ','Ε','Ζ','Η','Θ','Ι','Κ','Λ','Μ','Ν','Ξ','Ο','Π','Ρ','Σ','Τ','Υ','Φ','Χ','Ψ','Ω'];
$charactersLength = count($characters);
$randomString = '';
for ($i = 0; $i < $length; $i++) {
$randomString .= $characters[rand(0, $charactersLength - 1)];
}
return $randomString;
}
}
......@@ -187,13 +187,15 @@ class DirectorView extends ControllerBase
return $this->respondWithStatus([
'error_code' => 4003,
], Response::HTTP_FORBIDDEN);
} elseif ($userRole === 'epal') {
$selectIdNew = $epalId;
$selectIdNew = $selectId;
if ($classId == 1) {
$selectIdNew = -1;
$studentPerSchool = $this->entityTypeManager->getStorage('epal_student_class')->loadByProperties(array('epal_id' => $epalId, 'specialization_id' => $selectIdNew, 'currentclass' => $classId));
} else {
$studentPerSchool = $this->entityTypeManager->getStorage('epal_student_class')->loadByProperties(array('epal_id' => $epalId, 'specialization_id' => $selectIdNew, 'currentclass' => $classId));
}
$i = 0;
......
CREATE UNIQUE INDEX uidx_region_regno ON eepal_region_field_data(registry_no);
CREATE UNIQUE INDEX uidx_adminarea_regno ON eepal_admin_area_field_data(registry_no);
\ No newline at end of file
CREATE UNIQUE INDEX uidx_adminarea_regno ON eepal_admin_area_field_data(registry_no);
CREATE UNIQUE INDEX uidx_taxis_userid ON epal_users(taxis_userid);
CREATE INDEX uidx_authtoken ON epal_users(authtoken(150));
......@@ -9,6 +9,7 @@ use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Drupal\Core\Controller\ControllerBase;
use OAuth;
use DOMDocument;
use OAuthException;
use Drupal\user\Entity\User;
use Drupal\Core\Database\Connection;
......@@ -128,21 +129,25 @@ class CBController extends ControllerBase
public function authenticatePhase2($request, $authToken, $authVerifier)
{
$taxis_userid = null;
$trx = $this->connection->startTransaction();
try {
$taxis_userid = null;
$trx = $this->connection->startTransaction();
$oauth = new OAuth($this->consumer_key, $this->consumer_secret, OAUTH_SIG_METHOD_PLAINTEXT, OAUTH_AUTH_TYPE_URI);
$oauth->enableDebug();
// $oauth->enableDebug();
$oauth->setToken($authToken, $this->requestTokenSecret);
$accessToken = $oauth->getAccessToken($this->access_token_url, '', $authVerifier);
$oauth->setToken($accessToken['oauth_token'], $accessToken['oauth_token_secret']);
$oauth->fetch($this->api_url);
$this->logger->warning($oauth->getLastResponse());
$taxis_userid = $this->xmlParse($oauth->getLastResponse(), 'messageText');
$dom = $this->loadXML($oauth->getLastResponse());
$taxis_userData = $this->getXMLElements($dom);
if (!$taxis_userData || sizeof($taxis_userData) === 0) {
return false;
}
$currentTime = time();
$epalUsers = $this->entityTypeManager->getStorage('epal_users')->loadByProperties(array('taxis_userid' => $taxis_userid));
$epalUsers = $this->entityTypeManager->getStorage('epal_users')->loadByProperties(array('taxis_userid' => $taxis_userData['tin']));
$epalUser = reset($epalUsers);
$epalToken = md5(uniqid(mt_rand(), true));
......@@ -163,7 +168,6 @@ class CBController extends ControllerBase
$epalUser->save();
}
}
if ($epalUser === null || !$epalUser) {
//Create a User
......@@ -190,17 +194,15 @@ class CBController extends ControllerBase
$users = $this->entityTypeManager->getStorage('user')->loadByProperties(array('mail' => $unique_id));
$user = reset($users);
if ($user) {
$this->logger->warning('userid 190='.$user->id().'*** name='.$user->name->value);
$epalUser = $this->entityTypeManager()->getStorage('epal_users')->create(array(
'langcode' => 'el',
'user_id' => $user->id(),
'drupaluser_id' => $user->id(),
'taxis_userid' => $taxis_userid,
'taxis_taxid' => $unique_id,
'name' => $unique_id,
'surname' => $unique_id,
'fathername' => $unique_id,
'taxis_userid' => $taxis_userData['tin'],
'taxis_taxid' => $taxis_userData['tin'],
'name' => $taxis_userData['firstName'],
'surname' => $taxis_userData['surname'],
'fathername' => $taxis_userData['fathersName'],
'mothername' => $unique_id,
'accesstoken' => $accessToken['oauth_token'],
'accesstoken_secret' => $accessToken['oauth_token_secret'],
......@@ -221,7 +223,6 @@ class CBController extends ControllerBase
}
$this->oauthostSession->set('authtoken', $epalToken);
$this->oauthostSession->save();
// $this->oauthostSession->delete();
return $epalToken;
} catch (OAuthException $e) {
......@@ -237,7 +238,66 @@ class CBController extends ControllerBase
return false;
}
public function xmlParse($xmlText, $token){
return '12345';
public function loadXML($text_response){
$dom = new DOMDocument();
// Fix possible whitespace problems
$dom->preserveWhiteSpace = false;
if (!($dom->loadXML($text_response))) {
$this->logger->warning('dom->loadXML() failed');
return false;
}
if (!($tree_response = $dom->documentElement)) {
$this->logger->warning('documentElement() failed');
return false;
}
return $dom;
}
public function getXMLElements($doc){
$webUserDetails = $doc->getElementsByTagName( "WebUserDetails" );
if (!$webUserDetails || $webUserDetails->length === 0)
return array( // to be changed to empty array
'firstName' => '',
'surname' => '',
'fathersName' => '',
'comments' => '',
'tin' => '12345'
);
// return false;
foreach( $webUserDetails as $element )
{
$comments = $element->getElementsByTagName( "comments" );
$comment = $comments->item(0)->nodeValue;
$fathersNames = $element->getElementsByTagName( "fathersName" );
$fathersName = $fathersNames->item(0)->nodeValue;
$firstNames = $element->getElementsByTagName( "name" );
$firstName = $firstNames->item(0)->nodeValue;
$surnames = $element->getElementsByTagName( "surname" );
$surname = $surnames->item(0)->nodeValue;
$tins = $element->getElementsByTagName( "tin" );
$tin = $tins->item(0)->nodeValue;
if (!$tin || $tin === '')
return array( // to be changed to empty array
'firstName' => '',
'surname' => '',
'fathersName' => '',
'comments' => '',
'tin' => '12345'
);
return array(
'firstName' => $firstName,
'surname' => $surname,
'fathersName' => $fathersName,
'comments' => $comment,
'tin' => $tin
);
}
}
}
This diff is collapsed.
......@@ -28,25 +28,34 @@ import {
<div style="min-height: 500px;">
<form [formGroup]="formGroup">
<p style="margin-top: 20px; line-height: 2em;"> Στην παρακάτω'λίστα βλέπετε τα τμήματα του σχολείου σας με την αντίστοιχη δυναμίκη τους σε αίθουσες. Παρακαλώ για να τροποποποιήσετε τη δυναμικήαυτή κάντε κλικ στον αντίστοιχο αριθμό,
<p style="margin-top: 20px; line-height: 2em;"> Στην παρακάτω λίστα βλέπετε τα τμήματα του σχολείου σας με την αντίστοιχη δυναμίκη τους σε αίθουσες. Παρακαλώ για να τροποποποιήσετε τη δυναμικήαυτή κάντε κλικ στον αντίστοιχο σύμβολο,
επιλέξτε τη νέα δυναμική και πατήστε το σύμβολο <i>ok</i>. Προσοχή! Κανένα τμήμα δεν πρέπει να έχει δυναμική 0.</p>
<div class="row" style="margin-top: 20px; line-height: 2em;" > <b> Οι δηλώσεις σας </b></div>
<div *ngFor="let CapacityPerCourses$ of CapacityPerCourse$ | async; let i=index; let isOdd=odd; let isEven=even" >
<li *ngIf="(!(selectiontype | async) && (CapacityPerCourses$.class < 4)) ||((selectiontype | async) && (CapacityPerCourses$.class < 5))" class="list-group-item " [class.oddout]="isOdd" [class.evenout]="isEven" >
<div class="row">
<div class="col-md-5">
<h5 [class.changelistcolor]= "CapacityPerCourses$.capacity === 0" >{{CapacityPerCourses$.taxi}}&nbsp; <b></b></h5>
<h5 [class.changelistcolor]= "CapacityPerCourses$.capacity === null" >{{CapacityPerCourses$.taxi}}&nbsp; <b></b></h5>
</div>
<div class="col-md-4" col-md-offset-2>
<label *ngIf="!isEdit" (click)="isEdit=true" (click)="setActive(i)"> {{CapacityPerCourses$.capacity}} </label>
<div class="col-md-4" col-md-offset-1>
<label style="font-weight:bold!important" *ngIf="!isEdit || CapacityPerCourses$.globalindex !== courseActive" > {{CapacityPerCourses$.capacity}} </label>
<i *ngIf="!isEdit || CapacityPerCourses$.globalindex !== courseActive" (click)= "modifycapc(i,$event)" class="fa fa-pencil isclickable pull-right" style="font-size: 1.5em;"></i>
<input *ngIf="isEdit && CapacityPerCourses$.globalindex === courseActive"
id="{{CapacityPerCourses$.globalindex}}" type="number"
name="{{CapacityPerCourses$.globalindex}}" value ={{CapacityPerCourses$.capacity}}
(change)="handleChange($event)">
id="{{CapacityPerCourses$.globalindex}}" type="number"
name="{{CapacityPerCourses$.globalindex}}" value ={{CapacityPerCourses$.capacity}} (change)="handleChange($event)">
</div>
<div class="col-md-1">
<div class="col-md-1">
<i *ngIf="isEdit && CapacityPerCourses$.globalindex === courseActive" (click)= "isEdit = false" class="fa fa-ban isclickable" style="font-size: 1.5em;"></i>
</div>
<div class="col-md-2">
<button *ngIf="isEdit && CapacityPerCourses$.globalindex === courseActive" type="button" class="btn-primary pull-right"
(click)="isEdit=false" (click) ="saveCapacity(CapacityPerCourses$.newspecialit, CapacityPerCourses$.newsector, CapacityPerCourses$.class, CapacityPerCourses$.capacity)">
(click)="isEdit=false" (click) ="saveCapacity(CapacityPerCourses$.newspecialit, CapacityPerCourses$.newsector, CapacityPerCourses$.class, CapacityPerCourses$.capacity, CapacityPerCourses$.globalindex )">
<i class="fa fa-check" aria-hidden="true"></i>
</button>
</div>
......@@ -177,7 +186,8 @@ import {
this.newvalue = e.target['value'];
}
saveCapacity(spec,sect,taxi,oldvalue){
saveCapacity(spec,sect,taxi,oldvalue,ind){
console.log(taxi, sect, spec);
console.log(this.newvalue,"newvalue", oldvalue);
......@@ -190,19 +200,18 @@ import {
else
{
this.showLoader.next(true);
this.saveCapacitySub = this._hds.saveCapacity(taxi, sect, spec, this.newvalue).subscribe(data => {
this.showLoader.next(false);
this.CapacityPerCourseSub = this._hds.FindCapacityPerSchool().subscribe(x => {
this.CapacityPerCourse$.next(x);
},
error => {
this.CapacityPerCourse$.next([{}]);
console.log("Error Getting Capacity perSchool");
},
() => console.log("Getting School "));
let std = this.CapacityPerCourse$.getValue();
std[ind].capacity = this.newvalue;
this.saveCapacitySub = this._hds.saveCapacity(taxi, sect, spec, this.newvalue).subscribe(data => {
this.showLoader.next(false);
this.CapacityPerCourse$.next(std);
},
error => {
std[ind].capacity = oldvalue;
this.CapacityPerCourse$.next(std);
console.log("Error Saving Capacity");
},
......@@ -214,6 +223,11 @@ import {
}
}
else
{
if (oldvalue === null)
this.showModal("#checksaved");
}
}
......@@ -224,5 +238,11 @@ import {
}
modifycapc(ind, e:Event)
{
this.isEdit=true;
this.setActive(ind);
this.handleChange(e);
}
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment