2015-10-08 17:33:01 +02:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* PHPCI - Continuous Integration for PHP
|
|
|
|
*
|
|
|
|
* @copyright Copyright 2015, Block 8 Limited.
|
|
|
|
* @license https://github.com/Block8/PHPCI/blob/master/LICENSE.md
|
|
|
|
* @link https://www.phptesting.org/
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace PHPCI\Controller;
|
|
|
|
|
|
|
|
use b8;
|
|
|
|
use b8\Form;
|
|
|
|
use b8\Store;
|
|
|
|
use PHPCI\Controller;
|
|
|
|
use PHPCI\Model\ProjectGroup;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Project Controller - Allows users to create, edit and view projects.
|
|
|
|
* @author Dan Cryer <dan@block8.co.uk>
|
|
|
|
* @package PHPCI
|
|
|
|
* @subpackage Web
|
|
|
|
*/
|
|
|
|
class GroupController extends Controller
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @var \PHPCI\Store\ProjectGroupStore
|
|
|
|
*/
|
|
|
|
protected $groupStore;
|
|
|
|
|
2015-10-09 10:38:55 +02:00
|
|
|
/**
|
|
|
|
* Set up this controller.
|
|
|
|
*/
|
2015-10-08 17:33:01 +02:00
|
|
|
public function init()
|
|
|
|
{
|
|
|
|
$this->groupStore = b8\Store\Factory::getStore('ProjectGroup');
|
|
|
|
}
|
|
|
|
|
2015-10-09 10:38:55 +02:00
|
|
|
/**
|
|
|
|
* List project groups.
|
|
|
|
*/
|
2015-10-08 17:33:01 +02:00
|
|
|
public function index()
|
|
|
|
{
|
|
|
|
$this->requireAdmin();
|
|
|
|
|
|
|
|
$groups = array();
|
|
|
|
$groupList = $this->groupStore->getWhere(array(), 100, 0, array(), array('title' => 'ASC'));
|
|
|
|
|
|
|
|
foreach ($groupList['items'] as $group) {
|
|
|
|
$thisGroup = array(
|
|
|
|
'title' => $group->getTitle(),
|
|
|
|
'id' => $group->getId(),
|
|
|
|
);
|
|
|
|
$projects = b8\Store\Factory::getStore('Project')->getByGroupId($group->getId());
|
|
|
|
$thisGroup['projects'] = $projects['items'];
|
|
|
|
$groups[] = $thisGroup;
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->view->groups = $groups;
|
|
|
|
}
|
|
|
|
|
2015-10-09 10:38:55 +02:00
|
|
|
/**
|
|
|
|
* Add or edit a project group.
|
|
|
|
* @param null $groupId
|
|
|
|
* @return void|b8\Http\Response\RedirectResponse
|
|
|
|
*/
|
2015-10-08 21:24:32 +02:00
|
|
|
public function edit($groupId = null)
|
2015-10-08 17:33:01 +02:00
|
|
|
{
|
|
|
|
$this->requireAdmin();
|
|
|
|
|
2015-10-08 21:24:32 +02:00
|
|
|
if (!is_null($groupId)) {
|
2015-10-08 21:27:40 +02:00
|
|
|
$group = $this->groupStore->getById($groupId);
|
2015-10-08 17:33:01 +02:00
|
|
|
} else {
|
|
|
|
$group = new ProjectGroup();
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($this->request->getMethod() == 'POST') {
|
|
|
|
$group->setTitle($this->getParam('title'));
|
|
|
|
$this->groupStore->save($group);
|
|
|
|
|
|
|
|
$response = new b8\Http\Response\RedirectResponse();
|
|
|
|
$response->setHeader('Location', PHPCI_URL.'group');
|
|
|
|
return $response;
|
|
|
|
}
|
|
|
|
|
|
|
|
$form = new Form();
|
|
|
|
$form->setMethod('POST');
|
2015-10-08 21:24:32 +02:00
|
|
|
$form->setAction(PHPCI_URL . 'group/edit' . (!is_null($groupId) ? '/' . $groupId : ''));
|
2015-10-08 17:33:01 +02:00
|
|
|
|
|
|
|
$title = new Form\Element\Text('title');
|
|
|
|
$title->setContainerClass('form-group');
|
|
|
|
$title->setClass('form-control');
|
|
|
|
$title->setLabel('Group Title');
|
|
|
|
$title->setValue($group->getTitle());
|
|
|
|
|
|
|
|
$submit = new Form\Element\Submit();
|
|
|
|
$submit->setValue('Save Group');
|
|
|
|
|
|
|
|
$form->addField($title);
|
|
|
|
$form->addField($submit);
|
|
|
|
|
|
|
|
$this->view->form = $form;
|
|
|
|
}
|
|
|
|
|
2015-10-09 10:38:55 +02:00
|
|
|
/**
|
|
|
|
* Delete a project group.
|
|
|
|
* @param $groupId
|
|
|
|
* @return b8\Http\Response\RedirectResponse
|
|
|
|
*/
|
2015-10-08 21:24:32 +02:00
|
|
|
public function delete($groupId)
|
2015-10-08 17:33:01 +02:00
|
|
|
{
|
|
|
|
$this->requireAdmin();
|
2015-10-08 21:24:32 +02:00
|
|
|
$group = $this->groupStore->getById($groupId);
|
2015-10-08 17:33:01 +02:00
|
|
|
|
|
|
|
$this->groupStore->delete($group);
|
|
|
|
$response = new b8\Http\Response\RedirectResponse();
|
|
|
|
$response->setHeader('Location', PHPCI_URL.'group');
|
|
|
|
return $response;
|
|
|
|
}
|
|
|
|
}
|