app/Plugin/EccubePaymentLite42/Entity/RegularCycle.php line 18

Open in your IDE?
  1. <?php
  2. namespace Plugin\EccubePaymentLite42\Entity;
  3. use DateTime;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Criteria;
  6. use Doctrine\ORM\Mapping as ORM;
  7. use Eccube\Entity\AbstractEntity;
  8. /**
  9.  * @ORM\Table(name="plg_eccube_payment_lite42_regular_cycle")
  10.  * @ORM\InheritanceType("SINGLE_TABLE")
  11.  * @ORM\DiscriminatorColumn(name="discriminator_type", type="string", length=255)
  12.  * @ORM\HasLifecycleCallbacks()
  13.  * @ORM\Entity(repositoryClass="Plugin\EccubePaymentLite42\Repository\RegularCycleRepository")
  14.  */
  15. class RegularCycle extends AbstractEntity
  16. {
  17.     const SUNDAY 1;
  18.     const MONDAY 2;
  19.     const TUESDAY 3;
  20.     const WEDNESDAY 4;
  21.     const THURSDAY 5;
  22.     const FRIDAY 6;
  23.     const SATURDAY 7;
  24.     const SUNDAY_NAME '日曜日';
  25.     const MONDAY_NAME '月曜日';
  26.     const TUESDAY_NAME '火曜日';
  27.     const WEDNESDAY_NAME '水曜日';
  28.     const THURSDAY_NAME '木曜日';
  29.     const FRIDAY_NAME '金曜日';
  30.     const SATURDAY_NAME '土曜日';
  31.     /**
  32.      * @var int
  33.      *
  34.      * @ORM\Column(name="id", type="integer", options={"unsigned":true})
  35.      * @ORM\Id
  36.      * @ORM\GeneratedValue(strategy="IDENTITY")
  37.      */
  38.     private $id;
  39.     /**
  40.      * @ORM\ManyToOne(targetEntity="Plugin\EccubePaymentLite42\Entity\RegularCycleType")
  41.      * @ORM\JoinColumn(name="regular_cycle_type_id", referencedColumnName="id")
  42.      */
  43.     private $RegularCycleType;
  44.     /**
  45.      * @ORM\OneToMany(
  46.      *     targetEntity="Plugin\EccubePaymentLite42\Entity\ProductClassRegularCycle",
  47.      *     mappedBy="RegularCycle",
  48.      *     cascade={"persist"}
  49.      * )
  50.      */
  51.     private $ProductClassRegularCycle;
  52.     /**
  53.      * @var int
  54.      *
  55.      * @ORM\Column(name="day", type="integer", nullable=true)
  56.      */
  57.     private $day;
  58.     /**
  59.      * @var int
  60.      *
  61.      * @ORM\Column(name="week", type="integer", nullable=true)
  62.      */
  63.     private $week;
  64.     /**
  65.      * @var int|null
  66.      *
  67.      * @ORM\Column(name="sort_no", type="smallint", nullable=true, options={"unsigned":true})
  68.      */
  69.     private $sort_no;
  70.     /**
  71.      * @var DateTime
  72.      *
  73.      * @ORM\Column(name="create_date", type="datetimetz")
  74.      */
  75.     private $create_date;
  76.     /**
  77.      * @var DateTime
  78.      *
  79.      * @ORM\Column(name="update_date", type="datetimetz")
  80.      */
  81.     private $update_date;
  82.     /**
  83.      * @return string
  84.      */
  85.     public function __toString()
  86.     {
  87.         if ($this->getRegularCycleType()->getId() === RegularCycleType::REGULAR_DAILY_CYCLE) {
  88.             return $this->getDay().'日ごと';
  89.         }
  90.         if ($this->getRegularCycleType()->getId() === RegularCycleType::REGULAR_WEEKLY_CYCLE) {
  91.             return $this->getDay().'週ごと';
  92.         }
  93.         if ($this->getRegularCycleType()->getId() === RegularCycleType::REGULAR_MONTHLY_CYCLE) {
  94.             return $this->getDay().'ヶ月ごと';
  95.         }
  96.         if ($this->getRegularCycleType()->getId() === RegularCycleType::REGULAR_SPECIFIC_DAY_CYCLE) {
  97.             return '毎月'.$this->getDay().'日';
  98.         }
  99.         if ($this->getRegularCycleType()->getId() === RegularCycleType::REGULAR_SPECIFIC_WEEK_CYCLE) {
  100.             return '毎週'.$this->getWeekName();
  101.         }
  102.         return $this->getRegularCycleType()->getName();
  103.     }
  104.     public function __construct()
  105.     {
  106.         $this->ProductClassRegularCycle = new ArrayCollection();
  107.     }
  108.     public function getId()
  109.     {
  110.         return $this->id;
  111.     }
  112.     public function getRegularCycleType()
  113.     {
  114.         return $this->RegularCycleType;
  115.     }
  116.     public function setRegularCycleType(RegularCycleType $RegularCycleType)
  117.     {
  118.         $this->RegularCycleType $RegularCycleType;
  119.         return $this;
  120.     }
  121.     public function getDay()
  122.     {
  123.         return $this->day;
  124.     }
  125.     public function setDay($day null)
  126.     {
  127.         $this->day $day;
  128.         return $this;
  129.     }
  130.     public function getWeek()
  131.     {
  132.         return $this->week;
  133.     }
  134.     public function setWeek($week): self
  135.     {
  136.         $this->week $week;
  137.         return $this;
  138.     }
  139.     public function getSortNo()
  140.     {
  141.         return $this->sort_no;
  142.     }
  143.     public function setSortNo(?int $sort_no)
  144.     {
  145.         $this->sort_no $sort_no;
  146.         return $this;
  147.     }
  148.     public function getCreateDate(): DateTime
  149.     {
  150.         return $this->create_date;
  151.     }
  152.     public function setCreateDate(DateTime $create_date)
  153.     {
  154.         $this->create_date $create_date;
  155.         return $this;
  156.     }
  157.     public function getUpdateDate(): DateTime
  158.     {
  159.         return $this->update_date;
  160.     }
  161.     public function setUpdateDate(DateTime $update_date)
  162.     {
  163.         $this->update_date $update_date;
  164.         return $this;
  165.     }
  166.     public function addProductClassRegularCycle(ProductClassRegularCycle $ProductClassRegularCycle)
  167.     {
  168.         $this->ProductClassRegularCycle[] = ($ProductClassRegularCycle);
  169.         return $this;
  170.     }
  171.     public function removeProductClassRegularCycle(ProductClassRegularCycle $ProductClassRegularCycle)
  172.     {
  173.         return $this->ProductClassRegularCycle->removeElement($ProductClassRegularCycle);
  174.     }
  175.     public function hasProductClassRegularCycles()
  176.     {
  177.         $criteria Criteria::create()
  178.             ->orderBy(['id' => Criteria::ASC])
  179.             ->setFirstResult(0)
  180.             ->setMaxResults(1);
  181.         return $this->ProductClassRegularCycle->matching($criteria)->count() > 0;
  182.     }
  183.     public function getWeekName()
  184.     {
  185.         if ($this->week === self::SUNDAY) {
  186.             return self::SUNDAY_NAME;
  187.         } elseif ($this->week === self::MONDAY) {
  188.             return self::MONDAY_NAME;
  189.         } elseif ($this->week === self::TUESDAY) {
  190.             return self::TUESDAY_NAME;
  191.         } elseif ($this->week === self::WEDNESDAY) {
  192.             return self::WEDNESDAY_NAME;
  193.         } elseif ($this->week === self::THURSDAY) {
  194.             return self::THURSDAY_NAME;
  195.         } elseif ($this->week === self::FRIDAY) {
  196.             return self::FRIDAY_NAME;
  197.         } elseif ($this->week === self::SATURDAY) {
  198.             return self::SATURDAY_NAME;
  199.         }
  200.         return $this->week;
  201.     }
  202. }