1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
|
<?php
/*
* Copyright (C) 2011 - Till Glöggler <tgloeggl@uos.de>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
*/
require_once 'forum_controller.php';
class Course_Forum_AdminController extends ForumController
{
/* * * * * * * * * * * * * * * * * * * * */
/* * * A D M I N M E T H O D S * * */
/* * * * * * * * * * * * * * * * * * * * */
/**
* show the administration page for mass-editing forum-entries
*/
function index_action()
{
ForumPerm::check('admin', $this->getId());
$nav = Navigation::getItem('course/forum2');
$nav->setImage(Icon::create('forum', 'info'));
Navigation::activateItem('course/forum2/admin');
$list = ForumEntry::getList('flat', $this->getId());
// sort by cat
$new_list = [];
$this->categories = [];
// iterate over all categories and add the belonging areas to them
$categories = ForumCat::getListWithAreas($this->getId(), false) ;
foreach ($categories as $category) {
if (!empty($category['topic_id'])) {
$new_list[$category['category_id']][$category['topic_id']] = $list['list'][$category['topic_id']];
unset($list['list'][$category['topic_id']]);
} else if (ForumPerm::has('add_area', $this->seminar_id)) {
$new_list[$category['category_id']] = [];
}
$this->categories[$category['category_id']] = $category['entry_name'];
}
if (!empty($list['list'])) {
// append the remaining entries to the standard category
$new_list[$this->getId()] = array_merge((array)$new_list[$this->getId()], $list['list']);
}
$this->list = $new_list;
}
/**
* show child entries for the passed entry
*
* @param string $parent_id id of entry to get the childs for
*/
function childs_action($parent_id)
{
$this->set_layout(null);
// if the parent-id is a category-id, get all areas for this category
if ($cat = ForumCat::get($parent_id)) {
ForumPerm::check('admin', $cat['seminar_id']); // check the perms in the categories seminar
$this->entries = ForumEntry::parseEntries(ForumCat::getAreas($parent_id));
} else {
ForumPerm::check('admin', $this->getId(), $parent_id);
$entries = ForumEntry::getList('flat', $parent_id);
$this->entries = $entries['list'];
}
}
/**
* move the submitted topics[] to the passed destination
*
* @param string $destination id of seminar to move topics to
*/
function move_action($destination)
{
// check if destination is a category_id. if yes, use seminar_id instead
if (ForumCat::get($destination)) {
$category_id = $destination;
$destination = $this->getId();
} else {
$category_id = null;
}
ForumPerm::check('admin', $this->getId(), $destination);
foreach (Request::getArray('topics') as $topic_id) {
// make sure every passed topic_id is checked against the current seminar
ForumPerm::check('admin', $this->getId(), $topic_id);
// if the source is an area and the target a category, just move this area to the category
$entry = ForumEntry::getEntry($topic_id);
if ($entry['depth'] == 1 && $category_id) {
ForumCat::removeArea($topic_id);
ForumCat::addArea($category_id, $topic_id);
} else {
// first step: move the whole topic with all childs
ForumEntry::move($topic_id, $destination);
// if the current topic id is an area, remove it from any categories
ForumCat::removeArea($topic_id);
// second step: move all to deep childs a level up (depth > 3)
$data = ForumEntry::getList('depth_to_large', $topic_id);
if (!empty($data['list'])) {
foreach ($data['list'] as $entry) {
$path = ForumEntry::getPathToPosting($entry['topic_id']);
array_shift($path); // Category
array_shift($path); // Area
$thread = array_shift($path); // Thread
ForumEntry::move($entry['topic_id'], $thread['id']);
}
}
// add entry to passed category when moving to the top
if ($category_id) {
ForumCat::addArea($category_id, $topic_id);
}
}
}
$this->render_nothing();
}
}
|