merge branch ?charactergroupsqueststations?

This commit is contained in:
oliver 2016-01-28 22:33:53 +01:00
commit ba97244b15
13 changed files with 700 additions and 59 deletions

View file

@ -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',
@ -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.
*
@ -269,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 '.
@ -277,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.
*
@ -410,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
);
}
}
?>

View file

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