implement CRUD for Seminaries (resolves issue #33)
This commit is contained in:
parent
47270f8391
commit
a4ccb74e8c
9 changed files with 484 additions and 46 deletions
|
|
@ -135,6 +135,45 @@
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create a new moodpic.
|
||||
*
|
||||
* @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 createMoodpic($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);
|
||||
|
||||
// Upload file
|
||||
$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 Quests media by creating a new Seminarymedia and
|
||||
* adding it to the list of Quests media.
|
||||
|
|
|
|||
|
|
@ -133,23 +133,49 @@
|
|||
|
||||
|
||||
/**
|
||||
* Create a new seminary.
|
||||
* Check if a Seminary title already exists.
|
||||
*
|
||||
* @param string $title Title of seminary to create
|
||||
* @param int $userId ID of creating user
|
||||
* @return int ID of the newly created seminary
|
||||
* @param string $title Seminary title to check
|
||||
* @param int $seminaryId Do not check this ID (for editing)
|
||||
* @return boolean Whether Seminary title exists or not
|
||||
*/
|
||||
public function createSeminary($title, $userId)
|
||||
public function seminaryTitleExists($title, $seminaryId=null)
|
||||
{
|
||||
$data = $this->db->query(
|
||||
'SELECT id '.
|
||||
'FROM seminaries '.
|
||||
'WHERE title = ? OR url = ?',
|
||||
'ss',
|
||||
$title,
|
||||
\nre\core\Linker::createLinkParam($title)
|
||||
);
|
||||
|
||||
return (!empty($data) && (is_null($seminaryId) || $seminaryId != $data[0]['id']));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create a new Seminary.
|
||||
*
|
||||
* @param int $userId ID of creating user
|
||||
* @param string $title Title of Seminary to create
|
||||
* @param string $course Course of Seminary
|
||||
* @param string $description Description of new Seminary
|
||||
* @return int ID of the newly created Seminary
|
||||
*/
|
||||
public function createSeminary($userId, $title, $course, $description)
|
||||
{
|
||||
$this->db->query(
|
||||
'INSERT INTO seminaries '.
|
||||
'(created_user_id, title, url) '.
|
||||
'(created_user_id, title, url, course, description) '.
|
||||
'VALUES '.
|
||||
'(?, ?, ?)',
|
||||
'iss',
|
||||
'(?, ?, ?, ?, ?)',
|
||||
'issss',
|
||||
$userId,
|
||||
$title,
|
||||
\nre\core\Linker::createLinkParam($title)
|
||||
\nre\core\Linker::createLinkParam($title),
|
||||
$course,
|
||||
$description
|
||||
);
|
||||
|
||||
|
||||
|
|
@ -158,21 +184,44 @@
|
|||
|
||||
|
||||
/**
|
||||
* Edit a seminary.
|
||||
* Set the moodpic for a Seminary.
|
||||
*
|
||||
* @throws DatamodelException
|
||||
* @param int $seminaryId ID of the seminary to delete
|
||||
* @param string $title New title of seminary
|
||||
* @param int $seminaryId ID of Seminary to set moodpic for
|
||||
* @param int $mediaId ID of moodpic media
|
||||
*/
|
||||
public function editSeminary($seminaryId, $title)
|
||||
public function setMoodpicForSeminary($seminaryId, $mediaId)
|
||||
{
|
||||
$this->db->query(
|
||||
'UPDATE seminaries '.
|
||||
'SET title = ?, url = ? '.
|
||||
'SET seminarymedia_id = ? '.
|
||||
'WHERE id = ?',
|
||||
'ssi',
|
||||
'ii',
|
||||
$mediaId,
|
||||
$seminaryId
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Edit a seminary.
|
||||
*
|
||||
* @throws DatamodelException
|
||||
* @param int $seminaryId ID of Seminary to delete
|
||||
* @param string $title New title of Seminary
|
||||
* @param string $course New course of Seminary
|
||||
* @param string $description New description of Seminary
|
||||
*/
|
||||
public function editSeminary($seminaryId, $title, $course, $description)
|
||||
{
|
||||
$this->db->query(
|
||||
'UPDATE seminaries '.
|
||||
'SET title = ?, url = ?, course = ?, description = ? '.
|
||||
'WHERE id = ?',
|
||||
'ssssi',
|
||||
$title,
|
||||
\nre\core\Linker::createLinkParam($title),
|
||||
$course,
|
||||
$description,
|
||||
$seminaryId
|
||||
);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue