Advertisement
Guest User

Untitled

a guest
Jun 5th, 2017
27
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 14.44 KB | None | 0 0
  1. <?php
  2.  
  3. namespace MatchPint\Bundle\DugoutAccountBundle\Entity;
  4.  
  5. use BeSimple\SoapBundle\ServiceDefinition\Annotation as Soap;
  6.  
  7. use Doctrine\Common\Collections\ArrayCollection;
  8. use Doctrine\Common\Collections\Collection;
  9. use Doctrine\ORM\Mapping as ORM;
  10.  
  11. use Oro\Bundle\DataAuditBundle\Metadata\Annotation as Oro;
  12. use Oro\Bundle\EmailBundle\Model\EmailHolderInterface;
  13. use Oro\Bundle\EntityConfigBundle\Metadata\Annotation\Config;
  14. use Oro\Bundle\EntityConfigBundle\Metadata\Annotation\ConfigField;
  15. use Oro\Bundle\LocaleBundle\Model\NameInterface;
  16. use Oro\Bundle\OrganizationBundle\Entity\Organization;
  17. use Oro\Bundle\TagBundle\Entity\Taggable;
  18. use Oro\Bundle\UserBundle\Entity\User;
  19.  
  20. use OroCRM\Bundle\AccountBundle\Model\ExtendAccount;
  21. use OroCRM\Bundle\ContactBundle\Entity\Contact;
  22.  
  23. use Matchpint\Bundle\DugoutBundle\Service\XeroTrait;
  24.  
  25. /**
  26.  * @ORM\Entity()
  27.  * @ORM\Table(name="orocrm_account", indexes={@ORM\Index(name="account_name_idx", columns={"name"})})
  28.  * @ORM\HasLifecycleCallbacks()
  29.  * @Oro\Loggable
  30.  * @Config(
  31.  *      routeName="orocrm_account_index",
  32.  *      routeView="orocrm_account_view",
  33.  *      defaultValues={
  34.  *          "entity"={
  35.  *              "icon"="icon-suitcase"
  36.  *          },
  37.  *          "ownership"={
  38.  *              "owner_type"="USER",
  39.  *              "owner_field_name"="owner",
  40.  *              "owner_column_name"="user_owner_id",
  41.  *              "organization_field_name"="organization",
  42.  *              "organization_column_name"="organization_id"
  43.  *          },
  44.  *          "security"={
  45.  *              "type"="ACL",
  46.  *              "group_name"="",
  47.  *              "category"="account_management",
  48.  *              "field_acl_supported" = "true"
  49.  *          },
  50.  *          "merge"={
  51.  *              "enable"=true
  52.  *          },
  53.  *          "form"={
  54.  *              "form_type"="orocrm_account_select",
  55.  *              "grid_name"="accounts-select-grid",
  56.  *          },
  57.  *          "dataaudit"={
  58.  *              "auditable"=true
  59.  *          },
  60.  *          "grid"={
  61.  *              "default"="accounts-grid",
  62.  *              "context"="accounts-for-context-grid"
  63.  *          },
  64.  *          "tag"={
  65.  *              "enabled"=true
  66.  *          }
  67.  *      }
  68.  * )
  69.  */
  70. class Account extends ExtendAccount implements EmailHolderInterface, NameInterface, Taggable {
  71.   use XeroTrait;
  72.  
  73.   private $xero;
  74.   private $legacy;
  75.  
  76.   /**
  77.    * @ORM\Id
  78.    * @ORM\Column(type="integer")
  79.    * @ORM\GeneratedValue(strategy="AUTO")
  80.    * @Soap\ComplexType("int", nillable=true)
  81.    * @ConfigField(
  82.    *      defaultValues={
  83.    *          "importexport"={
  84.    *              "order"=10
  85.    *          }
  86.    *      }
  87.    * )
  88.    */
  89.   protected $id;
  90.  
  91.   /**
  92.    * @var string
  93.    *
  94.    * @ORM\Column(type="string", length=255)
  95.    * @Soap\ComplexType("string")
  96.    * @Oro\Versioned
  97.    * @ConfigField(
  98.    *      defaultValues={
  99.    *          "merge"={
  100.    *              "display"=true
  101.    *          },
  102.    *          "dataaudit"={
  103.    *              "auditable"=true
  104.    *          },
  105.    *          "importexport"={
  106.    *              "identity"=true,
  107.    *              "order"=20
  108.    *          }
  109.    *      }
  110.    * )
  111.    */
  112.   protected $name;
  113.  
  114.   /**
  115.    * @var User
  116.    * @ORM\ManyToOne(targetEntity="Oro\Bundle\UserBundle\Entity\User")
  117.    * @ORM\JoinColumn(name="user_owner_id", referencedColumnName="id", onDelete="SET NULL")
  118.    * @Soap\ComplexType("string", nillable=true)
  119.    * @Oro\Versioned
  120.    * @ConfigField(
  121.    *      defaultValues={
  122.    *          "merge"={
  123.    *              "display"=true
  124.    *          },
  125.    *          "dataaudit"={
  126.    *              "auditable"=true
  127.    *          },
  128.    *          "importexport"={
  129.    *              "order"=30,
  130.    *              "short"=true
  131.    *          }
  132.    *      }
  133.    * )
  134.    */
  135.   protected $owner;
  136.  
  137.   /**
  138.    * Contacts storage
  139.    *
  140.    * @var ArrayCollection $contacts
  141.    *
  142.    * @ORM\ManyToMany(targetEntity="OroCRM\Bundle\ContactBundle\Entity\Contact", inversedBy="accounts")
  143.    * @ORM\JoinTable(name="orocrm_account_to_contact")
  144.    * @ConfigField(
  145.    *      defaultValues={
  146.    *          "merge"={
  147.    *              "display"=true
  148.    *          },
  149.    *          "importexport"={
  150.    *              "order"=50,
  151.    *              "short"=true
  152.    *          }
  153.    *      }
  154.    * )
  155.    */
  156.   protected $contacts;
  157.  
  158.   /**
  159.    * Default contact entity
  160.    *
  161.    * @var Contact
  162.    *
  163.    * @ORM\ManyToOne(targetEntity="OroCRM\Bundle\ContactBundle\Entity\Contact", inversedBy="defaultInAccounts")
  164.    * @ORM\JoinColumn(name="default_contact_id", referencedColumnName="id", onDelete="SET NULL")
  165.    * @ConfigField(
  166.    *      defaultValues={
  167.    *          "merge"={
  168.    *              "display"=true,
  169.    *              "inverse_display"=false
  170.    *          },
  171.    *          "importexport"={
  172.    *              "order"=40,
  173.    *              "short"=true
  174.    *          }
  175.    *      }
  176.    * )
  177.    */
  178.   protected $defaultContact;
  179.  
  180.   /**
  181.    * Area manager contact entity.
  182.    *
  183.    * @var Contact
  184.    *
  185.    * @ORM\ManyToOne(targetEntity="OroCRM\Bundle\ContactBundle\Entity\Contact")
  186.    * @ORM\JoinColumn(name="mp_area_manager_id", referencedColumnName="id", onDelete="SET NULL")
  187.    * @ConfigField(
  188.    *      defaultValues={
  189.    *          "merge"={
  190.    *              "display"=true,
  191.    *              "inverse_display"=false
  192.    *          },
  193.    *          "importexport"={
  194.    *              "order"=40,
  195.    *              "short"=true
  196.    *          }
  197.    *      }
  198.    * )
  199.    */
  200.   protected $areaManager;
  201.  
  202.   /**
  203.    * @var \DateTime
  204.    *
  205.    * @ORM\Column(type="datetime")
  206.    * @Soap\ComplexType("dateTime", nillable=true)
  207.    * @ConfigField(
  208.    *      defaultValues={
  209.    *          "entity"={
  210.    *              "label"="oro.ui.created_at"
  211.    *          },
  212.    *          "importexport"={
  213.    *              "excluded"=true
  214.    *          }
  215.    *      }
  216.    * )
  217.    */
  218.   protected $createdAt;
  219.  
  220.   /**
  221.    * @var \DateTime
  222.    *
  223.    * @ORM\Column(type="datetime")
  224.    * @Soap\ComplexType("dateTime", nillable=true)
  225.    * @ConfigField(
  226.    *      defaultValues={
  227.    *          "entity"={
  228.    *              "label"="oro.ui.updated_at"
  229.    *          },
  230.    *          "importexport"={
  231.    *              "excluded"=true
  232.    *          }
  233.    *      }
  234.    * )
  235.    */
  236.   protected $updatedAt;
  237.  
  238.   /**
  239.    * @var Organization
  240.    *
  241.    * @ORM\ManyToOne(targetEntity="Oro\Bundle\OrganizationBundle\Entity\Organization")
  242.    * @ORM\JoinColumn(name="organization_id", referencedColumnName="id", onDelete="SET NULL")
  243.    */
  244.   protected $organization;
  245.  
  246.   /**
  247.    * @var Account
  248.    * @ORM\ManyToOne(targetEntity="Account")
  249.    * @ORM\JoinColumn(name="referred_by_id", referencedColumnName="id", onDelete="SET NULL")
  250.    */
  251.   protected $referredBy;
  252.  
  253.   /**
  254.    * @var ArrayCollection
  255.    * @ConfigField(
  256.    *      defaultValues={
  257.    *          "merge"={
  258.    *              "display"=true,
  259.    *              "inverse_display"=false
  260.    *          }
  261.    *      }
  262.    * )
  263.    */
  264.   protected $tags;
  265.  
  266.  
  267.   public function __construct() {
  268.     parent::__construct();
  269.  
  270.     $this->contacts = new ArrayCollection();
  271.   }
  272.  
  273.   /**
  274.    * Returns the account unique id.
  275.    *
  276.    * @return mixed
  277.    */
  278.   public function getId() {
  279.     return $this->id;
  280.   }
  281.  
  282.   /**
  283.    * @param int $id
  284.    * @return Account
  285.    */
  286.   public function setId($id) {
  287.     $this->id = $id;
  288.  
  289.     return $this;
  290.   }
  291.  
  292.   /**
  293.    * {@inheritDoc}
  294.    */
  295.   public function getName() {
  296.     return $this->name;
  297.   }
  298.  
  299.   /**
  300.    * Set account name
  301.    *
  302.    * @param string $name New name
  303.    *
  304.    * @return Account
  305.    */
  306.   public function setName($name) {
  307.     $this->name = $name;
  308.  
  309.     return $this;
  310.   }
  311.  
  312.   /**
  313.    * Get created date/time
  314.    *
  315.    * @return \DateTime
  316.    */
  317.   public function getCreatedAt() {
  318.     return $this->createdAt;
  319.   }
  320.  
  321.   /**
  322.    * @param \DateTime
  323.    *
  324.    * @return Account
  325.    */
  326.   public function setCreatedAt($created) {
  327.     $this->createdAt = $created;
  328.  
  329.     return $this;
  330.   }
  331.  
  332.   /**
  333.    * Get last update date/time
  334.    *
  335.    * @return \DateTime
  336.    */
  337.   public function getUpdatedAt() {
  338.     return $this->updatedAt;
  339.   }
  340.  
  341.   /**
  342.    * @param \DateTime
  343.    *
  344.    * @return Account
  345.    */
  346.   public function setUpdatedAt($updated) {
  347.     $this->updatedAt = $updated;
  348.  
  349.     return $this;
  350.   }
  351.  
  352.   /**
  353.    * Get contacts collection
  354.    *
  355.    * @return Collection|Contact[]
  356.    */
  357.   public function getContacts() {
  358.     return $this->contacts;
  359.   }
  360.  
  361.   /**
  362.    * Add specified contact
  363.    *
  364.    * @param Contact $contact
  365.    *
  366.    * @return Account
  367.    */
  368.   public function addContact(Contact $contact) {
  369.     if (!$this->getContacts()->contains($contact)) {
  370.       $this->getContacts()->add($contact);
  371.       $contact->addAccount($this);
  372.     }
  373.  
  374.     return $this;
  375.   }
  376.  
  377.   /**
  378.    * Set contacts collection
  379.    *
  380.    * @param Collection $contacts
  381.    *
  382.    * @return Account
  383.    */
  384.   public function setContacts(Collection $contacts) {
  385.     $this->contacts = $contacts;
  386.  
  387.     return $this;
  388.   }
  389.  
  390.   /**
  391.    * Remove specified contact
  392.    *
  393.    * @param Contact $contact
  394.    *
  395.    * @return Account
  396.    */
  397.   public function removeContact(Contact $contact) {
  398.     if ($this->getContacts()->contains($contact)) {
  399.       $this->getContacts()->removeElement($contact);
  400.       $contact->removeAccount($this);
  401.     }
  402.  
  403.     return $this;
  404.   }
  405.  
  406.   public function __toString() {
  407.     return (string)$this->getName();
  408.   }
  409.  
  410.   /**
  411.    * Pre persist event listener
  412.    *
  413.    * @ORM\PrePersist
  414.    */
  415.   public function beforeSave() {
  416.     $this->createdAt = new \DateTime('now', new \DateTimeZone('UTC'));
  417.     $this->updatedAt = new \DateTime('now', new \DateTimeZone('UTC'));
  418.   }
  419.  
  420.   /**
  421.    * Pre update event handler
  422.    *
  423.    * @ORM\PreUpdate
  424.    */
  425.   public function doPreUpdate() {
  426.     $this->updatedAt = new \DateTime('now', new \DateTimeZone('UTC'));
  427.   }
  428.  
  429.   /**
  430.    * @return User
  431.    */
  432.   public function getOwner() {
  433.     return $this->owner;
  434.   }
  435.  
  436.   /**
  437.    * @param User $owningUser
  438.    *
  439.    * @return Account
  440.    */
  441.   public function setOwner($owningUser) {
  442.     $this->owner = $owningUser;
  443.  
  444.     return $this;
  445.   }
  446.  
  447.   /**
  448.    * @param Contact $defaultContact
  449.    *
  450.    * @return Account
  451.    */
  452.   public function setDefaultContact($defaultContact) {
  453.     if ($this->defaultContact === $defaultContact) {
  454.       return $this;
  455.     }
  456.  
  457.     /**
  458.      * As resolving of $this->defaultContact->getDefaultInAccounts() lazy collection will
  459.      * overwrite $this->defaultContact to value from db, make sure the collection is resolved
  460.      */
  461.     if ($this->defaultContact) {
  462.       $this->defaultContact->getDefaultInAccounts()->toArray();
  463.     }
  464.  
  465.     $originalContact = $this->defaultContact;
  466.     $this->defaultContact = $defaultContact;
  467.  
  468.     if ($defaultContact) {
  469.       $defaultContact->addDefaultInAccount($this);
  470.     }
  471.  
  472.     if ($originalContact) {
  473.       $originalContact->removeDefaultInAccount($this);
  474.     }
  475.  
  476.     if ($defaultContact && !$this->contacts->contains($defaultContact)) {
  477.       $this->addContact($defaultContact);
  478.     }
  479.  
  480.     return $this;
  481.   }
  482.  
  483.   /**
  484.    * @return Contact
  485.    */
  486.   public function getDefaultContact() {
  487.     return $this->defaultContact;
  488.   }
  489.  
  490.   /**
  491.    * Get the primary email address of the default contact
  492.    *
  493.    * @return string
  494.    */
  495.   public function getEmail() {
  496.     $contact = $this->getDefaultContact();
  497.     if (!$contact) {
  498.       return null;
  499.     }
  500.  
  501.     return $contact->getEmail();
  502.   }
  503.  
  504.   /**
  505.    * Set organization
  506.    *
  507.    * @param Organization $organization
  508.    *
  509.    * @return Account
  510.    */
  511.   public function setOrganization(Organization $organization = null) {
  512.     $this->organization = $organization;
  513.  
  514.     return $this;
  515.   }
  516.  
  517.   /**
  518.    * Get organization
  519.    *
  520.    * @return Organization
  521.    */
  522.   public function getOrganization() {
  523.     return $this->organization;
  524.   }
  525.  
  526.   /**
  527.    * @return Account
  528.    */
  529.   public function getReferredBy() {
  530.     return $this->referredBy;
  531.   }
  532.  
  533.   /**
  534.    * @param Account $referredBy
  535.    *
  536.    * @return Account
  537.    */
  538.   public function setReferredBy(Account $referredBy = null) {
  539.     $this->referredBy = $referredBy;
  540.  
  541.     return $this;
  542.   }
  543.  
  544.   /**
  545.    * @param Contact $areaManager
  546.    *
  547.    * @return Account
  548.    */
  549.   public function setAreaManager($areaManager) {
  550.     if ($this->areaManager === $areaManager) {
  551.       return $this;
  552.     }
  553.  
  554.     /**
  555.      * As resolving of $this->areaManager->getDefaultInAccounts() lazy collection will
  556.      * overwrite $this->areaManager to value from db, make sure the collection is resolved
  557.      */
  558.     if ($this->areaManager) {
  559.       $this->areaManager->getDefaultInAccounts()->toArray();
  560.     }
  561.  
  562.     $originalContact = $this->areaManager;
  563.     $this->areaManager = $areaManager;
  564.  
  565.     if ($areaManager) {
  566.       $areaManager->addDefaultInAccount($this);
  567.     }
  568.  
  569.     if ($originalContact) {
  570.       $originalContact->removeDefaultInAccount($this);
  571.     }
  572.  
  573.     if ($areaManager && !$this->contacts->contains($areaManager)) {
  574.       $this->addContact($areaManager);
  575.     }
  576.  
  577.     return $this;
  578.   }
  579.  
  580.   /**
  581.    * @return Contact
  582.    */
  583.   public function getAreaManager() {
  584.     return $this->areaManager;
  585.   }
  586.  
  587.   /**
  588.    * {@inheritdoc}
  589.    */
  590.   public function getTaggableId() {
  591.     return $this->getId();
  592.   }
  593.  
  594.   /**
  595.    * {@inheritdoc}
  596.    */
  597.   public function getTags() {
  598.     $this->tags = $this->tags ?: new ArrayCollection();
  599.  
  600.     return $this->tags;
  601.   }
  602.  
  603.   /**
  604.    * {@inheritdoc}
  605.    */
  606.   public function setTags($tags) {
  607.     $this->tags = $tags;
  608.  
  609.     return $this;
  610.   }
  611.  
  612.   public function setXero($xero) {
  613.     $this->xero = $xero;
  614.  
  615.     return $this;
  616.   }
  617.  
  618.   public function getXero() {
  619.     if ($this->xero) {
  620.       return $this->xero;
  621.     }
  622.  
  623.     $venueId = $this->getMpVenueId();
  624.  
  625.     foreach ($this->getXeroCached('getXeroContacts') as $contact) {
  626.       if (isset($contact['AccountNumber']) && $contact['AccountNumber'] == $venueId) {
  627.         $this->xero['Contact'] = $contact;
  628.         return $this->xero;
  629.       }
  630.     }
  631.   }
  632.  
  633.   public function setLegacy($legacy) {
  634.     $this->legacy = $legacy;
  635.  
  636.     if (!$this->legacy['monthStats']) {
  637.       $this->legacy['monthStats'] = [
  638.         'xmlFeed' => 0,
  639.         'fixturesShared' => 0,
  640.         'postersPrinted' => 0,
  641.         'profileViews' => 0,
  642.         'checkIns' => 0,
  643.         'clickthroughFacebook' => 0,
  644.         'clickthroughTwitter' => 0,
  645.         'clickthroughWebsite' => 0,
  646.         'rewardRedemptions' => 0,
  647.       ];
  648.     }
  649.  
  650.     return $this;
  651.   }
  652.  
  653.   public function getLegacy() {
  654.     return $this->legacy;
  655.   }
  656.  
  657. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement