Commit 0c26ebb4 authored by Νίκος Κατσαούνος's avatar Νίκος Κατσαούνος
Browse files

Merge branch 'develop' of https://git.minedu.gov.gr/itminedu/e-epal into component_updates

parents 9795ad6d 50c623c6
......@@ -82,3 +82,44 @@ epal.allocation:
_controller: '\Drupal\epal\Controller\Distribution::createDistribution'
requirements:
_access: 'TRUE'
sectorperschool:
path: '/epal/sectorperSchool/{epalId}'
options:
_auth: [ 'basic_auth' ]
defaults:
_controller: '\Drupal\epal\Controller\DirectorView::getSectorsPerSchool'
requirements:
_user_is_logged_in: 'TRUE'
specialityperschool:
path: '/epal/specialityperSchool/{epalId}/{sectorId}'
options:
_auth: [ 'basic_auth' ]
defaults:
_controller: '\Drupal\epal\Controller\DirectorView::getSpecialPerSchool'
requirements:
_user_is_logged_in: 'TRUE'
confirmstudents:
path: '/epal/confirmstudent'
options:
_auth: [ 'basic_auth' ]
defaults:
_controller: '\Drupal\epal\Controller\DirectorView::ConfirmStudents'
requirements:
_user_is_logged_in: 'TRUE'
studentperschool:
path: '/epal/studentperSchool/{epalId}/{selectId}/{classId}'
options:
_auth: [ 'basic_auth' ]
defaults:
_controller: '\Drupal\epal\Controller\DirectorView::getStudentPerSchool'
requirements:
_user_is_logged_in: 'TRUE'
savecapacity:
path: '/epal/savecapacity/{taxi}/{tomeas}/{specialit}/{schoolid}'
options:
_auth: [ 'basic_auth' ]
defaults:
_controller: '\Drupal\epal\Controller\DirectorView::SaveCapacity'
requirements:
_user_is_logged_in: 'TRUE'
......@@ -71,7 +71,7 @@ class CreateDemoData extends ControllerBase {
$epaluserid = \Drupal::currentUser()->id();
for ($i = 1; $i <= 1100; $i++) {
for ($i = 1; $i <= 10000; $i++) {
//srand($this->make_seed());
//$curclass = rand(1,3);
......
<?php
namespace Drupal\epal\Controller;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\JsonResponse;
use Drupal\Core\Controller\ControllerBase;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Drupal\Core\Database\Connection;
use Drupal\Core\Logger\LoggerChannelFactoryInterface;
class DirectorView extends ControllerBase
{
protected $entityTypeManager;
public function __construct(EntityTypeManagerInterface $entityTypeManager)
{
$this->entityTypeManager = $entityTypeManager;
}
public static function create(ContainerInterface $container)
{
return new static(
$container->get('entity_type.manager')
);
}
public function getSectorsPerSchool(Request $request, $epalId)
{
$authToken = $request->headers->get('PHP_AUTH_USER');
$epalUsers = $this->entityTypeManager->getStorage('epal_users')->loadByProperties(array('authtoken' => $authToken));
$epalUser = reset($epalUsers);
if ($epalUser) {
$userid = $epalUser -> user_id -> entity -> id();
$epalIdNew = intval($epalId);
$sectorPerSchool = $this->entityTypeManager->getStorage('eepal_sectors_in_epal')->loadByProperties(array('epal_id'=> $epalIdNew));
$i = 0;
if ($sectorPerSchool) {
$list = array();
foreach ($sectorPerSchool as $object) {
$list[] = array(
'sector_id' => $object -> sector_id ->entity->get('name')->value ,
'id' => $object -> sector_id -> entity -> id()
);
$i++;
}
return $this->respondWithStatus(
$list
, Response::HTTP_OK);
}
else {
return $this->respondWithStatus([
'message' => t("School not found!!!"),
], Response::HTTP_FORBIDDEN);
}
} else {
return $this->respondWithStatus([
'message' => t("User not found!"),
], Response::HTTP_FORBIDDEN);
}
}
public function getSpecialPerSchool(Request $request, $epalId , $sectorId)
{
$authToken = $request->headers->get('PHP_AUTH_USER');
$epalUsers = $this->entityTypeManager->getStorage('epal_users')->loadByProperties(array('authtoken' => $authToken));
$epalUser = reset($epalUsers);
if ($epalUser) {
$userid = $epalUser -> user_id -> entity -> id();
$epalIdNew = intval($epalId);
$specialityPerSchool = $this->entityTypeManager->getStorage('eepal_specialties_in_epal')->loadByProperties(array('epal_id'=> $epalIdNew));
$i = 0;
if ($specialityPerSchool) {
$list = array();
$SectorIdNew = intval($sectorId);
foreach ($specialityPerSchool as $object) {
$idSpecial = $object -> specialty_id -> entity -> id() ;
$specialityPerSector = $this->entityTypeManager->getStorage('eepal_specialty')->loadByProperties(array('id'=> $idSpecial,'sector_id' => $SectorIdNew ));
$specialPerSec = reset($specialityPerSector);
if ($specialPerSec)
{ $list[] = array(
'specialty_id' => $object -> specialty_id ->entity->get('name')->value ,
'id' => $object -> specialty_id -> entity -> id() );
$i++;
}
}
return $this->respondWithStatus(
$list
, Response::HTTP_OK);
}
else {
return $this->respondWithStatus([
'message' => t("School not found!!!"),
], Response::HTTP_FORBIDDEN);
}
} else {
return $this->respondWithStatus([
'message' => t("User not found!"),
], Response::HTTP_FORBIDDEN);
}
}
public function getStudentPerSchool(Request $request, $epalId , $selectId, $classId)
{
$authToken = $request->headers->get('PHP_AUTH_USER');
$epalUsers = $this->entityTypeManager->getStorage('epal_users')->loadByProperties(array('authtoken' => $authToken));
$epalUser = reset($epalUsers);
if ($epalUser) {
$userid = $epalUser -> user_id -> entity -> id();
$epalIdNew = intval($epalId);
$selectIdNew = intval($selectId);
if ($classId == 1)
{
$selectIdNew = -1;
$studentPerSchool = $this->entityTypeManager->getStorage('epal_student_class')->loadByProperties(array('epal_id'=> $epalIdNew, 'specialization_id' => $selectIdNew, 'currentclass' => $classId ));
}
else
{
$studentPerSchool = $this->entityTypeManager->getStorage('epal_student_class')->loadByProperties(array('epal_id'=> $epalIdNew, 'specialization_id' => $selectIdNew, 'currentclass' => $classId ));
}
$i = 0;
if ($studentPerSchool) {
$list = array();
foreach ($studentPerSchool as $object)
{
$studentId = $object -> id() ;
$epalStudents = $this->entityTypeManager->getStorage('epal_student')->loadByProperties(array('id'=> $studentId));
$epalStudent = reset($epalStudents);
$i = 0;
if ($epalStudents) {
$list[] = array(
'id' => $epalStudent -> id(),
'name' => $epalStudent -> name ->value,
'studentsurname' => $epalStudent -> studentsurname ->value,
'fatherfirstname' => $epalStudent -> fatherfirstname ->value,
'fathersurname' =>$epalStudent -> fathersurname ->value,
'motherfirstname' => $epalStudent -> motherfirstname ->value,
'mothersurname' =>$epalStudent -> mothersurname ->value,
'birthdate' =>$epalStudent -> birthdate ->value,
);
$i++;
}
}
return $this->respondWithStatus(
$list
, Response::HTTP_OK);
}
else {
return $this->respondWithStatus([
'message' => t("No students found!!!"),
], Response::HTTP_FORBIDDEN);
}
}
else {
return $this->respondWithStatus([
'message' => t("User not found!"),
], Response::HTTP_FORBIDDEN);
}
}
public function ConfirmStudents(Request $request)
{
if (!$request->isMethod('POST')) {
return $this->respondWithStatus([
"message" => t("Method Not Allowed")
], Response::HTTP_METHOD_NOT_ALLOWED);
}
$authToken = $request->headers->get('PHP_AUTH_USER');
$epalUsers = $this->entityTypeManager->getStorage('epal_users')->loadByProperties(array('authtoken' => $authToken));
$epalUser = reset($epalUsers);
if ($epalUser) {
$postData = null;
if ($content = $request->getContent())
{
$postData = json_decode($content);
$arr = $postData->students;
foreach ($arr as $value) {
$valnew = intval($value);
$studentForConfirm = $this->entityTypeManager->getStorage('epal_student_class')->loadByProperties(array('id' => $valnew ));
$studentConfirm = reset($studentForConfirm);
if ($studentConfirm) {
$studentConfirm->set('directorconfirm', true);
$studentConfirm->save();
}
}
return $this->respondWithStatus([
'message' => t("saved"),
], Response::HTTP_OK);
}
else
{
return $this->respondWithStatus([
'message' => t("post with no data"),
], Response::HTTP_BAD_REQUEST);
}
} else {
return $this->respondWithStatus([
'message' => t("EPAL user not found"),
], Response::HTTP_FORBIDDEN);
}
}
public function SaveCapacity(Request $request,$taxi,$tomeas,$specialit,$schoolid)
{
if (!$request->isMethod('POST')) {
return $this->respondWithStatus([
"message" => t("Method Not Allowed")
], Response::HTTP_METHOD_NOT_ALLOWED);
}
$authToken = $request->headers->get('PHP_AUTH_USER');
$epalUsers = $this->entityTypeManager->getStorage('epal_users')->loadByProperties(array('authtoken' => $authToken));
$epalUser = reset($epalUsers);
if ($epalUser) {
$postData = null;
if ($content = $request->getContent())
{
$postData = json_decode($content);
$cap = $postData->capacity;
if (($tomeas == 0) || ($specialit == 0))
{
$CapacityPerClass = $this->entityTypeManager->getStorage('eepal_school')->loadByProperties(array('id' => $schoolid ));
$classcapacity = reset($CapacityPerClass);
if ($classcapacity) {
$classcapacity->set('capacity_class_a', $cap);
$classcapacity->save();
}
}
if (($tomeas != 0) || ($specialit == 0))
{
$CapacityPerClass = $this->entityTypeManager->getStorage('eepal_sectors_in_epal')->loadByProperties(array('epal_id' => $schoolid, 'sector_id' => $tomeas ));
$classcapacity = reset($CapacityPerClass);
if ($classcapacity) {
$classcapacity->set('capacity_class_sector', $cap);
$classcapacity->save();
}
}
if (($tomeas != 0) || ($specialit != 0))
{
$CapacityPerClass = $this->entityTypeManager->getStorage('eepal_specialties_in_epal')->loadByProperties(array('epal_id' => $schoolid, 'specialty_id' => $specialit));
$classcapacity = reset($CapacityPerClass);
if ($classcapacity) {
$classcapacity->set('capacity_class_specialty', $cap);
$classcapacity->save();
}
}
return $this->respondWithStatus([
'message' => t("saved"),
], Response::HTTP_OK);
}
else
{
return $this->respondWithStatus([
'message' => t("post with no data"),
], Response::HTTP_BAD_REQUEST);
}
} else {
return $this->respondWithStatus([
'message' => t("EPAL user not found"),
], Response::HTTP_FORBIDDEN);
}
}
private function respondWithStatus($arr, $s) {
$res = new JsonResponse($arr);
$res->setStatusCode($s);
return $res;
}
}
......@@ -122,6 +122,7 @@ class EpalStudentClass extends ContentEntityBase implements EpalStudentClassInte
return $this;
}
/**
* {@inheritdoc}
*/
......
......@@ -356,7 +356,7 @@ class EepalSchool extends ContentEntityBase implements EepalSchoolInterface {
->setDisplayConfigurable('form', TRUE)
->setDisplayConfigurable('view', TRUE);
$fields['e-mail'] = BaseFieldDefinition::create('string')
$fields['maile'] = BaseFieldDefinition::create('string')
->setLabel(t('e-mail Σχολείου'))
->setDescription(t('Δώσε το e-mail Σχολείου'))
->setSettings(array(
......
import { Component, OnInit, OnDestroy,ElementRef, ViewChild} from "@angular/core";
import { Injectable } from "@angular/core";
import { AppSettings } from '../../app.settings';
import { HelperDataService } from '../../services/helper-data-service';
import {Observable} from "rxjs/Observable";
import {Http, Headers, RequestOptions} from '@angular/http';
import { NgRedux, select } from 'ng2-redux';
import { IAppState } from '../../store/store';
import {Router, ActivatedRoute, Params} from '@angular/router';
import { BehaviorSubject, Subscription } from 'rxjs/Rx';
import { ILoginInfo } from '../../store/logininfo/logininfo.types';
import {
FormBuilder,
FormGroup,
FormControl,
FormArray,
Validators,
} from '@angular/forms';
@Component({
selector: 'director-classcapacity',
template: `
<form [formGroup]="formGroup">
<label for="taxi">Τάξη</label><br/>
<div class="form-group">
<select #txoption class="form-control" (change)="verifyclass(txoption)" formControlName="taxi">
<option value="1" >Α' Λυκείου</option>
<option value="2" >Β' Λυκείου</option>
<option value="3" >Γ' Λυκείου</option>
</select>
</div>
<div class="form-group">
<select #tmop class="form-control" *ngIf="(selectionBClass | async)" (change)="checkbclass(tmop,txoption)" formControlName="tomeas">
<option *ngFor="let SectorSelection$ of StudentSelected$ | async; let i=index" [value] = "SectorSelection$.id"> {{SectorSelection$.sector_id}} </option>
</select>
</div>
<div class="form-group">
<select #spop class="form-control" *ngIf="(selectionCClass | async)" formControlName="specialit">
<option *ngFor="let SpecialSelection$ of StudentSelectedSpecial$ | async; let i=index" [value] = "SpecialSelection$.id"> {{SpecialSelection$.specialty_id}} </option>
</select>
</div>
<strong>Δυναμική σε τμήματα:</strong>
<input type="number" formControlName="capacity" min="1" max="10">
<button type="button" class="btn-primary btn-sm pull-right" (click) ="saveCapacity()">
Αποθήκευση
</button>
`
})
@Injectable() export default class DirectorClassCapacity implements OnInit , OnDestroy{
public formGroup: FormGroup;
private StudentSelected$: BehaviorSubject<any>;
private StudentSelectedSub: Subscription;
private StudentSelectedSpecial$: BehaviorSubject<any>;
private StudentSelectedSpecialSub: Subscription;
private selectionBClass: BehaviorSubject<boolean>;
private selectionCClass: BehaviorSubject<boolean>;
private SchoolId = 147 ;
private currentclass: Number;
constructor( private fb: FormBuilder,
private _hds: HelperDataService,
private activatedRoute: ActivatedRoute,
private router: Router )
{
this.StudentSelected$ = new BehaviorSubject([{}]);
this.StudentSelectedSpecial$ = new BehaviorSubject([{}]);
this.selectionBClass = new BehaviorSubject(false);
this.selectionCClass = new BehaviorSubject(false);
this.formGroup = this.fb.group({
tomeas: ['', []],
taxi: ['', []],
specialit: ['', []],
capacity: ['', []],
});
}
ngOnDestroy()
{
if (this.StudentSelectedSub)
this.StudentSelectedSub.unsubscribe();
if (this.StudentSelectedSpecialSub)
this.StudentSelectedSpecialSub.unsubscribe();
if (this.selectionBClass)
this.selectionBClass.unsubscribe();
if (this.selectionCClass)
this.selectionCClass.unsubscribe();
}
ngOnInit() {
}
verifyclass(txop)
{
if (txop.value === "1")
{
this.selectionBClass.next(false);
this.selectionCClass.next(false);
this.formGroup.patchValue({
tomeas: '',
specialit: '',
});
}
else if (txop.value === "2")
{
this.formGroup.patchValue({
specialit: '',
});
this.selectionBClass.next(true);
this.selectionCClass.next(false);
this.StudentSelected$ = new BehaviorSubject([{}]);
this.StudentSelectedSub = this._hds.getSectorPerSchool(this.SchoolId).subscribe(this.StudentSelected$);
}
else if (txop.value === "3")
{
var sectorint = +this.formGroup.value.tomeas;
console.log(sectorint,"test");
if (this.formGroup.value.tomeas != '')
{
var sectorint = +this.formGroup.value.tomeas;
this.StudentSelectedSpecial$ = new BehaviorSubject([{}]);
this.StudentSelectedSpecialSub = this._hds.getSpecialityPerSchool(this.SchoolId, sectorint).subscribe(this.StudentSelectedSpecial$);
}
this.selectionBClass.next(true);
this.selectionCClass.next(true);
this.StudentSelected$ = new BehaviorSubject([{}]);
this.StudentSelectedSub = this._hds.getSectorPerSchool(this.SchoolId).subscribe(this.StudentSelected$);
}
}
checkbclass(tmop,txop)
{
var sectorint = +this.formGroup.value.tomeas;
console.log(sectorint,"tomeas");
if (txop.value === "3")
{
this.StudentSelectedSpecial$ = new BehaviorSubject([{}]);
this.StudentSelectedSpecialSub = this._hds.getSpecialityPerSchool(this.SchoolId, sectorint).subscribe(this.StudentSelectedSpecial$);
}
}
saveCapacity()