From 90736df4f20711650e778b8168bb515bf0233894 Mon Sep 17 00:00:00 2001 From: oliver Date: Fri, 22 Jan 2016 20:51:23 +0100 Subject: [PATCH 1/3] display icons for Character groups Quest Stations --- configs/AppConfig.inc | 4 + .../CharactergroupsquestsController.inc | 20 +++-- ...CharactergroupsqueststationsController.inc | 3 - controllers/MediaController.inc | 77 +++++++++++++++---- models/CharactergroupsqueststationsModel.inc | 27 +++++++ .../media/charactergroupsqueststation.tpl | 1 + views/html/charactergroupsquests/quest.tpl | 37 ++++++--- .../charactergroupsqueststations/station.tpl | 8 +- www/css/desktop.css | 3 + 9 files changed, 144 insertions(+), 36 deletions(-) create mode 100644 views/binary/media/charactergroupsqueststation.tpl diff --git a/configs/AppConfig.inc b/configs/AppConfig.inc index 585f6723..fc5233b3 100644 --- a/configs/AppConfig.inc +++ b/configs/AppConfig.inc @@ -104,6 +104,10 @@ 'charactergroupsquest' => array( 'width' => 80, 'height' => 80 + ), + 'charactergroupsqueststation' => array( + 'width' => 100, + 'height' => 100 ) ); diff --git a/controllers/CharactergroupsquestsController.inc b/controllers/CharactergroupsquestsController.inc index 24fdeafc..23e18f5c 100644 --- a/controllers/CharactergroupsquestsController.inc +++ b/controllers/CharactergroupsquestsController.inc @@ -89,12 +89,20 @@ // Get Stations $stations = null; - if(count(array_intersect(array('admin', 'moderator'), \hhu\z\controllers\SeminaryController::$character['characterroles'])) > 0) { - $stations = $this->Charactergroupsqueststations->getStationsForQuest($quest['id']); - } - elseif(!is_null($charactergroup)) { - $stations = $this->Charactergroupsqueststations->getStationsForQuestAndGroup($quest['id'], $charactergroup['id']); - foreach($stations as &$station) { + $stations = $this->Charactergroupsqueststations->getStationsForQuest($quest['id']); + foreach($stations as &$station) + { + // Icon + if(!is_null($station['stationpicture_id'])) { + $station['picture'] = $this->Media->getSeminaryMediaById($station['stationpicture_id']); + } + + // Entered state + if(!is_null($charactergroup)) { + $station['entered'] = $this->Charactergroupsqueststations->hasCharactergroupEnteredStation( + $station['id'], + $charactergroup['id'] + ); $station['solved'] = $this->Charactergroupsqueststations->hasCharactergroupSolvedStation( $station['id'], $charactergroup['id'] diff --git a/controllers/CharactergroupsqueststationsController.inc b/controllers/CharactergroupsqueststationsController.inc index 6000f874..6a6da2e3 100644 --- a/controllers/CharactergroupsqueststationsController.inc +++ b/controllers/CharactergroupsqueststationsController.inc @@ -124,9 +124,6 @@ // Get Station $station = $this->Charactergroupsqueststations->getStationByUrl($quest['id'], $stationUrl); - if(!is_null($station['stationpicture_id'])) { - $station['picture'] = $this->Media->getSeminaryMediaById($station['stationpicture_id']); - } // Get Character group $charactergroup = null; diff --git a/controllers/MediaController.inc b/controllers/MediaController.inc index 84818c0c..2670c69d 100644 --- a/controllers/MediaController.inc +++ b/controllers/MediaController.inc @@ -25,14 +25,15 @@ * @var array */ public $permissions = array( - 'index' => array('admin', 'moderator', 'user', 'guest'), - 'seminarymoodpic' => array('admin', 'moderator', 'user'), - 'seminarymap' => array('admin', 'moderator', 'user'), - 'seminary' => array('admin', 'moderator', 'user'), - 'avatar' => array('admin', 'moderator', 'user'), - 'achievement' => array('admin', 'moderator', 'user'), - 'charactergroup' => array('admin', 'moderator', 'user'), - 'charactergroupsquest' => array('admin', 'moderator', 'user') + 'index' => array('admin', 'moderator', 'user', 'guest'), + 'seminarymoodpic' => array('admin', 'moderator', 'user'), + 'seminarymap' => array('admin', 'moderator', 'user'), + 'seminary' => array('admin', 'moderator', 'user'), + 'avatar' => array('admin', 'moderator', 'user'), + 'achievement' => array('admin', 'moderator', 'user'), + 'charactergroup' => array('admin', 'moderator', 'user'), + 'charactergroupsquest' => array('admin', 'moderator', 'user'), + 'charactergroupsqueststation' => array('admin', 'moderator', 'user') ); /** * User seminary permissions @@ -40,17 +41,18 @@ * @var array */ public $seminaryPermissions = array( - 'seminary' => array('admin', 'moderator', 'user', 'guest'), - 'achievement' => array('admin', 'moderator', 'user', 'guest'), - 'charactergroup' => array('admin', 'moderator', 'user', 'guest'), - 'charactergroupsquest' => array('admin', 'moderator', 'user', 'guest') + 'seminary' => array('admin', 'moderator', 'user', 'guest'), + 'achievement' => array('admin', 'moderator', 'user', 'guest'), + 'charactergroup' => array('admin', 'moderator', 'user', 'guest'), + 'charactergroupsquest' => array('admin', 'moderator', 'user', 'guest'), + 'charactergroupsqueststation' => array('admin', 'moderator', 'user', 'guest') ); /** * Required models * * @var array */ - public $models = array('seminaries', 'achievements', 'media', 'avatars', 'charactergroups', 'charactergroupsquests', 'map'); + public $models = array('seminaries', 'achievements', 'media', 'avatars', 'charactergroups', 'charactergroupsquests', 'charactergroupsqueststations', 'map'); @@ -403,6 +405,47 @@ } + /** + * Action: charactergroupsqueststation + * + * Display the icon for a Character groups Quest Station. + * + * @throws \nre\exceptions\IdNotFoundException + * @param string $seminaryUrl URL-Title of a Seminary + * @param string $groupsgroupUrl URL-Title of a Character groups-group + * @param string $questUrl URL-Title of a Character groups Quest + * @param string $stationUrl URL-title of Station + */ + public function charactergroupsqueststation($seminaryUrl, $groupsgroupUrl, $questUrl, $stationUrl) + { + // Get seminary + $seminary = $this->Seminaries->getSeminaryByUrl($seminaryUrl); + + // Get Character groups-group + $groupsgroup = $this->Charactergroups->getGroupsgroupByUrl($seminary['id'], $groupsgroupUrl); + + // Get Character groups Quests + $quest = $this->Charactergroupsquests->getQuestByUrl($groupsgroup['id'], $questUrl); + + // Get Station + $station = $this->Charactergroupsqueststations->getStationByUrl($quest['id'], $stationUrl); + + // Get media + $media = $this->Media->getSeminaryMediaById($station['stationpicture_id']); + + // Get file + $file = $this->getMediaFile($media, 'charactergroupsqueststation'); + if(is_null($file)) { + return; + } + + + // Pass data to view + $this->set('media', $media); + $this->set('file', $file); + } + + /** @@ -495,6 +538,14 @@ \nre\configs\AppConfig::$media[$action]['height'] ); break; + case 'charactergroupsqueststation': + $file = self::resizeImage( + $media['filename'], + $format, + \nre\configs\AppConfig::$media[$action]['width'], + \nre\configs\AppConfig::$media[$action]['height'] + ); + break; default: throw new ParamsNotValidException($action); break; diff --git a/models/CharactergroupsqueststationsModel.inc b/models/CharactergroupsqueststationsModel.inc index 9169b5b0..8c28865a 100644 --- a/models/CharactergroupsqueststationsModel.inc +++ b/models/CharactergroupsqueststationsModel.inc @@ -184,6 +184,33 @@ } + /** + * Check if a Character group has entered a Station. + * + * @param int $stationId ID of Station to check + * @param int $groupId ID of Character group to check + * @return bool Whether the group has tried the station or not + */ + public function hasCharactergroupEnteredStation($stationId, $groupId) + { + $data = $this->db->query( + 'SELECT created '. + 'FROM charactergroupsqueststations_charactergroups '. + 'WHERE charactergroupsqueststation_id = ? AND charactergroup_id = ? AND status >= ?', + 'iii', + $stationId, + $groupId, + self::STATUS_ENTERED + ); + if(!empty($data)) { + return $data[0]['created']; + } + + + return false; + } + + /** * Check if a Character group has tried to solve a Station. * diff --git a/views/binary/media/charactergroupsqueststation.tpl b/views/binary/media/charactergroupsqueststation.tpl new file mode 100644 index 00000000..0d6fb0df --- /dev/null +++ b/views/binary/media/charactergroupsqueststation.tpl @@ -0,0 +1 @@ + diff --git a/views/html/charactergroupsquests/quest.tpl b/views/html/charactergroupsquests/quest.tpl index 85f4d48d..be47e89f 100644 --- a/views/html/charactergroupsquests/quest.tpl +++ b/views/html/charactergroupsquests/quest.tpl @@ -78,27 +78,42 @@ -
  1. - - - format(new \DateTime($station['created']))?> - format(new \DateTime($station['created']))?> - - + + + + + + + + -
- -

.

- + +
    + +
  1. + + + + + + + + + + + +
  2. + +
diff --git a/views/html/charactergroupsqueststations/station.tpl b/views/html/charactergroupsqueststations/station.tpl index 80c2a5ab..03bf37db 100644 --- a/views/html/charactergroupsqueststations/station.tpl +++ b/views/html/charactergroupsqueststations/station.tpl @@ -13,9 +13,7 @@ -

- @@ -94,8 +96,8 @@ - format(new \DateTime($group['solved']))))?> + diff --git a/www/css/desktop.css b/www/css/desktop.css index 1bc60fc0..ab08792a 100644 --- a/www/css/desktop.css +++ b/www/css/desktop.css @@ -298,6 +298,9 @@ input[type="submit"][disabled]{text-shadow:1px 2px #d48c4e;background:#f9ac69;bo .grpqlist .date{padding:0 15px 0 0;display:block} .grpqlist .xp{display:block} .gqgllry li{display:inline-block} +.grpqslist li{display:inline-block;width:100px;height:100px} +.grpqslist li a{color:#5e5c58} +.grpqslist li i{font-size:100px;padding:0} /** Achievements **/ From f28581e695154f7e4f73df1cd70ffead91560bf3 Mon Sep 17 00:00:00 2001 From: oliver Date: Fri, 22 Jan 2016 20:55:15 +0100 Subject: [PATCH 2/3] set permissions for CRUD actions of Character groups Quest Stations --- .../CharactergroupsqueststationsController.inc | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/controllers/CharactergroupsqueststationsController.inc b/controllers/CharactergroupsqueststationsController.inc index 6a6da2e3..ba182e85 100644 --- a/controllers/CharactergroupsqueststationsController.inc +++ b/controllers/CharactergroupsqueststationsController.inc @@ -39,7 +39,11 @@ */ public $permissions = array( 'index' => array('admin', 'moderator', 'user'), - 'station' => array('admin', 'moderator', 'user') + 'station' => array('admin', 'moderator', 'user'), + 'create' => array('admin', 'moderator', 'user'), + 'edit' => array('admin', 'moderator', 'user'), + 'edittask' => array('admin', 'moderator', 'user'), + 'delete' => array('admin', 'moderator', 'user') ); /** * User seminary permissions @@ -48,7 +52,11 @@ */ public $seminaryPermissions = array( 'index' => array('admin', 'moderator', 'user'), - 'station' => array('admin', 'moderator', 'user') + 'station' => array('admin', 'moderator', 'user'), + 'create' => array('admin', 'moderator'), + 'edit' => array('admin', 'moderator'), + 'edittask' => array('admin', 'moderator'), + 'delete' => array('admin', 'moderator') ); From 091d014815a611efcac376590200156c95de059a Mon Sep 17 00:00:00 2001 From: oliver Date: Sun, 24 Jan 2016 19:36:05 +0100 Subject: [PATCH 3/3] add media to right/wrong text of Character group Quest Stations --- configs/AppConfig.inc | 32 +++ ...CharactergroupsqueststationsController.inc | 241 +++++++++++++++++- db/create.sql | 14 +- models/CharactergroupsqueststationsModel.inc | 79 +++++- models/MediaModel.inc | 40 +++ .../charactergroupsqueststations/create.tpl | 53 +++- .../charactergroupsqueststations/edit.tpl | 86 ++++++- .../charactergroupsqueststations/station.tpl | 24 ++ 8 files changed, 547 insertions(+), 22 deletions(-) diff --git a/configs/AppConfig.inc b/configs/AppConfig.inc index fc5233b3..a412bf7b 100644 --- a/configs/AppConfig.inc +++ b/configs/AppConfig.inc @@ -164,6 +164,38 @@ 'mimetype' => 'image/png', 'size' => 10485760 ) + ), + 'stationimages' => array( + array( + 'mimetype' => 'image/jpeg', + 'size' => 1048576 + ), + array( + 'mimetype' => 'image/png', + 'size' => 2097152 + ) + ), + 'stationavs' => array( + array( + 'mimetype' => 'audio/mpeg', + 'size' => 2097152 + ), + array( + 'mimetype' => 'audio/ogg', + 'size' => 2097152 + ), + array( + 'mimetype' => 'audio/opus', + 'size' => 2097152 + ), + array( + 'mimetype' => 'video/mp4', + 'size' => 2097152 + ), + array( + 'mimetype' => 'video/webm', + 'size' => 2097152 + ) ) ); diff --git a/controllers/CharactergroupsqueststationsController.inc b/controllers/CharactergroupsqueststationsController.inc index ba182e85..db71f747 100644 --- a/controllers/CharactergroupsqueststationsController.inc +++ b/controllers/CharactergroupsqueststationsController.inc @@ -133,6 +133,20 @@ // Get Station $station = $this->Charactergroupsqueststations->getStationByUrl($quest['id'], $stationUrl); + // Get media + if(!is_null($station['rightimage_id'])) { + $station['rightimage'] = $this->Media->getSeminaryMediaById($station['rightimage_id']); + } + if(!is_null($station['rightav_id'])) { + $station['rightav'] = $this->Media->getSeminaryMediaById($station['rightav_id']); + } + if(!is_null($station['wrongimage_id'])) { + $station['wrongimage'] = $this->Media->getSeminaryMediaById($station['wrongimage_id']); + } + if(!is_null($station['wrongav_id'])) { + $station['wrongav'] = $this->Media->getSeminaryMediaById($station['wrongav_id']); + } + // Get Character group $charactergroup = null; $character = $this->Characters->getCharacterForUserAndSeminary($this->Auth->getUserId(), $seminary['id']); @@ -233,7 +247,9 @@ } // Get allowed mimetypes - $mimetypes = \nre\configs\AppConfig::$mimetypes['icons']; + $iconMimetypes = \nre\configs\AppConfig::$mimetypes['icons']; + $imageMimetypes = \nre\configs\AppConfig::$mimetypes['stationimages']; + $avMimetypes = \nre\configs\AppConfig::$mimetypes['stationavs']; // Values $title = ''; @@ -243,6 +259,12 @@ $latitude = null; $rightText = ''; $wrongText = ''; + $textMedia = array( + 'rightimage' => null, + 'rightav' => null, + 'wrongimage' => null, + 'wrongav' => null + ); $fields = array('title'); $validation = array(); @@ -289,7 +311,7 @@ // Check mimetype $mediaMimetype = null; $icon['mimetype'] = \hhu\z\Utils::getMimetype($icon['tmp_name'], $icon['type']); - foreach($mimetypes as &$mimetype) { + foreach($iconMimetypes as &$mimetype) { if($mimetype['mimetype'] == $icon['mimetype']) { $mediaMimetype = $mimetype; break; @@ -303,6 +325,51 @@ } } + // Validate media + if(!empty($_FILES)) + { + foreach(array_keys($textMedia) as $mediumKey) + { + if(array_key_exists($mediumKey, $_FILES) && $_FILES[$mediumKey]['error'] != UPLOAD_ERR_NO_FILE) + { + $mediumValidation = true; + $medium = $_FILES[$mediumKey]; + + // Check error + if($medium['error'] !== UPLOAD_ERR_OK) { + $mediumValidation = $this->Validation->addValidationResults($mediumValidation, 'error', $medium['error']); + } + else + { + // Check mimetype + $mediaMimetype = null; + $medium['mimetype'] = \hhu\z\Utils::getMimetype($medium['tmp_name'], $medium['type']); + $mediaMimetypes = (strpos($mediumKey, 'image') !== false) ? $imageMimetypes : $avMimetypes; + foreach($mediaMimetypes as &$mimetype) { + if($mimetype['mimetype'] == $medium['mimetype']) { + $mediaMimetype = $mimetype; + break; + } + } + if(is_null($mediaMimetype)) { + $mediumValidation = $this->Validation->addValidationResults($mediumValidation, 'mimetype', $medium['mimetype']); + } + elseif($medium['size'] > $mediaMimetype['size']) { + $mediumValidation = $this->Validation->addValidationResults($mediumValidation, 'size', $mediaMimetype['size']); + } + + if($validation == true) { + $textMedia[$mediumKey] = $medium; + } + } + + if($mediumValidation !== true) { + $validation = $this->Validation->addValidationResults($validation, $mediumKey, $mediumValidation); + } + } + } + } + // Create new Station if($validation === true) { @@ -335,6 +402,50 @@ } } + // Upload media + $textMediaIds = array(); + foreach($textMedia as $mediumKey => $medium) + { + if(!is_null($medium)) + { + $mediaId = $this->Media->createStationMedia( + $this->Auth->getUserId(), + $seminary['id'], + sprintf('station-%d-%s', $station['id'], $mediumKey), + $medium['name'], + $medium['type'], + $medium['tmp_name'] + ); + $textMediaIds[$mediumKey] = $mediaId; + } + } + + // Set media + if(array_key_exists('rightimage', $textMediaIds)) { + $this->Charactergroupsqueststations->setRightImageForStation( + $station['id'], + $textMediaIds['rightimage'] + ); + } + if(array_key_exists('rightav', $textMediaIds)) { + $this->Charactergroupsqueststations->setRightAvForStation( + $station['id'], + $textMediaIds['rightav'] + ); + } + if(array_key_exists('wrongimage', $textMediaIds)) { + $this->Charactergroupsqueststations->setWrongImageForStation( + $station['id'], + $textMediaIds['wrongimage'] + ); + } + if(array_key_exists('wrongav', $textMediaIds)) { + $this->Charactergroupsqueststations->setWrongAvForStation( + $station['id'], + $textMediaIds['wrongav'] + ); + } + // Redirect to Station page $this->redirect( $this->linker->link( @@ -369,7 +480,9 @@ $this->set('latitude', $latitude); $this->set('righttext', $rightText); $this->set('wrongtext', $wrongText); - $this->set('mimetypes', $mimetypes); + $this->set('iconMimetypes', $iconMimetypes); + $this->set('imageMimetypes', $imageMimetypes); + $this->set('avMimetypes', $avMimetypes); $this->set('stationtypes', $stationtypes); $this->set('validation', $validation); } @@ -400,6 +513,20 @@ // Get Station $station = $this->Charactergroupsqueststations->getStationByUrl($quest['id'], $stationUrl); + // Get media + if(!is_null($station['rightimage_id'])) { + $station['rightimage'] = $this->Media->getSeminaryMediaById($station['rightimage_id']); + } + if(!is_null($station['rightav_id'])) { + $station['rightav'] = $this->Media->getSeminaryMediaById($station['rightav_id']); + } + if(!is_null($station['wrongimage_id'])) { + $station['wrongimage'] = $this->Media->getSeminaryMediaById($station['wrongimage_id']); + } + if(!is_null($station['wrongav_id'])) { + $station['wrongav'] = $this->Media->getSeminaryMediaById($station['wrongav_id']); + } + // Get Quest types $stationtypes = $this->Stationtypes->getStationtypes(); foreach($stationtypes as &$stationtype) { @@ -407,7 +534,9 @@ } // Get allowed mimetypes - $mimetypes = \nre\configs\AppConfig::$mimetypes['icons']; + $iconMimetypes = \nre\configs\AppConfig::$mimetypes['icons']; + $imageMimetypes = \nre\configs\AppConfig::$mimetypes['stationimages']; + $avMimetypes = \nre\configs\AppConfig::$mimetypes['stationavs']; // Values $title = $station['title']; @@ -417,6 +546,12 @@ $latitude = $station['latitude']; $rightText = $station['righttext']; $wrongText = $station['wrongtext']; + $textMedia = array( + 'rightimage' => null, + 'rightav' => null, + 'wrongimage' => null, + 'wrongav' => null + ); $fields = array('title'); $validation = array(); @@ -463,7 +598,7 @@ // Check mimetype $mediaMimetype = null; $icon['mimetype'] = \hhu\z\Utils::getMimetype($icon['tmp_name'], $icon['type']); - foreach($mimetypes as &$mimetype) { + foreach($iconMimetypes as &$mimetype) { if($mimetype['mimetype'] == $icon['mimetype']) { $mediaMimetype = $mimetype; break; @@ -477,6 +612,51 @@ } } + // Validate media + if(!empty($_FILES)) + { + foreach(array_keys($textMedia) as $mediumKey) + { + if(array_key_exists($mediumKey, $_FILES) && $_FILES[$mediumKey]['error'] != UPLOAD_ERR_NO_FILE) + { + $mediumValidation = true; + $medium = $_FILES[$mediumKey]; + + // Check error + if($medium['error'] !== UPLOAD_ERR_OK) { + $mediumValidation = $this->Validation->addValidationResults($mediumValidation, 'error', $medium['error']); + } + else + { + // Check mimetype + $mediaMimetype = null; + $medium['mimetype'] = \hhu\z\Utils::getMimetype($medium['tmp_name'], $medium['type']); + $mediaMimetypes = (strpos($mediumKey, 'image') !== false) ? $imageMimetypes : $avMimetypes; + foreach($mediaMimetypes as &$mimetype) { + if($mimetype['mimetype'] == $medium['mimetype']) { + $mediaMimetype = $mimetype; + break; + } + } + if(is_null($mediaMimetype)) { + $mediumValidation = $this->Validation->addValidationResults($mediumValidation, 'mimetype', $medium['mimetype']); + } + elseif($medium['size'] > $mediaMimetype['size']) { + $mediumValidation = $this->Validation->addValidationResults($mediumValidation, 'size', $mediaMimetype['size']); + } + + if($validation == true) { + $textMedia[$mediumKey] = $medium; + } + } + + if($mediumValidation !== true) { + $validation = $this->Validation->addValidationResults($validation, $mediumKey, $mediumValidation); + } + } + } + } + // Edit Station if($validation === true) { @@ -509,6 +689,50 @@ } } + // Upload media + $textMediaIds = array(); + foreach($textMedia as $mediumKey => $medium) + { + if(!is_null($medium)) + { + $mediaId = $this->Media->createStationMedia( + $this->Auth->getUserId(), + $seminary['id'], + sprintf('station-%d-%s', $station['id'], $mediumKey), + $medium['name'], + $medium['type'], + $medium['tmp_name'] + ); + $textMediaIds[$mediumKey] = $mediaId; + } + } + + // Set media + if(array_key_exists('rightimage', $textMediaIds)) { + $this->Charactergroupsqueststations->setRightImageForStation( + $station['id'], + $textMediaIds['rightimage'] + ); + } + if(array_key_exists('rightav', $textMediaIds)) { + $this->Charactergroupsqueststations->setRightAvForStation( + $station['id'], + $textMediaIds['rightav'] + ); + } + if(array_key_exists('wrongimage', $textMediaIds)) { + $this->Charactergroupsqueststations->setWrongImageForStation( + $station['id'], + $textMediaIds['wrongimage'] + ); + } + if(array_key_exists('wrongav', $textMediaIds)) { + $this->Charactergroupsqueststations->setWrongAvForStation( + $station['id'], + $textMediaIds['wrongav'] + ); + } + // Redirect if(!is_null($this->request->getPostParam('edit-task'))) { // To task editing @@ -555,6 +779,7 @@ $this->set('seminary', $seminary); $this->set('groupsgroup', $groupsgroup); $this->set('quest', $quest); + $this->set('station', $station); $this->set('title', $title); $this->set('prolog', $prolog); $this->set('task', $task); @@ -562,14 +787,16 @@ $this->set('latitude', $latitude); $this->set('righttext', $rightText); $this->set('wrongtext', $wrongText); - $this->set('mimetypes', $mimetypes); + $this->set('iconMimetypes', $iconMimetypes); + $this->set('imageMimetypes', $imageMimetypes); + $this->set('avMimetypes', $avMimetypes); $this->set('stationtypes', $stationtypes); $this->set('validation', $validation); } /** - * TODO Action: edittask. + * Action: edittask. * * Edit the task of a Character groups Quest Station. * diff --git a/db/create.sql b/db/create.sql index cb2f4b87..1fe09b2e 100644 --- a/db/create.sql +++ b/db/create.sql @@ -590,15 +590,27 @@ CREATE TABLE `charactergroupsqueststations` ( `longitude` decimal(10,6) DEFAULT NULL, `righttext` text COLLATE utf8mb4_unicode_ci NOT NULL, `wrongtext` text COLLATE utf8mb4_unicode_ci NOT NULL, + `rightimage_id` int(11) DEFAULT NULL, + `rightav_id` int(11) DEFAULT NULL, + `wrongimage_id` int(11) DEFAULT NULL, + `wrongav_id` int(11) DEFAULT NULL, PRIMARY KEY (`id`), UNIQUE KEY `charactergroupsquest_id_2` (`charactergroupsquest_id`,`url`), UNIQUE KEY `charactergroupsquest_id_3` (`charactergroupsquest_id`,`pos`), KEY `charactergroupsquest_id` (`charactergroupsquest_id`), KEY `charactergroupsqueststationtype_id` (`stationtype_id`), KEY `stationpicture_id` (`stationpicture_id`) USING BTREE, + KEY `rightimage_id` (`rightimage_id`), + KEY `rightav_id` (`rightav_id`), + KEY `wrongimage_id` (`wrongimage_id`), + KEY `wrongav_id` (`wrongav_id`), CONSTRAINT `charactergroupsqueststations_ibfk_1` FOREIGN KEY (`charactergroupsquest_id`) REFERENCES `charactergroupsquests` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `charactergroupsqueststations_ibfk_2` FOREIGN KEY (`stationpicture_id`) REFERENCES `seminarymedia` (`id`) ON DELETE SET NULL ON UPDATE SET NULL, - CONSTRAINT `charactergroupsqueststations_ibfk_3` FOREIGN KEY (`stationtype_id`) REFERENCES `stationtypes` (`id`) + CONSTRAINT `charactergroupsqueststations_ibfk_3` FOREIGN KEY (`stationtype_id`) REFERENCES `stationtypes` (`id`), + CONSTRAINT `charactergroupsqueststations_ibfk_4` FOREIGN KEY (`rightimage_id`) REFERENCES `seminarymedia` (`id`) ON DELETE SET NULL ON UPDATE SET NULL, + CONSTRAINT `charactergroupsqueststations_ibfk_5` FOREIGN KEY (`rightav_id`) REFERENCES `seminarymedia` (`id`) ON DELETE SET NULL ON UPDATE SET NULL, + CONSTRAINT `charactergroupsqueststations_ibfk_6` FOREIGN KEY (`wrongimage_id`) REFERENCES `seminarymedia` (`id`) ON DELETE SET NULL ON UPDATE SET NULL, + CONSTRAINT `charactergroupsqueststations_ibfk_7` FOREIGN KEY (`wrongav_id`) REFERENCES `seminarymedia` (`id`) ON DELETE SET NULL ON UPDATE SET NULL ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; diff --git a/models/CharactergroupsqueststationsModel.inc b/models/CharactergroupsqueststationsModel.inc index 8c28865a..7aee5f95 100644 --- a/models/CharactergroupsqueststationsModel.inc +++ b/models/CharactergroupsqueststationsModel.inc @@ -63,7 +63,7 @@ public function getStationById($stationId) { $data = $this->db->query( - 'SELECT id, charactergroupsquest_id, stationtype_id, title, url, stationpicture_id, prolog, task, latitude, longitude, righttext, wrongtext '. + 'SELECT id, charactergroupsquest_id, stationtype_id, title, url, stationpicture_id, prolog, task, latitude, longitude, righttext, wrongtext, rightimage_id, rightav_id, wrongimage_id, wrongav_id '. 'FROM charactergroupsqueststations '. 'WHERE id = ?', 'i', @@ -88,7 +88,7 @@ public function getStationByUrl($groupsquestId, $stationUrl) { $data = $this->db->query( - 'SELECT id, charactergroupsquest_id, stationtype_id, title, url, stationpicture_id, prolog, task, latitude, longitude, righttext, wrongtext '. + 'SELECT id, charactergroupsquest_id, stationtype_id, title, url, stationpicture_id, prolog, task, latitude, longitude, righttext, wrongtext, rightimage_id, rightav_id, wrongimage_id, wrongav_id '. 'FROM charactergroupsqueststations '. 'WHERE charactergroupsquest_id = ? AND url = ?', 'is', @@ -296,7 +296,7 @@ * @param int $stationId ID of Station to upload media for * @param int $mediaId ID of Station media */ - public function setPictureForStation($station, $mediaId) + public function setPictureForStation($stationId, $mediaId) { $this->db->query( 'UPDATE charactergroupsqueststations '. @@ -304,11 +304,59 @@ 'WHERE id = ?', 'ii', $mediaId, - $station + $stationId ); } + /** + * Set the image for the right-text. + * + * @param int $stationId ID of Station to set image for + * @param int $mediaId ID of Seminary media to set + */ + public function setRightImageForStation($stationId, $mediaId) + { + $this->setMediaForStation($stationId, $mediaId, 'rightimage_id'); + } + + + /** + * Set the audio/video for the right-text. + * + * @param int $stationId ID of Station to set audio/video for + * @param int $mediaId ID of Seminary media to set + */ + public function setRightAVForStation($stationId, $mediaId) + { + $this->setMediaForStation($stationId, $mediaId, 'rightav_id'); + } + + + /** + * Set the image for the wrong-text. + * + * @param int $stationId ID of Station to set image for + * @param int $mediaId ID of Seminary media to set + */ + public function setWrongImageForStation($stationId, $mediaId) + { + $this->setMediaForStation($stationId, $mediaId, 'wrongimage_id'); + } + + + /** + * Set the audio/video for the wrong-text. + * + * @param int $stationId ID of Station to set audio/video for + * @param int $mediaId ID of Seminary media to set + */ + public function setWrongAvForStation($stationId, $mediaId) + { + $this->setMediaForStation($stationId, $mediaId, 'wrongav_id'); + } + + /** * Create a new Character groups Quest Station. * @@ -437,6 +485,29 @@ ); } + + /** + * Add a medium for a Character groups Quest Station. + * + * @param int $stationId ID of Station to upload media for + * @param int $mediaId ID of Seminary media + * @param string $field Field name to set media to + */ + private function setMediaForStation($stationId, $mediaId, $field) + { + $this->db->query( + sprintf( + 'UPDATE charactergroupsqueststations '. + 'SET %s = ? '. + 'WHERE id = ?', + $field + ), + 'ii', + $mediaId, + $stationId + ); + } + } ?> diff --git a/models/MediaModel.inc b/models/MediaModel.inc index 61125d36..b4ae0bec 100644 --- a/models/MediaModel.inc +++ b/models/MediaModel.inc @@ -557,6 +557,46 @@ } + /** + * Create a new Character groups Quest Station media by creating a new + * Seminarymedia . + * + * @param int $userId ID of user that does the upload + * @param int $seminaryId ID of Seminary + * @param string $filename Filename of uploading media + * @param string $description Description for media + * @param string $mimetype Mimetype of media + * @param string $tmpFilename Name of temporary uploaded file + * @return mixed ID of media record or false if upload failed + */ + public function createStationMedia($userId, $seminaryId, $filename, $description, $mimetype, $tmpFilename) + { + $mediaId = false; + $this->db->setAutocommit(false); + + try { + // Create Seminary media record + $mediaId = $this->createSeminaryMedia($userId, $seminaryId, $filename, $description, $mimetype); + + // Create filename + $filename = ROOT.DS.\nre\configs\AppConfig::$dirs['seminarymedia'].DS.$mediaId; + if(!move_uploaded_file($tmpFilename, $filename)) + { + $this->db->rollback(); + $mediaId = false; + } + } + catch(\nre\exceptions\DatamodelException $e) { + $this->db->rollback(); + $this->db->setAutocommit(true); + } + + + $this->db->setAutocommit(true); + return $mediaId; + } + + /** * Create a new Achievement media by creating a new Seminarymedia and * adding it to the list of media for Achievements. diff --git a/views/html/charactergroupsqueststations/create.tpl b/views/html/charactergroupsqueststations/create.tpl index c46c3374..cdca96b8 100644 --- a/views/html/charactergroupsqueststations/create.tpl +++ b/views/html/charactergroupsqueststations/create.tpl @@ -39,6 +39,20 @@ default: echo _('Title invalid'); } break; + case 'rightimage': + case 'rightav': + case 'wrongimage': + case 'wrongav': + switch($setting) { + case 'error': printf(_('Error during file upload: %s'), $value); + break; + case 'mimetype': printf(_('File has wrong type “%s”'), $value); + break; + case 'size': echo _('File exceeds size maximum'); + break; + default: echo _('File invalid'); + } + break; } ?> @@ -53,7 +67,7 @@

:

    - +
  • 0) : ?>(  MiB)
@@ -65,6 +79,9 @@
+ + + /> -
-
- - />



+
+
+ + +
    + +
  • 0) : ?>(  MiB)
  • + +
+ +
    + +
  • 0) : ?>(  MiB)
  • + +


+
+
+ + +
    + +
  • 0) : ?>(  MiB)
  • + +
+ +
    + +
  • 0) : ?>(  MiB)
  • + +


diff --git a/views/html/charactergroupsqueststations/edit.tpl b/views/html/charactergroupsqueststations/edit.tpl index 08c96a0e..e7466776 100644 --- a/views/html/charactergroupsqueststations/edit.tpl +++ b/views/html/charactergroupsqueststations/edit.tpl @@ -39,6 +39,20 @@ default: echo _('Title invalid'); } break; + case 'rightimage': + case 'rightav': + case 'wrongimage': + case 'wrongav': + switch($setting) { + case 'error': printf(_('Error during file upload: %s'), $value); + break; + case 'mimetype': printf(_('File has wrong type “%s”'), $value); + break; + case 'size': echo _('File exceeds size maximum'); + break; + default: echo _('File invalid'); + } + break; } ?> @@ -53,7 +67,7 @@

:

    - +
  • 0) : ?>(  MiB)
@@ -65,6 +79,9 @@
+ + + /> -
-
- - />



+
+ + + + + + +
+ +
+ +
    + +
  • 0) : ?>(  MiB)
  • + +
+ + + + + + + +
+ + +
    + +
  • 0) : ?>(  MiB)
  • + +


+
+
+ + + + + + +
+ +
+ +
    + +
  • 0) : ?>(  MiB)
  • + +
+ + + + + + + +
+ + +
    + +
  • 0) : ?>(  MiB)
  • + +


diff --git a/views/html/charactergroupsqueststations/station.tpl b/views/html/charactergroupsqueststations/station.tpl index 03bf37db..d773a8ff 100644 --- a/views/html/charactergroupsqueststations/station.tpl +++ b/views/html/charactergroupsqueststations/station.tpl @@ -122,10 +122,34 @@
+ + + +
+ + + + + + + + t($station['righttext'])?>
+ + + +
+ + + + + + + + t($station['wrongtext'])?>