Skip to content

Instantly share code, notes, and snippets.

@fsuter
Created July 16, 2012 13:47
Show Gist options
  • Save fsuter/3122816 to your computer and use it in GitHub Desktop.
Save fsuter/3122816 to your computer and use it in GitHub Desktop.
Simple FLOW3 controller
{namespace monitoring=Cobweb\Monitoring\ViewHelpers}
<f:layout name="Default" />
<f:section name="Title"><f:translate id="instance.groups" /></f:section>
<f:section name="Content">
<h2><f:translate id="create.new.instance.group" /></h2>
<f:form action="create" name="newInstanceGroup">
<div class="control-group {monitoring:hasError(for: 'name')}">
<label class="control-label"><f:translate id="name" /></label>
<div class="controls">
<f:form.textfield property="name" class="focus" />
<span class="help-inline">
<f:form.validationResults for="name">
<f:if condition="{validationResults.flattenedErrors}">
<ul class="errors">
<f:for each="{validationResults.errors}" as="error">
{error}<br />
</f:for>
</ul>
</f:if>
</f:form.validationResults>
</span>
</div>
</div>
<div class="form-actions">
<f:form.button type="submit" class="btn btn-inverse"><f:translate package="TYPO3.FLOW3" id="submit" /></f:form.button>
<f:link.action action="index" class="btn btn-danger"><f:translate id="cancel" /></f:link.action>
</div>
</f:form>
</f:section>
<?php
namespace Cobweb\Monitoring\Controller;
/* *
* This script belongs to the FLOW3 package "Cobweb.Monitoring". *
* *
* */
use TYPO3\FLOW3\Annotations as FLOW3;
use TYPO3\FLOW3\Mvc\Controller\ActionController;
use \Cobweb\Monitoring\Domain\Model\InstanceGroup;
/**
* InstanceGroup controller for the Cobweb.Monitoring package
*
* @FLOW3\Scope("singleton")
*/
class InstanceGroupController extends ActionController {
/**
* @FLOW3\Inject
* @var \Cobweb\Monitoring\Domain\Repository\InstanceGroupRepository
*/
protected $instanceGroupRepository;
/**
* @var \TYPO3\FLOW3\I18n\Translator
* @FLOW3\Inject
*/
protected $translator;
/**
* Shows a list of instance groups
*
* @return void
*/
public function indexAction() {
$this->view->assign('instanceGroups', $this->instanceGroupRepository->findAll());
}
/**
* Shows a form for creating a new instance group object
*
* @return void
*/
public function newAction() {
}
/**
* Adds the given new instance group object to the instance group repository
*
* @param \Cobweb\Monitoring\Domain\Model\InstanceGroup $newInstanceGroup A new instance group to add
* @return void
*/
public function createAction(\Cobweb\Monitoring\Domain\Model\InstanceGroup $newInstanceGroup) {
$this->instanceGroupRepository->add($newInstanceGroup);
$this->addFlashMessage(
$this->translator->translateById('instance.group.created')
);
$this->redirect('index');
}
/**
* Shows a form for editing an existing instance group object
*
* @param \Cobweb\Monitoring\Domain\Model\InstanceGroup $instanceGroup The instance group to edit
* @return void
*/
public function editAction(InstanceGroup $instanceGroup) {
$this->view->assign('instanceGroup', $instanceGroup);
}
/**
* Updates the given instance group object
*
* @param \Cobweb\Monitoring\Domain\Model\InstanceGroup $instanceGroup The instance group to update
* @return void
*/
public function updateAction(InstanceGroup $instanceGroup) {
$this->instanceGroupRepository->update($instanceGroup);
$this->addFlashMessage('Updated the instance group.');
$this->redirect('index');
}
/**
* Removes the given instance group object from the instance group repository
*
* @param \Cobweb\Monitoring\Domain\Model\InstanceGroup $instanceGroup The instance group to delete
* @return void
*/
public function deleteAction(InstanceGroup $instanceGroup) {
$this->instanceGroupRepository->remove($instanceGroup);
$this->addFlashMessage('Deleted a instance group.');
$this->redirect('index');
}
/**
* Overrides getErrorFlashMessage to present nice flash error messages.
*
* @return \TYPO3\FLOW3\Error\Message
*/
protected function getErrorFlashMessage() {
switch ($this->actionMethodName) {
case 'createAction' :
return new \TYPO3\FLOW3\Error\Error(
$this->translator->translateById('instance.group.not.created')
);
case 'updateAction' :
return new \TYPO3\FLOW3\Error\Error(
$this->translator->translateById('instance.group.not.updated')
);
default :
return parent::getErrorFlashMessage();
}
}
}
?>
<?php
namespace Cobweb\Monitoring\Domain\Model;
/* *
* This script belongs to the FLOW3 package "Cobweb.Monitoring". *
* *
* */
use TYPO3\FLOW3\Annotations as FLOW3;
use Doctrine\ORM\Mapping as ORM;
/**
* A Instance group
*
* @FLOW3\Entity
*/
class InstanceGroup {
/**
* The name
* @var string
* @FLOW3\Validate(type="StringLength", options={ "minimum"=3, "maximum"=255 })
*/
protected $name;
/**
* The instances contained in this group
*
* @var \Doctrine\Common\Collections\Collection<\Cobweb\Monitoring\Domain\Model\Instance>
* @ORM\OneToMany(mappedBy="groupMembership")
* @ORM\OrderBy({"name" = "ASC"})
*/
protected $instances;
/**
* Get the Instance group's name
*
* @return string The Instance group's name
*/
public function getName() {
return $this->name;
}
/**
* Sets this Instance group's name
*
* @param string $name The Instance group's name
* @return void
*/
public function setName($name) {
$this->name = $name;
}
/**
* Adds an instance to this group
*
* @param \Cobweb\Monitoring\Domain\Model\Instance $instance
* @return void
*/
public function addInstance(\Cobweb\Monitoring\Domain\Model\Instance $instance) {
$instance->setGroupMembership($this);
$this->instances->add($instance);
}
/**
* Removes an instance from this group
*
* @param \Cobweb\Monitoring\Domain\Model\Instance $instance
* @return \Cobweb\Monitoring\Domain\Model\Instance
*/
public function removeInstance(\Cobweb\Monitoring\Domain\Model\Instance $instance) {
$this->instances->removeElement($instance);
}
/**
* Returns all instances in this group
*
* @return \Doctrine\Common\Collections\Collection<\Cobweb\Monitoring\Domain\Model\Instance> The instances in this group
*/
public function getInstances() {
return $this->instances;
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment