settings['service_key'])) { $this->settings['service_key'] = $this->manager->generateServicePackKey(); } return $this->settings['service_key']; } public function getType(): int { return static::TYPE_SERVICEPACK; } /** * Get services keys in pack * @return array */ public function getPackServicesSettings(): array { $services = $this->settings['settings']['services'] ?? []; if (! empty($services) && is_array($services)) { return $services; } return []; } /** * Activate service pack * @param int|null $expires * @param array $opts * @return bool */ public function activate(?int $expires = null, array $opts = []): bool { if (! $this->manager->hasPacks()) { return false; } $success = $this->onActivateBefore(); if (! $success) { return false; } $services = $this->manager->getPackableServices(); if (empty($services)) { return false; } $settings = $this->getPackServicesSettings(); if (empty($settings)) { return false; } $activated = 0; foreach ($services as $key => $service) { if (! $service || ! $service->isEnabled() || empty($settings[$key])) { continue; } $service->setActivationPack($this); $service->setActivationSettings( $this->itemID, $this->userID, $settings ); if ($service->activate(null, $opts)) { $activated++; } } if ($activated > 0) { $this->onActivateAfter(); $this->manager->createBill($this); } return true; } /** * Service bill description * @return string */ public function getBillDescription(): string { $item = $this->manager->getItemData($this->itemID, ['link', 'title']); if (! $item) { return ''; } return $this->plugin()->lang('Service package "[pack]"
[title]', [ 'pack' => $this->getTitle(), 'link' => $item['link'], 'title' => $item['title'], ]); } /** * Admin settings form * @param Form $form * @return mixed|void */ public function onAdminSettings($form) { parent::onAdminSettings($form); $this->addFieldServices($form); $this->addAdminSettingsFormPrices($form); } /** * Admin settings form add Field services * @param Form $form * @return void */ protected function addFieldServices($form) { $services = $this->manager->getPackableServices(); if (empty($services)) { return; } $form ->union('services') ->param('box', false); $first = true; foreach ($services as $k => $v) { $form ->checkbox($k, ($first ? $this->plugin()->lang('Services Included in the Package') : ''), false) ->label($v->getTitle()) ->width(200) ; if (method_exists($v, 'onAdminSettingsPackServices')) { $v->onAdminSettingsPackServices($form); } $first = false; } $form->endUnion()->after('price'); } }