Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
Σταύρος Παπαδάκης
e-epal
Commits
394f6e34
Commit
394f6e34
authored
Mar 21, 2017
by
Χάρης Παπαδόπουλος
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
code review-fixes, WIP:parent form
parent
73207377
Changes
26
Hide whitespace changes
Inline
Side-by-side
Showing
26 changed files
with
277 additions
and
811 deletions
+277
-811
drupal/modules/epal/epal.routing.yml
drupal/modules/epal/epal.routing.yml
+4
-20
drupal/modules/epal/epal.services.yml
drupal/modules/epal/epal.services.yml
+4
-0
drupal/modules/epal/src/Controller/ApplicationSubmit.php
drupal/modules/epal/src/Controller/ApplicationSubmit.php
+88
-162
drupal/modules/epal/src/Controller/CurrentUser.php
drupal/modules/epal/src/Controller/CurrentUser.php
+65
-40
drupal/modules/epal/src/Controller/Login.php
drupal/modules/epal/src/Controller/Login.php
+0
-190
drupal/modules/oauthost/oauthost.services.yml
drupal/modules/oauthost/oauthost.services.yml
+1
-1
drupal/modules/oauthost/src/Controller/CBController.php
drupal/modules/oauthost/src/Controller/CBController.php
+2
-2
source/actions/amkafill.actions.ts
source/actions/amkafill.actions.ts
+0
-21
source/actions/index.ts
source/actions/index.ts
+2
-5
source/app.ts
source/app.ts
+0
-14
source/components/form-controls/form3.ts
source/components/form-controls/form3.ts
+0
-78
source/components/home.ts
source/components/home.ts
+14
-45
source/components/navbar/navbar.component.ts
source/components/navbar/navbar.component.ts
+1
-6
source/components/navbar/navbar.component.ts.save
source/components/navbar/navbar.component.ts.save
+0
-22
source/components/student-application-form/amka-fill.ts
source/components/student-application-form/amka-fill.ts
+0
-93
source/components/student-application-form/parent.form.ts
source/components/student-application-form/parent.form.ts
+74
-0
source/constants.ts
source/constants.ts
+1
-1
source/containers/main.routes.ts
source/containers/main.routes.ts
+3
-6
source/services/amkacheck-service.ts
source/services/amkacheck-service.ts
+0
-30
source/services/helper-data-service.ts
source/services/helper-data-service.ts
+16
-3
source/store/amkafill/amkafills.initial-state.ts
source/store/amkafill/amkafills.initial-state.ts
+0
-7
source/store/amkafill/amkafills.reducer.ts
source/store/amkafill/amkafills.reducer.ts
+0
-22
source/store/amkafill/amkafills.transformers.ts
source/store/amkafill/amkafills.transformers.ts
+0
-12
source/store/amkafill/amkafills.types.ts
source/store/amkafill/amkafills.types.ts
+0
-11
source/store/amkafill/index.ts
source/store/amkafill/index.ts
+0
-10
source/store/store.ts
source/store/store.ts
+2
-10
No files found.
drupal/modules/epal/epal.routing.yml
View file @
394f6e34
epal_is_logged_in
:
path
:
'
/epal/login/check'
defaults
:
_controller
:
'
\Drupal\epal\Controller\Login::helloWorld'
requirements
:
_access
:
'
TRUE'
epal_entityapi_test
:
path
:
'
/epal/entityapi/test'
user_data
:
path
:
'
/epal/userdata'
options
:
_auth
:
[
'
basic_auth'
]
requirements
:
_user_is_logged_in
:
'
TRUE'
defaults
:
_controller
:
'
\Drupal\epal\Controller\Login::testQuery'
epal_auth_test
:
path
:
'
epal/auth/test'
options
:
_auth
:
[
'
oauthost'
]
defaults
:
_controller
:
'
\Drupal\epal\Controller\Login::helloWorld'
_title
:
'
Greeting'
_controller
:
'
\Drupal\epal\Controller\CurrentUser::getEpalUserData'
requirements
:
_permission
:
'
access
content'
_user_is_logged_in
:
'
TRUE'
current_user
:
path
:
'
/epal/curuser'
options
:
_auth
:
[
'
basic_auth'
]
defaults
:
_controller
:
'
\Drupal\epal\Controller\CurrentUser::
content
'
_controller
:
'
\Drupal\epal\Controller\CurrentUser::
getLoginInfo
'
requirements
:
_user_is_logged_in
:
'
TRUE'
epal.application_submit
:
...
...
drupal/modules/epal/epal.services.yml
0 → 100644
View file @
394f6e34
services
:
logger.channel.oauth
:
parent
:
'
logger.channel_base'
arguments
:
[
'
oauthost'
]
drupal/modules/epal/src/Controller/ApplicationSubmit.php
View file @
394f6e34
<?php
/**
* @file
* Contains \Drupal\query_example\Controller\QueryExampleController.
*/
namespace
Drupal\epal\Controller
;
...
...
@@ -12,238 +8,168 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
use
Symfony\Component\HttpFoundation\JsonResponse
;
use
Drupal\Core\Controller\ControllerBase
;
use
Symfony\Component\HttpFoundation\RedirectResponse
;
use
Drupal\Core\Database\Connection
;
use
Symfony\Component\HttpFoundation\Request
;
use
Symfony\Component\HttpFoundation\Response
;
use
Drupal\Core\Logger\LoggerChannelFactoryInterface
;
class
ApplicationSubmit
extends
ControllerBase
{
protected
$entity_query
;
protected
$entityTypeManager
;
protected
$logger
;
protected
$connection
;
public
function
__construct
(
EntityTypeManagerInterface
$entityTypeManager
,
QueryFactory
$entity_query
,
Connection
$connection
,
LoggerChannelFactoryInterface
$loggerChannel
)
{
$this
->
entityTypeManager
=
$entityTypeManager
;
$this
->
entity_query
=
$entity_query
;
$this
->
connection
=
$connection
;
$this
->
logger
=
$loggerChannel
->
get
(
'
oauthost
'
);
$this
->
logger
=
$loggerChannel
->
get
(
'
epal
'
);
}
public
static
function
create
(
ContainerInterface
$container
)
{
return
new
static
(
$container
->
get
(
'entity.manager'
),
$container
->
get
(
'entity.query'
),
$container
->
get
(
'entity_type.manager'
),
$container
->
get
(
'database'
),
$container
->
get
(
'logger.factory'
)
);
}
public
function
appSubmitWORK
()
{
$db
=
\
Drupal\Core\Database\Database
::
getConnection
();
$transaction
=
$db
->
startTransaction
();
try
{
$student
=
array
(
'epaluser_id'
=>
1
,
'name'
=>
'ΝΙΚΟΣ'
,
'studentsurname'
=>
'ΚΑΤΣΑ'
,
'status'
=>
1
);
$entity_manager
=
\
Drupal
::
entityManager
();
$entity_storage_student
=
$entity_manager
->
getStorage
(
'epal_student'
);
$entity_storage_eidikotita
=
$entity_manager
->
getStorage
(
'epal_student_course_field'
);
$entity_object
=
$entity_storage_student
->
create
(
$student
);
$entity_storage_student
->
save
(
$entity_object
);
$created_student_id
=
$entity_object
->
id
();
public
function
appSubmit
(
Request
$request
)
{
$eidikotita
=
array
(
'name'
=>
'record1'
,
'student_id'
=>
1
,
'coursefield_id'
=>
4
,
'status'
=>
1
);
$entity_object
=
$entity_storage_eidikotita
->
create
(
$eidikotita
);
$entity_storage_eidikotita
->
save
(
$entity_object
);
$created_eidikotites_id
=
$entity_object
->
id
();
}
catch
(
\
Exception
$e
)
{
$transaction
->
rollback
();
}
}
public
function
appSubmit2
()
{
$db
=
\
Drupal\Core\Database\Database
::
getConnection
();
$transaction
=
$db
->
startTransaction
();
try
{
$student
=
array
(
'epaluser_id'
=>
1
,
'name'
=>
'ΝΙΚΟΣ'
,
'studentsurname'
=>
'ΚΑΤΣΑ'
,
'status'
=>
1
);
$entity_manager
=
\
Drupal
::
entityManager
();
$entity_storage_student
=
$entity_manager
->
getStorage
(
'epal_student'
);
$entity_storage_course
=
$entity_manager
->
getStorage
(
'epal_student_course_field'
);
$entity_object
=
$entity_storage_student
->
create
(
$student
);
$entity_storage_student
->
save
(
$entity_object
);
if
(
!
$request
->
isMethod
(
'POST'
))
{
return
$this
->
respondWithStatus
([
"message"
=>
t
(
"Method Not Allowed"
)
],
Response
::
HTTP_METHOD_NOT_ALLOWED
);
}
$created_student_id
=
$entity_object
->
id
();
$course
=
array
(
'name'
=>
'record1'
,
'student_id'
=>
1
,
'coursefield_id'
=>
4
,
'status'
=>
1
);
$entity_object
=
$entity_storage_course
->
create
(
$course
);
$entity_storage_course
->
save
(
$entity_object
);
}
$applicationForm
=
array
();
catch
(
\
Exception
$e
)
{
$transaction
->
rollback
();
}
$content
=
$request
->
getContent
();
}
public
function
appSubmit
()
{
$aitisi
=
array
();
$content
=
\
Drupal
::
request
()
->
getContent
();
if
(
!
empty
(
$content
))
{
$aitisi
=
json_decode
(
$content
,
TRUE
);
//$aitisi[0] --> student data, $aitisi[1][] --> epals chosen, $aitisi[2][] --> criteria, $aitisi[3] --> sector or course chosen
$applicationForm
=
json_decode
(
$content
,
TRUE
);
}
else
{
return
$this
->
respondWithStatus
([
"message"
=>
t
(
"Bad Request"
)
],
Response
::
HTTP_BAD_REQUEST
);
}
$db
=
\
Drupal\Core\Database\Database
::
getConnection
();
$transaction
=
$db
->
startTransaction
();
try
{
$transaction
=
$this
->
connection
->
startTransaction
();
try
{
//insert records in entity: epal_student
$entity_manager
=
\
Drupal
::
entityTypeManager
();
$epaluserid
=
\
Drupal
::
currentUser
()
->
id
();
$authToken
=
$request
->
headers
->
get
(
'PHP_AUTH_USER'
);
$epalUsers
=
$this
->
entityTypeManager
->
getStorage
(
'epal_users'
)
->
loadByProperties
(
array
(
'authtoken'
=>
$authToken
));
$epalUser
=
reset
(
$epalUsers
);
$student
=
array
(
//'epaluser_id' => $aitisi[0][epaluser_id],
'epaluser_id'
=>
$epaluserid
,
'name'
=>
$aitisi
[
0
][
name
],
'studentsurname'
=>
$aitisi
[
0
][
studentsurname
],
//'birthdate' => $aitisi[0][birthdate],
//'fatherfirstname' => $aitisi[0][fatherfirstname],
//'fathersurname' => $aitisi[0][fathersurname],
//'motherfirstname' => $aitisi[0][motherfirstname],
//'mothersurname' => $aitisi[0][mothersurname],
'studentamka'
=>
$aitisi
[
0
][
studentamka
],
'regionaddress'
=>
$aitisi
[
0
][
regionaddress
],
'regionarea'
=>
$aitisi
[
0
][
regionarea
],
'regiontk'
=>
$aitisi
[
0
][
regiontk
],
'certificatetype'
=>
$aitisi
[
0
][
certificatetype
],
//'lastam' => $aitisi[0][lastam],
'currentclass'
=>
$aitisi
[
0
][
currentclass
],
//'currentepal' => $aitisi[0][currentepal],
//'currentsector' => $aitisi[0][currentsector],
'relationtostudent'
=>
$aitisi
[
0
][
relationtostudent
],
'telnum'
=>
$aitisi
[
0
][
telnum
]
'epaluser_id'
=>
$epalUser
->
id
(),
'name'
=>
$applicationForm
[
0
][
name
],
'studentsurname'
=>
$applicationForm
[
0
][
studentsurname
],
//'birthdate' => $applicationForm[0][birthdate],
//'fatherfirstname' => $applicationForm[0][fatherfirstname],
//'fathersurname' => $applicationForm[0][fathersurname],
//'motherfirstname' => $applicationForm[0][motherfirstname],
//'mothersurname' => $applicationForm[0][mothersurname],
'studentamka'
=>
$applicationForm
[
0
][
studentamka
],
'regionaddress'
=>
$applicationForm
[
0
][
regionaddress
],
'regionarea'
=>
$applicationForm
[
0
][
regionarea
],
'regiontk'
=>
$applicationForm
[
0
][
regiontk
],
'certificatetype'
=>
$applicationForm
[
0
][
certificatetype
],
//'lastam' => $applicationForm[0][lastam],
'currentclass'
=>
$applicationForm
[
0
][
currentclass
],
//'currentepal' => $applicationForm[0][currentepal],
//'currentsector' => $applicationForm[0][currentsector],
'relationtostudent'
=>
$applicationForm
[
0
][
relationtostudent
],
'telnum'
=>
$applicationForm
[
0
][
telnum
]
);
$entity_storage_student
=
$entity
_m
anager
->
getStorage
(
'epal_student'
);
$entity_storage_student
=
$
this
->
entity
TypeM
anager
->
getStorage
(
'epal_student'
);
$entity_object
=
$entity_storage_student
->
create
(
$student
);
$entity_storage_student
->
save
(
$entity_object
);
$created_student_id
=
$entity_object
->
id
();
//insert records in entity: epal_student_epal_chosen
for
(
$i
=
0
;
$i
<
sizeof
(
$aitisi
[
1
]);
$i
++
)
{
//insert records in entity: epal_student_epal_chosen
for
(
$i
=
0
;
$i
<
sizeof
(
$applicationForm
[
1
]);
$i
++
)
{
$epalchosen
=
array
(
//'name' => $a
itisi
[1][$i][name],
//'name' => $a
pplicationForm
[1][$i][name],
'student_id'
=>
$created_student_id
,
'epal_id'
=>
$a
itisi
[
1
][
$i
][
epal_id
],
'choice_no'
=>
$a
itisi
[
1
][
$i
][
choice_no
]
//'points_for_order' => $a
itisi
[1][$i][points_for_order],
//'distance_from_epal' => $a
itisi
[1][$i][distance_from_epal],
//'points_for_distance' => $a
itisi
[1][$i][points_for_distance],
'epal_id'
=>
$a
pplicationForm
[
1
][
$i
][
epal_id
],
'choice_no'
=>
$a
pplicationForm
[
1
][
$i
][
choice_no
]
//'points_for_order' => $a
pplicationForm
[1][$i][points_for_order],
//'distance_from_epal' => $a
pplicationForm
[1][$i][distance_from_epal],
//'points_for_distance' => $a
pplicationForm
[1][$i][points_for_distance],
);
$entity_storage_epalchosen
=
$entity
_m
anager
->
getStorage
(
'epal_student_epal_chosen'
);
$entity_storage_epalchosen
=
$
this
->
entity
TypeM
anager
->
getStorage
(
'epal_student_epal_chosen'
);
$entity_object
=
$entity_storage_epalchosen
->
create
(
$epalchosen
);
$entity_storage_epalchosen
->
save
(
$entity_object
);
}
//insert records in entity: epal_student_moria
for
(
$i
=
0
;
$i
<
sizeof
(
$a
itisi
[
2
]);
$i
++
)
{
//insert records in entity: epal_student_moria
for
(
$i
=
0
;
$i
<
sizeof
(
$a
pplicationForm
[
2
]);
$i
++
)
{
$criteria
=
array
(
//'name' => $a
itisi
[2][$i][name],
//'name' => $a
pplicationForm
[2][$i][name],
'student_id'
=>
$created_student_id
,
'income'
=>
$a
itisi
[
2
][
$i
][
income
],
'criterio_id'
=>
$a
itisi
[
2
][
$i
][
criterio_id
],
//'moria' => $a
itisi
[2][$i][moria],
'income'
=>
$a
pplicationForm
[
2
][
$i
][
income
],
'criterio_id'
=>
$a
pplicationForm
[
2
][
$i
][
criterio_id
],
//'moria' => $a
pplicationForm
[2][$i][moria],
);
$entity_storage_criteria
=
$entity
_m
anager
->
getStorage
(
'epal_student_moria'
);
$entity_storage_criteria
=
$
this
->
entity
TypeM
anager
->
getStorage
(
'epal_student_moria'
);
$entity_object
=
$entity_storage_criteria
->
create
(
$criteria
);
$entity_storage_criteria
->
save
(
$entity_object
);
}
//insert records in entity: epal_student_course_field (αφορά μαθητές Γ' Λυκείου)
// or: epal_student_sector_field (αφορά μαθητές Β' Λυκείου)
if
(
$a
itisi
[
0
][
currentclass
]
===
"Γ' Λυκείου"
)
{
//$course = array('name
'=>'record1', 'student_id' => 1, 'coursefield_id' => 4, 'status'=> 1 );
if
(
$a
pplicationForm
[
0
][
currentclass
]
===
"Γ' Λυκείου"
)
{
//$course = array('name
$course
=
array
(
//'name' => $aitisi[3][name],
//'student_id' => $aitis[3][student_i],
'student_id'
=>
$created_student_id
,
'coursefield_id'
=>
$a
itisi
[
3
][
coursefield_id
]
'coursefield_id'
=>
$a
pplicationForm
[
3
][
coursefield_id
]
);
$entity_storage_course
=
$entity
_m
anager
->
getStorage
(
'epal_student_course_field'
);
$entity_storage_course
=
$
this
->
entity
TypeM
anager
->
getStorage
(
'epal_student_course_field'
);
$entity_object
=
$entity_storage_course
->
create
(
$course
);
$entity_storage_course
->
save
(
$entity_object
);
}
else
if
(
$a
itisi
[
0
][
currentclass
]
===
"Β' Λυκείου"
)
{
else
if
(
$a
pplicationForm
[
0
][
currentclass
]
===
"Β' Λυκείου"
)
{
$sector
=
array
(
//'name' => $a
itisi
[3][name],
//'name' => $a
pplicationForm
[3][name],
'student_id'
=>
$created_student_id
,
//'student_id' => $aitis[3][student_i],
'sectorfield_id'
=>
$a
itisi
[
3
][
sectorfield_id
]
'sectorfield_id'
=>
$a
pplicationForm
[
3
][
sectorfield_id
]
);
$entity_storage_sector
=
$entity
_m
anager
->
getStorage
(
'epal_student_sector_field'
);
$entity_storage_sector
=
$
this
->
entity
TypeM
anager
->
getStorage
(
'epal_student_sector_field'
);
$entity_object
=
$entity_storage_sector
->
create
(
$sector
);
$entity_storage_sector
->
save
(
$entity_object
);
}
$returnmsg
=
"Επιτυχής καταχώρηση στοιχείων αίτησης!"
;
$response
=
new
JsonResponse
([
$returnmsg
]);
return
$response
;
return
$this
->
respondWithStatus
([
"message"
=>
t
(
"Application saved successfully"
)
],
Response
::
HTTP_OK
);
}
catch
(
\
Exception
$e
)
{
$this
->
logger
->
warning
(
$e
->
getMessage
());
$transaction
->
rollback
();
$returnmsg
=
"Αποτυχία καταχώρησης στοιχείων αίτησης!"
;
$response
=
new
JsonResponse
([
$returnmsg
]);
return
$response
;
return
$this
->
respondWithStatus
([
"message"
=>
t
(
"An unexpected problem occured"
)
],
Response
::
HTTP_INTERNAL_SERVER_ERROR
);
}
}
private
function
respondWithStatus
(
$arr
,
$s
)
{
$res
=
new
JsonResponse
(
$arr
);
$res
->
setStatusCode
(
$s
);
return
$res
;
}
}
drupal/modules/epal/src/Controller/CurrentUser.php
View file @
394f6e34
...
...
@@ -2,59 +2,84 @@
namespace
Drupal\epal\Controller
;
use
Drupal\Core\Entity\Query\QueryFactory
;
use
Drupal\Core\Entity\EntityTypeManagerInterface
;
use
Symfony\Component\DependencyInjection\ContainerInterface
;
use
Symfony\Component\HttpFoundation\JsonResponse
;
use
Drupal\Core\Controller\ControllerBase
;
use
Drupal\Core\Entity\EntityFieldManagerInterface
;
use
Symfony\Component\HttpFoundation\Request
;
use
Symfony\Component\HttpFoundation\Response
;
class
CurrentUser
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'
)
);
}
class
CurrentUser
extends
ControllerBase
{
protected
$entityTypeManager
;
public
function
__construct
(
EntityTypeManagerInterface
$entityTypeManager
)
public
function
getLoginInfo
(
Request
$request
)
{
$this
->
entityTypeManager1
=
$entityTypeManager
;
$authToken
=
$request
->
headers
->
get
(
'PHP_AUTH_USER'
);
$epalUsers
=
$this
->
entityTypeManager
->
getStorage
(
'epal_users'
)
->
loadByProperties
(
array
(
'authtoken'
=>
$authToken
));
$epalUser
=
reset
(
$epalUsers
);
if
(
$epalUser
)
{
return
$this
->
respondWithStatus
([
'name'
=>
$epalUser
->
name
->
value
,
],
Response
::
HTTP_OK
);
}
else
{
return
$this
->
respondWithStatus
([
'message'
=>
t
(
"EPAL user not found"
),
],
Response
::
HTTP_FORBIDDEN
);
}
}
public
function
getEpalUserData
(
Request
$request
)
{
$authToken
=
$request
->
headers
->
get
(
'PHP_AUTH_USER'
);
public
static
function
create
(
ContainerInterface
$container
)
{
return
new
static
(
$container
->
get
(
'entity_type.manager'
),
$container
->
get
(
'entity.query'
),
$container
->
get
(
'entity_field.manager'
)
);
}
$epalUsers
=
$this
->
entityTypeManager
->
getStorage
(
'epal_users'
)
->
loadByProperties
(
array
(
'authtoken'
=>
$authToken
));
$epalUser
=
reset
(
$epalUsers
);
if
(
$epalUser
)
{
$user
=
$this
->
entityTypeManager
->
getStorage
(
'user'
)
->
load
(
$epalUser
->
user_id
->
target_id
);
if
(
$user
)
{
$userName
=
$epalUser
->
name
->
value
;
$userSurname
=
$epalUser
->
surname
->
value
;
$userFathername
=
$epalUser
->
fathername
->
value
;
$userMothername
=
$epalUser
->
mothername
->
value
;
$userEmail
=
$user
->
mail
->
value
;
return
$this
->
respondWithStatus
([
'userName'
=>
mb_substr
(
$epalUser
->
name
->
value
,
0
,
4
,
'UTF-8'
)
!==
"####"
?
$epalUser
->
name
->
value
:
''
,
'userSurname'
=>
mb_substr
(
$epalUser
->
surname
->
value
,
0
,
4
,
'UTF-8'
)
!==
"####"
?
$epalUser
->
surname
->
value
:
''
,
'userFathername'
=>
mb_substr
(
$epalUser
->
fathername
->
value
,
0
,
4
,
'UTF-8'
)
!==
"####"
?
$epalUser
->
fathername
->
value
:
''
,
'userMothername'
=>
mb_substr
(
$epalUser
->
mothername
->
value
,
0
,
4
,
'UTF-8'
)
!==
"####"
?
$epalUser
->
mothername
->
value
:
''
,
'userEmail'
=>
mb_substr
(
$user
->
mail
->
value
,
0
,
4
,
'UTF-8'
)
!==
"####"
?
$user
->
mail
->
value
:
''
,
],
Response
::
HTTP_OK
);
}
else
{
return
$this
->
respondWithStatus
([
'message'
=>
t
(
"user not found"
),
],
Response
::
HTTP_INTERNAL_SERVER_ERROR
);
}
public
function
content
(
Request
$request
)
{
$authToken
=
$request
->
headers
->
get
(
'PHP_AUTH_USER'
);
$epalUsers
=
$this
->
entityTypeManager1
->
getStorage
(
'epal_users'
)
->
loadByProperties
(
array
(
'authtoken'
=>
$authToken
));
$epalUser
=
reset
(
$epalUsers
);
if
(
$epalUser
)
{
$currentUserName
=
$epalUser
->
name
->
value
;
$response
=
new
JsonResponse
([
'name'
=>
$currentUserName
]);
}
else
{
$response
=
new
Response
();
$response
->
setContent
(
'forbidden'
);
$response
->
setStatusCode
(
Response
::
HTTP_FORBIDDEN
);
$response
->
headers
->
set
(
'Content-Type'
,
'application/json'
);
}
return
$response
;
}
}
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
;
}
}
drupal/modules/epal/src/Controller/Login.php
deleted
100644 → 0
View file @
73207377
<?php
/**
* @file
* Contains \Drupal\query_example\Controller\QueryExampleController.
*/
namespace
Drupal\epal\Controller
;
use
Drupal\Core\Entity\Query\QueryFactory
;
use
Drupal\Core\Entity\EntityTypeManagerInterface
;
use
Symfony\Component\DependencyInjection\ContainerInterface
;
use
Symfony\Component\HttpFoundation\JsonResponse
;
use
Drupal\Core\Controller\ControllerBase
;
use
Drupal\Core\Entity\EntityFieldManagerInterface
;
/**
* Controller routines for page example routes.
*/
class
Login
extends
ControllerBase
{
protected
$query_factory
;
protected
$entityTypeManager
;
protected
$entityFieldManager
;
public
function
__construct
(
EntityTypeManagerInterface
$entityTypeManager
,
QueryFactory
$query_factory
,
EntityFieldManagerInterface
$entityFieldManager
)
{
// public function __construct(QueryFactory $query_factory) {
$this
->
entityTypeManager
=
$entityTypeManager
;
$this
->
query_factory
=
$query_factory
;
$this
->
entityFieldManager
=
$entityFieldManager
;
}
public
static
function
create
(
ContainerInterface
$container
)
{
return
new
static
(
$container
->
get
(
'entity_type.manager'
),
$container
->
get
(
'entity.query'
),
$container
->
get
(
'entity_field.manager'
)
);
}
public
function
helloWorld
()
{
$name
=
\
Drupal
::
request
()
->
query
->
get
(
'name'
);
$authToken
=
"no authToken"
;
$accessKey
=
"no accessKey"
;
if
(
\
Drupal
::
request
()
->
headers
->
has
(
'X-AUTH-TOKEN'
))
{
$authToken
=
\
Drupal
::
request
()
->
headers
->
get
(
'X-AUTH-TOKEN'
);
}
if
(
\
Drupal
::
request
()
->
headers
->
has
(
'X-ACCESS-KEY'
))
{
$accessKey
=
\
Drupal
::
request
()
->
headers
->
get
(
'X-ACCESS-KEY'
);
}
$response
=
new
JsonResponse
([
'hello'
=>
'world'
,
'name'
=>
$name
,
'authToken'
=>
$authToken
,
'accessKey'
=>
$accessKey
]);
$response
->
headers
->
set
(
'X-AUTH-TOKEN'
,
'HELLOTOKEN'
);
return
$response
;
}
protected
function
simpleQuery
()
{
$query
=
$this
->
query_factory
->
get
(
'student_class'
);
// ->condition('status', 1);
$scids
=
$query
->
execute
();
$studentClass_storage
=
$this
->
entityTypeManager
->
getStorage
(
'student_class'
);
$studentClasses
=
$studentClass_storage
->
loadMultiple
(
$scids
);
$arrayToReturn
=
array
();
foreach
(
$studentClasses
as
$studentClass
)
{
array_push
(
$arrayToReturn
,
array
(
array
(
'data'
=>
$studentClass
->
get
(
'name'
)
->
value
,
'class'
=>
'not-editable'
),
array
(
'data'
=>
"hello"
)
));
}
return
array_values
(
$arrayToReturn
);
}
public
function
object_2_array
(
$result
)
{
$array
=
array
();
foreach
(
$result
as
$key
=>
$value
)
{
if
(
is_object
(
$value
))
{