Skip to content

Instantly share code, notes, and snippets.

@akadlec
Created March 12, 2014 12:07
Show Gist options
  • Save akadlec/9505625 to your computer and use it in GitHub Desktop.
Save akadlec/9505625 to your computer and use it in GitHub Desktop.
<?php
namespace Entities\Widgets;
use Gedmo\Mapping\Annotation as Gedmo;
use Doctrine\ORM\Mapping as ORM,
Doctrine\Common\Collections\ArrayCollection;
/**
* @ORM\Entity
* @ORM\Table(name="design_widgets")
* @Gedmo\Loggable(logEntryClass="Entities\Widgets\WidgetVersion")
* @Gedmo\TranslationEntity(class="Entities\Widgets\WidgetTranslation")
*/
class Widget extends \Entities\Doctrine\Entity implements \Gedmo\Translatable\Translatable
{
/**
* @ORM\Id
* @ORM\Column(type="integer", name="widget_id")
* @ORM\GeneratedValue
*/
protected $id;
/**
* @ORM\Column(type="string", name="widget_class", length=150, nullable=FALSE)
*/
protected $class;
/**
* @ORM\Column(type="string", name="widget_type", length=50, nullable=FALSE)
*/
protected $type;
/**
* @Gedmo\Versioned
* @ORM\Column(type="string", name="widget_position", length=200, nullable=FALSE)
*/
protected $position;
/**
* @Gedmo\Versioned
* @Gedmo\Translatable
* @ORM\Column(type="string", name="widget_name", length=250, nullable=FALSE)
*/
protected $name;
/**
* @ORM\Column(type="integer", name="ordering", nullable=TRUE)
*/
protected $ordering;
/**
* @ORM\Column(type="boolean", name="published", nullable=FALSE)
*/
protected $published;
/**
* @ORM\OneToMany(targetEntity="WidgetTranslation", mappedBy="object", cascade={"persist", "remove"})
*/
protected $translations;
/**
* @Gedmo\Locale
* Used locale to override Translation listener`s locale
* this is not a mapped field of entity metadata, just a simple property
*/
protected $locale;
public function setLocale($locale)
{
$this->locale = $locale;
}
public function getTranslations()
{
return $this->translations;
}
public function addTranslation(WidgetTranslation $t)
{
if (!$this->translations->contains($t)) {
$this->translations[] = $t;
$t->setObject($this);
}
}
}
<?php
namespace Entities\Widgets;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity
* @ORM\Table(name="design_widgets_translations",
* uniqueConstraints={@ORM\UniqueConstraint(name="lookup_unique_idx", columns={
* "translation_locale", "object_id", "translation_field"
* })}
* )
*/
class WidgetTranslation extends \Entities\Doctrine\EntityTranslation
{
/**
* @ORM\ManyToOne(targetEntity="Widget", inversedBy="translations")
* @ORM\JoinColumn(name="object_id", referencedColumnName="widget_id", onDelete="CASCADE")
*/
protected $object;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment