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
itminedu
gredu_labs
Commits
ad15c8f7
Commit
ad15c8f7
authored
Feb 12, 2016
by
kanellov
Browse files
Merge remote-tracking branch 'gtsakalos/modular' into modular
Conflicts: module/schools/bootstrap.php
parents
9312a992
68d8ce1f
Changes
14
Hide whitespace changes
Inline
Side-by-side
module/schools/bootstrap.php
View file @
ad15c8f7
...
...
@@ -19,20 +19,65 @@ return function (Slim\App $app) {
$events
(
'on'
,
'app.services'
,
function
(
$stop
,
$container
)
{
$container
[
GrEduLabs\Schools\Action\Index
::
class
]
=
function
(
$c
)
{
return
new
GrEduLabs\Schools\Action\Index
(
$c
->
get
(
'view'
));
return
new
GrEduLabs\Schools\Action\Index
(
$c
->
get
(
'view'
),
$c
->
get
(
'schoolservice'
)
);
};
$container
[
GrEduLabs\Schools\Action\Staff
::
class
]
=
function
(
$c
)
{
return
new
GrEduLabs\Schools\Action\Staff
(
$c
->
get
(
'view'
));
return
new
GrEduLabs\Schools\Action\Staff
(
$c
->
get
(
'view'
),
$c
->
get
(
'staffservice'
)
);
};
$container
[
GrEduLabs\Schools\Action\StaffCreate
::
class
]
=
function
(
$c
)
{
return
new
GrEduLabs\Schools\Action\StaffCreate
(
$c
->
get
(
'staffservice'
)
);
};
$container
[
GrEduLabs\Schools\Action\Labs
::
class
]
=
function
(
$c
)
{
return
new
GrEduLabs\Schools\Action\Labs
(
$c
->
get
(
'view'
));
return
new
GrEduLabs\Schools\Action\Labs
(
$c
->
get
(
'view'
)
);
};
$container
[
GrEduLabs\Schools\Action\LabCreate
::
class
]
=
function
(
$c
)
{
return
new
GrEduLabs\Schools\Action\LabCreate
(
$c
->
get
(
'labservice'
)
);
};
$container
[
GrEduLabs\Schools\Action\Assets
::
class
]
=
function
(
$c
)
{
return
new
GrEduLabs\Schools\Action\Assets
(
$c
->
get
(
'view'
));
};
$container
[
'schoolservice'
]
=
function
(
$c
){
return
new
GrEduLabs\Schools\Service\SchoolService
();
};
$container
[
'staffservice'
]
=
function
(
$c
){
return
new
GrEduLabs\Schools\Service\StaffService
(
$c
->
get
(
'schoolservice'
)
);
};
$container
[
'labservice'
]
=
function
(
$c
){
return
new
GrEduLabs\Schools\Service\LabService
(
$c
->
get
(
'schoolservice'
),
$c
->
get
(
'staffservice'
)
);
};
$container
[
'assetservice'
]
=
function
(
$c
){
return
new
GrEduLabs\Schools\Service\AssetService
(
$c
->
get
(
'schoolservice'
),
$c
->
get
(
'labservice'
)
);
};
});
$events
(
'on'
,
'app.bootstrap'
,
function
(
$stop
,
$app
,
$container
)
{
...
...
@@ -41,10 +86,9 @@ return function (Slim\App $app) {
$app
->
group
(
'/school'
,
function
()
{
$this
->
get
(
''
,
GrEduLabs\Schools\Action\Index
::
class
)
->
setName
(
'school'
);
$this
->
get
(
'/staff'
,
GrEduLabs\Schools\Action\Staff
::
class
)
->
setName
(
'school.staff'
);
$this
->
post
(
'/staff'
,
GrEduLabs\Schools\Action\StaffCreate
::
class
)
->
setName
(
'school.staffcreate'
);
$this
->
get
(
'/labs'
,
GrEduLabs\Schools\Action\Labs
::
class
)
->
setName
(
'school.labs'
);
$this
->
post
(
'/labs'
,
GrEduLabs\Schools\Action\LabCreate
::
class
)
->
setName
(
'school.labcreate'
);
$this
->
get
(
'/assets'
,
GrEduLabs\Schools\Action\Assets
::
class
)
->
setName
(
'school.assets'
);
});
});
};
module/schools/bootstrap.php.orig
0 → 100644
View file @
ad15c8f7
<?php
/**
* gredu_labs.
*
* @link https://github.com/eellak/gredu_labs for the canonical source repository
*
* @copyright Copyright (c) 2008-2015 Greek Free/Open Source Software Society (https://gfoss.ellak.gr/)
* @license GNU GPLv3 http://www.gnu.org/licenses/gpl-3.0-standalone.html
*/
return
function
(
Slim
\
App
$app
)
{
$container
=
$app
->
getContainer
();
$events
=
$container
[
'events'
];
<<<<<<<
HEAD
$events
(
'on'
,
'app.autoload'
,
function
(
$stop
,
$autoloader
)
{
$autoloader
->
addPsr4
(
'GrEduLabs\\Schools\\'
,
__DIR__
.
'/src/'
);
});
$events
(
'on'
,
'app.services'
,
function
(
$stop
,
$container
)
{
$container
[
GrEduLabs\Schools\Action\Index
::
class
]
=
function
(
$c
)
{
return
new
GrEduLabs\Schools\Action\Index
(
$c
->
get
(
'view'
));
};
$container
[
GrEduLabs\Schools\Action\Staff
::
class
]
=
function
(
$c
)
{
return
new
GrEduLabs\Schools\Action\Staff
(
$c
->
get
(
'view'
));
};
=======
$container
[
'autoloader'
]
->
addPsr4
(
'GrEduLabs\\Schools\\'
,
__DIR__
.
'/src/'
);
$container
[
GrEduLabs\Schools\Action\Index
::
class
]
=
function
(
$c
)
{
return
new
GrEduLabs\Schools\Action\Index
(
$c
->
get
(
'view'
),
$c
->
get
(
'schoolservice'
)
);
};
$container
[
GrEduLabs\Schools\Action\Staff
::
class
]
=
function
(
$c
)
{
return
new
GrEduLabs\Schools\Action\Staff
(
$c
->
get
(
'view'
),
$c
->
get
(
'staffservice'
)
);
};
$container
[
GrEduLabs\Schools\Action\StaffCreate
::
class
]
=
function
(
$c
)
{
return
new
GrEduLabs\Schools\Action\StaffCreate
(
$c
->
get
(
'staffservice'
)
);
};
$container
[
GrEduLabs\Schools\Action\Labs
::
class
]
=
function
(
$c
)
{
return
new
GrEduLabs\Schools\Action\Labs
(
$c
->
get
(
'view'
)
);
};
$container
[
GrEduLabs\Schools\Action\LabCreate
::
class
]
=
function
(
$c
)
{
return
new
GrEduLabs\Schools\Action\LabCreate
(
$c
->
get
(
'labservice'
)
);
};
>>>>>>>
gtsakalos
/
modular
$container
[
GrEduLabs\Schools\Action\Labs
::
class
]
=
function
(
$c
)
{
return
new
GrEduLabs\Schools\Action\Labs
(
$c
->
get
(
'view'
));
};
<<<<<<<
HEAD
$container
[
GrEduLabs\Schools\Action\Assets
::
class
]
=
function
(
$c
)
{
return
new
GrEduLabs\Schools\Action\Assets
(
$c
->
get
(
'view'
));
};
});
=======
$container
[
'schoolservice'
]
=
function
(
$c
){
return
new
GrEduLabs\Schools\Service\SchoolService
();
};
$container
[
'staffservice'
]
=
function
(
$c
){
return
new
GrEduLabs\Schools\Service\StaffService
(
$c
->
get
(
'schoolservice'
)
);
};
$container
[
'labservice'
]
=
function
(
$c
){
return
new
GrEduLabs\Schools\Service\LabService
(
$c
->
get
(
'schoolservice'
),
$c
->
get
(
'staffservice'
)
);
};
$container
[
'assetservice'
]
=
function
(
$c
){
return
new
GrEduLabs\Schools\Service\AssetService
(
$c
->
get
(
'schoolservice'
),
$c
->
get
(
'labservice'
)
);
};
$events
=
$container
[
'events'
];
>>>>>>>
gtsakalos
/
modular
$events
(
'on'
,
'app.bootstrap'
,
function
(
$stop
,
$app
,
$container
)
{
$container
[
'view'
]
->
getEnvironment
()
->
getLoader
()
->
prependPath
(
__DIR__
.
'/templates'
);
<<<<<<<
HEAD
$app
->
group
(
'/school'
,
function
()
{
$this
->
get
(
''
,
GrEduLabs\Schools\Action\Index
::
class
)
->
setName
(
'school'
);
$this
->
get
(
'/staff'
,
GrEduLabs\Schools\Action\Staff
::
class
)
->
setName
(
'school.staff'
);
$this
->
get
(
'/labs'
,
GrEduLabs\Schools\Action\Labs
::
class
)
->
setName
(
'school.labs'
);
$this
->
get
(
'/assets'
,
GrEduLabs\Schools\Action\Assets
::
class
)
->
setName
(
'school.assets'
);
});
=======
$app
->
group
(
'/school'
,
function
()
{
$this
->
get
(
''
,
GrEduLabs\Schools\Action\Index
::
class
)
->
setName
(
'school'
);
$this
->
get
(
'/staff'
,
GrEduLabs\Schools\Action\Staff
::
class
)
->
setName
(
'school.staff'
);
$this
->
post
(
'/staff'
,
GrEduLabs\Schools\Action\StaffCreate
::
class
)
->
setName
(
'school.staffcreate'
);
$this
->
get
(
'/labs'
,
GrEduLabs\Schools\Action\Labs
::
class
)
->
setName
(
'school.labs'
);
$this
->
post
(
'/labs'
,
GrEduLabs\Schools\Action\LabCreate
::
class
)
->
setName
(
'school.labcreate'
);
$this
->
get
(
'/assets'
,
GrEduLabs\Schools\Action\Assets
::
class
)
->
setName
(
'school.assets'
);
>>>>>>>
gtsakalos
/
modular
});
};
module/schools/src/Action/LabCreate.php
0 → 100644
View file @
ad15c8f7
<?php
/**
* gredu_labs.
*
* @link https://github.com/eellak/gredu_labs for the canonical source repository
*
* @copyright Copyright (c) 2008-2015 Greek Free/Open Source Software Society (https://gfoss.ellak.gr/)
* @license GNU GPLv3 http://www.gnu.org/licenses/gpl-3.0-standalone.html
*/
namespace
GrEduLabs\Schools\Action
;
use
Slim\Http\Request
;
use
Slim\Http\Response
;
class
LabCreate
{
public
function
__construct
(
$labservice
)
{
$this
->
labservice
=
$labservice
;
}
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
=
$this
->
labservice
->
updateLab
(
$params
,
$id
);
$lab
=
$this
->
labservice
->
getLabById
(
$id
);
}
else
{
$id
=
$this
->
labservice
->
createLab
(
$params
);
$lab
=
$this
->
labservice
->
getLabById
(
$id
);
}
$res
=
$res
->
withJson
(
$lab
->
export
());
return
$res
;
}
}
module/schools/src/Action/Staff.php
View file @
ad15c8f7
...
...
@@ -18,26 +18,17 @@ class Staff
{
protected
$view
;
public
function
__construct
(
Twig
$view
)
public
function
__construct
(
Twig
$view
,
$staffservice
)
{
$this
->
view
=
$view
;
$this
->
staffservice
=
$staffservice
;
}
public
function
__invoke
(
Request
$req
,
Response
$res
,
array
$args
=
[])
{
$staff
=
$this
->
staffservice
->
getTeachersBySchoolId
(
1
);
return
$this
->
view
->
render
(
$res
,
'schools/staff.twig'
,
[
'staff'
=>
array_fill
(
0
,
1
,
[
'id'
=>
150
,
'name'
=>
'test'
,
'surname'
=>
'test2'
,
'branch'
=>
'Some branch'
,
'telephone'
=>
'2413123212'
,
'email'
=>
'test@test.com'
,
'positionLabel'
=>
'Εκπαδευτικός'
,
'position'
=>
1
,
]
),
'staff'
=>
$staff
,
'positions'
=>
[
[
'value'
=>
1
,
'label'
=>
'Εκπαδευτικός'
],
[
'value'
=>
2
,
'label'
=>
'Διευθυντής σχολείου'
],
...
...
module/schools/src/Action/StaffCreate.php
0 → 100644
View file @
ad15c8f7
<?php
/**
* gredu_labs.
*
* @link https://github.com/eellak/gredu_labs for the canonical source repository
*
* @copyright Copyright (c) 2008-2015 Greek Free/Open Source Software Society (https://gfoss.ellak.gr/)
* @license GNU GPLv3 http://www.gnu.org/licenses/gpl-3.0-standalone.html
*/
namespace
GrEduLabs\Schools\Action
;
use
Slim\Http\Request
;
use
Slim\Http\Response
;
class
StaffCreate
{
public
function
__construct
(
$staffservice
)
{
$this
->
staffservice
=
$staffservice
;
}
public
function
__invoke
(
Request
$req
,
Response
$res
,
array
$args
=
[])
{
$params
=
$req
->
getParams
();
$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
);
if
(
$id
>
0
){
$teacher
=
$this
->
staffservice
->
getTeacherById
(
$id
);
}
}
if
(
isset
(
$teacher
)){
return
$res
->
withJson
(
$teacher
->
export
())
->
withStatus
(
201
);
}
else
{
return
$res
->
withStatus
(
400
);
}
}
}
module/schools/src/Service/AssetService.php
0 → 100644
View file @
ad15c8f7
<?php
/**
* gredu_labs
*
* @link https://github.com/eellak/gredu_labs for the canonical source repository
* @copyright Copyright (c) 2008-2015 Greek Free/Open Source Software Society (https://gfoss.ellak.gr/)
* @license GNU GPLv3 http://www.gnu.org/licenses/gpl-3.0-standalone.html
*/
namespace
GrEduLabs\Schools\Service
;
use
RedBeanPHP\R
;
class
AssetService
implements
AssetServiceInterface
{
protected
$schoolService
;
protected
$labService
;
public
function
__construct
(
SchoolServiceInterface
$schoolservice
,
LabService
$labservice
)
{
$this
->
schoolservice
=
$schoolservice
;
$this
->
labservice
=
$labservice
;
}
public
function
createItemCategory
(
$name
){
$item_category
=
R
::
dispense
(
'itemcategory'
);
$item_category
->
name
=
$name
;
$id
=
R
::
store
(
$item_category
);
return
$id
;
}
public
function
getAllItemCategories
(){
$categories
=
R
::
findAll
(
'itemcategory'
);
return
$categories
;
}
public
function
getItemCategoryByName
(
$name
){
$cat
=
R
::
findOne
(
'itemcategory'
,
'name = ?'
,
[
$name
]);
return
$cat
;
}
public
function
getItemCategoryById
(
$id
){
$cat
=
R
::
load
(
'itemcategory'
,
$id
);
return
$cat
;
}
//Software Category Actions
public
function
createSoftwareCategory
(
array
$data
){
$soft_category
=
R
::
dispense
(
'softwarecategory'
);
$soft_category
->
name
=
$data
[
'name'
];
$soft_category
->
manufacturer
=
$data
[
'manufacturer'
];
$soft_category
->
website
=
$data
[
'website'
];
$id
=
R
::
store
(
$soft_category
);
return
$id
;
}
public
function
getAllSoftwareCategories
(){
$categories
=
R
::
findAll
(
'softwarecategory'
);
return
$categories
;
}
public
function
getSoftwareCategoryByName
(
$name
){
$cat
=
R
::
findOne
(
'softwarecategory'
,
'name = ?'
,
[
$name
]);
return
$cat
;
}
public
function
getSoftwareCategoryById
(
$id
){
$cat
=
R
::
load
(
'softwarecategory'
,
$id
);
return
$cat
;
}
//Existing Item Actions
public
function
createExistingItem
(
array
$data
){
required
=
[
'location'
,
'category'
,
'description'
,
'qty'
,
'lab'
,
'purchasedate'
];
$item
=
R
::
dispense
(
'existingitem'
);
foreach
(
$required
as
$value
){
if
(
array_key_exists
(
$value
,
$data
))
{
$item
[
$value
]
=
data
[
$value
];
}
else
{
return
-
1
;
}
if
(
array_key_exists
(
'comments'
,
$data
))
{
$item
[
'comments'
]
=
$data
[
'comments'
];
}
else
{
$item
[
'comments'
]
=
''
;
}
R
::
store
(
$item
);
}
}
}
module/schools/src/Service/AssetServiceInterface.php
0 → 100644
View file @
ad15c8f7
<?php
/**
* gredu_labs
*
* @link https://github.com/eellak/gredu_labs for the canonical source repository
* @copyright Copyright (c) 2008-2015 Greek Free/Open Source Software Society (https://gfoss.ellak.gr/)
* @license GNU GPLv3 http://www.gnu.org/licenses/gpl-3.0-standalone.html
*/
namespace
GrEduLabs\Schools\Service
;
interface
AssetServiceInterface
{
public
function
createItemCategory
(
$name
);
public
function
getAllItemCategories
();
public
function
getItemCategoryByName
(
$name
);
public
function
getItemCategoryById
(
$id
);
public
function
createSoftwareCategory
(
array
$data
);
public
function
getAllSoftwareCategories
();
public
function
getSoftwareCategoryByName
(
$name
);
public
function
getSoftwareCategoryById
(
$id
);
public
function
createExistingItem
(
array
$data
);
}
module/schools/src/Service/LabService.php
0 → 100644
View file @
ad15c8f7
<?php
/**
* gredu_labs
*
* @link https://github.com/eellak/gredu_labs for the canonical source repository
* @copyright Copyright (c) 2008-2015 Greek Free/Open Source Software Society (https://gfoss.ellak.gr/)
* @license GNU GPLv3 http://www.gnu.org/licenses/gpl-3.0-standalone.html
*/
namespace
GrEduLabs\Schools\Service
;
use
RedBeanPHP\R
;
class
LabService
implements
LabServiceInterface
{
protected
$schoolService
;
protected
$staffService
;
public
function
__construct
(
SchoolServiceInterface
$schoolService
,
StaffServiceInterface
$staffService
)
{
$this
->
schoolService
=
$schoolService
;
$this
->
staffService
=
$staffService
;
}
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'
];
}
$id
=
R
::
store
(
$lab
);
return
$id
;
}
public
function
updateLab
(
array
$data
,
$id
){
$lab
=
R
::
load
(
'lab'
,
$id
);
foreach
(
$data
as
$key
=>
$value
){
$lab
[
$key
]
=
$value
;
}
$id
=
R
::
store
(
$lab
);
return
$id
;
}
public
function
getLabById
(
$id
)
{
$lab
=
R
::
load
(
'lab'
,
$id
);
return
$lab
;
}
public
function
getLabsBySchoolId
(
$id
)
{
$school
=
$this
->
schoolService
->
getSchool
(
$id
);
$labs
=
$school
->
ownLab
;
return
$labs
;
}
}
module/schools/src/Service/LabServiceInterface.php
0 → 100644
View file @
ad15c8f7
<?php
/**
* gredu_labs
*
* @link https://github.com/eellak/gredu_labs for the canonical source repository
* @copyright Copyright (c) 2008-2015 Greek Free/Open Source Software Society (https://gfoss.ellak.gr/)
* @license GNU GPLv3 http://www.gnu.org/licenses/gpl-3.0-standalone.html
*/
namespace
GrEduLabs\Schools\Service
;
interface
LabServiceInterface
{
public
function
createLab
(
array
$data
);
public
function
updateLab
(
array
$data
,
$id
);
public
function
getLabById
(
$id
);
public
function
getLabsBySchoolId
(
$id
);
}
module/schools/src/Service/SchoolService.php
0 → 100644
View file @
ad15c8f7
<?php
/**
* gredu_labs
*
* @link https://github.com/eellak/gredu_labs for the canonical source repository
* @copyright Copyright (c) 2008-2015 Greek Free/Open Source Software Society (https://gfoss.ellak.gr/)
* @license GNU GPLv3 http://www.gnu.org/licenses/gpl-3.0-standalone.html
*/
namespace
GrEduLabs\Schools\Service
;
use
RedBeanPHP\R
;
class
SchoolService
implements
SchoolServiceInterface
{
public
function
createSchool
(
array
$data
)
{
$school
=
R
::
dispense
(
'school'
);
$required
=
[
'registry_no'
,
'name'
,
'municipality'
,
'schooltype_id'
,
'prefecture_id'
,
'educationlevel_id'
,
'eduadmin_id'
,
'created'
,
'creator'
];
$optional
=
[
'street_address'
,
'postal_code'
,
'phone_number'
,
'fax_number'
,
'email'
];
foreach
(
$required
as
$value
)
{
if
(
array_key_exists
(
$value
,
$data
))
{
$school
[
$value
]
=
$data
[
$value
];
}
else
{
return
-
1
;
}
}
foreach
(
$optional
as
$value
)
{
if
(
array_key_exists
(
$value
,
$data
))
{
$school
[
$value
]
=
$data
[
$value
];
}
else
{
$school
[
$value
]
=
''
;
}
}
$id
=
R
::
store
(
$school
);
return
$id
;
}
public
function
getSchool
(
$id
)
{
$school
=
R
::
load
(
'school'
,
$id
);
return
$school
;
}
}
module/schools/src/Service/SchoolServiceInterface.php
0 → 100644
View file @
ad15c8f7
<?php
/**
* gredu_labs
*
* @link https://github.com/eellak/gredu_labs for the canonical source repository
* @copyright Copyright (c) 2008-2015 Greek Free/Open Source Software Society (https://gfoss.ellak.gr/)
* @license GNU GPLv3 http://www.gnu.org/licenses/gpl-3.0-standalone.html
*/
namespace
GrEduLabs\Schools\Service
;
interface
SchoolServiceInterface
{
public
function
createSchool
(
array
$data
);
public
function
getSchool
(
$id
);
}
module/schools/src/Service/StaffService.php
0 → 100644
View file @
ad15c8f7
<?php
/**
* gredu_labs
*
* @link https://github.com/eellak/gredu_labs for the canonical source repository