/** * @return array */ public function serialize() { if ($this->user->getPhone() == null) { throw new NotEnoughDataException('User phone is null'); } return ['phone' => $this->user->getPhone()->getValue(), 'user_promotions' => array_map(function (UserPromotion $userPromotion) { return $userPromotion->serializeForImport(); }, $this->userPromotions)]; }
/** * @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 getNewUsers(Phone $from = null, $count = null) { $response = $this->prepareRequest(Http::GET, $this->getUrl(self::NEW_USERS, ['from' => $from ? $from->getValue() : null, 'count' => $count ?: null]))->send(); $data = $this->getSuccessData($response); $result = []; foreach ($data as $phoneValue) { $user = new User(); $result[] = $user->setPhone(Phone::createFromString($phoneValue)); } return $result; }