fixes after merge

parent df6bd213
...@@ -28,6 +28,7 @@ return [ ...@@ -28,6 +28,7 @@ return [
['/school/staff', ['school'], ['get', 'post', 'delete']], ['/school/staff', ['school'], ['get', 'post', 'delete']],
['/school/assets', ['school'], ['get', 'post', 'delete']], ['/school/assets', ['school'], ['get', 'post', 'delete']],
['/school/labs/attachment', ['school'], ['get', 'delete']], ['/school/labs/attachment', ['school'], ['get', 'delete']],
['/school/software', ['school'], ['get', 'post', 'delete']],
['/application-form', ['school'], ['get', 'post'], 'GrEduLabs\ApplicationForm\Acl\Assertion\CanSubmit'], ['/application-form', ['school'], ['get', 'post'], 'GrEduLabs\ApplicationForm\Acl\Assertion\CanSubmit'],
['/application-form/submit-success', ['school'], ['get']], ['/application-form/submit-success', ['school'], ['get']],
['/#forum', ['guest', 'user'], ['get']], ['/#forum', ['guest', 'user'], ['get']],
......
...@@ -12,15 +12,6 @@ return [ ...@@ -12,15 +12,6 @@ return [
'file_upload' => [ 'file_upload' => [
'tmp_path' => 'data/tmp', 'tmp_path' => 'data/tmp',
'target_path' => 'data/uploads', 'target_path' => 'data/uploads',
'acl' => [
'guards' => [
'routes' => [
['/school', ['school'], ['get']],
['/school/labs', ['school'], ['get', 'post']],
['/school/staff', ['school'], ['get', 'post', 'delete']],
['/school/assets', ['school'], ['get', 'post', 'delete']],
['/school/software', ['school'], ['get', 'post', 'delete']],
],
], ],
], ],
]; ];
...@@ -460,7 +460,7 @@ CREATE TABLE `teacher` ( ...@@ -460,7 +460,7 @@ CREATE TABLE `teacher` (
`school_id` int(11) unsigned NOT NULL, `school_id` int(11) unsigned NOT NULL,
`name` varchar(191) COLLATE utf8mb4_unicode_ci NOT NULL, `name` varchar(191) COLLATE utf8mb4_unicode_ci NOT NULL,
`surname` varchar(191) COLLATE utf8mb4_unicode_ci NOT NULL, `surname` varchar(191) COLLATE utf8mb4_unicode_ci NOT NULL,
`telephone` int(11) unsigned NOT NULL, `telephone` varchar(20) COLLATE utf8mb4_unicode_ci NOT NULL,
`email` varchar(191) COLLATE utf8mb4_unicode_ci NOT NULL, `email` varchar(191) COLLATE utf8mb4_unicode_ci NOT NULL,
`branch_id` int(11) unsigned NOT NULL, `branch_id` int(11) unsigned NOT NULL,
`is_principle` tinyint(1) unsigned DEFAULT '0', `is_principle` tinyint(1) unsigned DEFAULT '0',
...@@ -516,6 +516,64 @@ LOCK TABLES `user` WRITE; ...@@ -516,6 +516,64 @@ LOCK TABLES `user` WRITE;
/*!40000 ALTER TABLE `user` DISABLE KEYS */; /*!40000 ALTER TABLE `user` DISABLE KEYS */;
/*!40000 ALTER TABLE `user` ENABLE KEYS */; /*!40000 ALTER TABLE `user` ENABLE KEYS */;
UNLOCK TABLES; UNLOCK TABLES;
--
-- Table structure for table `softwarecategory`
--
DROP TABLE IF EXISTS `softwarecategory`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `softwarecategory` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`name` varchar(191) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=11 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
--
-- Dumping data for table `softwarecategory`
--
LOCK TABLES `softwarecategory` WRITE;
/*!40000 ALTER TABLE `softwarecategory` DISABLE KEYS */;
INSERT INTO `softwarecategory` VALUES (1,'ΕΦΑΡΜΟΓΕΣ ΟΙΚΟΝΟΜΙΚΗΣ ΔΙΑΧΕΙΡΙΣΗΣ'),(2,'ΕΦΑΡΜΟΓΕΣ ΔΙΑΧΕΙΡΙΣΗΣ ΣΧΟΛΙΚΗΣ ΜΟΝΑΔΑΣ'),(3,'ΕΦΑΡΜΟΓΕΣ ΑΥΤΟΜΑΤΙΣΜΟΥ ΓΡΑΦΕΙΟΥ (OFFICE)'),(4,'ΒΑΣΕΙΣ ΔΕΔΟΜΕΝΩΝ'),(5,'ΓΛΩΣΣΕΣ ΠΡΟΓΡΑΜΜΑΤΙΣΜΟΥ'),(6,'ΕΚΠΑΙΔΕΥΤΙΚΟ ΛΟΓΙΣΜΙΚΟ'),(7,'ΔΙΑΧΕΙΡΙΣΗ ΔΙΚΤΥΟΥ'),(8,'ΛΕΙΤΟΥΡΓΙΚΑ ΣΥΣΤΗΜΑΤΑ'),(9,'ΑΣΦΑΛΕΙΑ ΚΑΙ ΠΡΟΣΤΑΣΙΑ'),(10,'ΒΟΗΘΗΜΑΤΑ');
/*!40000 ALTER TABLE `softwarecategory` ENABLE KEYS */;
UNLOCK TABLES;
--
-- Table structure for table `schoolasset`
--
DROP TABLE IF EXISTS `software`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `software` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`softwarecategory_id` int(11) unsigned NOT NULL,
`school_id` int(11) unsigned NOT NULL,
`lab_id` int(11) unsigned DEFAULT NULL,
`title` varchar(191) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`vendor` varchar(191) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`url` varchar(191) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `index_foreignkey_software_softwarecategory` (`softwarecategory_id`),
KEY `index_foreignkey_software_school` (`school_id`),
CONSTRAINT `c_fk_software_lab_id` FOREIGN KEY (`lab_id`) REFERENCES `lab` (`id`) ON DELETE SET NULL ON UPDATE SET NULL,
CONSTRAINT `c_fk_software_school_id` FOREIGN KEY (`school_id`) REFERENCES `school` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
CONSTRAINT `c_fk_software_softwarecategory_id` FOREIGN KEY (`softwarecategory_id`) REFERENCES `softwarecategory` (`id`) ON DELETE RESTRICT ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
--
-- Dumping data for table `software`
--
LOCK TABLES `software` WRITE;
/*!40000 ALTER TABLE `software` DISABLE KEYS */;
/*!40000 ALTER TABLE `software` ENABLE KEYS */;
UNLOCK TABLES;
/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */; /*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;
/*!40101 SET SQL_MODE=@OLD_SQL_MODE */; /*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
......
...@@ -21,8 +21,7 @@ class RedBeanPHP extends AbstractAdapter ...@@ -21,8 +21,7 @@ class RedBeanPHP extends AbstractAdapter
* @var string * @var string
*/ */
private static $failMessage = 'Δεν ήταν δυνατή η σύνδεση. Παρακαλώ ελέγξτε το ' . private static $failMessage = 'Δεν ήταν δυνατή η σύνδεση. Παρακαλώ ελέγξτε το email και το συνθηματικό σας και δοκιμάστε ξανά.';
'email και το συνθηματικό σας και δοκιμάστε ξανά.';
/** /**
* @var callable * @var callable
*/ */
......
...@@ -397,7 +397,7 @@ CREATE TABLE `teacher` ( ...@@ -397,7 +397,7 @@ CREATE TABLE `teacher` (
`school_id` int(11) unsigned NOT NULL, `school_id` int(11) unsigned NOT NULL,
`name` varchar(191) COLLATE utf8mb4_unicode_ci NOT NULL, `name` varchar(191) COLLATE utf8mb4_unicode_ci NOT NULL,
`surname` varchar(191) COLLATE utf8mb4_unicode_ci NOT NULL, `surname` varchar(191) COLLATE utf8mb4_unicode_ci NOT NULL,
`telephone` int(11) unsigned NOT NULL, `telephone` varchar(20) COLLATE utf8mb4_unicode_ci NOT NULL,
`email` varchar(191) COLLATE utf8mb4_unicode_ci NOT NULL, `email` varchar(191) COLLATE utf8mb4_unicode_ci NOT NULL,
`branch_id` int(11) unsigned NOT NULL, `branch_id` int(11) unsigned NOT NULL,
`is_principle` tinyint(1) unsigned DEFAULT '0', `is_principle` tinyint(1) unsigned DEFAULT '0',
...@@ -419,69 +419,6 @@ LOCK TABLES `teacher` WRITE; ...@@ -419,69 +419,6 @@ LOCK TABLES `teacher` WRITE;
/*!40000 ALTER TABLE `teacher` ENABLE KEYS */; /*!40000 ALTER TABLE `teacher` ENABLE KEYS */;
UNLOCK TABLES; UNLOCK TABLES;
--
-- Table structure for table `lesson`
--
DROP TABLE IF EXISTS `lesson`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `lesson` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`name` varchar(191) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
--
-- Table structure for table `lab`
--
DROP TABLE IF EXISTS `lab`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `lab` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`name` varchar(191) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`type` int(11) unsigned DEFAULT NULL,
`area` int(11) unsigned DEFAULT NULL,
`use_ext_program` varchar(191) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`use_in_program` varchar(191) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`attachment` varchar(191) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`has_network` varchar(191) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`has_server` tinyint(1) unsigned DEFAULT NULL,
`school_id` int(11) unsigned DEFAULT NULL,
`teacher_id` int(11) unsigned DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `index_foreignkey_lab_school` (`school_id`),
KEY `index_foreignkey_lab_teacher` (`teacher_id`),
CONSTRAINT `c_fk_lab_school_id` FOREIGN KEY (`school_id`) REFERENCES `school` (`id`) ON DELETE SET NULL ON UPDATE SET NULL
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8mb4
COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
--
-- Table structure for table `lesson_lab`
--
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `lab_lesson` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`lesson_id` int(11) unsigned DEFAULT NULL,
`lab_id` int(11) unsigned DEFAULT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `UQ_82ac3a020f1d21984f224331fbd99880f89b2e71` (`lab_id`,`lesson_id`),
KEY `index_foreignkey_lab_lesson_lesson` (`lesson_id`),
KEY `index_foreignkey_lab_lesson_lab` (`lab_id`),
CONSTRAINT `c_fk_lab_lesson_lab_id` FOREIGN KEY (`lab_id`) REFERENCES `lab` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
CONSTRAINT `c_fk_lab_lesson_lesson_id` FOREIGN KEY (`lesson_id`) REFERENCES `lesson` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=9 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
-- --
-- Table structure for table `softwarecategory` -- Table structure for table `softwarecategory`
-- --
...@@ -493,31 +430,18 @@ CREATE TABLE `softwarecategory` ( ...@@ -493,31 +430,18 @@ CREATE TABLE `softwarecategory` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT, `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`name` varchar(191) COLLATE utf8mb4_unicode_ci DEFAULT NULL, `name` varchar(191) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
PRIMARY KEY (`id`) PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; ) ENGINE=InnoDB AUTO_INCREMENT=11 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
-- --
-- Table structure for table `schoolasset` -- Dumping data for table `softwarecategory`
-- --
DROP TABLE IF EXISTS `schoolasset`; LOCK TABLES `softwarecategory` WRITE;
/*!40101 SET @saved_cs_client = @@character_set_client */; /*!40000 ALTER TABLE `softwarecategory` DISABLE KEYS */;
/*!40101 SET character_set_client = utf8 */; INSERT INTO `softwarecategory` VALUES (1,'ΕΦΑΡΜΟΓΕΣ ΟΙΚΟΝΟΜΙΚΗΣ ΔΙΑΧΕΙΡΙΣΗΣ'),(2,'ΕΦΑΡΜΟΓΕΣ ΔΙΑΧΕΙΡΙΣΗΣ ΣΧΟΛΙΚΗΣ ΜΟΝΑΔΑΣ'),(3,'ΕΦΑΡΜΟΓΕΣ ΑΥΤΟΜΑΤΙΣΜΟΥ ΓΡΑΦΕΙΟΥ (OFFICE)'),(4,'ΒΑΣΕΙΣ ΔΕΔΟΜΕΝΩΝ'),(5,'ΓΛΩΣΣΕΣ ΠΡΟΓΡΑΜΜΑΤΙΣΜΟΥ'),(6,'ΕΚΠΑΙΔΕΥΤΙΚΟ ΛΟΓΙΣΜΙΚΟ'),(7,'ΔΙΑΧΕΙΡΙΣΗ ΔΙΚΤΥΟΥ'),(8,'ΛΕΙΤΟΥΡΓΙΚΑ ΣΥΣΤΗΜΑΤΑ'),(9,'ΑΣΦΑΛΕΙΑ ΚΑΙ ΠΡΟΣΤΑΣΙΑ'),(10,'ΒΟΗΘΗΜΑΤΑ');
CREATE TABLE `schoolasset` ( /*!40000 ALTER TABLE `softwarecategory` ENABLE KEYS */;
`id` int(11) unsigned NOT NULL AUTO_INCREMENT, UNLOCK TABLES;
`itemcategory_id` int(11) unsigned NOT NULL,
`school_id` int(11) unsigned NOT NULL,
`qty` int(11) unsigned NOT NULL,
`lab_id` int(11) unsigned NOT NULL,
`acquisition_year` char(4) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`comments` text COLLATE utf8mb4_unicode_ci,
PRIMARY KEY (`id`),
KEY `index_foreignkey_schoolasset_itemcategory` (`itemcategory_id`),
KEY `index_foreignkey_schoolasset_school` (`school_id`),
KEY `index_foreignkey_schoolasset_lab` (`lab_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
-- --
-- Table structure for table `schoolasset` -- Table structure for table `schoolasset`
...@@ -528,8 +452,8 @@ DROP TABLE IF EXISTS `software`; ...@@ -528,8 +452,8 @@ DROP TABLE IF EXISTS `software`;
/*!40101 SET character_set_client = utf8 */; /*!40101 SET character_set_client = utf8 */;
CREATE TABLE `software` ( CREATE TABLE `software` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT, `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`softwarecategory_id` int(11) unsigned DEFAULT NULL, `softwarecategory_id` int(11) unsigned NOT NULL,
`school_id` int(11) unsigned DEFAULT NULL, `school_id` int(11) unsigned NOT NULL,
`lab_id` int(11) unsigned DEFAULT NULL, `lab_id` int(11) unsigned DEFAULT NULL,
`title` varchar(191) COLLATE utf8mb4_unicode_ci DEFAULT NULL, `title` varchar(191) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`vendor` varchar(191) COLLATE utf8mb4_unicode_ci DEFAULT NULL, `vendor` varchar(191) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
...@@ -538,11 +462,20 @@ DROP TABLE IF EXISTS `software`; ...@@ -538,11 +462,20 @@ DROP TABLE IF EXISTS `software`;
KEY `index_foreignkey_software_softwarecategory` (`softwarecategory_id`), KEY `index_foreignkey_software_softwarecategory` (`softwarecategory_id`),
KEY `index_foreignkey_software_school` (`school_id`), KEY `index_foreignkey_software_school` (`school_id`),
CONSTRAINT `c_fk_software_lab_id` FOREIGN KEY (`lab_id`) REFERENCES `lab` (`id`) ON DELETE SET NULL ON UPDATE SET NULL, CONSTRAINT `c_fk_software_lab_id` FOREIGN KEY (`lab_id`) REFERENCES `lab` (`id`) ON DELETE SET NULL ON UPDATE SET NULL,
CONSTRAINT `c_fk_software_school_id` FOREIGN KEY (`school_id`) REFERENCES `school` (`id`) ON DELETE SET NULL ON UPDATE SET NULL, CONSTRAINT `c_fk_software_school_id` FOREIGN KEY (`school_id`) REFERENCES `school` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
CONSTRAINT `c_fk_software_softwarecategory_id` FOREIGN KEY (`softwarecategory_id`) REFERENCES `softwarecategory` (`id`) ON DELETE SET NULL ON UPDATE SET NULL CONSTRAINT `c_fk_software_softwarecategory_id` FOREIGN KEY (`softwarecategory_id`) REFERENCES `softwarecategory` (`id`) ON DELETE RESTRICT ON UPDATE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */; /*!40101 SET character_set_client = @saved_cs_client */;
--
-- Dumping data for table `software`
--
LOCK TABLES `software` WRITE;
/*!40000 ALTER TABLE `software` DISABLE KEYS */;
/*!40000 ALTER TABLE `software` ENABLE KEYS */;
UNLOCK TABLES;
/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */; /*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;
/*!40101 SET SQL_MODE=@OLD_SQL_MODE */; /*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
......
...@@ -22,7 +22,7 @@ class ListAll ...@@ -22,7 +22,7 @@ class ListAll
public function __construct(Twig $view, SoftwareServiceInterface $softwareService) public function __construct(Twig $view, SoftwareServiceInterface $softwareService)
{ {
$this->view = $view; $this->view = $view;
$this->softwareService = $softwareService; $this->softwareService = $softwareService;
} }
...@@ -34,9 +34,11 @@ class ListAll ...@@ -34,9 +34,11 @@ class ListAll
} }
$software = $this->softwareService->getSoftwareBySchoolId($school->id); $software = $this->softwareService->getSoftwareBySchoolId($school->id);
$categories = $this->softwareService->getSoftwareCategories(); $categories = $this->softwareService->getSoftwareCategories();
return $this->view->render($res, 'schools/software.twig', [ return $this->view->render($res, 'schools/software.twig', [
'school' => $school,
'softwareArray' => $software, 'softwareArray' => $software,
'categories' => array_map(function ($category) { 'categories' => array_map(function ($category) {
return ['value' => $category['id'], 'label' => $category['name']]; return ['value' => $category['id'], 'label' => $category['name']];
}, $categories), }, $categories),
]); ]);
......
...@@ -42,7 +42,7 @@ class Software ...@@ -42,7 +42,7 @@ class Software
$school_id->setRequired(true) $school_id->setRequired(true)
->getValidatorChain() ->getValidatorChain()
->attach(new Validator\Digits()); ->attach(new Validator\Digits());
$lab_id = new Input('lab_id'); $lab_id = new Input('lab_id');
$lab_id->setRequired(false) $lab_id->setRequired(false)
->getValidatorChain() ->getValidatorChain()
......
...@@ -9,7 +9,6 @@ ...@@ -9,7 +9,6 @@
namespace GrEduLabs\Schools\Service; namespace GrEduLabs\Schools\Service;
use InvalidArgumentException;
use RedBeanPHP\R; use RedBeanPHP\R;
class SoftwareService implements SoftwareServiceInterface class SoftwareService implements SoftwareServiceInterface
...@@ -17,7 +16,7 @@ class SoftwareService implements SoftwareServiceInterface ...@@ -17,7 +16,7 @@ class SoftwareService implements SoftwareServiceInterface
public function createSoftwareCategory($name) public function createSoftwareCategory($name)
{ {
$software_category = R::dispense('softwarecategory'); $software_category = R::dispense('softwarecategory');
$software_category->name = $name; $software_category->name = $name;
R::store($software_category); R::store($software_category);
} }
...@@ -25,18 +24,22 @@ class SoftwareService implements SoftwareServiceInterface ...@@ -25,18 +24,22 @@ class SoftwareService implements SoftwareServiceInterface
public function getSoftwareCategoryById($id) public function getSoftwareCategoryById($id)
{ {
$software_category = R::load('softwarecategory', $id); $software_category = R::load('softwarecategory', $id);
return $software_category->export(); return $software_category->export();
} }
public function getSoftwareCategories() public function getSoftwareCategories()
{ {
$software_categories = R::findAll('softwarecategory'); $software_categories = R::findAll('softwarecategory');
return $this->exportAll($software_categories);
return array_map(function ($bean) {
return $bean->export();
}, $software_categories);
} }
public function updateSoftwareCategory($id, $data) public function updateSoftwareCategory($id, $data)
{ {
$software_category = R::load('softwarecategory'); $software_category = R::load('softwarecategory');
$software_category->name = $name; $software_category->name = $name;
R::store($software_category); R::store($software_category);
} }
...@@ -46,7 +49,8 @@ class SoftwareService implements SoftwareServiceInterface ...@@ -46,7 +49,8 @@ class SoftwareService implements SoftwareServiceInterface
unset($data['id']); unset($data['id']);
$software = R::dispense('software'); $software = R::dispense('software');
$this->persistSoftware($software, $data); $this->persistSoftware($software, $data);
return $software->export();
return $this->export($software);
} }
public function updateSoftware(array $data, $id) public function updateSoftware(array $data, $id)
...@@ -56,40 +60,44 @@ class SoftwareService implements SoftwareServiceInterface ...@@ -56,40 +60,44 @@ class SoftwareService implements SoftwareServiceInterface
throw new \InvalidArgumentException('No software found'); throw new \InvalidArgumentException('No software found');
} }
$this->persistSoftware($software, $data); $this->persistSoftware($software, $data);
return $software->export();
return $this->export($software);
} }
private function persistSoftware($software, array $data) private function persistSoftware($software, array $data)
{ {
if (!$data['lab_id']){ if (!$data['lab_id']) {
$data['lab_id'] = NULL; $data['lab_id'] = NULL;
} }
$software->softwarecategory_id = $data['softwarecategory_id']; $software->softwarecategory_id = $data['softwarecategory_id'];
$software->school_id = $data['school_id']; $software->school_id = $data['school_id'];
$software->lab_id = $data['lab_id']; $software->lab_id = $data['lab_id'];
$software->title = $data['title']; $software->title = $data['title'];
$software->vendor = $data['vendor']; $software->vendor = $data['vendor'];
$software->url = $data['url']; $software->url = $data['url'];
R::store($software); R::store($software);
} }
public function getSoftwareById($id) public function getSoftwareById($id)
{ {
$software = R::load('software', $id); $software = R::load('software', $id);
return $software->export();
return $this->export($software);
} }
public function getSoftwareBySchoolId($id) public function getSoftwareBySchoolId($id)
{ {
$software = R::findAll('software', 'school_id = ?', [$id]); $software = R::findAll('software', 'school_id = ?', [$id]);
return $this->exportAll($software); return $this->exportAll($software);
} }
public function getSoftwareByLabId($id) public function getSoftwareByLabId($id)
{ {
$software = R::findAll('software', 'lab_id = ?', [$id]); $software = R::findAll('software', 'lab_id = ?', [$id]);
return $software->exportAll(); return $software->exportAll();
} }
...@@ -98,16 +106,21 @@ class SoftwareService implements SoftwareServiceInterface ...@@ -98,16 +106,21 @@ class SoftwareService implements SoftwareServiceInterface
R::trash('software', $id); R::trash('software', $id);
} }
private function export($bean)
{
$softwareCategory = $bean->softwarecategory;
$softwareCategoryName = ($softwareCategory) ? $softwareCategory->name : '';
$lab = $bean->lab;
$labName = ($lab) ? $lab->name : '';
return array_merge($bean->export(), [
'softwarecategory' => $softwareCategoryName,
'lab' => $labName,
]);
}
private function exportAll($beans) private function exportAll($beans)
{ {
$exported = []; return array_map([$this, 'export'], $beans);
foreach($beans as $bean)
{
$cat = $this->getSoftwareCategoryById($bean->id);
$exported_bean = $bean->export();
$exported_bean['softwarecategory'] = $cat['name'];
$exported[] = $exported_bean;
}
return $exported;
} }
} }
...@@ -21,5 +21,4 @@ interface SoftwareServiceInterface ...@@ -21,5 +21,4 @@ interface SoftwareServiceInterface
public function getSoftwareBySchoolId($id); public function getSoftwareBySchoolId($id);
public function getSoftwareByLabId($id); public function getSoftwareByLabId($id);
public function removeSoftware($id); public function removeSoftware($id);
} }
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
{% block schoolContent %} {% block schoolContent %}
<div id="school-software"> <div id="school-software">
<p></p>
<div class="table-responsive"> <div class="table-responsive">
<table class="table table-hover table-striped"> <table class="table table-hover table-striped">
<thead> <thead>
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment