implement icons for Character groups Quests and improve media handilng for Character groups
This commit is contained in:
parent
75b81302ca
commit
072333c88b
12 changed files with 334 additions and 96 deletions
|
|
@ -230,6 +230,25 @@
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set the media for a Character groups Quest.
|
||||
*
|
||||
* @param int $questId ID of Quest to upload media for
|
||||
* @param int $mediaId ID of Quests media
|
||||
*/
|
||||
public function setMediaForQuest($questId, $mediaId)
|
||||
{
|
||||
$this->db->query(
|
||||
'UPDATE charactergroupsquests '.
|
||||
'SET questsmedia_id = ? '.
|
||||
'WHERE id = ?',
|
||||
'ii',
|
||||
$mediaId,
|
||||
$questId
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Upload a media for a Character groups Quest.
|
||||
*
|
||||
|
|
|
|||
|
|
@ -136,114 +136,30 @@
|
|||
|
||||
|
||||
/**
|
||||
* Create a new Questsmedia by creating a new Seminarymedia and
|
||||
* adding it to the list of Questsmedia.
|
||||
* TODO Currently only temporary for easier data import.
|
||||
* Create a new Quests media by creating a new Seminarymedia and
|
||||
* adding it to the list of Quests media.
|
||||
*
|
||||
* @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 createQuestMedia($userId, $seminaryId, $filename, $description, $mimetype, $tmpFilename)
|
||||
{
|
||||
$uploadId = false;
|
||||
$this->db->setAutocommit(false);
|
||||
|
||||
try {
|
||||
// Create database record
|
||||
$this->db->query(
|
||||
'INSERT INTO seminarymedia '.
|
||||
'(created_user_id, seminary_id, name, url, description, mimetype) '.
|
||||
'VALUES '.
|
||||
'(?, ? ,? ,?, ?, ?)',
|
||||
'iissss',
|
||||
$userId,
|
||||
$seminaryId,
|
||||
$filename,
|
||||
\nre\core\Linker::createLinkParam($filename),
|
||||
$description,
|
||||
$mimetype
|
||||
);
|
||||
$uploadId = $this->db->getInsertId();
|
||||
|
||||
$this->db->query(
|
||||
'INSERT INTO questsmedia '.
|
||||
'(media_id, created_user_id) '.
|
||||
'VALUES '.
|
||||
'(?, ?)',
|
||||
'ii',
|
||||
$uploadId,
|
||||
$userId
|
||||
);
|
||||
|
||||
// Create filename
|
||||
$filename = ROOT.DS.'seminarymedia'.DS.$uploadId;
|
||||
if(!move_uploaded_file($tmpFilename, $filename))
|
||||
{
|
||||
$this->db->rollback();
|
||||
$uploadId = false;
|
||||
}
|
||||
}
|
||||
catch(\nre\exceptions\DatamodelException $e) {
|
||||
$this->db->rollback();
|
||||
$this->db->setAutocommit(true);
|
||||
}
|
||||
|
||||
|
||||
$this->db->setAutocommit(true);
|
||||
return $uploadId;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create a new Character groups media by creating a new Seminarymedia and
|
||||
* adding it to the list of media for Character groups.
|
||||
*
|
||||
* @param int $userId
|
||||
* @param int $seminaryId
|
||||
* @param string $filename
|
||||
* @param string $description
|
||||
* @param string $mimetype
|
||||
* @param string $tmpFilename
|
||||
* @return
|
||||
*/
|
||||
public function createCharactergroupMedia($userId, $seminaryId, $filename, $description, $mimetype, $tmpFilename)
|
||||
{
|
||||
$mediaId = false;
|
||||
$this->db->setAutocommit(false);
|
||||
|
||||
try {
|
||||
// Check for existing database record
|
||||
$data = $this->db->query(
|
||||
'SELECT id '.
|
||||
'FROM seminarymedia '.
|
||||
'WHERE url = ?',
|
||||
's',
|
||||
\nre\core\Linker::createLinkParam($filename)
|
||||
);
|
||||
if(!empty($data)) {
|
||||
$mediaId = $data[0]['id'];
|
||||
}
|
||||
// Create Seminary media record
|
||||
$mediaId = $this->createSeminaryMedia($userId, $seminaryId, $filename, $description, $mimetype);
|
||||
|
||||
// Create database record
|
||||
if($mediaId === false)
|
||||
{
|
||||
$this->db->query(
|
||||
'INSERT INTO seminarymedia '.
|
||||
'(created_user_id, seminary_id, name, url, description, mimetype) '.
|
||||
'VALUES '.
|
||||
'(?, ? ,? ,?, ?, ?)',
|
||||
'iissss',
|
||||
$userId,
|
||||
$seminaryId,
|
||||
$filename,
|
||||
\nre\core\Linker::createLinkParam($filename),
|
||||
$description,
|
||||
$mimetype
|
||||
);
|
||||
$mediaId = $this->db->getInsertId();
|
||||
}
|
||||
|
||||
// Add media to Character groups media
|
||||
// Add media to Quests media
|
||||
$this->db->query(
|
||||
'INSERT INTO charactergroupsmedia '.
|
||||
'(seminarymedia_id, created_user_id) '.
|
||||
'INSERT INTO questsmedia '.
|
||||
'(media_id, created_user_id) '.
|
||||
'VALUES '.
|
||||
'(?, ?) '.
|
||||
'ON DUPLICATE KEY UPDATE '.
|
||||
|
|
@ -255,7 +171,7 @@
|
|||
);
|
||||
|
||||
// Create filename
|
||||
$filename = ROOT.DS.'seminarymedia'.DS.$mediaId;
|
||||
$filename = ROOT.DS.\nre\configs\AppConfig::$dirs['seminarymedia'].DS.$mediaId;
|
||||
if(!move_uploaded_file($tmpFilename, $filename))
|
||||
{
|
||||
$this->db->rollback();
|
||||
|
|
@ -272,6 +188,106 @@
|
|||
return $mediaId;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create a new Character groups media by creating a new Seminarymedia and
|
||||
* adding it to the list of media for Character groups.
|
||||
*
|
||||
* @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 createCharactergroupMedia($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);
|
||||
|
||||
// Add media to Character groups media
|
||||
$this->db->query(
|
||||
'INSERT INTO charactergroupsmedia '.
|
||||
'(seminarymedia_id, created_user_id) '.
|
||||
'VALUES '.
|
||||
'(?, ?) '.
|
||||
'ON DUPLICATE KEY UPDATE '.
|
||||
'created_user_id = ?',
|
||||
'iii',
|
||||
$mediaId,
|
||||
$userId,
|
||||
$userId
|
||||
);
|
||||
|
||||
// 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 Seminary media.
|
||||
*
|
||||
* @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
|
||||
* @return mixed ID of media record or false if upload failed
|
||||
*/
|
||||
private function createSeminaryMedia($userId, $seminaryId, $filename, $description, $mimetype)
|
||||
{
|
||||
// Check for existing database record
|
||||
$data = $this->db->query(
|
||||
'SELECT id '.
|
||||
'FROM seminarymedia '.
|
||||
'WHERE url = ?',
|
||||
's',
|
||||
\nre\core\Linker::createLinkParam($filename)
|
||||
);
|
||||
if(!empty($data)) {
|
||||
return $data[0]['id'];
|
||||
}
|
||||
|
||||
// Create database record
|
||||
$this->db->query(
|
||||
'INSERT INTO seminarymedia '.
|
||||
'(created_user_id, seminary_id, name, url, description, mimetype) '.
|
||||
'VALUES '.
|
||||
'(?, ? ,? ,?, ?, ?)',
|
||||
'iissss',
|
||||
$userId,
|
||||
$seminaryId,
|
||||
$filename,
|
||||
\nre\core\Linker::createLinkParam($filename),
|
||||
$description,
|
||||
$mimetype
|
||||
);
|
||||
|
||||
|
||||
return $this->db->getInsertId();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue