summaryrefslogtreecommitdiffstats
path: root/application/modules/user/controllers/SessionController.php
blob: f90845a48727dacd7b39544b85540d189be490fe (plain) (blame)
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
<?php
/*
 * Copyright (c) 2011 - OpenSLX GmbH, RZ Uni Freiburg
* This program is free software distributed under the GPL version 2.
* See http://gpl.openslx.org/
*
* If you have any feedback please consult http://feedback.openslx.org/ and
* send your suggestions, praise, or complaints to feedback@openslx.org
*
* General information about OpenSLX can be found at http://openslx.org/
*/

class User_SessionController extends Zend_Controller_Action {
  private $membership;
  public function init() {
    if (Zend_Auth::getInstance()->hasIdentity()) {
      $userIDsNamespace = Zend_Session::namespaceGet('userIDs');
      if($userIDsNamespace['membershipID'] == '') {
        $pbsNotifier = new Pbs_Notifier();
        echo $pbsNotifier->notify('No membershipID set', 'forbidden');
      }

      $membershipMapper = new Application_Model_MembershipMapper();
      $this->membership = new Application_Model_Membership();
      $membershipMapper->find($userIDsNamespace['membershipID'], $this->membership);
    } else {
      $this->_helper->redirector('login', 'auth');
    }

    $this->page = $this->_request->getParam('page');
  }

  public function indexAction() {
    if(!Pbs_Acl::checkRight('so'))
      { $this->_redirect('/user/index'); }

    $sessionMapper = new Application_Model_SessionMapper();
    $bootisoMapper = new Application_Model_BootIsoMapper();
    $bootosMapper = new Application_Model_BootOsMapper();
    $bootmenuentriesMapper = new Application_Model_BootMenuEntriesMapper();
    $membershipMapper = new Application_Model_MembershipMapper();
    $personMapper = new Application_Model_PersonMapper();

    $bootisos = $bootisoMapper->findBy(array('groupID' => $this->membership->getGroupID()));
    foreach($bootisos as $bootiso) {
      $sessions = $sessionMapper->findBy(array('bootisoID' => $bootiso->getID()));
      foreach($sessions as $session) {
#echo $session->getBootosID();
        if($session->getBootosID() != '') {
          $bo = $bootosMapper->find($session->getBootosID());
          if($bo != null)
            { $session->setBootosID("[".$session->getBootosID()."] ".$bo->getTitle()); }
        }

        if($session->getBootmenuentryID() != '') {
          $bm = $bootmenuentriesMapper->find($session->getBootmenuentryID());
          if($bm != null)
            { $session->setBootmenuentryID("[".$session->getBootmenuentryID()."] ".$bm->getTitle()); }

        }

        if($session->getBootisoID() != '') {
          $bi = $bootisoMapper->find($session->getBootisoID());
          if($bi != null)
            { $session->setBootisoID("[".$session->getBootisoID()."] ".$bi->getTitle()); }
        }

        if($session->getMembershipID() != '') {
          $personID = $membershipMapper->find($session->getMembershipID())->getPersonID();
          $p = new Application_Model_Person();
          $personMapper->find($personID, $p);
          if($p != null)
            { $session->setMembershipID("[".$session->getMembershipID()."] ".$p->getFirstname()." ".$p->getName()); }
        }
        $session->setTime(date(Zend_Registry::get('dateformat'), $session->getTime()));
        $mySessions[] = $session;
      }
    }
    // Sort after date/id
    usort($mySessions, 'sortFunc');

    // Search
    $search = $this->_request->getParam('search');
    $mySearch = new Pbs_Search();
    $mySearch->setSearchTerm($search);
    $mySearch->setModule('session');
    if($search != '') {
      $this->view->search = $mySearch->getSearchTerm();
      $mySessions = $mySearch->search($mySessions);
    }
    $this->view->searchform = $mySearch->searchForm();

    // Pagination
    $pagination = new Pbs_Pagination();
    $pagination->setPerPage(10)
    ->setElement($mySessions)
    ->setRequestPage($this->_request->getParam('page'))
    ->setPageUrl('/user/session/index'.((isset($this->view->search)) ? '/search/'.$this->view->search : ''));
    $mySessions = $pagination->getElements();

    $this->view->pagination = $pagination->pagination();
    $this->view->page     = $pagination->getRequestPage();
    $this->view->sessions = $mySessions;

  }

  public function searchAction() {
    $this->_redirect('/user/session/index/search/'.($_GET['search']));
  }


}
function sortFunc($func_a, $func_b) {
  if($func_a->getID() == $func_b->getID()) { return 0; }
  return ($func_a->getID() < $func_b->getID()) ? 1 : -1;
}