*/ /** * This controller will handle the creation of a group * * @package GalleryCore * @subpackage UserInterface * */ class AdminCreateGroupController extends GalleryController { /** * @see GalleryController::handleRequest */ function handleRequest($form) { $ret = GalleryCoreApi::assertUserIsSiteAdministrator(); if ($ret) { return array($ret->wrap(__FILE__, __LINE__), null); } $results = $status = $error = array(); if (isset($form['action']['cancel'])) { /* Go back to the AdminGroups view */ $redirect['view'] = 'core.SiteAdmin'; $redirect['subView'] = 'core.AdminGroups'; } else if (isset($form['action']['create'])) { /* * If all the right fields are in place then go ahead and * create the group. */ if (!empty($form['groupName'])) { list ($ret, $group) = GalleryCoreApi::newFactoryInstance('GalleryEntity', 'GalleryGroup'); if ($ret) { return array($ret->wrap(__FILE__, __LINE__), null); } if (!isset($group)) { return array(GalleryCoreApi::error(ERROR_MISSING_OBJECT, __FILE__, __LINE__), null); } $ret = $group->create($form['groupName']); if ($ret) { if (!($ret->getErrorCode() & ERROR_COLLISION)) { return array($ret->wrap(__FILE__, __LINE__), null); } // Set our error status and fall back to the view. $error[] = 'form[error][groupName][exists]'; } else { $ret = $group->save(); if ($ret) { return array($ret->wrap(__FILE__, __LINE__), null); } /* Request a redirect to the confirmation screen */ $redirect['view'] = 'core.SiteAdmin'; $redirect['subView'] = 'core.AdminGroups'; $status['createdGroup'] = $group->getGroupName(); } } else { // Set our error status and fall back to the view. $error[] = 'form[error][groupName][missing]'; } } if (!empty($redirect)) { $results['redirect'] = $redirect; } else { $results['delegate']['view'] = 'core.SiteAdmin'; $results['delegate']['subView'] = 'core.AdminCreateGroup'; } $results['status'] = $status; $results['error'] = $error; return array(null, $results); } } /** * This view will prompt for data to create a new group * * @package GalleryCore * @subpackage UserInterface */ class AdminCreateGroupView extends GalleryView { /** * @see GalleryView::loadTemplate */ function loadTemplate(&$template, &$form) { $ret = GalleryCoreApi::assertUserIsSiteAdministrator(); if ($ret) { return array($ret->wrap(__FILE__, __LINE__), null); } if ($form['formName'] != 'AdminCreateGroup') { $form['groupName'] = ''; $form['formName'] = 'AdminCreateGroup'; } $template->setVariable('AdminCreateGroup', array()); $template->setVariable('controller', 'core.AdminCreateGroup'); return array(null, array('body' => 'modules/core/templates/AdminCreateGroup.tpl')); } } ?>