Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Σταύρος Παπαδάκης
gredu_labs
Commits
c8e4c941
Commit
c8e4c941
authored
Feb 12, 2016
by
Georgios Tsakalos
Browse files
connect staff service with view
parent
14ddb086
Changes
3
Hide whitespace changes
Inline
Side-by-side
module/schools/src/Action/StaffCreate.php
View file @
c8e4c941
...
...
@@ -24,18 +24,24 @@ class StaffCreate
public
function
__invoke
(
Request
$req
,
Response
$res
,
array
$args
=
[])
{
$params
=
$req
->
getParams
();
if
(
array_key_exists
(
'id'
,
$params
)){
$id
=
$params
[
'id'
];
unset
(
$params
[
'id'
]);
$id
=
$params
[
'id'
];
unset
(
$params
[
'id'
]
)
;
if
(
$id
>
0
){
$id
=
$this
->
staffservice
->
updateTeacher
(
$params
,
$id
);
$teacher
=
$this
->
staffservice
->
getTeacherById
(
$id
);
}
else
{
$id
=
$this
->
staffservice
->
createTeacher
(
$params
);
$teacher
=
$this
->
staffservice
->
getTeacherById
(
$id
);
if
(
$id
>
0
){
$teacher
=
$this
->
staffservice
->
getTeacherById
(
$id
);
}
}
$res
=
$res
->
withJson
(
$teacher
->
export
());
return
$res
;
if
(
isset
(
$teacher
)){
return
$res
->
withJson
(
$teacher
->
export
())
->
withStatus
(
201
);
}
else
{
return
$res
->
withStatus
(
400
);
}
}
}
module/schools/src/Service/StaffService.php
View file @
c8e4c941
...
...
@@ -21,9 +21,11 @@ class StaffService implements StaffServiceInterface
public
function
createTeacher
(
array
$data
)
{
unset
(
$data
[
'id'
]);
$teacher
=
R
::
dispense
(
'teacher'
);
$required
=
[
'school_id'
,
'name'
,
'surname'
,
'phoneNumber'
,
'labSupervisor'
,
'schoolPrincipal'
];
$optional
=
[
'speciality'
,
'email'
];
$required
=
[
'school_id'
,
'name'
,
'email'
,
'surname'
,
'telephone'
,
'position'
,
'branch'
];
$data
[
'school_id'
]
=
1
;
foreach
(
$required
as
$value
)
{
if
(
array_key_exists
(
$value
,
$data
))
{
$teacher
[
$value
]
=
$data
[
$value
];
...
...
@@ -31,13 +33,6 @@ class StaffService implements StaffServiceInterface
return
-
1
;
}
}
foreach
(
$optional
as
$value
)
{
if
(
array_key_exists
(
$value
,
$data
))
{
$teacher
[
$value
]
=
$data
[
$value
];
}
else
{
$$value
=
''
;
}
}
$id
=
R
::
store
(
$teacher
);
return
$id
;
}
...
...
public/js/schools/staff.js
View file @
c8e4c941
...
...
@@ -109,15 +109,17 @@
hash
[
pair
.
name
]
=
pair
.
value
;
return
hash
;
},
{});
var
that
=
this
;
evt
.
preventDefault
();
if
(
!
data
.
id
)
{
data
.
id
=
(
100
*
Math
.
random
()).
toFixed
(
0
);
}
this
.
form
.
data
(
'
done
'
)(
data
);
this
.
form
.
data
(
'
done
'
,
undefined
);
this
.
hide
();
$
.
post
(
""
,
data
).
done
(
function
(
response
){
that
.
form
.
data
(
'
done
'
)(
response
);
console
.
log
(
response
);
that
.
form
.
data
(
'
done
'
,
undefined
);
that
.
hide
();
});
}
});
new
StaffView
({
model
:
new
Staff
()
});
}());
\ No newline at end of file
}());
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