/app/bundles/EmailBundle/Entity/StatDevice.php

https://gitlab.com/mautic-master/mautic · PHP · 171 lines · 83 code · 26 blank · 62 comment · 0 complexity · e94d60d66f4a67f9c07cd85a5f8fb4dc MD5 · raw file

  1. <?php
  2. /**
  3. * @package Mautic
  4. * @copyright 2014 Mautic Contributors. All rights reserved.
  5. * @author Mautic
  6. * @link http://mautic.org
  7. * @license GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
  8. */
  9. namespace Mautic\EmailBundle\Entity;
  10. use Doctrine\ORM\Mapping as ORM;
  11. use JMS\Serializer\Annotation as Serializer;
  12. use Mautic\CoreBundle\Doctrine\Mapping\ClassMetadataBuilder;
  13. use Mautic\CoreBundle\Entity\IpAddress;
  14. use Mautic\ApiBundle\Serializer\Driver\ApiMetadataDriver;
  15. use Mautic\LeadBundle\Entity\LeadDevice;
  16. /**
  17. * Class StatDevice
  18. *
  19. * @package Mautic\EmailBundle\Entity
  20. */
  21. class StatDevice
  22. {
  23. /**
  24. * @var int
  25. */
  26. private $id;
  27. /**
  28. * @var array
  29. */
  30. private $stat;
  31. /**
  32. * @var \Mautic\LeadBundle\Entity\LeadDevice
  33. */
  34. private $device;
  35. /**
  36. * @var \Mautic\CoreBundle\Entity\IpAddress
  37. */
  38. private $ipAddress;
  39. /**
  40. * @var \DateTime
  41. */
  42. private $dateOpened;
  43. /**
  44. * @param ORM\ClassMetadata $metadata
  45. */
  46. public static function loadMetadata (ORM\ClassMetadata $metadata)
  47. {
  48. $builder = new ClassMetadataBuilder($metadata);
  49. $builder->setTable('email_stats_devices')
  50. ->setCustomRepositoryClass('Mautic\EmailBundle\Entity\StatDeviceRepository')
  51. ->addIndex(['date_opened'], 'date_opened_search');
  52. $builder->addId();
  53. $builder->createManyToOne('device', 'Mautic\LeadBundle\Entity\LeadDevice')
  54. ->addJoinColumn('device_id', 'id', true, false, 'CASCADE')
  55. ->build();
  56. $builder->createManyToOne('stat', 'Stat')
  57. ->addJoinColumn('stat_id', 'id', true, false, 'CASCADE')
  58. ->build();;
  59. $builder->addIpAddress(true);
  60. $builder->createField('dateOpened', 'datetime')
  61. ->columnName('date_opened')
  62. ->build();
  63. }
  64. /**
  65. * Prepares the metadata for API usage
  66. *
  67. * @param $metadata
  68. */
  69. public static function loadApiMetadata(ApiMetadataDriver $metadata)
  70. {
  71. $metadata->setGroupPrefix('stat')
  72. ->addProperties(
  73. array(
  74. 'id',
  75. 'device',
  76. 'ipAddress',
  77. 'stat'
  78. )
  79. )
  80. ->build();
  81. }
  82. /**
  83. * @return mixed
  84. */
  85. public function getId ()
  86. {
  87. return $this->id;
  88. }
  89. /**
  90. * @return IpAddress
  91. */
  92. public function getIpAddress ()
  93. {
  94. return $this->ipAddress;
  95. }
  96. /**
  97. * @param mixed $ip
  98. */
  99. public function setIpAddress (IpAddress $ip)
  100. {
  101. $this->ipAddress = $ip;
  102. }
  103. /**
  104. * @return Stat
  105. */
  106. public function getStat ()
  107. {
  108. return $this->stat;
  109. }
  110. /**
  111. * @param Stat
  112. */
  113. public function setStat (Stat $stat)
  114. {
  115. $this->stat = $stat;
  116. }
  117. /**
  118. * @return mixed
  119. */
  120. public function getDateOpened ()
  121. {
  122. return $this->dateOpened;
  123. }
  124. /**
  125. * @param mixed $dateOpened
  126. */
  127. public function setDateOpened ($dateOpened)
  128. {
  129. $this->dateOpened = $dateOpened;
  130. }
  131. /**
  132. * @return mixed
  133. */
  134. public function getDevice ()
  135. {
  136. return $this->device;
  137. }
  138. /**
  139. * @param mixed $device
  140. */
  141. public function setDevice (LeadDevice $device)
  142. {
  143. $this->device = $device;
  144. }
  145. }