Skip to content
Snippets Groups Projects
Commit c14686ea authored by Jan-Hendrik Willms's avatar Jan-Hendrik Willms Committed by Jan-Hendrik Willms
Browse files

make course topic title and description translatable, fixes #401

parent d259140c
Branches
No related tags found
No related merge requests found
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
class Course_TopicsController extends AuthenticatedController class Course_TopicsController extends AuthenticatedController
{ {
protected $allow_nobody = true; protected $allow_nobody = true;
protected $_autobind = true;
public function before_filter(&$action, &$args) public function before_filter(&$action, &$args)
{ {
...@@ -13,136 +14,123 @@ class Course_TopicsController extends AuthenticatedController ...@@ -13,136 +14,123 @@ class Course_TopicsController extends AuthenticatedController
checkObject(); checkObject();
checkObjectModule("schedule"); checkObjectModule("schedule");
Navigation::activateItem('/course/schedule/topics');
PageLayout::setTitle(sprintf('%s - %s', Course::findCurrent()->getFullname(), _("Themen"))); PageLayout::setTitle(sprintf('%s - %s', Course::findCurrent()->getFullname(), _("Themen")));
$seminar = new Seminar(Course::findCurrent()); $seminar = new Seminar(Course::findCurrent());
$this->forum_activated = $seminar->getSlotModule('forum'); $this->forum_activated = $seminar->getSlotModule('forum');
$this->documents_activated = $seminar->getSlotModule('documents'); $this->documents_activated = $seminar->getSlotModule('documents');
if ($action !== 'index' && !$GLOBALS['perm']->have_studip_perm('tutor', Context::getId())) {
throw new AccessDeniedException();
}
$this->setupSidebar($action); $this->setupSidebar($action);
} }
public function index_action() public function index_action()
{ {
if (Request::isPost() && Request::get("edit") && $GLOBALS['perm']->have_studip_perm("tutor", Context::getId())) { $this->topics = CourseTopic::findBySeminar_id(Context::getId());
$topic = new CourseTopic(Request::option("issue_id")); $this->cancelled_dates_locked = LockRules::Check(Context::getId(), 'cancelled_dates');
if ($topic['seminar_id'] && ($topic['seminar_id'] !== Context::getId())) { }
throw new AccessDeniedException();
}
$topic['title'] = Request::get("title"); public function delete_action(CourseTopic $topic)
$topic['description'] = Studip\Markup::purifyHtml(Request::get("description")); {
$topic['paper_related'] = (bool) Request::int('paper_related'); if (!Request::isPost()) {
if ($topic->isNew()) { throw new MethodNotAllowedException();
$topic['seminar_id'] = Context::getId(); }
}
$topic->store();
//change dates for this topic if ($topic->seminar_id && ($topic->seminar_id !== Context::getId())) {
$former_date_ids = $topic->dates->pluck("termin_id"); throw new AccessDeniedException();
$new_date_ids = array_keys(Request::getArray("date")); }
foreach (array_diff($former_date_ids, $new_date_ids) as $delete_termin_id) {
$topic->dates->unsetByPk($delete_termin_id);
}
foreach (array_diff($new_date_ids, $former_date_ids) as $add_termin_id) {
$date = CourseDate::find($add_termin_id);
if ($date) {
$topic->dates[] = $date;
}
}
$topic->store();
if (Request::get("folder")) { if ($topic->delete()) {
$topic->connectWithDocumentFolder(); PageLayout::postSuccess(_('Thema gelöscht.'));
} }
// create a connection to the module forum (can be anything) $this->redirect('course/topics');
// will update title and description automagically }
if (Request::get("forumthread")) {
$topic->connectWithForumThread();
}
if (Request::option("issue_id") === "new") { public function edit_action(CourseTopic $topic = null)
Request::set("open", $topic->getId()); {
} PageLayout::setTitle($topic->isNew() ? _('Neues Thema erstellen') : sprintf(_('Bearbeiten: %s'), $topic->title));
PageLayout::postMessage(MessageBox::success(_("Thema gespeichert.")));
$this->redirect("course/topics/index"); $this->dates = CourseDate::findBySeminar_id(Context::getId());
}
public function store_action(CourseTopic $topic = null)
{
if (!Request::isPost()) {
throw new MethodNotAllowedException();
} }
if (Request::isPost() && Request::option("move_down")) { if ($topic->seminar_id && ($topic->seminar_id !== Context::getId())) {
$topics = CourseTopic::findBySeminar_id(Context::getId()); throw new AccessDeniedException();
$mainkey = null;
foreach ($topics as $key => $topic) {
if ($topic->getId() === Request::option("move_down")) {
$mainkey = $key;
}
$topic['priority'] = $key + 1;
}
if ($mainkey !== null && $mainkey < count($topics)) {
$topics[$mainkey]->priority++;
$topics[$mainkey + 1]->priority--;
}
foreach ($topics as $key => $topic) {
$topic->store();
}
} }
if (Request::isPost() && Request::option("move_up")) {
$topics = CourseTopic::findBySeminar_id(Context::getId()); $topic->title = Request::i18n("title");
foreach ($topics as $key => $topic) { $topic->description = Request::i18n('description', null, function ($string) {
if (($topic->getId() === Request::option("move_up")) && $key > 0) { return Studip\Markup::purifyHtml($string);
$topic['priority'] = $key;
$topics[$key - 1]->priority = $key + 1; });
$topics[$key - 1]->store(); $topic->paper_related = Request::bool('paper_related', false);
} else { if ($topic->isNew()) {
$topic['priority'] = $key + 1; $topic->seminar_id = Context::getId();
} }
$topic->store(); $topic->store();
//change dates for this topic
$former_date_ids = $topic->dates->pluck('termin_id');
$new_date_ids = array_keys(Request::getArray('date'));
foreach (array_diff($former_date_ids, $new_date_ids) as $delete_termin_id) {
$topic->dates->unsetByPk($delete_termin_id);
}
foreach (array_diff($new_date_ids, $former_date_ids) as $add_termin_id) {
$date = CourseDate::find($add_termin_id);
if ($date) {
$topic->dates[] = $date;
} }
} }
$topic->store();
Navigation::activateItem('/course/schedule/topics'); if (Request::bool('folder')) {
$this->topics = CourseTopic::findBySeminar_id(Context::getId()); $topic->connectWithDocumentFolder();
$this->cancelled_dates_locked = LockRules::Check(Context::getId(), 'cancelled_dates'); }
}
public function delete_action($topic_id) // create a connection to the module forum (can be anything)
{ // will update title and description automagically
if (!$GLOBALS['perm']->have_studip_perm("tutor", Context::getId())) { if (Request::bool('forumthread')) {
throw new AccessDeniedException(); $topic->connectWithForumThread();
} }
$topic = new CourseTopic($topic_id); PageLayout::postSuccess(_('Thema gespeichert.'));
$this->redirect($this->indexURL(['open' => $topic->id]));
}
if ($topic['seminar_id'] && ($topic['seminar_id'] !== Context::getId())) { public function move_up_action(CourseTopic $topic)
throw new AccessDeniedException(); {
if (!Request::isPost()) {
throw new MethodNotAllowedException();
} }
$topic->delete(); $topic->increasePriority();
PageLayout::postSuccess(_('Thema gelöscht.'));
$this->redirect('course/topics'); $this->redirect($this->indexURL(['open' => $topic->id]));
} }
public function edit_action($topic_id = null) public function move_down_action(CourseTopic $topic)
{ {
if (!$GLOBALS['perm']->have_studip_perm("tutor", Context::getId())) { if (!Request::isPost()) {
throw new AccessDeniedException(); throw new MethodNotAllowedException();
} }
$this->topic = new CourseTopic($topic_id);
$this->dates = CourseDate::findBySeminar_id(Context::getId());
if (Request::isXhr()) { $topic->decreasePriority();
PageLayout::setTitle($topic_id ? sprintf(_('Bearbeiten: %s'), $this->topic['title']) : _("Neues Thema erstellen"));
} else { $this->redirect($this->indexURL(['open' => $topic->id]));
Navigation::activateItem('/course/schedule/topics');
}
} }
public function allow_public_action() public function allow_public_action()
{ {
if (!$GLOBALS['perm']->have_studip_perm("tutor", Context::getId())) {
throw new AccessDeniedException();
}
$config = CourseConfig::get(Context::getId()); $config = CourseConfig::get(Context::getId());
$config->store('COURSE_PUBLIC_TOPICS', !$config->COURSE_PUBLIC_TOPICS); $config->store('COURSE_PUBLIC_TOPICS', !$config->COURSE_PUBLIC_TOPICS);
$this->redirect("course/topics"); $this->redirect("course/topics");
...@@ -150,9 +138,6 @@ class Course_TopicsController extends AuthenticatedController ...@@ -150,9 +138,6 @@ class Course_TopicsController extends AuthenticatedController
public function copy_action() public function copy_action()
{ {
if (!$GLOBALS['perm']->have_studip_perm("tutor", Context::getId())) {
throw new AccessDeniedException();
}
if (Request::submitted("copy")) { if (Request::submitted("copy")) {
$prio = 1; $prio = 1;
foreach (Course::find(Context::getId())->topics as $topic) { foreach (Course::find(Context::getId())->topics as $topic) {
...@@ -227,9 +212,6 @@ class Course_TopicsController extends AuthenticatedController ...@@ -227,9 +212,6 @@ class Course_TopicsController extends AuthenticatedController
public function fetch_topics_action() public function fetch_topics_action()
{ {
if (!$GLOBALS['perm']->have_studip_perm("tutor", Request::option("seminar_id"))) {
throw new AccessDeniedException();
}
$this->topics = CourseTopic::findBySeminar_id(Request::option("seminar_id")); $this->topics = CourseTopic::findBySeminar_id(Request::option("seminar_id"));
$output = [ $output = [
'html' => $this->render_template_as_string("course/topics/_topiclist.php") 'html' => $this->render_template_as_string("course/topics/_topiclist.php")
...@@ -272,8 +254,8 @@ class Course_TopicsController extends AuthenticatedController ...@@ -272,8 +254,8 @@ class Course_TopicsController extends AuthenticatedController
if ($GLOBALS['perm']->have_studip_perm('tutor', Context::getId())) { if ($GLOBALS['perm']->have_studip_perm('tutor', Context::getId())) {
$options = $sidebar->addWidget(new OptionsWidget()); $options = $sidebar->addWidget(new OptionsWidget());
$options->addCheckbox( $options->addCheckbox(
_("Themen öffentlich einsehbar"), _('Themen öffentlich einsehbar'),
CourseConfig::get(Context::getId())->COURSE_PUBLIC_TOPICS, (bool) CourseConfig::get(Context::getId())->COURSE_PUBLIC_TOPICS,
$this->url_for('course/topics/allow_public') $this->url_for('course/topics/allow_public')
); );
} }
......
<? $date_ids = $topic->dates->pluck("termin_id") ?> <? $date_ids = $topic->dates->pluck("termin_id") ?>
<form action="<?= URLHelper::getLink("dispatch.php/course/topics") ?>" method="post" class="default"> <form action="<?= $controller->store($topic) ?>" method="post" class="default">
<?= CSRFProtection::tokenTag() ?> <?= CSRFProtection::tokenTag() ?>
<input type="hidden" name="issue_id" value="<?=htmlReady($topic->getId()) ?>"> <input type="hidden" name="open" value="<?= htmlReady($topic->getId()) ?>">
<input type="hidden" name="open" value="<?=htmlReady($topic->getId()) ?>">
<input type="hidden" name="edit" value="1"> <input type="hidden" name="edit" value="1">
<fieldset> <fieldset>
<legend><?= _('Thema bearbeiten') ?></legend> <legend><?= _('Thema bearbeiten') ?></legend>
<label for="topic_title"> <label>
<span class="required"><?= _("Titel") ?></span> <span class="required"><?= _('Titel') ?></span>
<input type="text" name="title" id="topic_title" value="<?= htmlReady($topic['title']) ?>" required> <?= I18N::input('title', $topic->title, ['required' => '']) ?>
</label> </label>
<label for="topic_description"> <label>
<?= _("Beschreibung") ?> <?= _("Beschreibung") ?>
<textarea class="add_toolbar wysiwyg size-l" name="description" id="topic_description"><?= wysiwygReady($topic['description']) ?></textarea> <?= I18N::textarea('description', $topic->description, [
<? if (Request::isAjax()) : ?> 'class' => 'add_toolbar wysiwyg size-l',
<script>jQuery('.add_toolbar').addToolbar();</script> ]) ?>
<? endif ?>
</label> </label>
<? if ($documents_activated) : ?> <? if ($documents_activated) : ?>
<label> <label>
<? $folder = $topic->folders->first() ?> <? $folder = $topic->folders->first() ?>
<? if ($folder) : ?> <? if ($folder) : ?>
<?= Icon::create('accept', 'accept')->asImg(['class' => "text-bottom"]) ?> <?= Icon::create('accept', Icon::ROLE_ACCEPT)->asImg(['class' => 'text-bottom']) ?>
<?= _("Dateiordner vorhanden ") ?> <?= _('Dateiordner vorhanden ') ?>
<? else : ?> <? else : ?>
<input type="checkbox" name="folder" id="topic_folder"> <input type="checkbox" name="folder" id="topic_folder" value="1">
<?= _("Dateiordner anlegen") ?> <?= _('Dateiordner anlegen') ?>
<? endif ?>
</label>
<? endif ?> <? endif ?>
</label>
<? endif ?>
<? if ($forum_activated) : ?> <? if ($forum_activated) : ?>
<label> <label>
<? if ($topic->forum_thread_url) : ?> <? if ($topic->forum_thread_url) : ?>
<?= Icon::create('accept', 'accept')->asImg(['class' => "text-bottom"]) ?> <?= Icon::create('accept', Icon::ROLE_ACCEPT)->asImg(['class' => 'text-bottom']) ?>
<?= _("Forenthema vorhanden ") ?> <?= _('Forenthema vorhanden ') ?>
<? else : ?> <? else : ?>
<input type="checkbox" name="forumthread" id="topic_forumthread"> <input type="checkbox" name="forumthread" id="topic_forumthread" value="1">
<?= _("Forenthema anlegen") ?> <?= _('Forenthema anlegen') ?>
<? endif ?>
</label>
<? endif ?> <? endif ?>
</label>
<? endif ?>
<h2><?= _("Termine") ?></h2> <h2><?= _('Termine') ?></h2>
<? foreach ($dates as $date) : ?> <? foreach ($dates as $date) : ?>
<label> <label>
<input type="checkbox" name="date[<?= $date->getId() ?>]" value="1" class="text-bottom"<?= in_array($date->getId(), $date_ids) ? " checked" : "" ?>> <input type="checkbox" name="date[<?= htmlReady($date->id) ?>]" value="1" class="text-bottom"
<?= Icon::create('date', 'info')->asImg(['class' => "text-bottom"]) ?> <? if (in_array($date->id, $date_ids)) echo 'checked'; ?>>
<?= (floor($date['date'] / 86400) !== floor($date['end_time'] / 86400)) ? date("d.m.Y, H:i", $date['date'])." - ".date("d.m.Y, H:i", $date['end_time']) : date("d.m.Y, H:i", $date['date'])." - ".date("H:i", $date['end_time']) ?> <?= Icon::create('date', Icon::ROLE_INFO)->asImg(['class' => 'text-bottom']) ?>
<? $localtopics = $date->topics ?> <?= floor($date['date'] / 86400) !== floor($date['end_time'] / 86400) ? date("d.m.Y, H:i", $date['date'])." - ".date("d.m.Y, H:i", $date['end_time']) : date("d.m.Y, H:i", $date['date'])." - ".date("H:i", $date['end_time']) ?>
<? if (count($localtopics)) : ?>
<? if (count($date->topics) > 0) : ?>
( (
<? foreach ($localtopics as $key => $localtopic) : ?> <? foreach ($date->topics as $key => $localtopic) : ?>
<a href="<?= URLHelper:: getLink("dispatch.php/course/topics/index", ['open' => $localtopic->getId()]) ?>"> <a href="<?= $controller->index(['open' => $localtopic->id]) ?>">
<?= Icon::create('topic', 'clickable')->asImg(['class' => "text-bottom"]) ?> <?= Icon::create('topic')->asImg(['class' => 'text-bottom']) ?>
<?= htmlReady($localtopic['title']) ?> <?= htmlReady($localtopic->title) ?>
</a> </a>
<? endforeach ?> <? endforeach ?>
) )
...@@ -90,5 +89,3 @@ ...@@ -90,5 +89,3 @@
</div> </div>
</footer> </footer>
</form> </form>
<br>
...@@ -83,34 +83,36 @@ ...@@ -83,34 +83,36 @@
</table> </table>
<div style="text-align: center;"> <div style="text-align: center;">
<? if ($GLOBALS['perm']->have_studip_perm("tutor", Context::getId())) : ?> <? if ($GLOBALS['perm']->have_studip_perm("tutor", Context::getId())) : ?>
<?= \Studip\LinkButton::createEdit(_('Bearbeiten'), <?= Studip\LinkButton::createEdit(
$controller->url_for('course/topics/edit/' . $topic->getId()), [ _('Bearbeiten'),
'data-dialog' => '' $controller->editURL($topic),
]) ?> ['data-dialog' => '']
<?= Studip\LinkButton::create(
_('Löschen'),
$controller->url_for('course/topics/delete/' . $topic->getId()),
['data-confirm' => _('Wirklich löschen?')]
) ?> ) ?>
<form action="<?= $controller->delete($topic) ?>" method="post" style="display: inline">
<?= Studip\Button::create(
_('Löschen'),
'delete',
['data-confirm' => _('Wirklich löschen?')]
) ?>
</form>
<? if (!$cancelled_dates_locked && $topic->dates->count()) : ?> <? if (!$cancelled_dates_locked && $topic->dates->count()) : ?>
<?= \Studip\LinkButton::create(_("Alle Termine ausfallen lassen"), URLHelper::getURL("dispatch.php/course/cancel_dates", ['issue_id' => $topic->getId()]), ['data-dialog' => '']) ?> <?= \Studip\LinkButton::create(_("Alle Termine ausfallen lassen"), URLHelper::getURL("dispatch.php/course/cancel_dates", ['issue_id' => $topic->getId()]), ['data-dialog' => '']) ?>
<? endif ?> <? endif ?>
<span class="button-group">
<? if ($key > 0) : ?> <? if ($key > 0) : ?>
<form action="<?=$controller->link_for()?>" method="post" style="display: inline;"> <form action="<?= $controller->move_up($topic) ?>" method="post" style="display: inline;">
<input type="hidden" name="move_up" value="<?= $topic->getId() ?>"> <?= Studip\Button::createMoveUp(_('nach oben verschieben')) ?>
<input type="hidden" name="open" value="<?= $topic->getId() ?>">
<?= \Studip\Button::createMoveUp(_("nach oben verschieben")) ?>
</form> </form>
<? endif ?> <? endif ?>
<? if ($key < count($topics) - 1) : ?> <? if ($key < count($topics) - 1) : ?>
<form action="<?=$controller->link_for()?>" method="post" style="display: inline;"> <form action="<?=$controller->move_down($topic)?>" method="post" style="display: inline;">
<input type="hidden" name="move_down" value="<?= $topic->getId() ?>"> <?= Studip\Button::createMoveDown(_('nach unten verschieben')) ?>
<input type="hidden" name="open" value="<?= $topic->getId() ?>"> </form>
<?= \Studip\Button::createMoveDown(_("nach unten verschieben")) ?>
</form>
<? endif ?> <? endif ?>
</span>
<? endif ?> <? endif ?>
</div> </div>
</div> </div>
......
...@@ -19,57 +19,33 @@ ...@@ -19,57 +19,33 @@
* @property string priority database column * @property string priority database column
* @property string mkdate database column * @property string mkdate database column
* @property string chdate database column * @property string chdate database column
* @property DocumentFolder folder belongs_to DocumentFolder * @property Folder folder belongs_to DocumentFolder
* @property Course course belongs_to Course * @property Course course belongs_to Course
* @property User author belongs_to User * @property User author belongs_to User
* @property SimpleORMapCollection dates has_and_belongs_to_many CourseDate * @property SimpleORMapCollection dates has_and_belongs_to_many CourseDate
*/ */
class CourseTopic extends SimpleORMap class CourseTopic extends SimpleORMap
{ {
public static function findByTermin_id($termin_id)
{
return self::findBySQL("INNER JOIN themen_termine USING (issue_id)
WHERE themen_termine.termin_id = ?
ORDER BY priority ASC",
[$termin_id]
);
}
public static function findBySeminar_id($seminar_id, $order_by = 'ORDER BY priority')
{
return parent::findBySeminar_id($seminar_id, $order_by);
}
public static function findByTitle($seminar_id, $name)
{
return self::findOneBySQL("seminar_id = ? AND title = ?", [$seminar_id, $name]);
}
public static function getMaxPriority($seminar_id)
{
return DBManager::get()->fetchColumn("SELECT MAX(priority) FROM themen WHERE seminar_id=?", [$seminar_id]);
}
protected static function configure($config = []) protected static function configure($config = [])
{ {
$config['db_table'] = 'themen'; $config['db_table'] = 'themen';
$config['has_and_belongs_to_many']['dates'] = [ $config['has_and_belongs_to_many']['dates'] = [
'class_name' => 'CourseDate', 'class_name' => CourseDate::class,
'thru_table' => 'themen_termine', 'thru_table' => 'themen_termine',
'order_by' => 'ORDER BY date', 'order_by' => 'ORDER BY date',
'on_delete' => 'delete', 'on_delete' => 'delete',
'on_store' => 'store' 'on_store' => 'store'
]; ];
$config['has_many']['folders'] = [ $config['has_many']['folders'] = [
'class_name' => 'Folder', 'class_name' => Folder::class,
'assoc_func' => 'findByTopic_id' 'assoc_func' => 'findByTopic_id'
]; ];
$config['belongs_to']['course'] = [ $config['belongs_to']['course'] = [
'class_name' => 'Course', 'class_name' => Course::class,
'foreign_key' => 'seminar_id' 'foreign_key' => 'seminar_id'
]; ];
$config['belongs_to']['author'] = [ $config['belongs_to']['author'] = [
'class_name' => 'User', 'class_name' => User::class,
'foreign_key' => 'author_id' 'foreign_key' => 'author_id'
]; ];
...@@ -79,9 +55,36 @@ class CourseTopic extends SimpleORMap ...@@ -79,9 +55,36 @@ class CourseTopic extends SimpleORMap
$config['registered_callbacks']['after_store'][] = 'cbUpdateConnectedContentModules'; $config['registered_callbacks']['after_store'][] = 'cbUpdateConnectedContentModules';
$config['registered_callbacks']['before_delete'][] = 'cbUnlinkConnectedContentModules'; $config['registered_callbacks']['before_delete'][] = 'cbUnlinkConnectedContentModules';
$config['i18n_fields']['title'] = true;
$config['i18n_fields']['description'] = true;
parent::configure($config); parent::configure($config);
} }
public static function findByTermin_id($termin_id)
{
return self::findBySQL("INNER JOIN themen_termine USING (issue_id)
WHERE themen_termine.termin_id = ?
ORDER BY priority ASC",
[$termin_id]
);
}
public static function findBySeminar_id($seminar_id, $order_by = 'ORDER BY priority')
{
return parent::findBySeminar_id($seminar_id, $order_by);
}
public static function findByTitle($seminar_id, $name)
{
return self::findOneBySQL("seminar_id = ? AND title = ?", [$seminar_id, $name]);
}
public static function getMaxPriority($seminar_id)
{
return DBManager::get()->fetchColumn("SELECT MAX(priority) FROM themen WHERE seminar_id=?", [$seminar_id]);
}
/** /**
* set or update connection with document folder * set or update connection with document folder
*/ */
...@@ -179,7 +182,7 @@ class CourseTopic extends SimpleORMap ...@@ -179,7 +182,7 @@ class CourseTopic extends SimpleORMap
$folders = array_merge($folders, $date->folders->getArrayCopy()); $folders = array_merge($folders, $date->folders->getArrayCopy());
} }
foreach ($folders as $folder) { foreach ($folders as $folder) {
list($files, $typed_folders) = array_values(FileManager::getFolderFilesRecursive($folder->getTypedFolder(), $user_id)); [$files, $typed_folders] = array_values(FileManager::getFolderFilesRecursive($folder->getTypedFolder(), $user_id));
foreach ($files as $file) { foreach ($files as $file) {
$all_files[$file->id] = $file; $all_files[$file->id] = $file;
} }
...@@ -187,4 +190,67 @@ class CourseTopic extends SimpleORMap ...@@ -187,4 +190,67 @@ class CourseTopic extends SimpleORMap
} }
return ['files' => $all_files, 'folders' => $all_folders]; return ['files' => $all_files, 'folders' => $all_folders];
} }
/**
* Increases the priority of this topic. Meaning the topic will be sorted further up.
* Be aware that this actually decreases the priority property since lower numbers
* mean higher priority.
*
* @return boolean
*/
public function increasePriority()
{
// Update all the course's topics with a lower priority than this one
$query = "UPDATE `themen`
SET `priority` = `priority` + 1
WHERE `seminar_id` = :course_id
AND `priority` < :current_priority
ORDER BY `priority` DESC
LIMIT 1";
$changed = DBManager::get()->execute($query, [
':course_id' => $this->seminar_id,
':current_priority' => $this->priority,
]);
// If anything has changed, decrease priority. Otherwise the current
// topic is already at top.
if ($changed) {
$this->priority -= 1;
$this->store();
return true;
}
return false;
}
/**
* Decreases the priority of this topic. Meaning the topic will be sorted further down.
* Be aware that this actually increases the priority property since higher numbers
* mean lower priority.
*/
public function decreasePriority()
{
// Update all the course's topics with a higher priority than this one
$query = "UPDATE `themen`
SET `priority` = `priority` - 1
WHERE `seminar_id` = :course_id
AND `priority` > :current_priority
ORDER BY `priority` ASC
LIMIT 1";
$changed = DBManager::get()->execute($query, [
':course_id' => $this->seminar_id,
':current_priority' => $this->priority,
]);
// If anything has changed, increase priority. Otherwise the current
// topic is already at bottom.
if ($changed) {
$this->priority += 1;
$this->store();
return true;
}
return false;
}
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment