pages/manager/GroupHandler.inc.php

Go to the documentation of this file.
00001 <?php
00002 
00015 //$Id$
00016 
00017 import('pages.manager.ManagerHandler');
00018 
00019 class GroupHandler extends ManagerHandler {
00021    var $group;
00022    
00024    var $user;
00025    
00027    var $groupMembership;
00028       
00032    function GroupHandler() {
00033       parent::ManagerHandler();
00034    }
00035 
00039    function groups() {
00040       $this->validate();
00041       $this->setupTemplate();
00042 
00043       $schedConf =& Request::getSchedConf();
00044       $schedConfId = $schedConf? $schedConf->getId():0;
00045 
00046       $rangeInfo =& Handler::getRangeInfo('groups', array());
00047       $groupDao =& DAORegistry::getDAO('GroupDAO');
00048       while (true) {
00049          $groups =& $groupDao->getGroups(ASSOC_TYPE_SCHED_CONF, $schedConfId, null, $rangeInfo);
00050          if ($groups->isInBounds()) break;
00051          unset($rangeInfo);
00052          $rangeInfo =& $groups->getLastPageRangeInfo();
00053          unset($groups);
00054       }
00055 
00056       $templateMgr =& TemplateManager::getManager();
00057       $templateMgr->assign_by_ref('groups', $groups);
00058       $templateMgr->assign('boardEnabled', $schedConf->getSetting('boardEnabled'));
00059       $templateMgr->display('manager/groups/groups.tpl');
00060    }
00061 
00066    function deleteGroup($args) {
00067       $groupId = isset($args[0])?(int)$args[0]:0;
00068       $this->validate($groupId);
00069       $schedConf =& Request::getSchedConf();
00070       $group =& $this->group;    
00071       
00072       $groupDao =& DAORegistry::getDAO('GroupDAO');
00073       $groupDao->deleteObject($group);
00074       $groupDao->resequenceGroups(ASSOC_TYPE_SCHED_CONF, $schedConf->getId());
00075 
00076       Request::redirect(null, null, null, 'groups');
00077    }
00078 
00082    function moveGroup() {
00083       $groupId = (int) Request::getUserVar('id');
00084       $this->validate($groupId);
00085 
00086       $group =& $this->group;
00087       $groupDao =& DAORegistry::getDAO('GroupDAO');
00088       $direction = Request::getUserVar('d');
00089       
00090       if ($direction != null) {
00091          // moving with up or down arrow
00092          $group->setSequence($group->getSequence() + ($direction == 'u' ? -1.5 : 1.5));
00093          
00094       } else {
00095          // Dragging and dropping
00096          $prevId = Request::getUserVar('prevId');
00097          if ($prevId == null)
00098             $prevSeq = 0;
00099          else {
00100             $schedConf =& Request::getSchedConf();
00101             $prevGroup =& $groupDao->getGroup($prevId, ASSOC_TYPE_SCHED_CONF, $schedConf->getId());
00102             $prevSeq = $prevGroup->getSequence();
00103          }
00104 
00105          $group->setSequence($prevSeq + .5);
00106       }
00107 
00108 
00109       $groupDao->updateObject($group);
00110       $groupDao->resequenceGroups($group->getAssocType(), $group->getAssocId());
00111 
00112       // Moving up or down with the arrows requires a page reload.
00113       // In the case of a drag and drop move, the display has been
00114       // updated on the client side, so no reload is necessary.
00115       if ($direction != null) {
00116          Request::redirect(null, null, null, 'groups');
00117       }
00118    }
00119 
00124    function editGroup($args = array()) {
00125       $groupId = isset($args[0])?(int)$args[0]:null;
00126       $this->validate();
00127       $schedConf =& Request::getSchedConf();
00128 
00129       if ($groupId !== null) {
00130          $groupDao =& DAORegistry::getDAO('GroupDAO');
00131          $group =& $groupDao->getGroup($groupId, ASSOC_TYPE_SCHED_CONF, $schedConf->getId());
00132          if (!$group) {
00133             Request::redirect(null, null, null, 'groups');
00134          }
00135       } else $group = null;
00136 
00137       $this->setupTemplate($group, true);
00138       import('manager.form.GroupForm');
00139 
00140       $templateMgr =& TemplateManager::getManager();
00141 
00142       $templateMgr->assign('pageTitle',
00143          $group === null?
00144             'manager.groups.createTitle':
00145             'manager.groups.editTitle'
00146       );
00147 
00148       $groupForm = new GroupForm($group);
00149       if ($groupForm->isLocaleResubmit()) {
00150          $groupForm->readInputData();
00151       } else {
00152          $groupForm->initData();
00153       }
00154       $groupForm->display();
00155    }
00156 
00160    function createGroup($args) {
00161       $this->editGroup($args);
00162    }
00163 
00167    function updateGroup() {
00168       $groupId = Request::getUserVar('groupId') === null? null : (int) Request::getUserVar('groupId');
00169       if ($groupId === null) {
00170          $this->validate();
00171          $group = null;
00172       } else {
00173          $this->validate($groupId);
00174          $group =& $this->group;
00175       }
00176       $this->setupTemplate($group);
00177 
00178       import('manager.form.GroupForm');
00179 
00180       $groupForm = new GroupForm($group);
00181       $groupForm->readInputData();
00182 
00183       if ($groupForm->validate()) {
00184          $groupForm->execute();
00185          Request::redirect(null, null, null, 'groups');
00186       } else {
00187          $templateMgr =& TemplateManager::getManager();
00188          $templateMgr->append('pageHierarchy', array(Request::url(null, null, 'manager', 'groups'), 'manager.groups'));
00189 
00190          $templateMgr->assign('pageTitle',
00191             $group?
00192                'manager.groups.editTitle':
00193                'manager.groups.createTitle'
00194          );
00195 
00196          $groupForm->display();
00197       }
00198    }
00199 
00203    function groupMembership($args) {
00204       $groupId = isset($args[0])?(int)$args[0]:0;
00205       $this->validate($groupId);
00206       $group =& $this->group;
00207       
00208       $rangeInfo =& Handler::getRangeInfo('membership', array($groupId));
00209 
00210       $this->setupTemplate($group, true);
00211       $groupMembershipDao =& DAORegistry::getDAO('GroupMembershipDAO');
00212       while (true) {
00213          $memberships =& $groupMembershipDao->getMemberships($group->getId(), $rangeInfo);
00214          if ($memberships->isInBounds()) break;
00215          unset($rangeInfo);
00216          $rangeInfo =& $memberships->getLastPageRangeInfo();
00217          unset($memberships);
00218       }
00219       $templateMgr =& TemplateManager::getManager();
00220       $templateMgr->assign_by_ref('memberships', $memberships);
00221       $templateMgr->assign_by_ref('group', $group);
00222       $templateMgr->display('manager/groups/memberships.tpl');
00223    }
00224 
00228    function addMembership($args) {
00229       $groupId = isset($args[0])?(int)$args[0]:0;
00230       $userId = isset($args[1])?(int)$args[1]:null;
00231 
00232       $groupMembershipDao =& DAORegistry::getDAO('GroupMembershipDAO');
00233 
00234       // If a user has been selected, add them to the group.
00235       // Otherwise list users.
00236       if ($userId !== null) {
00237          $this->validate($groupId, $userId);
00238          $schedConf =& Request::getSchedConf();
00239          $group =& $this->group;
00240          $user =& $this->user;
00241 
00242          // A valid user has been chosen. Add them to
00243          // the membership list and redirect.
00244 
00245          // Avoid duplicating memberships.
00246          $groupMembership =& $groupMembershipDao->getMembership($group->getId(), $user->getId());
00247 
00248          if (!$groupMembership) {
00249             $groupMembership = new GroupMembership();
00250             $groupMembership->setGroupId($group->getId());
00251             $groupMembership->setUserId($user->getId());
00252             // For now, all memberships are displayed in About
00253             $groupMembership->setAboutDisplayed(true);
00254             $groupMembershipDao->insertMembership($groupMembership);
00255          }
00256          Request::redirect(null, null, null, 'groupMembership', $group->getId());
00257       } else {
00258          $this->validate($groupId);
00259          $groupDao =& DAORegistry::getDAO('GroupDAO');
00260          $conference =& Request::getConference();
00261          $schedConf =& Request::getSchedConf();
00262          $group =& $this->group;
00263 
00264          $this->setupTemplate($group, true);
00265          $searchType = null;
00266          $searchMatch = null;
00267          $search = $searchQuery = Request::getUserVar('search');
00268          $searchInitial = Request::getUserVar('searchInitial');
00269          if (!empty($search)) {
00270             $searchType = Request::getUserVar('searchField');
00271             $searchMatch = Request::getUserVar('searchMatch');
00272 
00273          } elseif (!empty($searchInitial)) {
00274             $searchInitial = String::strtoupper($searchInitial);
00275             $searchType = USER_FIELD_INITIAL;
00276             $search = $searchInitial;
00277          }
00278 
00279          $rangeInfo =& Handler::getRangeInfo('users', array($groupId, (string) $search, (string) $searchMatch, (string) $searchType));
00280 
00281          $roleDao =& DAORegistry::getDAO('RoleDAO');
00282          while (true) {
00283             $users = $roleDao->getUsersByRoleId(null, $conference->getId(), null, $searchType, $search, $searchMatch, $rangeInfo);
00284             if ($users->isInBounds()) break;
00285             unset($rangeInfo);
00286             $rangeInfo =& $users->getLastPageRangeInfo();
00287             unset($users);
00288          }
00289 
00290          $templateMgr =& TemplateManager::getManager();
00291 
00292          $templateMgr->assign('searchField', $searchType);
00293          $templateMgr->assign('searchMatch', $searchMatch);
00294          $templateMgr->assign('search', $searchQuery);
00295          $templateMgr->assign('searchInitial', Request::getUserVar('searchInitial'));
00296 
00297          $templateMgr->assign_by_ref('users', $users);
00298          $templateMgr->assign('fieldOptions', Array(
00299             USER_FIELD_FIRSTNAME => 'user.firstName',
00300             USER_FIELD_LASTNAME => 'user.lastName',
00301             USER_FIELD_USERNAME => 'user.username',
00302             USER_FIELD_EMAIL => 'user.email'
00303          ));
00304          $templateMgr->assign('alphaList', explode(' ', __('common.alphaList')));
00305          $templateMgr->assign_by_ref('group', $group);
00306 
00307          $templateMgr->display('manager/groups/selectUser.tpl');
00308       }
00309    }
00310 
00314    function deleteMembership($args) {
00315       $groupId = isset($args[0])?(int)$args[0]:0;
00316       $userId = isset($args[1])?(int)$args[1]:0;
00317 
00318       $this->validate($groupId, $userId, true);
00319       $schedConf =& Request::getSchedConf();
00320       $group =& $this->group;
00321       $user =& $this->user;
00322       $groupMembership =& $this->groupMembership;
00323 
00324       $groupMembershipDao =& DAORegistry::getDAO('GroupMembershipDAO');
00325       $groupMembershipDao->deleteMembershipById($group->getId(), $user->getId());
00326       $groupMembershipDao->resequenceMemberships($group->getId());
00327 
00328       Request::redirect(null, null, null, 'groupMembership', $group->getId());
00329    }
00330 
00334    function moveMembership($args) {
00335       $groupId = isset($args[0])?(int)$args[0]:0;
00336       $userId = (int) Request::getUserVar('id');
00337       $this->validate($groupId, $userId, true);
00338       $group =& $this->group;
00339       $groupMembership =& $this->groupMembership;
00340 
00341       $groupMembershipDao =& DAORegistry::getDAO('GroupMembershipDAO');
00342       $direction = Request::getUserVar('d');
00343       if ($direction != null) {
00344          // moving with up or down arrow
00345          $groupMembership->setSequence($groupMembership->getSequence() + ($direction == 'u' ? -1.5 : 1.5));
00346       } else {
00347          // drag and drop
00348          $prevId = Request::getUserVar('prevId');
00349          if ($prevId == null)
00350             $prevSeq = 0;
00351          else {
00352             $prevMembership =& $groupMembershipDao->getMembership($groupId, $prevId);
00353             $prevSeq = $prevMembership->getSequence();
00354          }
00355 
00356          $groupMembership->setSequence($prevSeq + .5);
00357       }
00358       $groupMembershipDao->updateObject($groupMembership);
00359       $groupMembershipDao->resequenceMemberships($group->getId());
00360 
00361       // Moving up or down with the arrows requires a page reload.
00362       // In the case of a drag and drop move, the display has been
00363       // updated on the client side, so no reload is necessary.
00364       if ($direction != null) {
00365          Request::redirect(null, null, null, 'groupMembership', $group->getId());
00366       }
00367    }
00368 
00369    function setBoardEnabled($args) {
00370       $this->validate();
00371       $conference =& Request::getConference();
00372       $boardEnabled = Request::getUserVar('boardEnabled')==1?true:false;
00373       $schedConf =& Request::getSchedConf();
00374       $schedConf->updateSetting('boardEnabled', $boardEnabled);
00375       Request::redirect(null, null, null, 'groups');
00376    }
00377 
00378    function setupTemplate($group = null, $subclass = false) {
00379       parent::setupTemplate(true);
00380       $templateMgr =& TemplateManager::getManager();
00381       if ($subclass) {
00382          $templateMgr->append('pageHierarchy', array(Request::url(null, null, 'manager', 'groups'), 'manager.groups'));
00383       }
00384       if ($group) {
00385          $templateMgr->append('pageHierarchy', array(Request::url(null, null, 'manager', 'editGroup', $group->getId()), $group->getLocalizedTitle(), true));
00386       }
00387       $templateMgr->assign('helpTopicId', 'conference.currentConferences.organizingTeam');
00388    }
00389 
00400    function validate($groupId = null, $userId = null, $fetchMembership = false) {
00401       parent::validate();
00402 
00403       $conference =& Request::getConference();
00404       $schedConf =& Request::getSchedConf();
00405 
00406       $passedValidation = true;
00407 
00408       if ($groupId !== null) {
00409          $groupDao =& DAORegistry::getDAO('GroupDAO');
00410          $group =& $groupDao->getGroup($groupId, ASSOC_TYPE_SCHED_CONF, $schedConf->getId());
00411 
00412          if (!$group) $passedValidation = false;
00413          else $this->group =& $group;
00414 
00415          if ($userId !== null) {
00416             $userDao =& DAORegistry::getDAO('UserDAO');
00417             $user =& $userDao->getUser($userId);
00418 
00419             if (!$user) $passedValidation = false;
00420             else $this->user =& $user;
00421 
00422             if ($fetchMembership === true) {
00423                $groupMembershipDao =& DAORegistry::getDAO('GroupMembershipDAO');
00424                $groupMembership =& $groupMembershipDao->getMembership($groupId, $userId);
00425                if (!$groupMembership) $validationPassed = false;
00426                else $this->groupMembership =& $groupMembership;
00427             }
00428          }
00429       }
00430       if (!$passedValidation) Request::redirect(null, null, null, 'groups');
00431       return true;
00432    }
00433 }
00434 
00435 ?>

Generated on 25 Jul 2013 for Open Conference Systems by  doxygen 1.4.7