Skip to content

Instantly share code, notes, and snippets.

@marcospassos
Last active December 15, 2015 09:19
Show Gist options
  • Save marcospassos/5237096 to your computer and use it in GitHub Desktop.
Save marcospassos/5237096 to your computer and use it in GitHub Desktop.
<?php
namespace Colibri\Bundle\ProductBundle\Model\Option;
use Doctrine\Common\Collections\Collection;
use Doctrine\Common\Collections\ArrayCollection;
/**
* Product option model.
*
* @author Marcos Passos <[email protected]>
*/
abstract class Option implements OptionInterface
{
/**
* @var string
*/
protected $name;
/**
* @var string
*/
protected $presentation;
/**
* @var Collection of OptionChoiceInterface
*/
protected $choices;
/**
* Constructor.
*/
public function __construct()
{
$this->choices = new ArrayCollection();
}
/**
* {@inheritDoc}
*/
public function getName()
{
return $this->name;
}
/**
* {@inheritDoc}
*/
public function setName($name)
{
$this->name = $name;
}
/**
* {@inheritDoc}
*/
public function getPresentation()
{
return $this->presentation;
}
/**
* {@inheritDoc}
*/
public function setPresentation($presentation)
{
$this->presentation = $presentation;
}
/**
* {@inheritdoc}
*/
public function getChoices()
{
return $this->choices;
}
/**
* {@inheritdoc}
*/
public function setChoices(Collection $choices)
{
$this->choices = $choices;
}
/**
* {@inheritdoc}
*/
public function addChoice(OptionChoiceInterface $choice)
{
if (!$this->hasChoice($choice)) {
$choice->setOption($this);
return $this->choices->add($choice);
}
return false;
}
/**
* {@inheritdoc}
*/
public function removeChoice(OptionChoiceInterface $choice)
{
if ($this->hasChoice($choice)) {
$return = $this->choices->removeElement($choice);
$choice->setOption(null);
return $return;
}
return false;
}
/**
* {@inheritdoc}
*/
public function hasChoice(OptionChoiceInterface $choice)
{
return $this->choices->contains($choice);
}
}
<?php
namespace Colibri\Bundle\ProductBundle\Entity\Option;
use Colibri\Bundle\ProductBundle\Model\Option\Option as BaseOption;
/**
* Option mapped superclass.
*
* @author Marcos Passos <[email protected]>
*/
abstract class Option extends BaseOption
{
/**
* @var int
*/
protected $id;
/**
* {@inheritDoc}
*/
public function getId()
{
return $this->id;
}
}
<?php
namespace Colibri\Bundle\ProductBundle\Entity\Option;
use Colibri\Bundle\ProductBundle\Model\Option\OptionNumberInterface;
/**
* Number option entity.
*
* @author Marcos Passos <[email protected]>
*/
class OptionNumber extends Option implements OptionNumberInterface
{
/**
* @var number
*/
protected $defaultValue;
/**
* @var boolean
*/
protected $wholeNumbersOnly;
/**
* @var number
*/
protected $lowestValue;
/**
* @var number
*/
protected $highestValue;
/**
* Constructor.
*/
public function __construct()
{
$this->wholeNumbersOnly = false;
}
/**
* {@inheritDoc}
*/
public static function getType()
{
return 'number';
}
/**
* {@inheritDoc}
*/
public function getDefaultValue()
{
return $this->defaultValue;
}
/**
* {@inheritDoc}
*/
public function setDefaultValue($defaultValue)
{
$this->defaultValue = $defaultValue;
}
/**
* {@inheritDoc}
*/
public function isWholeNumbersOnly()
{
return $this->wholeNumbersOnly;
}
/**
* {@inheritDoc}
*/
public function setWholeNumbersOnly($wholeNumbersOnly)
{
$this->wholeNumbersOnly = (Boolean) $wholeNumbersOnly;
}
/**
* {@inheritDoc}
*/
public function getLowestValue()
{
return $this->lowestValue;
}
/**
* {@inheritDoc}
*/
public function setLowestValue($lowestValue)
{
$this->lowestValue = $lowestValue;
}
/**
* {@inheritDoc}
*/
public function getHighestValue()
{
return $this->highestValue;
}
/**
* {@inheritDoc}
*/
public function setHighestValue($highestValue)
{
$this->highestValue = $highestValue;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment