%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /var/www/html/bbw/farmaci/kritik-portale/module/ReviewBase/src/ReviewBase/Model/
Upload File :
Create Path :
Current File : /var/www/html/bbw/farmaci/kritik-portale/module/ReviewBase/src/ReviewBase/Model/Contract.php

<?php
namespace ReviewBase\Model;

use Basis\Model\EventBasis;
use DateTime;
use DateTimeZone;
use Locale;
use ReviewBase\Event\Contract\ContractChangedBillingAddress;
use ReviewBase\Event\Contract\ContractChangedBillingNumber;
use ReviewBase\Event\Contract\ContractChangedContractDeleted;
use ReviewBase\Event\Contract\ContractChangedContractNumber;
use ReviewBase\Event\Contract\ContractChangedCustomerNumber;
use ReviewBase\Event\Contract\ContractChangedExternalCustomerHash;
use ReviewBase\Event\Contract\ContractChangedExternalStatus;
use ReviewBase\Event\Contract\ContractChangedExternalSubscriptionHash;
use ReviewBase\Event\Contract\ContractChangedModified;
use ReviewBase\Event\Contract\ContractChangedObjectID;
use ReviewBase\Event\Contract\ContractChangedPlanAutoExtension;
use ReviewBase\Event\Contract\ContractChangedPlanEarlyEnd;
use ReviewBase\Event\Contract\ContractChangedPlanEnd;
use ReviewBase\Event\Contract\ContractChangedPlanName;
use ReviewBase\Event\Contract\ContractChangedPlanPrice;
use ReviewBase\Event\Contract\ContractChangedPlanStart;
use ReviewBase\Event\Contract\ContractChangedPlanVersion;
use ReviewBase\Event\Contract\ContractChangedStatus;
use ReviewBase\Event\Contract\ContractChangedUserID;
use ReviewBase\Event\Contract\ContractCreatedAt;
use ReviewBase\Event\Contract\ContractDeleted;
use Zend\Db\Adapter\Adapter;
use Zend\Json\Json;

/**
 * Description of Contract
 *
 * @author Florian Koller ( conlabz GmbH ) <florian.koller at conlabz.de>
 */
class Contract extends EventBasis
{
    protected $entityid;
    protected $userid;
    protected $objectid;
    protected $plan_name;
    protected $plan_version;
    protected $plan_start;
    protected $plan_end;
    protected $external_customer_hash;
    protected $external_subscription_hash;
    protected $status;
    protected $external_status;
    protected $plan_early_end;
    protected $plan_price;
    protected $created_at;
    protected $modified;
    protected $plan_auto_extension;
    protected $billing_address;
    protected $customer_number;
    protected $contract_number;
    protected $billing_number;
    protected $contract_deleted;
    
    protected $defaultDateFormat;
    protected $defaultDateTimeFormat;
    protected $defaultDateTimeStorageFormat;
    protected $utcTimezone;
    protected $applicationTimezone;
    
    public function __construct()
    {
        $this->defaultDateFormat = "d.m.Y";
        $this->defaultDateTimeFormat = "d.m.Y H:i:s";
        $this->defaultDateTimeStorageFormat = "Y-m-d H:i:s";
        $this->utcTimezone = new DateTimeZone('UTC');
        $applicationLocale = Locale::getDefault();
        $applicationTimezone = date_default_timezone_get();
        $this->applicationTimezone = new DateTimeZone($applicationTimezone);
    }
    
    public function setId($id)
    {
        $this->entityid = $id;
    }
    
    public function getId()
    {
        return $this->entityid;
    }

    public function generateId()
    {
        $this->entityid = uniqid();
        $now = new DateTime();
        $now = $now->format($this->defaultDateTimeStorageFormat);
        
        $this->setCreatedAt($now);
    }
    
    /**
     * @param string $createdAt
     */
    public function setCreatedAt($createdAt)
    {
        if ($this->created_at !== $createdAt) {
            $this->created_at = $createdAt;
            $createdAt = $this->convertDateTime($createdAt, $this->applicationTimezone, $this->utcTimezone, $this->defaultDateTimeStorageFormat);
            $event = new ContractCreatedAt();
            $event->setParams(array(
                "created_at" => $createdAt
            ));
            $this->addEvent($event);
        }
    }

    /**
     * @return string
     */
    public function getCreatedAt()
    {
        return $this->convertDateTime($this->created_at, $this->utcTimezone, $this->applicationTimezone, $this->defaultDateTimeFormat);
    }
    
    public function setObjectID($objectid)
    {
        if ($this->objectid !== $objectid) {
            $this->objectid = $objectid;
            $event = new ContractChangedObjectID();
            $event->setParams(array(
                "objectid" => $objectid
            ));
            $this->addEvent($event);
        }
    }

    public function getObjectID()
    {
        return $this->objectid;
    }
    
    public function setUserID($userid)
    {
        if ($this->userid !== $userid) {
            $this->userid = $userid;
            $event = new ContractChangedUserID();
            $event->setParams(array(
                "userid" => $userid
            ));
            $this->addEvent($event);
        }
    }

    public function getUserID()
    {
        return $this->userid;
    }
    
    public function setPlanName($plan_name)
    {
        if ($this->plan_name !== $plan_name) {
            $this->plan_name = $plan_name;
            $event = new ContractChangedPlanName();
            $event->setParams(array(
                "plan_name" => $plan_name
            ));
            $this->addEvent($event);
        }
    }

    public function getPlanName()
    {
        return $this->plan_name;
    }
    
    public function setPlanVersion($plan_version)
    {
        if ($this->plan_version !== $plan_version) {
            $this->plan_version = $plan_version;
            $event = new ContractChangedPlanVersion();
            $event->setParams(array(
                "plan_version" => $plan_version
            ));
            $this->addEvent($event);
        }
    }

    public function getPlanVersion()
    {
        return $this->plan_version;
    }
    
    public function setPlanStart($plan_start)
    {
        $plan_start = $this->convertDateTime($plan_start, $this->applicationTimezone, $this->utcTimezone, $this->defaultDateTimeStorageFormat);
        if ($this->plan_start !== $plan_start) {
            $this->plan_start = $plan_start;
            //convert into utc and storage format
            //$plan_start = $this->convertDateTime($plan_start, $this->applicationTimezone, $this->utcTimezone, $this->defaultDateTimeStorageFormat);
            $event = new ContractChangedPlanStart();
            $event->setParams(array(
                "plan_start" => $plan_start
            ));
            $this->addEvent($event);
        }
    }

    public function getPlanStart()
    {
        
        return $this->convertDateTime($this->plan_start, $this->utcTimezone, $this->applicationTimezone, $this->defaultDateFormat);
    }
    
    public function setPlanEnd($plan_end)
    {
        //convert into utc and storage format
        $plan_end = $this->convertDateTime($plan_end, $this->applicationTimezone, $this->utcTimezone, $this->defaultDateTimeStorageFormat);
        if ($this->plan_end !== $plan_end) {
            $this->plan_end = $plan_end;
            $event = new ContractChangedPlanEnd();
            $event->setParams(array(
                "plan_end" => $plan_end
            ));
            $this->addEvent($event);
        }
    }

    public function getPlanEnd()
    {
        return $this->convertDateTime($this->plan_end, $this->utcTimezone, $this->applicationTimezone, $this->defaultDateFormat);
    }
    
    public function setExternalCustomerHash($customerHash)
    {
        if ($this->external_customer_hash !== $customerHash) {
            $this->external_customer_hash = $customerHash;
            $event = new ContractChangedExternalCustomerHash();
            $event->setParams(array(
                "external_customer_hash" => $customerHash
            ));
            $this->addEvent($event);
        }
    }
    
    public function getExternalCustomerHash()
    {
        return $this->external_customer_hash;
    }
    
    public function setExternalSubscriptionHash($subscriptionHash)
    {
        if ($this->external_subscription_hash !== $subscriptionHash) {
            $this->external_subscription_hash = $subscriptionHash;
            $event = new ContractChangedExternalSubscriptionHash();
            $event->setParams(array(
                "external_subscription_hash" => $subscriptionHash
            ));
            $this->addEvent($event);
        }
    }
    
    public function getExternalSubscriptionHash()
    {
        return $this->external_subscription_hash;
    }
    
    public function setStatus($status)
    {
        if ($this->status !== $status) {
            $this->status = $status;
            $event = new ContractChangedStatus();
            $event->setParams(array(
                "status" => $status
            ));
            $this->addEvent($event);
        }
    }
    
    public function getStatus()
    {
        return $this->status;
    }
    
    public function setExternalStatus($external_status)
    {
        if ($this->external_status !== $external_status) {
            $this->external_status = $external_status;
            $event = new ContractChangedExternalStatus();
            $event->setParams(array(
                "external_status" => $external_status
            ));
            $this->addEvent($event);
        }
    }

    public function getExternalStatus()
    {
        return $this->external_status;
    }
    
    public function setPlanEarlyEnd($plan_early_end)
    {
        $plan_early_end = $this->convertDateTime($plan_early_end, $this->applicationTimezone, $this->utcTimezone, $this->defaultDateTimeStorageFormat);
        if ($this->plan_early_end !== $plan_early_end) {
            $this->plan_early_end = $plan_early_end;
            $event = new ContractChangedPlanEarlyEnd();
            $event->setParams(array(
                "plan_early_end" => $plan_early_end
            ));
            $this->addEvent($event);
        }
    }

    public function getPlanEarlyEnd()
    {
        return $this->convertDateTime($this->plan_early_end, $this->utcTimezone, $this->applicationTimezone, $this->defaultDateFormat);
    }
    
    public function setPlanPrice($plan_price)
    {
        $numbersEqual = bccomp($this->plan_price, $plan_price, 4);
        if ($numbersEqual !== 0) {
            $this->plan_price = $plan_price;
            $event = new ContractChangedPlanPrice();
            $event->setParams(array(
                "plan_price" => $plan_price
            ));
            $this->addEvent($event);
        }
    }

    public function getPlanPrice()
    {
        return $this->plan_price;
    }
    
    public function setModified($modified)
    {
        //convert into utc and storage format
        $modified = $this->convertDateTime($modified, $this->applicationTimezone, $this->utcTimezone, $this->defaultDateTimeStorageFormat);
        if ($this->modified !== $modified) {
            $this->modified = $modified;
            $event = new ContractChangedModified();
            $event->setParams(array(
                "modified" => $modified
            ));
            $this->addEvent($event);
        }
    }

    public function getModified()
    {
        return $this->convertDateTime($this->modified, $this->utcTimezone, $this->applicationTimezone, $this->defaultDateTimeFormat);
    }
    
    public function setPlanAutoExtension($plan_auto_extension)
    {
        if ($this->plan_auto_extension !== $plan_auto_extension) {
            $this->plan_auto_extension = $plan_auto_extension;
            $event = new ContractChangedPlanAutoExtension();
            $event->setParams(array(
                "plan_auto_extension" => $plan_auto_extension
            ));
            $this->addEvent($event);
        }
    }

    public function getPlanAutoExtension()
    {
        return $this->plan_auto_extension;
    }
    
    public function setBillingAddress($billing_address)
    {
        if ($this->billing_address !== $billing_address) {
            $this->billing_address = $billing_address;
            $event = new ContractChangedBillingAddress();
            $event->setParams(array(
                "billing_address" => $billing_address
            ));
            $this->addEvent($event);
        }
    }

    public function getBillingAddress()
    {
        return $this->billing_address;
    }
    
    public function setCustomerNumber($customer_number)
    {
        if ($this->customer_number !== $customer_number) {
            $this->customer_number = $customer_number;
            $event = new ContractChangedCustomerNumber();
            $event->setParams(array(
                "customer_number" => $customer_number
            ));
            $this->addEvent($event);
        }
    }

    public function getCustomerNumber()
    {
        return $this->customer_number;
    }
    
    public function setContractNumber($contract_number)
    {
        if ($this->contract_number !== $contract_number) {
            $this->contract_number = $contract_number;
            $event = new ContractChangedContractNumber();
            $event->setParams(array(
                "contract_number" => $contract_number
            ));
            $this->addEvent($event);
        }
    }

    public function getContractNumber()
    {
        return $this->contract_number;
    }
    
    public function setBillingNumber($billing_number)
    {
        if ($this->billing_number !== $billing_number) {
            $this->billing_number = $billing_number;
            $event = new ContractChangedBillingNumber();
            $event->setParams(array(
                "billing_number" => $billing_number
            ));
            $this->addEvent($event);
        }
    }

    public function getBillingNumber()
    {
        return $this->billing_number;
    }
    
    public function setContractDeleted($contract_deleted)
    {
        if ($this->contract_deleted !== $contract_deleted) {
            $this->contract_deleted = $contract_deleted;
            $event = new ContractChangedContractDeleted();
            $event->setParams(array(
                "contract_deleted" => $contract_deleted
            ));
            $this->addEvent($event);
        }
    }

    public function getContractDeleted()
    {
        return $this->contract_deleted;
    }
    
    public function delete()
    {
        $event = new ContractDeleted();
        $event->setParams(array(
            "entityid" => $this->getId()
        ));
        $this->addEvent($event);
    }

    /**
     * @param $property
     * @param $value
     */
    protected function set($property, $value)
    {
        $this->$property = $value;
    }
    
    /**
     * @param array $events
     * @param \Basis\EventBus\EventBus $eventBus
     * @param Adapter $databaseAdapter
     */
    public function setFromEvents($events, \Basis\EventBus\EventBus $eventBus, Adapter $databaseAdapter)
    {
        foreach ($events as $event) {
            /* @var $event \Basis\Event\Event */
            $data = Json::decode($event->__get("domaindata"));
            switch ($event->__get("eventtype")) {
                default:
                    foreach ($data as $key => $value) {
                        $this->set($key, $value);
                    }
                    break;
            }
        }
    }
    
    /**
     * Converts a supplied datetime string from one timezone to another
     * @param string $datetime the datetime string to be converted
     * @param type $fromTimezone the timezone the supplied datetime string is in
     * @param type $toTimezone the timezone into which the supplied datetime string is converted
     * @param string Format pattern for the returned datetime string
     * @return convertedDateTime
     */
    protected function convertDateTime($datetime, $fromTimezone, $toTimezone, $format = 'Y-m-d H:i:s')
    {
        $convertedDateTime = null;
        if ($datetime === "")
        {
            //catch the empty strings
            $datetime = null;
        }
        if (!is_null($datetime))
        {
            $dt = new DateTime($datetime, $fromTimezone);
            $dt->setTimezone($toTimezone);
            $convertedDateTime = $dt->format($format);
        }
        return $convertedDateTime;
    }
    
    public function hydrate(array $data)
    {
        if (!$this->getId()) {
            $this->generateId();
        }
//        isset($data["objectid"]) ? ($this->setObjectID($data["objectid"])) : '';
//        isset($data["plan_name"]) ? ($this->setPlanName($data["objectid"])) : '';
//        isset($data["plan_version"]) ? ($this->setPlanVersion($data["objectid"])) : '';
//        isset($data["plan_start"]) ? $this->setPlanStart($data["plan_start"]) : '';
//        isset($data["plan_price"]) ? $this->setPlanPrice($data["plan_price"]) : '';
//        isset($data["userid"]) ? $this->setUserID($data["userid"]) : '';
//        isset($data["plan_end"]) ? $this->setPlanEnd($data["plan_end"]) : '';
//        isset($data["plan_early_end"]) ? $this->setPlanEarlyEnd($data["plan_early_end"]) : '';
//        isset($data["created_at"]) ? $this->setCreatedAt($data["created_at"]) : '';
//        isset($data["modified"]) ? $this->setModified($data["modified"]) : '';
//        isset($data["plan_auto_extension"]) ? $this->setPlanAutoExtension($data["plan_auto_extension"]) : '';
//        isset($data["billing_address"]) ? $this->setBillingAddress($data["billing_address"]) : '';
//        isset($data["customer_number"]) ? $this->setCustomerNumber($data["customer_number"]) : '';
//        isset($data["contract_number"]) ? $this->setContractNumber($data["contract_number"]) : '';
//        isset($data["billing_number"]) ? $this->setBillingNumber($data["billing_number"]) : '';
//        isset($data["contract_deleted"]) ? $this->setContractDeleted($data["contract_deleted"]) : '';
        $this->setObjectID($data["objectid"]);
        $this->setPlanName($data["plan_name"]);
        $this->setPlanVersion($data["plan_version"]);
        $this->setPlanStart($data["plan_start"]);
        $this->setPlanPrice($data["plan_price"]);
        $this->setUserID($data["userid"]);
        $this->setPlanEnd($data["plan_end"]);
        $this->setPlanEarlyEnd($data["plan_early_end"]);
        //$this->setCreatedAt($data["created_at"]);
        $this->setModified($data["modified"]);
        $this->setPlanAutoExtension($data["plan_auto_extension"]);
        $this->setBillingAddress($data["billing_address"]);
        $this->setCustomerNumber($data["customer_number"]);
        $this->setContractNumber($data["contract_number"]);
        $this->setBillingNumber($data["billing_number"]);
        $this->setContractDeleted($data["contract_deleted"]);
    }

}

Zerion Mini Shell 1.0