/** * @return array */ public function serialize() { $data = ['auth_data' => $this->authData, 'value' => $this->value]; if ($this->promotion === null) { throw new NotEnoughDataException('promotion is null'); } if ($this->promotion->getId() !== null) { $data['promotion_id'] = $this->promotion->getId(); } elseif ($this->promotion->getAlias() !== null) { $data['promotion_alias'] = $this->promotion->getAlias(); } else { throw new NotEnoughDataException('promotion->id is null and promotion->alias is null'); } return $data; }
/** * @param \stdClass $data * * @return UserPromotion */ public static function createFromStdClass(\stdClass $data) { $userPromotion = new self(); $userPromotion->setId($data->id)->setPromotion(Promotion::createFromStdClass($data->promotion))->setRealValue($data->real_value)->setAuthData($data->auth_data); if ($data->expires_at !== null) { $userPromotion->setExpiresAt((new \DateTime(null, new \DateTimeZone('UTC')))->setTimestamp($data->expires_at)); } return $userPromotion; }
/** * @return array */ public function serialize() { $parentData = parent::serialize(); if ($this->promotion === null) { throw new NotEnoughDataException('promotion is null'); } if ($this->promotion->getAlias() === null) { throw new NotEnoughDataException('promotion->alias is null'); } if ($this->user === null) { throw new NotEnoughDataException('user is null'); } if ($this->user->getId() === null) { throw new NotEnoughDataException('user->id is null'); } $parentData['promotion_alias'] = $this->promotion->getAlias(); $parentData['user_id'] = $this->user->getId(); return $parentData; }
/** * {@inheritdoc} */ public function getOrganizationPromotions() { $response = $this->prepareRequest(Http::GET, $this->getUrl(self::PROMOTIONS))->send(); $data = $this->getSuccessData($response); $result = []; foreach ($data as $promotionData) { $result[] = Promotion::createFromStdClass($promotionData); } return $result; }