src/Entity/UserStats.php line 17

  1. <?php
  2. namespace App\Entity;
  3. use Doctrine\Common\Collections\ArrayCollection;
  4. use Doctrine\Common\Collections\Collection;
  5. use App\Entity\Reserva;
  6. use App\Entity\Transaccion;
  7. use Doctrine\ORM\Mapping as ORM;
  8. use JMS\Serializer\Annotation as JMS;
  9. /**
  10.  *
  11.  * @ORM\Table(name="user_stats")
  12.  * @ORM\Entity(repositoryClass="App\Repository\UserStatsRepository")
  13.  */
  14. class UserStats
  15. {
  16.     /**
  17.      * @ORM\Id
  18.      * @ORM\Column(type="integer")
  19.      * @ORM\GeneratedValue(strategy="AUTO")
  20.      */
  21.     protected $id;
  22.     /**
  23.      * @var string
  24.      * @ORM\Column(name="session_id", type="string")
  25.      */
  26.     protected $sessionId;
  27.     /**
  28.      * @var User
  29.      * @ORM\ManyToOne(targetEntity="User")
  30.      * @ORM\JoinColumn(name="user", nullable=true)
  31.      */
  32.     protected $user;
  33.     /**
  34.      * @var string
  35.      * @ORM\Column(name="uuid", type="string", nullable=true)
  36.      * @JMS\Groups({"api-stats"})
  37.      */
  38.     protected $uuid;
  39.     /**
  40.      * @var \DateTime
  41.      * @ORM\Column(name="session_start", type="datetime")
  42.      * @JMS\Groups({"api-stats"})
  43.      */
  44.     protected $sessionStart;
  45.     /**
  46.      * @var \DateTime
  47.      * @ORM\Column(name="last_update", type="datetime")
  48.      * @JMS\Groups({"api-stats"})
  49.      */
  50.     protected $lastUpdate;
  51.     /**
  52.      * @var string[]
  53.      * @ORM\Column(name="visited_pages", type="json", nullable=true)
  54.      * @JMS\Groups({"api-stats"})
  55.      */
  56.     protected $visitedPages;
  57.     /**
  58.      * @var string
  59.      * @ORM\Column(name="referer", type="string", nullable=true)
  60.      * @JMS\Groups({"api-stats"})
  61.      */
  62.     protected $referer;
  63.     /**
  64.      * @var string
  65.      * @ORM\Column(name="ip" ,type="string")
  66.      * @JMS\Groups({"api-stats"})
  67.      */
  68.     protected $ip;
  69.     /**
  70.      * @var Collection|Reserva[]
  71.      * @ORM\ManyToMany(targetEntity="Reserva", inversedBy="userStats")
  72.      * @ORM\JoinTable(name="user__stats_booking")
  73.      */
  74.     protected $bookingConversions;
  75.     /**
  76.      * @var Collection|Transaccion[]
  77.      * @ORM\ManyToMany(targetEntity="Transaccion", inversedBy="userStats")
  78.      * @ORM\JoinTable(name="user__stats_order")
  79.      */
  80.     protected $orderConversions;
  81.     /**
  82.      * @var string
  83.      * @ORM\Column(name="device", type="string", nullable=true)
  84.      * @JMS\Groups({"api-stats"})
  85.      */
  86.     protected $device;
  87.     /**
  88.      * @var string
  89.      * @ORM\Column(name="country", type="string", nullable=true)
  90.      * @JMS\Groups({"api-stats"})
  91.      */
  92.     protected $country;
  93.     /**
  94.      * @var string
  95.      * @ORM\Column(name="region", type="string", nullable=true)
  96.      * @JMS\Groups({"api-stats"})
  97.      */
  98.     protected $region;
  99.     /**
  100.      * @var string
  101.      * @ORM\Column(name="city", type="string", nullable=true)
  102.      * @JMS\Groups({"api-stats"})
  103.      */
  104.     protected $city;
  105.     /**
  106.      * @var string
  107.      * @ORM\Column(name="zip", type="string", nullable=true)
  108.      * @JMS\Groups({"api-stats"})
  109.      */
  110.     protected $zip;
  111.     /**
  112.      * @var string
  113.      * @ORM\Column(name="locale", type="string", nullable=true)
  114.      * @JMS\Groups({"api-stats"})
  115.      */
  116.     protected $locale;
  117.     /**
  118.      * Constructor
  119.      */
  120.     public function __construct()
  121.     {
  122.         $this->bookingConversions = new ArrayCollection();
  123.         $this->orderConversions = new  ArrayCollection();
  124.         $this->sessionStart = new \DateTime();
  125.         $this->visitedPages = [];
  126.     }
  127.     /**
  128.      * Get id
  129.      *
  130.      * @return integer
  131.      */
  132.     public function getId()
  133.     {
  134.         return $this->id;
  135.     }
  136.     /**
  137.      * Set sessionId
  138.      *
  139.      * @param string $sessionId
  140.      *
  141.      * @return UserStats
  142.      */
  143.     public function setSessionId($sessionId)
  144.     {
  145.         $this->sessionId $sessionId;
  146.         return $this;
  147.     }
  148.     /**
  149.      * Get sessionId
  150.      *
  151.      * @return string
  152.      */
  153.     public function getSessionId()
  154.     {
  155.         return $this->sessionId;
  156.     }
  157.     /**
  158.      * Set sessionStart
  159.      *
  160.      * @param \DateTime $sessionStart
  161.      *
  162.      * @return UserStats
  163.      */
  164.     public function setSessionStart($sessionStart)
  165.     {
  166.         $this->sessionStart $sessionStart;
  167.         return $this;
  168.     }
  169.     /**
  170.      * Get sessionStart
  171.      *
  172.      * @return \DateTime
  173.      */
  174.     public function getSessionStart()
  175.     {
  176.         return $this->sessionStart;
  177.     }
  178.     /**
  179.      * Set lastUpdate
  180.      *
  181.      * @param \DateTime $lastUpdate
  182.      *
  183.      * @return UserStats
  184.      */
  185.     public function setLastUpdate($lastUpdate)
  186.     {
  187.         $this->lastUpdate $lastUpdate;
  188.         return $this;
  189.     }
  190.     /**
  191.      * Get lastUpdate
  192.      *
  193.      * @return \DateTime
  194.      */
  195.     public function getLastUpdate()
  196.     {
  197.         return $this->lastUpdate;
  198.     }
  199.     /**
  200.      * Set visitedPages
  201.      *
  202.      * @param array $visitedPages
  203.      *
  204.      * @return UserStats
  205.      */
  206.     public function setVisitedPages($visitedPages)
  207.     {
  208.         $this->visitedPages $visitedPages;
  209.         return $this;
  210.     }
  211.     /**
  212.      * Get visitedPages
  213.      *
  214.      * @return array
  215.      */
  216.     public function getVisitedPages()
  217.     {
  218.         return $this->visitedPages;
  219.     }
  220.     /**
  221.      * @param string $visitedPage
  222.      * @return $this
  223.      */
  224.     public function addVisitedPage($visitedPage)
  225.     {
  226.         foreach ($this->visitedPages as $page)
  227.         {
  228.             if($visitedPage==$page) return $this;
  229.         }
  230.         $this->visitedPages[]=$visitedPage;
  231.         return $this;
  232.     }
  233.     /**
  234.      * @param $visitedPage
  235.      * @return $this
  236.      */
  237.     public function removeVisitedPage($visitedPage)
  238.     {
  239.         foreach ($this->visitedPages as $key=>$page)
  240.         {
  241.             if($visitedPage==$page) unset($this->visitedPages[$key]);
  242.         }
  243.         return $this;
  244.     }
  245.     
  246.     public function getVisitedPagesAsString()
  247.     {   
  248.         $pages implode(','$this->visitedPages);
  249.         if (strlen($pages) > 30
  250.             $pages substr(implode(','$this->visitedPages), 030)."...";
  251.         
  252.         return $pages;
  253.     }    
  254.     /**
  255.      * @param string $referer
  256.      *
  257.      * @return UserStats
  258.      */
  259.     public function setReferer($referer)
  260.     {
  261.         $this->referer $referer;
  262.         return $this;
  263.     }
  264.     /**
  265.      * Get referer
  266.      *
  267.      * @return string
  268.      */
  269.     public function getReferer()
  270.     {
  271.         return $this->referer;
  272.     }
  273.     /**
  274.      * Set ip
  275.      *
  276.      * @param string $ip
  277.      *
  278.      * @return UserStats
  279.      */
  280.     public function setIp($ip)
  281.     {
  282.         $this->ip $ip;
  283.         return $this;
  284.     }
  285.     /**
  286.      * Get ip
  287.      *
  288.      * @return string
  289.      */
  290.     public function getIp()
  291.     {
  292.         return $this->ip;
  293.     }
  294.     /**
  295.      * Set device
  296.      *
  297.      * @param string $device
  298.      *
  299.      * @return UserStats
  300.      */
  301.     public function setDevice($device)
  302.     {
  303.         $this->device $device;
  304.         return $this;
  305.     }
  306.     /**
  307.      * Get device
  308.      *
  309.      * @return string
  310.      */
  311.     public function getDevice()
  312.     {
  313.         return $this->device;
  314.     }
  315.     /**
  316.      * Set user
  317.      *
  318.      * @param User $user
  319.      *
  320.      * @return UserStats
  321.      */
  322.     public function setUser(User $user null)
  323.     {
  324.         $this->user $user;
  325.         return $this;
  326.     }
  327.     /**
  328.      * Get user
  329.      *
  330.      * @return User
  331.      */
  332.     public function getUser()
  333.     {
  334.         return $this->user;
  335.     }
  336.     /**
  337.      * @param string $uuid
  338.      */
  339.     public function setUuid($uuid)
  340.     {
  341.         $this->uuid $uuid;
  342.     }
  343.     /**
  344.      * @return string
  345.      */
  346.     public function getUuid()
  347.     {
  348.         return $this->uuid;
  349.     }
  350.     /**
  351.      * Add bookingConversion
  352.      *
  353.      * @param Reserva $bookingConversion
  354.      *
  355.      * @return UserStats
  356.      */
  357.     public function addBookingConversion(Reserva $bookingConversion)
  358.     {
  359.         $this->bookingConversions[] = $bookingConversion;
  360.         return $this;
  361.     }
  362.     /**
  363.      * Remove bookingConversion
  364.      *
  365.      * @param Reserva $bookingConversion
  366.      */
  367.     public function removeBookingConversion(Reserva $bookingConversion)
  368.     {
  369.         $this->bookingConversions->removeElement($bookingConversion);
  370.     }
  371.     /**
  372.      * Get bookingConversion
  373.      *
  374.      * @return Collection
  375.      */
  376.     public function getBookingConversions()
  377.     {
  378.         return $this->bookingConversions;
  379.     }
  380.     /**
  381.      * Add orderConversion
  382.      *
  383.      * @param Transaccion $orderConversion
  384.      *
  385.      * @return UserStats
  386.      */
  387.     public function addOrderConversion(Transaccion $orderConversion)
  388.     {
  389.         $this->orderConversions[] = $orderConversion;
  390.         return $this;
  391.     }
  392.     /**
  393.      * Remove orderConversion
  394.      *
  395.      * @param Transaccion $orderConversion
  396.      */
  397.     public function removeOrderConversion(Transaccion $orderConversion)
  398.     {
  399.         $this->orderConversions->removeElement($orderConversion);
  400.     }
  401.     /**
  402.      * Get orderConversion
  403.      *
  404.      * @return Collection
  405.      */
  406.     public function getOrderConversions()
  407.     {
  408.         return $this->orderConversions;
  409.     }
  410.     /**
  411.      * @param string $country
  412.      */
  413.     public function setCountry($country)
  414.     {
  415.         $this->country $country;
  416.     }
  417.     /**
  418.      * @return string
  419.      */
  420.     public function getCountry()
  421.     {
  422.         return $this->country;
  423.     }
  424.     /**
  425.      * @param string $region
  426.      */
  427.     public function setRegion($region)
  428.     {
  429.         $this->region $region;
  430.     }
  431.     /**
  432.      * @return string
  433.      */
  434.     public function getRegion()
  435.     {
  436.         return $this->region;
  437.     }
  438.     /**
  439.      * @param string $city
  440.      */
  441.     public function setCity($city)
  442.     {
  443.         $this->city $city;
  444.     }
  445.     /**
  446.      * @return string
  447.      */
  448.     public function getCity()
  449.     {
  450.         return $this->city;
  451.     }
  452.     /**
  453.      * @param string $zip
  454.      */
  455.     public function setZip($zip)
  456.     {
  457.         $this->zip $zip;
  458.     }
  459.     /**
  460.      * @return string
  461.      */
  462.     public function getZip()
  463.     {
  464.         return $this->zip;
  465.     }
  466.     /**
  467.      * @param array $location
  468.      */
  469.     public function setLocation(array $location)
  470.     {
  471.         if(isset($location['country']))
  472.         {
  473.             $this->country=$location['country'];
  474.         }
  475.         if(isset($location['regionName']))
  476.         {
  477.             $this->region=$location['regionName'];
  478.         }
  479.         if(isset($location['city']))
  480.         {
  481.             $this->city=$location['city'];
  482.         }
  483.         if(isset($location['zip']))
  484.         {
  485.             $this->zip=$location['zip'];
  486.         }
  487.     }
  488.     /**
  489.      * @param string $locale
  490.      */
  491.     public function setLocale($locale)
  492.     {
  493.         $this->locale $locale;
  494.     }
  495.     /**
  496.      * @return string
  497.      */
  498.     public function getLocale()
  499.     {
  500.         return $this->locale;
  501.     }
  502. }