diff --git a/lib/classes/StudipSemTree.class.php b/lib/classes/StudipSemTree.class.php index 203bec15e389324bb18aa56919bfe993af2cf654..39bb1a1fd72639ec7008ee9f625288c674107ef9 100644 --- a/lib/classes/StudipSemTree.class.php +++ b/lib/classes/StudipSemTree.class.php @@ -73,17 +73,13 @@ class StudipSemTree extends TreeAbstract { parent::init(); - $db = $this->view->get_query("view:SEM_TREE_GET_DATA_NO_ENTRIES"); - - while ($db->next_record()){ - $this->tree_data[$db->f("sem_tree_id")] = ['type' => $db->f('type'), "info" => $db->f("info"),"studip_object_id" => $db->f("studip_object_id"), "entries" => 0]; - if ($db->f("studip_object_id")){ - $name = $db->f("studip_object_name"); - } else { - $name = $db->f("name"); - } - $this->storeItem($db->f("sem_tree_id"), $db->f("parent_id"), $name, $db->f("priority")); - } + StudipStudyArea::findEachBySQL( + function ($area) { + $this->tree_data[$area->id] = array_merge($area->toArray(), ['entries' => 0]); + $this->storeItem($area->id, $area->parent_id, $area->name, $area->priority); + }, + '1 ORDER BY priority' + ); } public function initEntries() @@ -141,8 +137,9 @@ class StudipSemTree extends TreeAbstract public function getSemData($item_id,$sem_data_from_kids = false) { - if (!$this->tree_data[$item_id]) + if (!$this->tree_data[$item_id]) { return false; + } $this->view->params[0] = $this->sem_status; $this->view->params[1] = $this->visible_only ? "visible=1" : "1"; if ($sem_data_from_kids && $item_id != 'root'){ @@ -162,8 +159,9 @@ class StudipSemTree extends TreeAbstract public function getLonelySemData($item_id) { - if (!$institut_id = $this->tree_data[$item_id]['studip_object_id']) + if (!$institut_id = $this->tree_data[$item_id]['studip_object_id']) { return false; + } $this->view->params[0] = $this->sem_status; $this->view->params[1] = $this->visible_only ? "visible=1" : "1"; $this->view->params[2] = $institut_id; @@ -182,57 +180,61 @@ class StudipSemTree extends TreeAbstract } return parent::getNumEntries($item_id, $num_entries_from_kids); - /* - if (!$num_entries_from_kids){ - return $this->tree_data[$item_id]["entries"]; - } else { - $item_list = $this->getKidsKids($item_id); - $item_list[] = $item_id; - $ret = 0; - $num_items = count($item_list); - for ($i = 0; $i < $num_items; ++$i){ - $ret += $this->tree_data[$item_list[$i]]["entries"]; - } - return $ret; - } - */ } public function getAdminRange($item_id) { - if (!$this->tree_data[$item_id]) + if (!$this->tree_data[$item_id]) { return false; - if ($item_id == "root") - return "root"; + } + if ($item_id == 'root') { + return 'root'; + } $ret_id = $item_id; while (!$this->tree_data[$ret_id]['studip_object_id']){ $ret_id = $this->tree_data[$ret_id]['parent_id']; - if ($ret_id == "root") + if ($ret_id == 'root') { break; + } } return $ret_id; } public function InsertItem($item_id, $parent_id, $item_name, $item_info, $priority, $studip_object_id, $type) { - $view = new DbView(); - $view->params = [$item_id,$parent_id,$item_name,$priority,$item_info,$studip_object_id, $type]; - $rs = $view->get_query("view:SEM_TREE_INS_ITEM"); + $item = new StudipStudyArea($item_id); + $item->setData([ + 'parent_id' => $parent_id, + 'priority' => $priority, + 'name' => $item_name, + 'info' => $item_info, + 'studip_object_id' => $studip_object_id, + 'type' => $type, + ]); + // Logging - StudipLog::log("STUDYAREA_ADD",$item_id); - NotificationCenter::postNotification("StudyAreaDidCreate", $item_id, $GLOBALS['user']->id); + if ($item->store()) { + StudipLog::log('STUDYAREA_ADD', $item_id); + NotificationCenter::postNotification('StudyAreaDidCreate', $item_id, $GLOBALS['user']->id); + return true; + } - return $rs->affected_rows(); + return false; } public function UpdateItem($item_id, $item_name, $item_info, $type) { - $view = new DbView(); - $view->params = [$item_name,$item_info,$type,$item_id]; - $rs = $view->get_query("view:SEM_TREE_UPD_ITEM"); - NotificationCenter::postNotification("StudyAreaDidUpdate", $item_id, $GLOBALS['user']->id); + $item = StudipStudyArea::find($item_id); + $item->name = $item_name; + $item->info = $item_info; + $item->type = $type; + + if ($item->store()) { + NotificationCenter::postNotification('StudyAreaDidUpdate', $item_id, $GLOBALS['user']->id); + return true; + } - return $rs->affected_rows(); + return false; } public function DeleteItems($items_to_delete) @@ -240,14 +242,16 @@ class StudipSemTree extends TreeAbstract $view = new DbView(); $view->params[0] = (is_array($items_to_delete)) ? $items_to_delete : [$items_to_delete]; $view->auto_free_params = false; - $rs = $view->get_query("view:SEM_TREE_DEL_ITEM"); - $deleted['items'] = $rs->affected_rows(); - $rs = $view->get_query("view:SEMINAR_SEM_TREE_DEL_RANGE"); - $deleted['entries'] = $rs->affected_rows(); + + $deleted = [ + 'items' => StudipStudyArea::deleteBySQL('sem_tree_id IN (?)', $items_to_delete), + 'entries' => $view->get_query('view:SEMINAR_SEM_TREE_DEL_RANGE')->affected_rows(), + ]; + // Logging foreach ($items_to_delete as $item_id) { - StudipLog::log("STUDYAREA_DELETE",$item_id); - NotificationCenter::postNotification("StudyAreaDidDelete", $item_id, $GLOBALS['user']->id); + StudipLog::log('STUDYAREA_DELETE',$item_id); + NotificationCenter::postNotification('StudyAreaDidDelete', $item_id, $GLOBALS['user']->id); } return $deleted; } @@ -256,39 +260,39 @@ class StudipSemTree extends TreeAbstract { $view = new DbView(); if ($item_ids && $sem_entries) { - $sem_tree_ids = $view->params[0] = (is_array($item_ids)) ? $item_ids : [$item_ids]; - $seminar_ids = $view->params[1] = (is_array($sem_entries)) ? $sem_entries : [$sem_entries]; - $rs = $view->get_query("view:SEMINAR_SEM_TREE_DEL_SEM_RANGE"); + $sem_tree_ids = $view->params[0] = is_array($item_ids) ? $item_ids : [$item_ids]; + $seminar_ids = $view->params[1] = is_array($sem_entries) ? $sem_entries : [$sem_entries]; + $rs = $view->get_query('view:SEMINAR_SEM_TREE_DEL_SEM_RANGE'); $ret = $rs->affected_rows(); // Logging foreach ($sem_tree_ids as $range) { foreach ($seminar_ids as $sem) { - StudipLog::log("SEM_DELETE_STUDYAREA",$sem,$range); + StudipLog::log('SEM_DELETE_STUDYAREA',$sem,$range); } } - if($ret){ - foreach ($sem_tree_ids as $sem_tree_id){ + if ($ret) { + foreach ($sem_tree_ids as $sem_tree_id) { $studyarea = StudipStudyArea::find($sem_tree_id); - if($studyarea->isModule()) { + if ($studyarea->isModule()) { foreach ($seminar_ids as $seminar_id) { NotificationCenter::postNotification('CourseRemovedFromModule', $studyarea, ['module_id' => $sem_tree_id, 'course_id' => $seminar_id]); } } } } - } elseif ($item_ids){ - $view->params[0] = (is_array($item_ids)) ? $item_ids : [$item_ids]; + } elseif ($item_ids) { + $view->params[0] = is_array($item_ids) ? $item_ids : [$item_ids]; // Logging foreach ($view->params[0] as $range) { - StudipLog::log("SEM_DELETE_STUDYAREA","all",$range); + StudipLog::log('SEM_DELETE_STUDYAREA', 'all',$range); } - $rs = $view->get_query("view:SEMINAR_SEM_TREE_DEL_RANGE"); + $rs = $view->get_query('view:SEMINAR_SEM_TREE_DEL_RANGE'); $ret = $rs->affected_rows(); } elseif ($sem_entries){ $view->params[0] = (is_array($sem_entries)) ? $sem_entries : [$sem_entries]; // Logging foreach ($view->params[0] as $sem) { - StudipLog::log("SEM_DELETE_STUDYAREA",$sem,"all"); + StudipLog::log('SEM_DELETE_STUDYAREA', $sem, 'all'); } $rs = $view->get_query("view:SEMINAR_SEM_TREE_DEL_SEMID_RANGE"); $ret = $rs->affected_rows(); @@ -304,12 +308,12 @@ class StudipSemTree extends TreeAbstract $view = new DbView(); $view->params[0] = $seminar_id; $view->params[1] = $sem_tree_id; - $rs = $view->get_query("view:SEMINAR_SEM_TREE_INS_ITEM"); - if($ret = $rs->affected_rows()){ + $rs = $view->get_query('view:SEMINAR_SEM_TREE_INS_ITEM'); + if ($ret = $rs->affected_rows()){ // Logging - StudipLog::log("SEM_ADD_STUDYAREA",$seminar_id,$sem_tree_id); + StudipLog::log('SEM_ADD_STUDYAREA',$seminar_id,$sem_tree_id); $studyarea = StudipStudyArea::find($sem_tree_id); - if($studyarea->isModule()){ + if ($studyarea->isModule()){ NotificationCenter::postNotification('CourseAddedToModule', $studyarea, ['module_id' => $sem_tree_id, 'course_id' => $seminar_id]); } } diff --git a/lib/classes/StudipSemTreeViewAdmin.class.php b/lib/classes/StudipSemTreeViewAdmin.class.php index c615f9859e1481931e73439bcd47f1eae42455a3..277cf0dc066a9484d05aa1b94cbd95e926184cf4 100644 --- a/lib/classes/StudipSemTreeViewAdmin.class.php +++ b/lib/classes/StudipSemTreeViewAdmin.class.php @@ -31,45 +31,42 @@ use Studip\Button, Studip\LinkButton; /** -* class to print out the seminar tree (admin mode) -* -* This class prints out a html representation of the whole or part of the tree -* -* @access public -* @author André Noack <noack@data-quest.de> -* @package -*/ + * class to print out the seminar tree (admin mode) + * + * This class prints out a html representation of the whole or part of the tree + * + * @access public + * @author André Noack <noack@data-quest.de> + */ class StudipSemTreeViewAdmin extends TreeView { - var $admin_ranges = []; - var $msg = []; - var $marked_item; - var $marked_sem; - var $mode; - var $move_item_id; - var $edit_item_id; + public $msg = []; + public $marked_item; + public $marked_sem; + public $mode; + public $move_item_id; /** - * constructor - * - * @access public - */ - function __construct($start_item_id = "root"){ - $this->start_item_id = ($start_item_id) ? $start_item_id : "root"; + * constructor + */ + public function __construct($start_item_id = 'root') + { + $this->start_item_id = $start_item_id ?: 'root'; $this->root_content = $GLOBALS['UNI_INFO']; - parent::__construct("StudipSemTree"); //calling the baseclass constructor - URLHelper::bindLinkParam("_marked_item", $this->marked_item); + + parent::__construct('StudipSemTree'); //calling the baseclass constructor + + URLHelper::bindLinkParam('_marked_item', $this->marked_item); + $this->marked_sem =& $_SESSION['_marked_sem']; $this->parseCommand(); } /** - * manages the session variables used for the open/close thing - * - * @access private - */ - function handleOpenRanges(){ - + * manages the session variables used for the open/close thing + */ + protected function handleOpenRanges() + { $this->open_ranges[$this->start_item_id] = true; if (Request::option('close_item') || Request::option('open_item')){ @@ -81,11 +78,13 @@ class StudipSemTreeViewAdmin extends TreeView } } - if (Request::option('item_id')) $this->anchor = Request::option('item_id'); - + if (Request::option('item_id')) { + $this->anchor = Request::option('item_id'); + } } - function openItem($item_id){ + public function openItem($item_id) + { if ($this->tree->hasKids($item_id)){ $this->start_item_id = $item_id; $this->open_ranges = null; @@ -97,30 +96,31 @@ class StudipSemTreeViewAdmin extends TreeView $this->open_items[$item_id] = true; $this->start_item_id = $this->tree->tree_data[$item_id]['parent_id']; } - if ($this->start_item_id == "root"){ + if ($this->start_item_id === 'root') { $this->open_ranges = null; $this->open_ranges[$this->start_item_id] = true; } $this->anchor = $item_id; } - function parseCommand(){ - $this->mode = ''; - if (Request::quoted('mode')) - $this->mode = Request::quoted('mode'); + protected function parseCommand() + { + $this->mode = Request::option('mode', $this->mode ?? ''); + if (Request::option('cmd')){ - $exec_func = "execCommand" . Request::option('cmd'); - if (method_exists($this,$exec_func)){ - if ($this->$exec_func()){ + $exec_func = 'execCommand' . Request::option('cmd'); + if (method_exists($this, $exec_func)) { + if ($this->$exec_func()) { $this->tree->init(); } } } - if ($this->mode == "MoveItem" || $this->mode == "CopyItem") - $this->move_item_id = $this->marked_item; + if ($this->mode === 'MoveItem' || $this->mode === 'CopyItem') { + $this->move_item_id = $this->marked_item; + } } - public function execCommandOrderItemsAlphabetically() + protected function execCommandOrderItemsAlphabetically() { $item_id = Request::option('sort_id'); $sorted_items_stmt = DBManager::get()->prepare( @@ -142,84 +142,92 @@ class StudipSemTreeViewAdmin extends TreeView return true; } - function execCommandOrderItem(){ - $direction = Request::quoted('direction'); + protected function execCommandOrderItem() + { + $direction = Request::option('direction'); $item_id = Request::option('item_id'); $items_to_order = $this->tree->getKids($this->tree->tree_data[$item_id]['parent_id']); - if (!$this->isParentAdmin($item_id) || !$items_to_order) - return false; + if (!$this->isParentAdmin($item_id) || !$items_to_order) { + return false; + } for ($i = 0; $i < count($items_to_order); ++$i){ - if ($item_id == $items_to_order[$i]) - break; + if ($item_id == $items_to_order[$i]) { + break; + } } - if ($direction == "up" && isset($items_to_order[$i-1])){ - $items_to_order[$i] = $items_to_order[$i-1]; + if ($direction === 'up' && isset($items_to_order[$i - 1])){ + $items_to_order[$i] = $items_to_order[$i - 1]; $items_to_order[$i-1] = $item_id; - } elseif (isset($items_to_order[$i+1])){ - $items_to_order[$i] = $items_to_order[$i+1]; + } elseif (isset($items_to_order[$i + 1])){ + $items_to_order[$i] = $items_to_order[$i + 1]; $items_to_order[$i+1] = $item_id; } - $view = DbView::getView('sem_tree'); - for ($i = 0; $i < count($items_to_order); ++$i){ - $view->params = [$i, $items_to_order[$i]]; - $rs = $view->get_query("view:SEM_TREE_UPD_PRIO"); + for ($i = 0; $i < count($items_to_order); ++$i) { + $item = StudipStudyArea::find($items_to_order[$i]); + $item->priority = $i; + $item->store(); } - $this->mode = ""; - $this->msg[$item_id] = "msg§" . (($direction == "up") ? _("Element wurde eine Position nach oben verschoben.") : _("Element wurde eine Position nach unten verschoben.")); + $this->mode = ''; + $this->msg[$item_id] = 'msg§' . (($direction === 'up') ? _('Element wurde eine Position nach oben verschoben.') : _('Element wurde eine Position nach unten verschoben.')); return true; } - function execCommandNewItem(){ + protected function execCommandNewItem() + { $item_id = Request::option('item_id'); - if ($this->isItemAdmin($item_id)){ + if ($this->isItemAdmin($item_id)) { $new_item_id = DbView::get_uniqid(); - $this->tree->storeItem($new_item_id,$item_id,_("Neuer Eintrag"), $this->tree->getNumKids($item_id) +1); + $this->tree->storeItem($new_item_id, $item_id, _('Neuer Eintrag'), $this->tree->getNumKids($item_id) + 1); $this->openItem($new_item_id); $this->edit_item_id = $new_item_id; - if ($this->mode != "NewItem") $this->msg[$new_item_id] = "info§" . _("Hier können Sie die Bezeichnung und die Kurzinformation zu diesem Bereich eingeben."); - $this->mode = "NewItem"; + if ($this->mode !== 'NewItem') { + $this->msg[$new_item_id] = 'info§' . _('Hier können Sie die Bezeichnung und die Kurzinformation zu diesem Bereich eingeben.'); + } + $this->mode = 'NewItem'; } return false; } - function execCommandEditItem(){ + protected function execCommandEditItem() + { $item_id = Request::option('item_id'); if ($this->isItemAdmin($item_id) || $this->isParentAdmin($item_id)){ $this->mode = "EditItem"; $this->anchor = $item_id; $this->edit_item_id = $item_id; - if($this->tree->tree_data[$this->edit_item_id]['studip_object_id']){ - $this->msg[$item_id] = "info§" . _("Hier können Sie die Kurzinformation zu diesem Bereich eingeben. Der Name kann nicht geändert werden, da es sich um eine Stud.IP-Einrichtung handelt."); + if ($this->tree->tree_data[$this->edit_item_id]['studip_object_id']) { + $this->msg[$item_id] = 'info§' . _('Hier können Sie die Kurzinformation zu diesem Bereich eingeben. Der Name kann nicht geändert werden, da es sich um eine Stud.IP-Einrichtung handelt.'); } else { - $this->msg[$item_id] = "info§" . _("Hier können Sie die Bezeichnung und die Kurzinformation zu diesem Bereich eingeben"); + $this->msg[$item_id] = 'info§' . _('Hier können Sie die Bezeichnung und die Kurzinformation zu diesem Bereich eingeben'); } } return false; } - function execCommandInsertItem(){ + protected function execCommandInsertItem() + { $item_id = Request::option('item_id'); $parent_id = Request::option('parent_id'); - $item_name = Request::quoted('edit_name'); - $item_info = Request::quoted('edit_info'); + $item_name = Request::i18n('edit_name'); + $item_info = Request::i18n('edit_info'); $item_type = Request::int('edit_type'); - if ($this->mode == "NewItem" && $item_id){ + if ($this->mode === 'NewItem' && $item_id) { if ($this->isItemAdmin($parent_id)){ $priority = count($this->tree->getKids($parent_id)); - if ($this->tree->InsertItem($item_id,$parent_id,$item_name,$item_info,$priority,null,$item_type)){ - $this->mode = ""; + if ($this->tree->InsertItem($item_id, $parent_id, $item_name, $item_info, $priority, null, $item_type)) { + $this->mode = ''; $this->tree->init(); $this->openItem($item_id); - $this->msg[$item_id] = "msg§" . _("Dieser Bereich wurde neu eingefügt."); + $this->msg[$item_id] = 'msg§' . _('Dieser Bereich wurde neu eingefügt.'); } } } - if ($this->mode == "EditItem"){ + if ($this->mode === 'EditItem') { if ($this->isParentAdmin($item_id)){ if ($this->tree->UpdateItem($item_id, $item_name, $item_info, $item_type)){ - $this->msg[$item_id] = "msg§" . _("Bereich wurde geändert."); + $this->msg[$item_id] = 'msg§' . _('Bereich wurde geändert.'); } else { - $this->msg[$item_id] = "info§" . _("Keine Veränderungen vorgenommen."); + $this->msg[$item_id] = 'info§' . _('Keine Veränderungen vorgenommen.'); } $this->mode = ""; $this->tree->init(); @@ -229,7 +237,8 @@ class StudipSemTreeViewAdmin extends TreeView return false; } - function execCommandAssertDeleteItem(){ + protected function execCommandAssertDeleteItem() + { $item_id = Request::option('item_id'); if ($this->isParentAdmin($item_id)){ $this->mode = "AssertDeleteItem"; @@ -247,7 +256,8 @@ class StudipSemTreeViewAdmin extends TreeView return false; } - function execCommandDeleteItem(){ + protected function execCommandDeleteItem() + { $item_id = Request::option('item_id'); $item_name = $this->tree->tree_data[$item_id]['name']; if ($this->isParentAdmin($item_id) && $this->mode == "AssertDeleteItem"){ @@ -268,28 +278,35 @@ class StudipSemTreeViewAdmin extends TreeView return true; } - function execCommandMoveItem(){ + protected function execCommandMoveItem() + { $item_id = Request::option('item_id'); $this->anchor = $item_id; $this->marked_item = $item_id; - $this->mode = "MoveItem"; + $this->mode = 'MoveItem'; return false; } - function execCommandCopyItem(){ + protected function execCommandCopyItem() + { $item_id = Request::option('item_id'); $this->anchor = $item_id; $this->marked_item = $item_id; - $this->mode = "CopyItem"; + $this->mode = 'CopyItem'; return false; } - function execCommandDoMoveItem(){ + protected function execCommandDoMoveItem() + { $item_id = Request::option('item_id'); $item_to_move = $this->marked_item; - if ($this->mode == "MoveItem" && ($this->isItemAdmin($item_id) || $this->isParentAdmin($item_id)) - && ($item_to_move != $item_id) && ($this->tree->tree_data[$item_to_move]['parent_id'] != $item_id) - && !$this->tree->isChildOf($item_to_move,$item_id)){ + if ( + $this->mode === 'MoveItem' + && ($this->isItemAdmin($item_id) || $this->isParentAdmin($item_id)) + && ($item_to_move !== $item_id) + && ($this->tree->tree_data[$item_to_move]['parent_id'] !== $item_id) + && !$this->tree->isChildOf($item_to_move, $item_id) + ) { $view = DbView::getView('sem_tree'); $view->params = [$item_id, count($this->tree->getKids($item_id)), $item_to_move]; $rs = $view->get_query("view:SEM_TREE_MOVE_ITEM"); @@ -305,32 +322,42 @@ class StudipSemTreeViewAdmin extends TreeView return false; } - function execCommandDoCopyItem(){ + protected function execCommandDoCopyItem() + { $item_id = Request::option('item_id'); $item_to_copy = $this->marked_item; - if ($this->mode == "CopyItem" && ($this->isItemAdmin($item_id) || $this->isParentAdmin($item_id)) - && ($item_to_copy != $item_id) && ($this->tree->tree_data[$item_to_copy]['parent_id'] != $item_id) - && !$this->tree->isChildOf($item_to_copy,$item_id)){ + if ( + $this->mode === 'CopyItem' + && ($this->isItemAdmin($item_id) || $this->isParentAdmin($item_id)) + && ($item_to_copy !== $item_id) + && ($this->tree->tree_data[$item_to_copy]['parent_id'] !== $item_id) + && !$this->tree->isChildOf($item_to_copy,$item_id) + ) { $items_to_copy = $this->tree->getKidsKids($item_to_copy); $seed = DbView::get_uniqid(); $new_item_id = md5($item_to_copy . $seed); $parent_id = $item_id; - $num_copy = $this->tree->InsertItem($new_item_id,$parent_id, - addslashes($this->tree->tree_data[$item_to_copy]['name']), - addslashes($this->tree->tree_data[$item_to_copy]['info']), - $this->tree->getMaxPriority($parent_id)+1, - ($this->tree->tree_data[$item_to_copy]['studip_object_id'] ? $this->tree->tree_data[$item_to_copy]['studip_object_id'] : null), - $this->tree->tree_data[$item_to_copy]['type']); - if($num_copy){ + $num_copy = $this->tree->InsertItem( + $new_item_id, + $parent_id, + $this->tree->tree_data[$item_to_copy]['name'], + $this->tree->tree_data[$item_to_copy]['info'], + $this->tree->getMaxPriority($parent_id) + 1, + $this->tree->tree_data[$item_to_copy]['studip_object_id'] ?: null, + $this->tree->tree_data[$item_to_copy]['type'] + ); + if ($num_copy){ if ($items_to_copy){ - for ($i = 0; $i < count($items_to_copy); ++$i){ - $num_copy += $this->tree->InsertItem(md5($items_to_copy[$i] . $seed), - md5($this->tree->tree_data[$items_to_copy[$i]]['parent_id'] . $seed), - addslashes($this->tree->tree_data[$items_to_copy[$i]]['name']), - addslashes($this->tree->tree_data[$items_to_copy[$i]]['info']), - $this->tree->tree_data[$items_to_copy[$i]]['priority'], - ($this->tree->tree_data[$items_to_copy[$i]]['studip_object_id'] ? $this->tree->tree_data[$items_to_copy[$i]]['studip_object_id'] : null), - $this->tree->tree_data[$item_to_copy]['type']); + for ($i = 0; $i < count($items_to_copy); ++$i) { + $num_copy += $this->tree->InsertItem( + md5($items_to_copy[$i] . $seed), + md5($this->tree->tree_data[$items_to_copy[$i]]['parent_id'] . $seed), + $this->tree->tree_data[$items_to_copy[$i]]['name'], + $this->tree->tree_data[$items_to_copy[$i]]['info'], + $this->tree->tree_data[$items_to_copy[$i]]['priority'], + $this->tree->tree_data[$items_to_copy[$i]]['studip_object_id'] ?: null, + $this->tree->tree_data[$item_to_copy]['type'] + ); } } $items_to_copy[] = $item_to_copy; @@ -345,40 +372,46 @@ class StudipSemTreeViewAdmin extends TreeView } if ($num_copy){ - $this->msg[$new_item_id] = "msg§" . sprintf(_("%s Bereich(e) wurde(n) kopiert."), $num_copy) . "<br>" - . sprintf(_("%s Veranstaltungszuordnungen wurden kopiert"), $num_entries); + $this->msg[$new_item_id] = 'msg§' . sprintf(_('%s Bereich(e) wurde(n) kopiert.'), $num_copy) . '<br>' + . sprintf(_('%s Veranstaltungszuordnungen wurden kopiert'), $num_entries); } else { - $this->msg[$new_item_id] = "error§" . _("Keine Kopie durchgeführt."); + $this->msg[$new_item_id] = 'error§' . _('Keine Kopie durchgeführt.'); } $this->tree->init(); $this->openItem($new_item_id); } - $this->mode = ""; + $this->mode = ''; return false; } - function execCommandInsertFak(){ - if($this->isItemAdmin("root") && Request::quoted('insert_fak')){ - $view = DbView::getView('sem_tree'); - $item_id = $view->get_uniqid(); - $view->params = [$item_id,'root','',$this->tree->getNumKids('root')+1,'',Request::quoted('insert_fak'),0]; - $rs = $view->get_query("view:SEM_TREE_INS_ITEM"); - if ($rs->affected_rows()){ + protected function execCommandInsertFak() + { + if ($this->isItemAdmin('root') && Request::option('insert_fak')){ + $item = StudipStudyArea::create([ + 'parent_id' => 'root', + 'priority' => $this->tree->getNumKids('root') + 1, + 'name' => '', + 'info' => '', + 'studip_object_id' => Request::option('insert_fak'), + 'type' => 0, + ]); + if ($item) { $this->tree->init(); - $this->openItem($item_id); - $this->msg[$item_id] = "msg§" . _("Dieser Bereich wurde neu eingefügt."); + $this->openItem($item->id); + $this->msg[$item->id] = 'msg§' . _('Dieser Bereich wurde neu eingefügt.'); return false; } } return false; } - function execCommandMarkSem(){ + protected function execCommandMarkSem() + { $item_id = Request::option('item_id'); $marked_sem_array = Request::quotedArray('marked_sem'); $marked_sem = array_values(array_unique($marked_sem_array)); $sem_aktion = explode("_",Request::quoted('sem_aktion')); - if (($sem_aktion[0] == 'mark' || $sem_aktion[1] == 'mark') && count($marked_sem)){ + if (($sem_aktion[0] === 'mark' || $sem_aktion[1] === 'mark') && count($marked_sem) > 0) { $count_mark = 0; for ($i = 0; $i < count($marked_sem); ++$i){ if (!isset($this->marked_sem[$marked_sem[$i]])){ @@ -422,65 +455,33 @@ class StudipSemTreeViewAdmin extends TreeView return false; } - function execCommandCancel(){ + protected function execCommandCancel() + { $item_id = Request::option('item_id'); - $this->mode = ""; + $this->mode = ''; $this->anchor = $item_id; return false; } - function showSemTree(){ - ?> - <script type="text/javascript"> - function invert_selection(the_form){ - my_elements = document.forms[the_form].elements['marked_sem[]']; - if(!my_elements.length){ - if(my_elements.checked) - my_elements.checked = false; - else - my_elements.checked = true; - } else { - for(i = 0; i < my_elements.length; ++i){ - if(my_elements[i].checked) - my_elements[i].checked = false; - else - my_elements[i].checked = true; - } - } - } - </script> - <? - echo "\n<table width=\"99%\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">"; - if ($this->start_item_id != 'root'){ - echo "\n<tr><td class=\"table_row_odd\" align=\"left\" valign=\"top\"><div style=\"font-size:10pt;margin-left:10px\"><b>" - . _("Studienbereiche") . ":</b><br>" . $this->getSemPath() - . "</div></td></tr>"; - } - echo "\n<tr><td class=\"blank\" align=\"left\" valign=\"top\">"; - $this->showTree($this->start_item_id); - echo "\n</td></tr></table>"; - } - - function getSemPath(){ - $ret = ""; - //$ret = "<a href=\"" . parent::getSelf("start_item_id=root") . "\">" .htmlReady($this->tree->root_name) . "</a>"; - if ($parents = $this->tree->getParents($this->start_item_id)){ - for($i = count($parents)-1; $i >= 0; --$i){ - $ret .= " > <a class=\"tree\" href=\"" . URLHelper::getLink($this->getSelf("start_item_id={$parents[$i]}&open_item={$parents[$i]}",false)) - . "\">" .htmlReady($this->tree->tree_data[$parents[$i]]["name"]) . "</a>"; - } - } - return $ret; + public function showSemTree() + { + return $this->renderTemplate('sem-tree.php', [ + 'start_item_id' => $this->start_item_id, + 'parents' => $this->tree->getParents($this->start_item_id), + 'tree' => $this->capture(function () { + $this->showTree($this->start_item_id); + }), + ]); } /** - * returns html for the icons in front of the name of the item - * - * @access private - * @param string $item_id - * @return string - */ - function getItemHeadPics($item_id){ + * returns html for the icons in front of the name of the item + * + * @param string $item_id + * @return string + */ + public function getItemHeadPics($item_id) + { $head = $this->getItemHeadFrontPic($item_id); $head .= "\n<td class=\"printhead\" nowrap align=\"left\" valign=\"bottom\">"; if ($this->tree->hasKids($item_id)){ @@ -491,96 +492,41 @@ class StudipSemTreeViewAdmin extends TreeView return $head . "</td>"; } - function getItemContent($item_id){ - if (!empty($this->edit_item_id) && ($item_id == $this->edit_item_id)) return $this->getEditItemContent(); - if(empty($GLOBALS['SEM_TREE_TYPES'][$this->tree->getValue($item_id, 'type')]['editable'])){ - $is_not_editable = true; - $this->msg[$item_id] = "info§" . sprintf(_("Der Typ dieses Elementes verbietet eine Bearbeitung.")); - } - if (!empty($this->move_item_id) && ($item_id == $this->move_item_id)) { - $this->msg[$item_id] = "info§" . sprintf(_("Dieses Element wurde zum Verschieben / Kopieren markiert. Bitte wählen Sie ein Einfügesymbol %s aus, um das Element zu verschieben / kopieren."), Icon::create('arr_2right', 'sort', ['title' => "Einfügesymbol"])->asImg(16, ["alt" => "Einfügesymbol"])); - } - $content = "\n<table width=\"90%\" cellpadding=\"2\" cellspacing=\"2\" align=\"center\" style=\"font-size:10pt;\">"; - $content .= $this->getItemMessage($item_id); - $content .= "\n<tr><td style=\"font-size:10pt;\">"; - if (empty($is_not_editable)) { - if ($this->isItemAdmin($item_id) ){ - $content .= LinkButton::create(_('Neues Objekt'), - URLHelper::getURL($this->getSelf('cmd=NewItem&item_id='.$item_id)), - ['title' => _('Innerhalb dieser Ebene ein neues Element einfügen')]) . ' '; - $content .= LinkButton::create(_('Sortieren'), - URLHelper::getURL($this->getSelf('cmd=OrderItemsAlphabetically&sort_id='.$item_id)), - ['title' => _('Sortiert die untergeordneten Elemente alphabetisch')]) . ' '; - } - if ($this->isParentAdmin($item_id) && $item_id != "root"){ - $content .= LinkButton::create(_('Bearbeiten'), - URLHelper::getURL($this->getSelf('cmd=EditItem&item_id=' . $item_id)), - ['title' => 'Dieses Element bearbeiten']) . ' '; - - $content .= LinkButton::create(_('Löschen'), - URLHelper::getURL($this->getSelf('cmd=AssertDeleteItem&item_id=' . $item_id)), - ['title' => _('Dieses Element löschen')]) . ' '; - - if (!empty($this->move_item_id) && ($this->move_item_id == $item_id) && ($this->mode == "MoveItem" || $this->mode == "CopyItem")){ - $content .= LinkButton::create(_('Abbrechen'), - URLHelper::getURL($this->getSelf('cmd=Cancel&item_id=' . $item_id)), - ['title' => _('Verschieben / Kopieren abbrechen')]) . ' '; - } else { - $content .= LinkButton::create(_('Verschieben'), - URLHelper::getURL($this->getSelf('cmd=MoveItem&item_id='.$item_id)), - ['title' => _('Dieses Element in eine andere Ebene verschieben')]) . ' '; - $content .= LinkButton::create(_('Kopieren'), - URLHelper::getURL($this->getSelf('cmd=CopyItem&item_id='.$item_id)), - ['title' => _('Dieses Element in eine andere Ebene kopieren')]); - } - } + function getItemContent($item_id) + { + if ($item_id === $this->edit_item_id) { + return $this->getEditItemContent(); } - if ($item_id == 'root' && $this->isItemAdmin($item_id)){ - $view = DbView::getView('sem_tree'); - $rs = $view->get_query("view:SEM_TREE_GET_LONELY_FAK"); - $content .= "\n<p><form action=\"" . URLHelper::getLink($this->getSelf("cmd=InsertFak")) . "\" method=\"post\" class=\"default\">" - . CSRFProtection::tokenTag() - . '<div><label>' - . _("Stud.IP-Fakultät einfügen") - . "\n<select style=\"width:200px;\" name=\"insert_fak\">"; - while($rs->next_record()){ - $content .= "\n<option value=\"" . $rs->f("Institut_id") . "\">" . htmlReady(my_substr($rs->f("Name"),0,50)) . "</option>"; - } - $content .= "</select></label></div><div class=\"col-1\"> " . Button::create(_('Eintragen'), ['title' => _("Fakultät einfügen")]) . "</div></form></p>"; - } - $content .= "</td></tr></table>"; - - $content .= "\n<table border=\"0\" width=\"90%\" cellpadding=\"2\" cellspacing=\"0\" align=\"center\" style=\"font-size:10pt\">"; - if ($item_id == "root"){ - $content .= "\n<tr><td class=\"table_header_bold\" align=\"left\" style=\"font-size:10pt;\">" . htmlReady($this->tree->root_name) ." </td></tr>"; - $content .= "\n<tr><td class=\"table_row_even\" align=\"left\" style=\"font-size:10pt;\">" . htmlReady($this->root_content) ." </td></tr>"; - $content .= "\n</table>"; - return $content; - } - if ($this->tree->tree_data[$item_id]['info']){ - $content .= "\n<tr><td style=\"font-size:10pt;\" class=\"table_row_even\" align=\"left\" colspan=\"3\">"; - $content .= formatReady($this->tree->tree_data[$item_id]['info']) . "</td></tr>"; - } - $content .= "<tr><td style=\"font-size:10pt;\"colspan=\"3\"> </td></tr>"; - if (!empty($this->tree->tree_data[$item_id]['lonely_sem']) && ($this->tree->getNumEntries($item_id) - $this->tree->tree_data[$item_id]['lonely_sem'])) { - $content .= "<tr><td class=\"table_row_even\" style=\"font-size:10pt;\" align=\"left\" colspan=\"3\"><b>" . _("Einträge auf dieser Ebene:"); - $content .= "</b>\n</td></tr>"; - $entries = $this->tree->getSemData($item_id); - $content .= $this->getSemDetails($entries,$item_id); - } else { - $content .= "\n<tr><td class=\"table_row_even\" style=\"font-size:10pt;\" colspan=\"3\">" . _("Keine Einträge auf dieser Ebene vorhanden!") . "</td></tr>"; + if (empty($GLOBALS['SEM_TREE_TYPES'][$this->tree->getValue($item_id, 'type')]['editable'])) { + $this->msg[$item_id] = "info§" . sprintf(_('Der Typ dieses Elementes verbietet eine Bearbeitung.')); } - if (!empty($this->tree->tree_data[$item_id]['lonely_sem'])) { - $content .= "<tr><td class=\"table_row_even\" align=\"left\" style=\"font-size:10pt;\" colspan=\"3\"><b>" . _("Nicht zugeordnete Veranstaltungen auf dieser Ebene:"); - $content .= "</b>\n</td></tr>"; - $entries = $this->tree->getLonelySemData($item_id); - $content .= $this->getSemDetails($entries,$item_id,true); + if ($item_id === $this->move_item_id){ + $this->msg[$item_id] = 'info§' . sprintf( + _('Dieses Element wurde zum Verschieben / Kopieren markiert. Bitte wählen Sie ein Einfügesymbol %s aus, um das Element zu verschieben / kopieren.'), + Icon::create('arr_2right', Icon::ROLE_SORT)->asImg(tooltip2(_('Einfügesymbol'))) + ); } - $content .= "</table>"; - return $content; + + $unassigned_faculties = Institute::findBySQL( + 'LEFT JOIN sem_tree ON (studip_object_id = Institut_id) + WHERE Institut_id = fakultaets_id + AND studip_object_id IS NULL' + ); + + return $this->renderTemplate('item-content.php', [ + 'item_id' => $item_id, + 'editable' => $GLOBALS['SEM_TREE_TYPES'][$this->tree->getValue($item_id, 'type')]['editable'], + 'is_item_admin' => $this->isItemAdmin($item_id), + 'is_parent_admin' => $this->isParentAdmin($item_id) && $item_id !== 'root', + 'moving_or_copying' => $this->move_item_id === $item_id && ($this->mode === 'MoveItem' || $this->mode === 'CopyItem'), + 'message' => $this->getItemMessage($item_id), + 'tree' => $this->tree, + 'unassigned_faculties' => $unassigned_faculties, + ]); } - function getSemDetails($snap, $item_id, $lonely_sem = false){ + public function getSemDetails($snap, $item_id, $lonely_sem = false) + { $form_name = DbView::get_uniqid(); $content = "<form class=\"default\" name=\"$form_name\" action=\"" . URLHelper::getLink($this->getSelf("cmd=MarkSem")) ."\" method=\"post\"> <input type=\"hidden\" name=\"item_id\" value=\"$item_id\">"; @@ -678,93 +624,49 @@ class StudipSemTreeViewAdmin extends TreeView return $content; } - function getEditItemContent(){ - ob_start(); - ?> - <form name="item_form" action="<?= URLHelper::getLink($this->getSelf("cmd=InsertItem&item_id={$this->edit_item_id}")) ?>" method="POST" class="default" style="width: 90%; margin: auto;"> - <?= CSRFProtection::tokenTag(); ?> - <input type="hidden" name="parent_id" value="<?= $this->tree->tree_data[$this->edit_item_id]['parent_id'] ?>"> - - <table style="width: 100%"><?= $this->getItemMessage($this->edit_item_id,2) ?></table> - - <fieldset> - <legend><?= _("Bereich editieren") ?></legend> - - <label> - <?= _("Name des Elements") ?> - <input type="text" name="edit_name" - <?= ($this->tree->tree_data[$this->edit_item_id]['studip_object_id']) ? 'disabled="disabled"' : '' ?> - value="<?= htmlReady($this->tree->tree_data[$this->edit_item_id]['name']) ?>"> - </label> - - <? if (count($GLOBALS['SEM_TREE_TYPES']) > 1) : ?> - <label> - <?= _("Typ des Elements") ?> - <select name="edit_type"> - <? foreach ($GLOBALS['SEM_TREE_TYPES'] as $sem_tree_type_key => $sem_tree_type) : - if ($sem_tree_type['editable']) : - $selected = $sem_tree_type_key == $this->tree->getValue($this->edit_item_id, 'type') ? 'selected' : ''; - echo '<option value="'.htmlReady($sem_tree_type_key).'"'.$selected.'>'; - echo htmlReady($sem_tree_type['name'] ? $sem_tree_type['name'] : $sem_tree_type_key); - echo '</option>'; - endif; - endforeach; - ?> - </select> - </label> - <? else : # Auswahl ausblenden, wenn nur ein Typ vorhanden ?> - <input type='hidden' name='edit_type' value='0'> - <? endif ?> - - <? $buttonlink_id = ($this->mode == "NewItem") ? $this->tree->tree_data[$this->edit_item_id]['parent_id'] : $this->edit_item_id; ?> - - <label> - <?= _("Infotext:") ?> - <textarea rows="5" name="edit_info" wrap="virtual"><?= htmlReady($this->tree->tree_data[$this->edit_item_id]['info']) ?></textarea> - </label> - </fieldset> - - <footer> - <?= Button::createAccept(_('Absenden'), ['title' => _('Einstellungen übernehmen')]) ?> - <?= LinkButton::createCancel(_('Abbrechen'), - URLHelper::getURL($this->getSelf('cmd=Cancel&item_id='.$buttonlink_id)), - ['title' => _('Aktion abbrechen')]) - ?> - </footer> - </form> - - <? - return ob_get_clean(); + public function getEditItemContent() + { + $study_area = StudipStudyArea::find($this->edit_item_id); + + $sem_tree_types = array_filter($GLOBALS['SEM_TREE_TYPES'], function ($type) { + return $type['editable']; + }); + + return $this->renderTemplate('item-edit.php', [ + 'action_url' => $this->getSelf("cmd=InsertItem&item_id={$study_area->id}"), + 'cancel_url' => $this->getSelf('cmd=Cancel&item_id=' . ($this->mode === 'NewItem' ? $study_area->parent_id : $study_area->id)), + 'message' => $this->getItemMessage($study_area->id, 2), + 'study_area' => $study_area, + 'sem_tree_types' => $sem_tree_types, + 'mode' => $this->mode, + ]); } - - function isItemAdmin($item_id){ - global $auth; - if ($auth->auth['perm'] == "root"){ + public function isItemAdmin($item_id) + { + if ($GLOBALS['auth']->auth['perm'] === 'root') { return true; } if (!($admin_id = $this->tree->tree_data[$this->tree->getAdminRange($item_id)]['studip_object_id'])){ return false; } - if(!isset($this->admin_ranges[$admin_id])){ + if (!isset($this->admin_ranges[$admin_id])) { $view = DbView::getView('sem_tree'); $view->params[0] = $auth->auth['uid']; $view->params[1] = $admin_id; $rs = $view->get_query("view:SEM_TREE_CHECK_PERM"); $this->admin_ranges[$admin_id] = ($rs->next_record()) ? true : false; } - if ($this->admin_ranges[$admin_id]){ - return true; - } else { - return false; - } + return (bool) $this->admin_ranges[$admin_id]; } - function isParentAdmin($item_id){ + public function isParentAdmin($item_id) + { return $this->isItemAdmin($this->tree->tree_data[$item_id]['parent_id']); } - function getItemHead($item_id){ + public function getItemHead($item_id) + { $head = ""; if (($this->mode == "MoveItem" || $this->mode == "CopyItem") && ($this->isItemAdmin($item_id) || $this->isParentAdmin($item_id)) && ($this->move_item_id != $item_id) && ($this->tree->tree_data[$this->move_item_id]['parent_id'] != $item_id) @@ -793,37 +695,76 @@ class StudipSemTreeViewAdmin extends TreeView return $head; } - function getItemMessage($item_id,$colspan = 1){ - $content = ""; - if (!empty($this->msg[$item_id])) { - $msg = explode("§",$this->msg[$item_id]); - $pics = [ - 'error' => Icon::create('decline', 'attention'), - 'info' => Icon::create('exclaim', 'inactive'), - 'msg' => Icon::create('accept', 'accept')]; - $content = "\n<tr><td colspan=\"{$colspan}\"><table border=\"0\" cellspacing=\"0\" cellpadding=\"2\" width=\"100%\" style=\"font-size:10pt\"> - <tr><td class=\"blank\" align=\"center\" width=\"25\">" . $pics[$msg[0]]->asImg(['class' => 'text-top']) . "</td> - <td class=\"blank\" align=\"left\">" . $msg[1] . "</td></tr> - </table></td></tr><tr>"; + public function getItemMessage($item_id, $colspan = 1) + { + if (empty($this->msg[$item_id])) { + return ''; } - return $content; + + $icons = [ + 'error' => Icon::create('decline', Icon::ROLE_ATTENTION), + 'info' => Icon::create('exclaim', Icon::ROLE_INACTIVE), + 'msg' => Icon::create('accept', Icon::ROLE_ACCEPT), + ]; + + $msg = explode('§', $this->msg[$item_id]); + + return $this->renderTemplate('item-message.php', [ + 'colspan' => $colspan, + 'icon' => $icons[$msg[0]], + 'message' => $msg[1], + ]); } - function getSelf($param = "", $with_start_item = true){ + public function getSelf($param = '', $with_start_item = true) + { $url_params = "foo=" . DbView::get_uniqid(); - if ($this->mode) $url_params .= "&mode=" . $this->mode; - if ($with_start_item) $url_params .= "&start_item_id=" . $this->start_item_id; - if ($param) $url_params .= '&' . $param; + if ($this->mode) { + $url_params .= '&mode=' . $this->mode; + } + if ($with_start_item) { + $url_params .= '&start_item_id=' . $this->start_item_id; + } + if ($param) { + $url_params .= '&' . $param; + } return parent::getSelf($url_params); } + + public function url_for($to = '') + { + $args = func_get_args(); + $params = []; + if (is_array(end($args))) { + $params = array_pop($args); + } + + $params['foo'] = DbView::get_uniqid(); + if ($this->mode) { + $params['mode'] = $this->mode; + } + + return URLHelper::getURL(parent::getSelf(http_build_query($params))); + } + + public function link_for($to = '') + { + return htmlReady(call_user_func_array([$this, 'url_for'], func_get_args())); + } + + private function renderTemplate($template, array $variables = []) + { + $template = $GLOBALS['template_factory']->open("sem_tree/{$template}"); + $template->controller = $this; + $template->tree_data = $this->tree->tree_data; + $template->set_attributes($variables); + return $template->render(); + } + + private function capture(callable $callable) + { + ob_start(); + $callable(); + return ob_get_clean(); + } } -//test -//page_open(array("sess" => "Seminar_Session", "auth" => "Seminar_Default_Auth", "perm" => "Seminar_Perm", "user" => "Seminar_User")); -//include 'lib/include/html_head.inc.php'; -//include ('lib/seminar_open.php'); // initialise Stud.IP-Session -//$test = new StudipSemTreeViewAdmin(Request::quoted('start_item_id')); -//$test->showSemTree(); -//echo "<hr><pre>"; -//print_r($_open_items); -//page_close(); -?> diff --git a/lib/classes/TreeAbstract.class.php b/lib/classes/TreeAbstract.class.php index 9f546545d2acc25ed22766d2b78703c257fecf93..5320efedfa81b916b983ffa3e04b80b5b51f9932 100644 --- a/lib/classes/TreeAbstract.class.php +++ b/lib/classes/TreeAbstract.class.php @@ -215,7 +215,7 @@ class TreeAbstract { */ public function getNumKids($item_id) { - if(!isset($this->tree_num_childs[$item_id])){ + if (!isset($this->tree_num_childs[$item_id])){ $this->tree_num_childs[$item_id] = (!empty($this->tree_childs[$item_id]) && is_array($this->tree_childs[$item_id])) ? count($this->tree_childs[$item_id]) : 0; } return $this->tree_num_childs[$item_id]; @@ -238,7 +238,7 @@ class TreeAbstract { if ($num_kids){ $kids = $this->getKids($item_id); $kidskids = array_merge((array)$kidskids, (array)$kids); - for ($i = 0; $i < $num_kids; ++$i){ + for ($i = 0; $i < $num_kids; ++$i) { $this->getKidsKids($kids[$i],true); } } diff --git a/lib/classes/TreeView.class.php b/lib/classes/TreeView.class.php index 243a9b9e6312ba42b342a6a7fdb4f462a423c127..1980fc1e24d3659ce088410f4f58c29866ebc7fc 100644 --- a/lib/classes/TreeView.class.php +++ b/lib/classes/TreeView.class.php @@ -204,24 +204,23 @@ class TreeView { * @access public * @param string $item_id */ - function showTree($item_id = "root"){ - $items = []; - if (!is_array($item_id)){ - $items[0] = $item_id; - $this->start_item_id = $item_id; - } else { - $items = $item_id; - } - $num_items = count($items); - for ($j = 0; $j < $num_items; ++$j){ - $this->printLevelOutput($items[$j]); - $this->printItemOutput($items[$j]); + function showTree($item_id = "root") { + $items = []; + if (!is_array($item_id)){ + $items[0] = $item_id; + $this->start_item_id = $item_id; + } else { + $items = $item_id; + } + $num_items = count($items); + for ($j = 0; $j < $num_items; ++$j){ + $this->printLevelOutput($items[$j]); + $this->printItemOutput($items[$j]); if ($this->tree->hasKids($items[$j]) && !empty($this->open_ranges[$items[$j]])) { - $this->showTree($this->tree->tree_childs[$items[$j]]); + $this->showTree($this->tree->tree_childs[$items[$j]]); + } } } - return; -} /** * prints out the lines before an item ("Strichlogik" (c) rstockm) diff --git a/lib/dbviews/sem_tree.view.php b/lib/dbviews/sem_tree.view.php index f82767dd1ebec9f264280409f2d0ffece0dbf941..548bf078a6f8c2a1209a2b0f8ca2f7afa88a2b54 100644 --- a/lib/dbviews/sem_tree.view.php +++ b/lib/dbviews/sem_tree.view.php @@ -35,10 +35,6 @@ $_views = []; $_views['sem_number_sql'] = "INTERVAL(start_time," . join(",",$sem_start_times) .")"; $_views['sem_number_end_sql'] = "IF(duration_time=-1,-1,INTERVAL(start_time+duration_time," . join(",",$sem_start_times) ."))"; -$_views["SEM_TREE_GET_DATA_NO_ENTRIES"] = ["pk"=>"sem_tree_id","temp_table_type"=>"HEAP", - "query"=>"SELECT a.*, c.Name AS studip_object_name - FROM sem_tree a LEFT JOIN Institute c ON (a.studip_object_id = c.Institut_id) - ORDER BY priority"]; $_views["SEM_TREE_GET_ENTRIES"] = ["pk"=>"sem_tree_id","temp_table_type"=>"HEAP", "query" => "SELECT st.sem_tree_id, count(b.Seminar_id) AS entries FROM seminare b INNER JOIN seminar_sem_tree st ON(st.seminar_id = b.Seminar_id) @@ -69,10 +65,6 @@ $_views["SEM_TREE_GET_NUM_LONELY_SEM"] = ["query" => "SELECT COUNT(DISTINCT(b.se WHERE ISNULL(c.sem_tree_id) AND a.fakultaets_id LIKE ? AND NOT ISNULL(b.seminar_id) GROUP BY sem_number,sem_number_end § "]; $_views["SEM_TREE_GET_LONELY_FAK"] = ["query" => "SELECT Institut_id,a.Name FROM Institute a LEFT JOIN sem_tree b ON(studip_object_id=Institut_id) WHERE Institut_id = fakultaets_id AND ISNULL(studip_object_id) ORDER BY a.Name"]; -$_views["SEM_TREE_UPD_PRIO"] = ["query" => "UPDATE sem_tree SET priority=§ WHERE sem_tree_id=?"]; -$_views["SEM_TREE_INS_ITEM"] = ["query" => "INSERT INTO sem_tree (sem_tree_id,parent_id,name,priority,info,studip_object_id,type) VALUES (?,?,?,?,?,?,?)"]; -$_views["SEM_TREE_UPD_ITEM"] = ["query" => "UPDATE sem_tree SET name=?, info=?, type=? WHERE sem_tree_id=?"]; -$_views["SEM_TREE_DEL_ITEM"] = ["query" => "DELETE FROM sem_tree WHERE sem_tree_id IN (&)"]; $_views["SEM_TREE_MOVE_ITEM"] = ["query" => "UPDATE sem_tree SET parent_id=?, priority=§ WHERE sem_tree_id=?"]; $_views["SEM_TREE_SEARCH_SEM"] = ["query" => "SELECT b.seminar_id, " . $_views['sem_number_sql'] . " AS sem_number, " . $_views['sem_number_end_sql'] . " AS sem_number_end FROM sem_tree a LEFT JOIN seminar_sem_tree b USING(sem_tree_id) LEFT JOIN seminare c USING(seminar_id) diff --git a/lib/models/StudipStudyArea.class.php b/lib/models/StudipStudyArea.class.php index 4ef7a5783fb27322680da9453ae314a3df13ab7c..f6b9e00d73ce073bc8ac2a18d724a458a13d5cba 100644 --- a/lib/models/StudipStudyArea.class.php +++ b/lib/models/StudipStudyArea.class.php @@ -19,8 +19,8 @@ * @property string id alias column for sem_tree_id * @property string parent_id database column * @property string priority database column - * @property string info database column - * @property string name database column + * @property I18NString info database column + * @property I18NString name database column * @property string studip_object_id database column * @property string type database column * @property SimpleORMapCollection _children has_many StudipStudyArea @@ -28,7 +28,6 @@ * @property StudipStudyArea _parent belongs_to StudipStudyArea * @property SimpleORMapCollection courses has_and_belongs_to_many Course */ - class StudipStudyArea extends SimpleORMap { /** @@ -58,6 +57,10 @@ class StudipStudyArea extends SimpleORMap 'class_name' => StudipStudyArea::class, 'foreign_key' => 'parent_id', ]; + + $config['i18n_fields']['name'] = true; + $config['i18n_fields']['info'] = true; + parent::configure($config); } @@ -79,14 +82,11 @@ class StudipStudyArea extends SimpleORMap */ public static function find($id) { - $result = NULL; if ($id === self::ROOT) { $result = self::getRootArea(); - } - - else { + } else { $result = parent::find($id); } @@ -101,26 +101,6 @@ class StudipStudyArea extends SimpleORMap return $this->id; } - - /** - * Get the comment of this study area. - */ - public function getInfo() - { - return $this->content['info']; - } - - - /** - * Set the comment of this study area. - */ - public function setInfo($info) - { - $this->content['info'] = (string) $info; - return $this; - } - - /** * Get the display name of this study area. */ @@ -129,19 +109,10 @@ class StudipStudyArea extends SimpleORMap if ($this->studip_object_id) { return $this->institute->name; } - return $this->content['name']; - } - /** - * Set the display name of this study area. - */ - public function setName($name) - { - $this->content['name'] = (string) $name; - return $this; + return $this->content['name']; } - /** * Get the parent ID of this study area. */ @@ -174,23 +145,6 @@ class StudipStudyArea extends SimpleORMap return $this; } - /** - * get the type of this study area. - */ - public function getType() - { - return $this->content['type']; - } - - /** - * set the type of this study area. - */ - public function setType($type) - { - $this->content['type'] = (int) $type; - return $this; - } - /** * get the name of the type of this study area, see $SEM_TREE_TYPES in config.inc.php * @@ -198,11 +152,7 @@ class StudipStudyArea extends SimpleORMap */ public function getTypeName() { - if(isset($GLOBALS['SEM_TREE_TYPES'][$this->getType()]['name'])){ - return $GLOBALS['SEM_TREE_TYPES'][$this->getType()]['name']; - } else { - return ''; - } + return $GLOBALS['SEM_TREE_TYPES'][$this->getType()]['name'] ?? ''; } /** @@ -212,11 +162,7 @@ class StudipStudyArea extends SimpleORMap */ public function isEditable() { - if(isset($GLOBALS['SEM_TREE_TYPES'][$this->getType()]['editable'])){ - return (bool)$GLOBALS['SEM_TREE_TYPES'][$this->getType()]['editable']; - } else { - return false; - } + return (bool) ($GLOBALS['SEM_TREE_TYPES'][$this->getType()]['editable'] ?? false); } /** @@ -226,23 +172,17 @@ class StudipStudyArea extends SimpleORMap */ public function isHidden() { - if (isset($GLOBALS['SEM_TREE_TYPES'][$this->getType()]['hidden'])) { - return (bool) $GLOBALS['SEM_TREE_TYPES'][$this->getType()]['hidden']; - } else { - return false; - } + return ($GLOBALS['SEM_TREE_TYPES'][$this->getType()]['hidden'] ?? false); } /** * Get the path along the sem_tree to this study area. * * @param string optional; TODO - * * @return mixed TODO */ public function getPath($separator = NULL) { - $path = []; $area = $this; @@ -263,26 +203,6 @@ class StudipStudyArea extends SimpleORMap : $path; } - - /** - * Get the priority of this study area. - */ - public function getPriority() - { - return $this->content['priority']; - } - - - /** - * Set the priority of this study area. - */ - public function setPriority($priority) - { - $this->content['priority'] = (int) $priority; - return $this; - } - - /** * Get the studip_object_id of this study area. */ @@ -302,7 +222,6 @@ class StudipStudyArea extends SimpleORMap return $this; } - /** * Returns the children of this study area. */ @@ -316,10 +235,9 @@ class StudipStudyArea extends SimpleORMap */ public function hasChildren() { - return sizeof($this->_children) > 0; + return count($this->_children) > 0; } - /** * Returns TRUE if this area is the root. */ @@ -328,7 +246,6 @@ class StudipStudyArea extends SimpleORMap return $this->getId() === self::ROOT; } - /** * Returns TRUE if this area can be select. */ @@ -367,7 +284,6 @@ class StudipStudyArea extends SimpleORMap return $course ? $course->study_areas : new SimpleCollection(); } - /** * Returns the not really existing root study area. * @@ -377,11 +293,10 @@ class StudipStudyArea extends SimpleORMap { $root = new StudipStudyArea(); $root->setID(self::ROOT); - $root->setName(Config::get()->UNI_NAME_CLEAN); + $root->name = Config::get()->UNI_NAME_CLEAN; return $root; } - /** * Search for study areas whose name matches the given search term. * @@ -449,5 +364,4 @@ class StudipStudyArea extends SimpleORMap // plant the tree return $root; } - } diff --git a/public/admin_sem_tree.php b/public/admin_sem_tree.php index e981be7230d0d51971a9698059cbbcdf16e9adb5..7eac0c2da3c22c8926118a003de4210604b44918 100644 --- a/public/admin_sem_tree.php +++ b/public/admin_sem_tree.php @@ -226,7 +226,7 @@ if ($the_tree->mode === "MoveItem" || $the_tree->mode === "CopyItem"){ <table width="100%" border="0" cellpadding="0" cellspacing="0"> <tr> <td class="blank" width="75%" align="left" valign="top" colspan="2"> - <? $the_tree->showSemTree(); ?> + <?= $the_tree->showSemTree(); ?> </td> </tr> </table> diff --git a/templates/sem_tree/item-content.php b/templates/sem_tree/item-content.php new file mode 100644 index 0000000000000000000000000000000000000000..36499267f72cb4ea01ec0130f40f4ef187514b36 --- /dev/null +++ b/templates/sem_tree/item-content.php @@ -0,0 +1,120 @@ +<table width="90%" cellpadding="2" cellspacing="2" align="center" style="font-size:10pt;"> + <?= $message ?> + <tr> + <td style="font-size:10pt;"> + <? if ($editable): ?> + <? if ($is_item_admin): ?> + <?= Studip\LinkButton::create( + _('Neues Objekt'), + $controller->link_for(['cmd' => 'NewItem', 'item_id' => $item_id]), + ['title' => _('Innerhalb dieser Ebene ein neues Element einfÃŒgen')] + ) ?> + <?= Studip\LinkButton::create( + _('Sortieren'), + $controller->link_for(['cmd' => 'OrderItemsAlphabetically', 'sort_id' => $item_id]), + ['title' => _('Sortiert die untergeordneten Elemente alphabetisch')] + ) ?> + <? endif; ?> + <? if ($is_parent_admin): ?> + <?= Studip\LinkButton::create( + _('Bearbeiten'), + $controller->link_for(['cmd' => 'EditItem', 'sort_id' => $item_id]), + ['title' => _('Dieses Element bearbeiten')] + ) ?> + <?= Studip\LinkButton::create( + _('Löschen'), + $controller->link_for(['cmd' => 'AssertDeleteItem', 'sort_id' => $item_id]), + ['title' => _('Dieses Element löschen')] + ) ?> + + <? if ($moving_or_copying): ?> + <?= Studip\LinkButton::create( + _('Abbrechen'), + $controller->link_for(['cmd' => 'Cancel', 'item_id' => $item_id]), + ['title' => _('Verschieben / Kopieren abbrechen')] + ) ?> + <? else: ?> + <?= Studip\LinkButton::create( + _('Verschieben'), + $controller->link_for(['cmd' => 'MoveItem', 'item_id' => $item_id]), + ['title' => _('Dieses Element in eine andere Ebene verschieben')] + ) ?> + <?= Studip\LinkButton::create( + _('Kopieren'), + $controller->link_for(['cmd' => 'CopyItem', 'item_id' => $item_id]), + ['title' => _('Dieses Element in eine andere Ebene kopieren')] + ) ?> + <? endif; ?> + <? endif; ?> + <? endif; ?> + <? if ($item_id === 'root' && $is_item_admin): ?> + <form action="<?= $controller->link_for(['cmd' => 'InsertFak']) ?>" method="post" class="default"> + <?= CSRFProtection::tokenTag() ?> + <div> + <label> + <?= _('Stud.IP-FakultÀt einfÃŒgen') ?> + <select style="width: 200px" name="insert_fak"> + <? foreach ($unassigned_faculties as $faculty): ?> + <option value="<?= htmlReady($faculty->id) ?>"> + <?= htmlReady($faculty->name) ?> + </option> + <? endforeach; ?> + </select> + </label> + </div> + <div class="col-1"> + <?= Studip\Button::create(_('Eintragen'), ['title' => _('FakultÀt einfÃŒgen')]) ?> + </div> + </form> + <? endif; ?> + </td> + </tr> +</table> + +<table border="0" width="90%" cellpadding="2" cellspacing="0" align="center" style="font-size:10pt"> +<? if ($item_id === 'root') :?> + <tr> + <td class="table_header_bold" align="left" style="font-size:10pt;"> + <?= htmlReady($tree->root_name) ?> + </td> + </tr> + <tr> + <td class="table_row_even" align="left" style="font-size:10pt;"> + <?= htmlReady($tree->root_content) ?> + </td> + </tr> +<? else: ?> + <? if ($tree_data[$item_id]['info']): ?> + <tr> + <td style="font-size:10pt;" class="table_row_even" align="left" colspan="3"> + <?= formatReady($tree_data[$item_id]['info']) ?> + </td> + </tr> + <? endif; ?> + <tr> + <td style="font-size:10pt;" colspan="3"> </td> + </tr> + <? if ($tree->getNumEntries($item_id) - $tree_data[$item_id]['lonely_sem']): ?> + <tr> + <td class="table_row_even" style="font-size:10pt;" align="left" colspan="3"> + <strong><?= _('EintrÀge auf dieser Ebene:') ?></strong> + </td> + </tr> + <?= $controller->getSemDetails($tree->getSemData($item_id), $item_id) ?> + <? else: ?> + <tr> + <td class="table_row_even" style="font-size:10pt;" colspan="3"> + <?= _('Keine EintrÀge auf dieser Ebene vorhanden!') ?> + </td> + </tr> + <? endif; ?> + <? if ($tree_data[$item_id]['lonely_sem']): ?> + <tr> + <td class="table_row_even" align="left" style="font-size:10pt;" colspan="3"> + <strong><?= _("Nicht zugeordnete Veranstaltungen auf dieser Ebene:") ?></strong> + </td> + </tr> + <?= $controller->getSemDetails($tree->getLonelySemData($item_id), $item_id, true) ?> + <? endif; ?> +<? endif; ?> +</table> diff --git a/templates/sem_tree/item-edit.php b/templates/sem_tree/item-edit.php new file mode 100644 index 0000000000000000000000000000000000000000..b9200dd54f84ef378c233c614319803e38fd8a7b --- /dev/null +++ b/templates/sem_tree/item-edit.php @@ -0,0 +1,47 @@ +<form name="item_form" action="<?= URLHelper::getLink($action_url) ?>" method="POST" class="default" style="width: 90%; margin: auto;"> + <?= CSRFProtection::tokenTag(); ?> + <input type="hidden" name="parent_id" value="<?= $study_area->parent_id ?>"> + + <table style="width: 100%"><?= $message ?></table> + + <fieldset> + <legend><?= _('Bereich editieren') ?></legend> + + <label> + <?= _('Name des Elements') ?> + <?= I18N::input( + 'edit_name', + $study_area->name, + $study_area->studip_object_id ? ['disabled' => ''] : [] + ) ?> + </label> + + <? if (count($GLOBALS['SEM_TREE_TYPES']) > 1) : ?> + <label> + <?= _('Typ des Elements') ?> + <select name="edit_type"> + <? foreach ($sem_tree_types as $sem_tree_type_key => $sem_tree_type): ?> + <option value="<?= htmlReady($sem_tree_type_key) ?>" <? if ($sem_tree_type_key == $study_area->type) echo 'selected'; ?>> + <?= htmlReady($sem_tree_type['name'] ?: $sem_tree_type_key) ?> + </option> + <? endforeach; ?> + </select> + </label> + <? else : # Auswahl ausblenden, wenn nur ein Typ vorhanden ?> + <input type='hidden' name='edit_type' value='0'> + <? endif ?> + + <label> + <?= _('Infotext:') ?> + <?= I18N::textarea('edit_info', $study_area->info, ['wrap' => 'virtual', 'rows' => 5]) ?> + </label> + </fieldset> + + <footer> + <?= Studip\Button::createAccept(_('Absenden'), ['title' => _('Einstellungen ÃŒbernehmen')]) ?> + <?= Studip\LinkButton::createCancel(_('Abbrechen'), + URLHelper::getURL($cancel_url), + ['title' => _('Aktion abbrechen')]) + ?> + </footer> +</form> diff --git a/templates/sem_tree/item-message.php b/templates/sem_tree/item-message.php new file mode 100644 index 0000000000000000000000000000000000000000..f184a5888f3f2abbad9b95f10f7a980c57293736 --- /dev/null +++ b/templates/sem_tree/item-message.php @@ -0,0 +1,10 @@ +<tr> + <td colspan="<?= $colspan ?>"> + <table border="0" cellspacing="0" cellpadding="2" width="100%" style="font-size:10pt"> + <tr> + <td class="blank" align="center" width="25"><?= $icon->asImg(['class' => 'text-top']) ?></td> + <td class="blank" align="left"><?= htmlReady($message) ?></td> + </tr> + </table> + </td> +</tr> diff --git a/templates/sem_tree/sem-tree.php b/templates/sem_tree/sem-tree.php new file mode 100644 index 0000000000000000000000000000000000000000..f828cee58439337a38cb297d22176435c30f42bb --- /dev/null +++ b/templates/sem_tree/sem-tree.php @@ -0,0 +1,36 @@ +<script type="text/javascript"> +function invert_selection(the_form) { + my_elements = document.forms[the_form].elements['marked_sem[]']; + if(!my_elements.length){ + my_elements.checked = !my_elements.checked; + } else { + for (i = 0; i < my_elements.length; ++i) { + my_elements[i].checked = !my_elements[i].checked; + } + } +} +</script> +<table width="99%" border="0" cellpadding="0" cellspacing="0"> +<? if ($start_item_id !== 'root'): ?> + <tr> + <td class="table_row_odd" align="left" valign="top"> + <div style="font-size:10pt; margin-left:10px"> + <strong><?= _('Studienbereiche') ?>:</strong><br> + <? if ($parents): ?> + <? foreach (array_reverse($parents) as $parent): ?> + > + <a class="tree" href="<?= $controller->link_for(['start_item_id' => $parent, 'open_item' => $parent]) ?>"> + <?= htmlReady($tree_data[$parent]['name']) ?> + </a> + <? endforeach; ?> + <? endif; ?> + </div> + </td> + </tr> +<? endif; ?> + <tr> + <td class="blank" align="left" valign="top"> + <?= $tree ?> + </td> + </tr> +</table>