diff --git a/app/controllers/studiengaenge/informationen.php b/app/controllers/studiengaenge/informationen.php index 4bbdd019a958cec71694219eebb4f0cb8431f7f6..29b223aa80b97454af0b082b22e949ea12045db5 100644 --- a/app/controllers/studiengaenge/informationen.php +++ b/app/controllers/studiengaenge/informationen.php @@ -12,8 +12,8 @@ class Studiengaenge_InformationenController extends MVVController { parent::before_filter($action, $args); - if (!($GLOBALS['perm']->have_perm('root') || RolePersistence::isAssignedRole( - $GLOBALS['user']->id, 'MVVAdmin'))) { + if (!($GLOBALS['perm']->have_perm('root') + || User::findCurrent()->hasRole('MVVAdmin'))) { throw new AccessDeniedException(); } PageLayout::setTitle(_('Verwaltung der Studiengänge')); @@ -49,21 +49,16 @@ class Studiengaenge_InformationenController extends MVVController { $this->studycourse = Fach::find($studycourse_id); $this->nr = $nr; - $this->degree = Degree::findBySQL('abschluss_id IN (SELECT DISTINCT(abschluss_id) FROM user_studiengang ' - . 'WHERE fach_id = :studycourse_id AND abschluss_id IN (:abschluss_ids)) ' - . 'ORDER BY name', - ['studycourse_id' => $studycourse_id, - 'abschluss_ids' => $this->studycourse->degrees->pluck('abschluss_id')]); } public function showstudycourse_action($degree_id, $nr = 0) { $this->nr = $nr; - $this->degree = Degree::find($degree_id); - if ($GLOBALS['perm']->have_perm("root",$GLOBALS['user']->id)) { - $this->studycourses = StudyCourse::findBySQL('fach_id IN (SELECT DISTINCT(fach_id) FROM user_studiengang ' - . 'WHERE abschluss_id = :abschluss_id AND fach_id IN (:studycourse_ids)) ORDER BY name', - [':abschluss_id' => $degree_id, ':studycourse_ids' => $this->degree->professions->pluck('fach_id')]); + $this->degree = Abschluss::find($degree_id); + $this->professions = $this->degree->professions; + + if ($GLOBALS['perm']->have_perm('root',$GLOBALS['user']->id)) { + $this->studycourses = $this->degree->professions; } else { $inst_ids = SimpleCollection::createFromArray(Institute::findBySQL('Institut_id IN (SELECT institut_id FROM roles_user WHERE userid = :user_id) OR fakultaets_id IN (SELECT institut_id FROM roles_user WHERE userid = :user_id)', @@ -78,37 +73,32 @@ class Studiengaenge_InformationenController extends MVVController public function messagehelper_action() { - $fach_id = Request::get('fach_id'); - $degree_id = Request::get('abschluss_id'); - - $fach = new Fach($fach_id); - $degree = new Degree($degree_id); + $fach = Fach::find(Request::get('fach_id')); + $degree = Degree::find(Request::get('abschluss_id')); - $user = array(); - if (is_null($degree_id) && !is_null($fach_id)) { - $user = UserStudyCourse::findBySql('fach_id = :fach_id', - [':fach_id' => $fach->fach_id]); - } else if (!is_null($degree_id) && !is_null($fach_id)) { - $user = UserStudyCourse::findBySql('fach_id = :fach_id AND abschluss_id = :abschluss_id', - [':fach_id' => $fach_id, ':abschluss_id' => $degree_id]); - } else if (!is_null($degree_id) && is_null($fach_id)) { - $user = UserStudyCourse::findBySql('abschluss_id = :abschluss_id', - [':abschluss_id' => $degree_id]); + if (!$degree && $fach) { + $users = UserStudyCourse::findBySql('fach_id = :fach_id', [':fach_id' => $fach->id]); + } else if ($degree && !$fach) { + $users = UserStudyCourse::findBySql('abschluss_id = :abschluss_id', [':abschluss_id' => $degree->id]); + } else { + $users = UserStudyCourse::findBySql('fach_id = :fach_id AND abschluss_id = :abschluss_id', + [':fach_id' => $fach->id, ':abschluss_id' => $degree->id] + ); } - if (empty($user)) { + if (empty($users)) { PageLayout::postError(_('Keine Studierenden zu den gewählten Angaben gefunden')); - $this->redirect('index'); + $this->redirect($this->indexURL()); return; } - foreach ($user as $u) { - $send_to[] = $u->user->username; - } - - $_SESSION['sms_data']['p_rec'] = $send_to; + $_SESSION['sms_data']['p_rec'] = SimpleCollection::createFromArray( + SimpleCollection::createFromArray($users)->pluck('user') + )->pluck('username'); - $subject = sprintf(_('Information zum Studiengang: %s %s'), - !$fach->isNew() ? $fach->name: '' , !$degree->isNew() ? $degree->name : ''); + $subject = sprintf( + _('Information zum Studiengang: %s %s'), + $fach ? $fach->name: '' , $degree ? $degree->name : '' + ); $this->redirect(URLHelper::getURL('dispatch.php/messages/write', ['default_subject' => $subject, 'emailrequest' => 1] @@ -118,29 +108,10 @@ class Studiengaenge_InformationenController extends MVVController private function createSidebar($view = 'subject' ) { $widget = new ViewsWidget(); - $widget->addLink(_('Gruppieren nach Fächern'), $this->url_for('/index')) - ->setActive($view == 'subject'); - $widget->addLink(_('Gruppieren nach Abschlüssen'), $this->url_for('/degree')) - ->setActive($view == 'degrees'); + $widget->addLink(_('Gruppieren nach Fächern'), $this->indexURL()) + ->setActive($view === 'subject'); + $widget->addLink(_('Gruppieren nach Abschlüssen'), $this->degreeURL()) + ->setActive($view === 'degrees'); Sidebar::Get()->addWidget($widget); } - - public static function getStudyCount($degree_id) - { - if ($GLOBALS['perm']->have_perm('root', $GLOBALS['user']->id)) { - return UserStudyCourse::countBySql('abschluss_id = :abschluss_id', - [':abschluss_id' => $degree_id]); - } else { - $inst_ids = SimpleCollection::createFromArray(Institute::findBySQL('Institut_id IN (SELECT institut_id FROM roles_user WHERE userid = :user_id) - OR fakultaets_id IN (SELECT institut_id FROM roles_user WHERE userid = :user_id)', - [':user_id' => $GLOBALS['user']->user_id]))->pluck('institut_id'); - - return UserStudyCourse::countBySql('JOIN mvv_fach_inst as fach_inst ON (user_studiengang.fach_id = fach_inst.fach_id) - WHERE user_studiengang.abschluss_id = :abschluss_id AND fach_inst.institut_id IN (:inst_ids)', - [':abschluss_id' => $degree_id, ':inst_ids' => $inst_ids]); - - - } - } - } \ No newline at end of file diff --git a/app/views/studiengaenge/informationen/degree.php b/app/views/studiengaenge/informationen/degree.php index 206a0a9737bdc2c95b01c27dc28499a7da1f699b..c42da60f97deb513a1c67509df407dba967d0426 100644 --- a/app/views/studiengaenge/informationen/degree.php +++ b/app/views/studiengaenge/informationen/degree.php @@ -12,34 +12,32 @@ </tr> </thead> <? foreach ($degree as $key => $deg) : ?> - <? if (($studycount = Studiengaenge_InformationenController::getStudyCount($deg->abschluss_id)) > 0 ) : ?> - <tbody class="collapsed"> - <tr class="table-header header-row"> - <td class="toggle-indicator"> - <a id="<?= $deg->abschluss_id?>" class="mvv-load-in-new-row" - href="<?= $controller->url_for('/showstudycourse', $deg->abschluss_id, $key+1)?>" - onclick="icon_toggle(this)"> - - <?= htmlReady($deg->name) ?> - </a> - </td> - <td> - <?= $studycount ?> - </td> - <td class="dont-hide actions"> - <? if ($GLOBALS['perm']->have_perm("root", $GLOBALS['user']->id)) : ?> - - <a href="<?= $controller->url_for('/messagehelper', - ['abschluss_id' => $deg->abschluss_id]) ?>" data-dialog > - - <?= Icon::create('mail', Icon::ROLE_CLICKABLE, - ['title' => htmlReady(sprintf(_('Alle Studierenden mit dem Studienabschluss %s benachrichtigen.'), - $deg->name))]) ?> + <? if ($deg->count_user > 0) : ?> + <tbody class="collapsed"> + <tr class="table-header header-row"> + <td class="toggle-indicator"> + <a id="<?= $deg->abschluss_id ?>" class="mvv-load-in-new-row" + href="<?= $controller->url_for('/showstudycourse', $deg->abschluss_id, $key + 1) ?>"> + <?= htmlReady($deg->name) ?> </a> - <? endif; ?> - </td> - </tr> - </tbody> - <? endif; ?> - <? endforeach; ?> + </td> + <td> + <?= $deg->count_user ?> + </td> + <td class="dont-hide actions"> + <? if ($GLOBALS['perm']->have_perm('root', $GLOBALS['user']->id)) : ?> + <a href="<?= $controller->messagehelper(['abschluss_id' => $deg->abschluss_id]) ?>" + data-dialog> + <?= Icon::create('mail')->asImg( + ['title' => htmlReady(sprintf( + _('Alle Studierenden mit dem Studienabschluss %s benachrichtigen.'), + $deg->name)) + ]) ?> + </a> + <? endif ?> + </td> + </tr> + </tbody> + <? endif ?> + <? endforeach ?> </table> diff --git a/app/views/studiengaenge/informationen/index.php b/app/views/studiengaenge/informationen/index.php index 5895f05644a2a1a8bceff190c6be5eb1e7ede157..0914cf1d5fd9fabd99dd612d8ef8e1b25dd1d083 100644 --- a/app/views/studiengaenge/informationen/index.php +++ b/app/views/studiengaenge/informationen/index.php @@ -1,8 +1,8 @@ <table class="default nohover collapsable"> <colgroup> - <col width="70%"> - <col width="29%"> - <col width="1%"> + <col style="width: 70%"> + <col style="width: 29%"> + <col style="width: 1%"> </colgroup> <thead> <tr> @@ -14,26 +14,28 @@ <? foreach ($studycourses as $key => $studycourse) : ?> <? $count = UserStudyCourse::countBySql('fach_id = ?', [$studycourse->fach_id]); ?> <? if ($count > 0) : ?> - <tbody class="collapsed"> - <tr class="table-header header-row"> - <td class="toggle-indicator"> - <a id="<?= $studycourse->fach_id?>" class="mvv-load-in-new-row" - href="<?= $controller->url_for('/showdegree', $studycourse->fach_id, $key+1)?>"> - <?= htmlReady($studycourse->name) ?> - </a> - </td> - <td> - <?= $count ?> - </td> - <td class="dont-hide actions"> - <a href="<?= $controller->url_for('/messagehelper', ['fach_id' => $studycourse->fach_id]) ?>" data-dialog > - <?= Icon::create('mail', Icon::ROLE_CLICKABLE, - ['title' => htmlReady(sprintf(_('Alle Studierenden des Faches %s benachrichtigen.'), - $studycourse->name))]) ?> - </a> - </td> - </tr> - </tbody> - <? endif; ?> - <? endforeach; ?> + <tbody class="collapsed"> + <tr class="table-header header-row"> + <td class="toggle-indicator"> + <a id="<?= $studycourse->fach_id ?>" class="mvv-load-in-new-row" + href="<?= $controller->showdegree($studycourse->fach_id, $key + 1) ?>"> + <?= htmlReady($studycourse->name) ?> + </a> + </td> + <td> + <?= $count ?> + </td> + <td class="dont-hide actions"> + <a href="<?= $controller->messagehelper(['fach_id' => $studycourse->fach_id]) ?>" data-dialog> + <?= Icon::create('mail')->asImg( + ['title' => sprintf( + _('Alle Studierenden des Faches %s benachrichtigen.'), + htmlReady($studycourse->name)) + ]) ?> + </a> + </td> + </tr> + </tbody> + <? endif ?> + <? endforeach ?> </table> diff --git a/app/views/studiengaenge/informationen/showdegree.php b/app/views/studiengaenge/informationen/showdegree.php index 25badec476d27c93f8f845c688a07e2bce54d39b..4dfb8b0e95c58b6a2ccbfde6a6429d2a5d120ca7 100644 --- a/app/views/studiengaenge/informationen/showdegree.php +++ b/app/views/studiengaenge/informationen/showdegree.php @@ -1,32 +1,37 @@ <td colspan="3"> <table class="default"> <colgroup> - <col width="70%"> - <col width="29%"> - <col width="1%"> + <col style="width: 70%"> + <col style="width: 29%"> + <col style="width: 1%"> </colgroup> - <? foreach ($degree as $key => $deg) : ?> - <tbody> - <tr> - <td><?= htmlReady($deg->name) ?></td> - <td> - <?= UserStudyCourse::countBySql('fach_id = :fach_id AND abschluss_id = :abschluss_id', - [':fach_id' => $studycourse->fach_id, ':abschluss_id' => $deg->abschluss_id])?> + <? foreach ($studycourse->degrees as $key => $deg) : ?> + <tbody> + <tr> + <td><?= htmlReady($deg->name) ?></td> + <td> + <?= UserStudyCourse::countBySql('fach_id = :fach_id AND abschluss_id = :abschluss_id', + [':fach_id' => $studycourse->fach_id, ':abschluss_id' => $deg->abschluss_id]) ?> </td> - <td class="actions"> - <? $action =ActionMenu::get() - ->setContext($deg->name) - ->addLink($controller->url_for('/messagehelper', - ['fach_id' => $studycourse->fach_id, 'abschluss_id' => $deg->abschluss_id]), - _('Nachricht an Studierende schreiben'), - Icon::create('mail', Icon::ROLE_CLICKABLE, - ['title' => htmlReady(sprintf(_('Nachricht an alle Studierende mit dem Studiengang %s mit dem Abschluss %s'), - $studycourse->name, $deg->name))]), - ['data-dialog' => '']) ?> - <?= $action ?> - </td> - </tr> - </tbody> - <? endforeach; ?> + <td class="actions"> + <?= $action = ActionMenu::get() + ->setContext($deg->name) + ->addLink($controller->messagehelperURL( + ['fach_id' => $studycourse->fach_id, 'abschluss_id' => $deg->abschluss_id]), + _('Nachricht an Studierende schreiben'), + Icon::create( + 'mail', + Icon::ROLE_CLICKABLE, + ['title' => htmlReady(sprintf( + _('Nachricht an alle Studierende mit dem Studiengang %s mit dem Abschluss %s'), + $studycourse->name, $deg->name)) + ]), + ['data-dialog' => '']) + ->render() + ?> + </td> + </tr> + </tbody> + <? endforeach ?> </table> </td> diff --git a/app/views/studiengaenge/informationen/showstudycourse.php b/app/views/studiengaenge/informationen/showstudycourse.php index ae4f745aa453a22c5066e4c4c3951565a75ce24e..94c886f14c3b6f0f9be28621d209fe2d3bafacda 100644 --- a/app/views/studiengaenge/informationen/showstudycourse.php +++ b/app/views/studiengaenge/informationen/showstudycourse.php @@ -1,32 +1,35 @@ <td colspan="3"> <table class="default"> <colgroup> - <col width="70%"> - <col width="29%"> - <col width="1%"> + <col style="width: 70%"> + <col style="width: 29%"> + <col style="width: 1%"> </colgroup> - <? foreach ($studycourses as $key => $course) : ?> - <? if (($count = UserStudyCourse::countBySql('fach_id = :fach_id AND abschluss_id = :abschluss_id', - [':fach_id' => $course->fach_id, ':abschluss_id' => $degree->abschluss_id])) > 0) : ?> - - <tr> - <td><?= htmlReady($course->name) ?></td> - <td> - <?= $count ?> - </td> - <td class="actions"> - <? $action =ActionMenu::get()->setContext($course->name) - ->addLink($controller->url_for('/messagehelper', - ['fach_id' => $course->fach_id, 'abschluss_id' => $degree->abschluss_id]), - _('Nachricht an Studierende schreiben'), - Icon::create('mail', Icon::ROLE_CLICKABLE, - ['title' => htmlReady(sprintf(_('Nachricht an alle Studierende mit dem Studiengang %s mit dem Abschluss %s'), - $course->name, $degree->name))]), - ['data-dialog' => '']) ?> - <?= $action ?> - </td> - </tr> - <? endif; ?> - <? endforeach; ?> + <? foreach ($studycourses as $key => $course) : ?> + <? if (($count = UserStudyCourse::countBySql('fach_id = :fach_id AND abschluss_id = :abschluss_id', + [':fach_id' => $course->fach_id, ':abschluss_id' => $degree->abschluss_id])) > 0) : ?> + <tr> + <td><?= htmlReady($course->name) ?></td> + <td> + <?= $count ?> + </td> + <td class="actions"> + <?= $action = ActionMenu::get()->setContext($course->name) + ->addLink($controller->messagehelperURL( + ['fach_id' => $course->fach_id, 'abschluss_id' => $degree->abschluss_id]), + _('Nachricht an Studierende schreiben'), + Icon::create( + 'mail', + Icon::ROLE_CLICKABLE, + ['title' => htmlReady(sprintf( + _('Nachricht an alle Studierende mit dem Studiengang %s mit dem Abschluss %s'), + $course->name, $degree->name)) + ]), + ['data-dialog' => ''])->render() + ?> + </td> + </tr> + <? endif ?> + <? endforeach ?> </table> </td> diff --git a/lib/models/Degree.class.php b/lib/models/Degree.class.php index 04c4da6bdb67bf67627e13e3e1bad9c5716dd283..c5b83c5d14c4e4fe740b326cad138e0d0f4ac6f5 100644 --- a/lib/models/Degree.class.php +++ b/lib/models/Degree.class.php @@ -35,16 +35,27 @@ class Degree extends SimpleORMap ]; $config['additional_fields']['count_user']['get'] = 'countUser'; - + $config['registered_callbacks']['before_store'][] = "cbUpdateAuthorId"; parent::configure($config); } public function countUser() { - $stmt = DBManager::get()->prepare('SELECT COUNT(DISTINCT user_id) ' - . 'FROM user_studiengang WHERE abschluss_id = ?'); - $stmt->execute([$this->id]); - return $stmt->fetchColumn(); + $sql = 'SELECT COUNT(DISTINCT `user_id`) FROM `user_studiengang`'; + $parameters = [':degree_id' => $this->id]; + if (!$GLOBALS['perm']->have_perm('root')) { + $inst_ids = SimpleCollection::createFromArray(Institute::findBySQL('Institut_id IN (SELECT institut_id FROM roles_user WHERE userid = :user_id) + OR fakultaets_id IN (SELECT institut_id FROM roles_user WHERE userid = :user_id)', + [':user_id' => $GLOBALS['user']->user_id]))->pluck('institut_id'); + + $sql .= 'JOIN `mvv_fach_inst` as `fach_inst` ON (`user_studiengang`.`fach_id` = `fach_inst`.`fach_id`) + WHERE `user_studiengang`.`abschluss_id` = :degree_id AND `fach_inst`.`institut_id` IN (:inst_ids)'; + $parameters[':inst_ids'] = $inst_ids; + } else { + $sql .= ' WHERE `user_studiengang`.`abschluss_id` = :degree_id'; + } + + return DBManager::get()->fetchColumn($sql, $parameters); } public function countUserByStudycourse($studycourse_id) @@ -56,7 +67,7 @@ class Degree extends SimpleORMap return $stmt->fetchColumn(); } - public function store() + public function cbUpdateAuthorId() { if ($this->isNew() || $this->isDirty()) { $this->editor_id = $GLOBALS['user']->id; @@ -64,8 +75,5 @@ class Degree extends SimpleORMap $this->author_id = $GLOBALS['user']->id; } } - - return parent::store(); } - }