From 05a1daf177a4aa7609734de65fb4165cd7b24e62 Mon Sep 17 00:00:00 2001 From: oliver Date: Sat, 9 Apr 2016 16:20:29 +0200 Subject: [PATCH] use AppConfig instead of database table to configure mimetypes for questtype ?Submit? --- configs/AppConfig.inc | 4 ++++ db/create.sql | 23 ------------------- questtypes/submit/SubmitQuesttypeModel.inc | 26 ++++++++++++++-------- 3 files changed, 21 insertions(+), 32 deletions(-) diff --git a/configs/AppConfig.inc b/configs/AppConfig.inc index a9b6f7f3..4c3ab885 100644 --- a/configs/AppConfig.inc +++ b/configs/AppConfig.inc @@ -153,6 +153,10 @@ array( 'mimetype' => 'image/png', 'size' => 1048576 + ), + array( + 'mimetype' => 'application/pdf', + 'size' => 1048576 ) ), 'map' => array( diff --git a/db/create.sql b/db/create.sql index eb88e859..b6c1edc6 100644 --- a/db/create.sql +++ b/db/create.sql @@ -1865,29 +1865,6 @@ CREATE TABLE `questtypes_submit_characters_comments` ( ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; --- --- Table structure for table `questtypes_submit_mimetypes` --- - -DROP TABLE IF EXISTS `questtypes_submit_mimetypes`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `questtypes_submit_mimetypes` ( - `id` int(11) NOT NULL AUTO_INCREMENT, - `created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, - `created_user_id` int(11) NOT NULL, - `seminary_id` int(11) NOT NULL, - `mimetype` varchar(32) COLLATE utf8mb4_unicode_ci NOT NULL, - `size` int(10) unsigned NOT NULL DEFAULT '0', - PRIMARY KEY (`id`), - UNIQUE KEY `mimetype` (`mimetype`,`seminary_id`), - KEY `created_user_id` (`created_user_id`), - KEY `seminary_id` (`seminary_id`), - CONSTRAINT `questtypes_submit_mimetypes_ibfk_1` FOREIGN KEY (`created_user_id`) REFERENCES `users` (`id`), - CONSTRAINT `questtypes_submit_mimetypes_ibfk_2` FOREIGN KEY (`seminary_id`) REFERENCES `seminaries` (`id`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; -/*!40101 SET character_set_client = @saved_cs_client */; - -- -- Table structure for table `questtypes_submit_similarities` -- diff --git a/questtypes/submit/SubmitQuesttypeModel.inc b/questtypes/submit/SubmitQuesttypeModel.inc index 98d618bb..7b829511 100644 --- a/questtypes/submit/SubmitQuesttypeModel.inc +++ b/questtypes/submit/SubmitQuesttypeModel.inc @@ -25,6 +25,12 @@ * @var float */ const SIMILARITY_MIN = 0.8; + /** + * Supported mimetypes + * + * @var array + */ + const mimetypes = array('application/pdf'); /** * Required models @@ -144,18 +150,20 @@ /** * Get allowed mimetypes for uploading a file. * - * @param int $seminaryId ID of Seminary - * @return array Allowed mimetypes + * @param int $seminaryId ID of Seminary + * @return array Allowed mimetypes */ public function getAllowedMimetypes($seminaryId) { - return $this->db->query( - 'SELECT id, mimetype, size '. - 'FROM questtypes_submit_mimetypes '. - 'WHERE seminary_id = ?', - 'i', - $seminaryId - ); + $mimetypes = array(); + foreach(\nre\configs\AppConfig::$mimetypes['questtypes'] as $mimetype) { + if(in_array($mimetype['mimetype'], self::mimetypes)) { + $mimetypes[] = $mimetype; + } + } + + + return $mimetypes; }