Skip to content

Instantly share code, notes, and snippets.

@bartrail
Created October 6, 2011 16:34
Show Gist options
  • Save bartrail/1267876 to your computer and use it in GitHub Desktop.
Save bartrail/1267876 to your computer and use it in GitHub Desktop.
Country Class with incrementing userAmount
<?php
namespace Application\LocationBundle\Document;
use Doctrine\ODM\MongoDB\Mapping\Annotations as MongoDB;
use Symfony\Component\Validator\Constraints as Assert;
use Gedmo\Mapping\Annotation as Gedmo;
use Doctrine\ODM\MongoDB\SoftDelete\SoftDeleteable;
use Gedmo\Translatable\Translatable;
use FOS\UserBundle\Util\Canonicalizer;
/**
* @MongoDB\Document(
* repositoryClass="Application\LocationBundle\Document\CountryRepository",
* collection="country"
* )
* @MongoDB\Indexes({
* @MongoDB\Index(keys={"iocCode"="asc"}, options={"unique"="true"}),
* @MongoDB\Index(keys={"name"="asc"}),
* @MongoDB\Index(keys={"nameCanonical"="asc"})
* })
*/
class Country implements SoftDeleteable, Translatable
{
/**
* Id
*
* @var \MongoId
* @MongoDB\Id
*/
protected $id = null;
/**
* The official IOC Code of this Country
*
* @MongoDB\Field(type="string")
* @Assert\NotBlank(
* message = "country.iocCode.required"
* )
* @var string
*/
protected $iocCode;
/**
* The English name of this country
*
* @MongoDB\Field(type="string")
* @Gedmo\Translatable
* @Assert\NotBlank(
* message = "country.name.required"
* )
* @var string
*/
protected $name = '';
/**
* The English name of this country canonicalized
*
* @MongoDB\Field(type="string")
* @Assert\NotBlank(
* message = "country.nameCanonical.required"
* )
* @var string
*/
protected $nameCanonical;
/**
* The Shortcut of this country name in english chars
*
* @MongoDB\Field(type="string")
* @Assert\NotBlank(
* message = "country.shortcut.required"
* )
* @var String
*/
protected $shortcut;
/**
* Counts the registered users for every country to start everywhere with the
* same base number for registration
*
* @MongoDB\Field(type="int")
* @MongoDB\Increment
* @var Integer
*/
protected $userAmount = 10000;
/**
* Geonames.org ID of this Country
*
* @MongoDB\Field(type="int")
* @var Int
*/
protected $geonamesId;
/**
* contains a date when this user is deleted
*
* @MongoDB\Field(type="date")
* @var MongoDate
*/
protected $deletedAt;
/**
* @Gedmo\Locale
* @var String
*/
private $locale;
/**
* All Translations of this entity
*
* @var Array
*/
private $translations = array();
/**
* Get id
*
* @return id $id
*/
public function getId()
{
return $this->id;
}
/**
* Set iocCode
*
* @param string $iocCode
*/
public function setIocCode($iocCode)
{
$this->iocCode = $iocCode;
}
/**
* Get iocCode
*
* @return string $iocCode
*/
public function getIocCode()
{
return $this->iocCode;
}
/**
* Set name and name canonicalize
*
* @param string $name
* @param boolean updateCanonical
*/
public function setName($name, $updateCanonical = true)
{
$this->name = $name;
if($updateCanonical) {
$this->setNameCanonical($name);
}
}
/**
* Get name
*
* @return string $name
*/
public function getName()
{
return $this->name;
}
/**
* Set nameCanonical
*
* @param string $nameCanonical
*/
public function setNameCanonical($nameCanonical)
{
$canonicalizer = new Canonicalizer();
$this->nameCanonical = $canonicalizer->canonicalize($nameCanonical);
}
/**
* Get nameCanonical
*
* @return string $nameCanonical
*/
public function getNameCanonical()
{
return $this->nameCanonical;
}
/**
* Set shortcut
*
* @param string $shortcut
*/
public function setShortcut($shortcut)
{
$this->shortcut = $shortcut;
}
/**
* Get shortcut
*
* @return string $shortcut
*/
public function getShortcut()
{
return $this->shortcut;
}
/**
* Set userAmount
*
* @param int $userAmount
*/
public function setUserAmount($userAmount)
{
$this->userAmount = $userAmount;
}
/**
* Get userAmount
*
* @return int $userAmount
*/
public function getUserAmount()
{
return $this->userAmount;
}
/**
* Increments the UserAmount
*/
public function incrementUserAmount()
{
$this->userAmount++;
}
/**
*
* @param Int $geonamesId
*/
public function setGeonamesId($geonamesId)
{
$this->geonamesId = $geonamesId;
}
/**
*
* @return Int
*/
public function getGeonamesId()
{
return $this->geonamesId;
}
/**
* If this object is deleted, this will return a date
*
* @return MongoDate
*/
public function getDeletedAt()
{
return $this->deletedAt;
}
/**
* set the language of this document
*
* @param String $locale
*/
public function setTranslatableLocale($locale)
{
$this->locale = $locale;
}
/**
* set the translations in which this document is translated
*
* @param Array $translations
*/
public function setTranslations($translations)
{
$this->translations = $translations;
}
/**
* get the translations of this country
*
* @return Array
*/
public function getTranslations()
{
return $this->translations;
}
public function __toString()
{
return $this->getName();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment