Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
E
e-epal
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Σταύρος Παπαδάκης
e-epal
Commits
e5dedd32
Commit
e5dedd32
authored
Aug 03, 2017
by
Σταύρος Παπαδάκης
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Available to all users
parent
bfcc2069
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
38 additions
and
73 deletions
+38
-73
drupal/modules/epal/src/Controller/HelpDesk.php
drupal/modules/epal/src/Controller/HelpDesk.php
+38
-73
No files found.
drupal/modules/epal/src/Controller/HelpDesk.php
View file @
e5dedd32
<?php
/**
* @file
* Contains \Drupal\query_example\Controller\QueryExampleController
.
* Contains \Drupal\query_example\Controller\QueryExampleController
*/
namespace
Drupal\epal\Controller
;
...
...
@@ -20,8 +20,6 @@ use Drupal\Core\Logger\LoggerChannelFactoryInterface;
use
Drupal\Core\TypedData\Plugin\DataType\TimeStamp
;
use
Drupal\Core\Language\LanguageManagerInterface
;
class
HelpDesk
extends
ControllerBase
{
protected
$entity_query
;
...
...
@@ -35,12 +33,11 @@ class HelpDesk extends ControllerBase {
Connection
$connection
,
LoggerChannelFactoryInterface
$loggerChannel
)
{
$this
->
entityTypeManager
=
$entityTypeManager
;
$this
->
entity_query
=
$entity_query
;
$connection
=
Database
::
getConnection
();
$this
->
connection
=
$connection
;
$this
->
logger
=
$loggerChannel
->
get
(
'epal'
);
$this
->
entityTypeManager
=
$entityTypeManager
;
$this
->
entity_query
=
$entity_query
;
$connection
=
Database
::
getConnection
();
$this
->
connection
=
$connection
;
$this
->
logger
=
$loggerChannel
->
get
(
'epal'
);
}
public
static
function
create
(
ContainerInterface
$container
)
...
...
@@ -53,44 +50,36 @@ class HelpDesk extends ControllerBase {
);
}
private
function
respondWithStatus
(
$arr
,
$s
)
{
$res
=
new
JsonResponse
(
$arr
);
$res
->
setStatusCode
(
$s
);
return
$res
;
}
public
function
sendEmail
(
Request
$request
)
public
function
sendEmail
(
Request
$request
)
{
if
(
!
$request
->
isMethod
(
'POST'
))
{
return
$this
->
respondWithStatus
([
"message"
=>
t
(
"Method Not Allowed"
)
],
Response
::
HTTP_METHOD_NOT_ALLOWED
);
"message"
=>
t
(
"Method Not Allowed"
)
],
Response
::
HTTP_METHOD_NOT_ALLOWED
);
}
$postData
=
null
;
if
(
$content
=
$request
->
getContent
())
{
$postData
=
json_decode
(
$content
);
$this
->
sendEmailToHelpDesk
(
$postData
->
userEmail
,
$postData
->
userName
,
$postData
->
userMessage
,
$postData
->
userSurname
);
return
$this
->
respondWithStatus
([
'error_code'
=>
0
,
],
Response
::
HTTP_OK
);
}
else
{
return
$this
->
respondWithStatus
([
'message'
=>
t
(
"post with no data"
),
],
Response
::
HTTP_BAD_REQUEST
);
}
$postData
=
null
;
if
(
$content
=
$request
->
getContent
())
{
$postData
=
json_decode
(
$content
);
$this
->
sendEmailToHelpDesk
(
$postData
->
userEmail
,
$postData
->
userName
,
$postData
->
userMessage
,
$postData
->
userSurname
);
return
$this
->
respondWithStatus
([
'error_code'
=>
0
,
],
Response
::
HTTP_OK
);
}
else
{
return
$this
->
respondWithStatus
([
'message'
=>
t
(
"post with no data"
),
],
Response
::
HTTP_BAD_REQUEST
);
}
}
private
function
sendEmailToHelpDesk
(
$email
,
$name
,
$cont_message
,
$surname
)
{
$mailManager
=
\
Drupal
::
service
(
'plugin.manager.mail'
);
...
...
@@ -113,50 +102,26 @@ class HelpDesk extends ControllerBase {
return
;
}
public
function
findTotalStudents
(
Request
$request
)
public
function
findTotalStudents
(
Request
$request
)
{
$authToken
=
$request
->
headers
->
get
(
'PHP_AUTH_USER'
);
$users
=
$this
->
entityTypeManager
->
getStorage
(
'user'
)
->
loadByProperties
(
array
(
'name'
=>
$authToken
));
$user
=
reset
(
$users
);
if
(
!
$user
)
{
return
$this
->
respondWithStatus
([
'message'
=>
t
(
"User not found"
),
],
Response
::
HTTP_FORBIDDEN
);
}
$list
=
array
();
$sCon
=
$this
->
connection
->
select
(
'epal_student'
,
'eStudent'
)
->
fields
(
'eStudent'
,
array
(
'id'
));
$numApplications
=
$sCon
->
countQuery
()
->
execute
()
->
fetchField
();
array_push
(
$list
,
(
object
)
array
(
'name'
=>
"Αριθμός Αιτήσεων (συνολικά)"
,
'numStudents'
=>
$numApplications
));
$authToken
=
$request
->
headers
->
get
(
'PHP_AUTH_USER'
);
$users
=
$this
->
entityTypeManager
->
getStorage
(
'user'
)
->
loadByProperties
(
array
(
'name'
=>
$authToken
));
$user
=
reset
(
$users
);
if
(
!
$user
)
{
return
$this
->
respondWithStatus
([
'message'
=>
t
(
"User not found"
),
],
Response
::
HTTP_FORBIDDEN
);
}
//user role validation
$roles
=
$user
->
getRoles
();
$validRole
=
false
;
foreach
(
$roles
as
$role
)
{
if
(
$role
===
"applicant"
)
{
$validRole
=
true
;
break
;
}
}
if
(
!
$validRole
)
{
return
$this
->
respondWithStatus
([
'message'
=>
t
(
"User Invalid Role"
),
],
Response
::
HTTP_FORBIDDEN
);
}
$list
=
array
();
$sCon
=
$this
->
connection
->
select
(
'epal_student'
,
'eStudent'
)
->
fields
(
'eStudent'
,
array
(
'id'
));
$numApplications
=
$sCon
->
countQuery
()
->
execute
()
->
fetchField
();
array_push
(
$list
,
(
object
)
array
(
'name'
=>
"Αριθμός Αιτήσεων (συνολικά)"
,
'numStudents'
=>
$numApplications
));
return
$this
->
respondWithStatus
(
$list
,
Response
::
HTTP_OK
);
return
$this
->
respondWithStatus
(
$list
,
Response
::
HTTP_OK
);
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment