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
403e3caa
Commit
403e3caa
authored
Feb 19, 2016
by
Georgios Tsakalos
Browse files
update lab actions and service
dirty - needs clean up
parent
c1a090f6
Changes
4
Hide whitespace changes
Inline
Side-by-side
module/schools/src/Action/Lab/.PersistLab.php.swp
0 → 100644
View file @
403e3caa
File added
module/schools/src/Action/Lab/ListAll.php
View file @
403e3caa
...
...
@@ -38,20 +38,6 @@ class ListAll
return
$res
->
withStatus
(
403
,
'No school'
);
}
// $lab = R::dispense('lab');
// $lab->school_id = 1;
// $teacher = R::load('teacher', 2);
// $lab->sharedCourse = array($course1, $course2);
// $lab->area = 55;
// $lab->in_school_use = true;
// $lab->out_school_use = false;
// $lab->attachment = 'foo/bar/qux/arxeio.gph';
// $lab->has_network = true;
// $lab->has_server = true;
// R::store($lab);
$labs
=
$this
->
labservice
->
getLabsBySchoolId
(
$school
->
id
);
$staff
=
$this
->
staffservice
->
getTeachersBySchoolId
(
$school
->
id
);
$clean_staff
=
[];
...
...
@@ -68,8 +54,6 @@ class ListAll
foreach
(
$courses
as
$lesson
)
{
$lessons
[]
=
[
'value'
=>
$lesson
->
id
,
'label'
=>
$lesson
->
name
];
}
error_log
(
print_r
(
$courses
,
TRUE
));
error_log
(
print_r
(
'courses'
,
TRUE
));
return
$this
->
view
->
render
(
$res
,
'schools/labs.twig'
,
[
'labs'
=>
$labs
,
...
...
module/schools/src/Action/Lab/PersistLab.php
View file @
403e3caa
...
...
@@ -33,6 +33,7 @@ class PersistLab
$params
=
$req
->
getParams
();
$id
=
$params
[
'id'
];
$params
[
'school_id'
]
=
$school
->
id
;
$params
[
'lessons'
]
=
[
1
,
2
];
unset
(
$params
[
'id'
]);
try
{
...
...
@@ -40,7 +41,10 @@ class PersistLab
$id
=
$this
->
labservice
->
updateLab
(
$params
,
$id
);
$lab
=
$this
->
labservice
->
getLabById
(
$id
);
}
else
{
error_log
(
print_r
(
'in else'
,
TRUE
));
$id
=
$this
->
labservice
->
createLab
(
$params
);
error_log
(
print_r
(
'created lab'
,
TRUE
));
if
(
$id
>
0
)
{
$lab
=
$this
->
labservice
->
getLabById
(
$id
);
}
...
...
module/schools/src/Service/LabService.php
View file @
403e3caa
...
...
@@ -26,35 +26,43 @@ class LabService implements LabServiceInterface
public
function
createLab
(
array
$data
)
{
$lab
=
R
::
dispense
(
'lab'
);
$required
=
[
'school_id'
,
'name'
,
'type'
,
'area'
,
'in_school_use'
,
'out_school_use'
,
'courses'
,
'attachment'
,
'has_network'
,
'has_server'
,
];
foreach
(
$required
as
$value
)
{
if
(
array_key_exists
(
$value
,
$data
))
{
$lab
[
$value
]
=
$data
[
$value
];
}
else
{
return
-
1
;
}
}
if
(
array_key_exists
(
'teacher_id'
,
$data
))
{
$lab
[
'teacher_id'
]
=
$data
[
'teacher_id'
];
}
error_log
(
print_r
(
'creating'
,
TRUE
));
unset
(
$data
[
'id'
]);
$lab
=
R
::
dispense
(
'lab'
);
$this
->
persist
(
$lab
,
$data
);
$id
=
R
::
store
(
$lab
);
return
$id
;
//return $this->export($lab);
return
$lab
;
}
public
function
updateLab
(
array
$data
,
$id
)
{
$lab
=
R
::
load
(
'lab'
,
$id
);
foreach
(
$data
as
$key
=>
$value
)
{
$lab
[
$key
]
=
$value
;
$lab
=
R
::
load
(
'lab'
,
$id
);
if
(
!
$lab
->
id
)
{
throw
new
\
InvalidArgumentException
(
'No lab found'
)
;
}
$id
=
R
::
store
(
$lab
);
$this
->
persist
(
$lab
,
$data
);
return
$this
->
export
(
$lab
);
}
return
$id
;
private
function
persist
(
$lab
,
$data
)
{
R
::
debug
(
TRUE
);
error_log
(
print_r
(
$data
,
TRUE
));
$lab
->
school_id
=
$data
[
'school_id'
];
$lab
->
name
=
$data
[
'name'
];
$lab
->
type
=
$data
[
'type'
];
$lab
->
area
=
$data
[
'area'
];
$lab
->
sharedCourse
=
$this
->
getCoursesById
(
$data
[
'lessons'
]);
$lab
->
out_school_use
=
$data
[
'use_ext_program'
];
$lab
->
in_school_use
=
$data
[
'use_in_program'
];
$lab
->
attachment
=
'attachment'
;
$lab
->
has_network
=
isset
(
$data
[
'has_network'
]);
$lab
->
has_server
=
isset
(
$data
[
'has_server'
]);
$lab
->
responsible
=
$data
[
'responsible'
];
$id
=
R
::
store
(
$lab
);
}
public
function
getLabById
(
$id
)
...
...
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