use AppConfig instead of database table to configure mimetypes for questtype ?Submit?

This commit is contained in:
oliver 2016-04-09 16:20:29 +02:00
parent 37d33bc636
commit 05a1daf177
3 changed files with 21 additions and 32 deletions

View file

@ -153,6 +153,10 @@
array(
'mimetype' => 'image/png',
'size' => 1048576
),
array(
'mimetype' => 'application/pdf',
'size' => 1048576
)
),
'map' => array(

View file

@ -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`
--

View file

@ -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;
}