Produkt

Struktur

Eigene Module werden im Ordner Products des übergeordneten Ordners Components eines Moduls angelegt. Alle Dateien, die für die Funktionsfähigkeit der Produkte zwingend erforderlich sind, sind unten-stehend rot hervorgehoben.

  • Components
    • Hosting
      • methoden_name
        • Module.php

Service

Service erstellen

Die Methode add(int $contract_id, array $order) erstellt einen Service. Die Parameter der Methode sind beistehend beschrieben.

string $contract_id Enthält den eindeutigen Identifier vom betroffenen Vertrag.
array $order Enthält alle Daten zu der Bestellung (Benutzerdaten und Produktkonfiguration).

Service sperren

Die Methode lock(int $contract_id) sperrt einen Service. Die Parameter der Methode sind beistehend beschrieben.

string $contract_id Enthält den eindeutigen Identifier vom betroffenen Vertrag.

Service entsperren

Die Methode unlock(int $contract_id) entsperrt einen Service. Die Parameter der Methode sind beistehend beschrieben.

string $contract_id Enthält den eindeutigen Identifier vom betroffenen Vertrag.

Service löschen

Die Methode delete(int $contract_id) löscht einen Service. Die Parameter der Methode sind beistehend beschrieben.

string $contract_id Enthält den eindeutigen Identifier vom betroffenen Vertrag.

Rückgaben

Rückgaben definieren den Status des etwaigen Vorgangs. Die unten stehenden Stati sind derzeit vom Product Framework interpretierbar.

Erfolgreicher Vorgang

Der Vorgang wurde erfolgreich abgeschlossen. Es erfolgt eine weiterführende Verarbeitung durch das Product Framework.

return [
    "status" => "success",
];

Technischer Fehler

Es ist ein technischer Fehler bei der Aktion aufgetreten. Erhält das Product Framework diesen Status, werden jegliche weiterführende Verarbeitungs-Logiken abgebrochen. Die Bestellung wird nicht weiter verarbeitet.

return [
    "status" => "false",
];

Module.php

Herunterladen: Module.php

<?php

namespace Modules\Products\Components\Products\Sample;

use Core\Model;
use Modules\Hosting\Helpers\Balancer;

class Module extends Model
{
    /**
     * Database table for the module.
     */
    const DATABASE_TABLE = PREFIX . 'servers_sample';
    
    /**
     * Module constructor.
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Get the real name for the hosting module. This may contain formatted,
     * human readable text.
     *
     * @return string
     */
    public function getName()
    {
        return "Sample";
    }

    /**
     * Technical name for the hosting module. This may only contain lower-case
     * letters, dashes, underscores and numbers to ensure that the string is
     * fully readable by PHP.
     *
     * @return string
     */
    public function getTechnicalName()
    {
        return "sample";
    }

    /**
     * This function is used for identifying all services that belong to a 
     * specified contract id. This can basically be done any way you like. In 
     * this example the preferred method is selection from a database table.
     * To keep every module working similar it's advised to return an array 
     * or at least a countable here which can be looped through.
     * 
     * @param $contract_id
     * 
     * @return array
     */
    public function get($contract_id) 
    {
        return $this->db->select('SELECT * FROM ' . static::DATABASE_TABLE . ' WHERE contract_id = :contract_id', [
            ':contract_id' => $contract_id,
        ]);
    }

    /**
     * This function is called when a new service is added. This is 
     * usually done by processing the order job. Before this function is 
     * called a contract object is added and the accounting is done for the 
     * product. Thus you can create the product here. The entire order data 
     * as well as the generated unique contract id, which acts as an identifier,
     * is available here.
     * 
     * @param $contract_id
     * @param $order
     * 
     * @return array
     */
    public function add($contract_id, $order) 
    {
        $rootserver = Balancer::getRoot($order->data->type);
        
        if (! empty($rootserver)) {
            //TODO: Add the service.
            
            return [
                "status" => "success",
            ];
        } else {
            return [
                "status" => "false",
            ];
        }
    }

    /**
     * This function is called when a new service is expired. Products 
     * are usually locked before they are deleted so the products can be 
     * reactivated without data loss. If you don't want the grace-period 
     * to apply to the product, just call $this->delete($order) here. 
     * The grace period applies if an invoice becomes overdue and the product 
     * should not be able to be used anymore. However the invoice may still 
     * be payed and the service has to be resumed.
     *
     * @param $contract_id
     *
     * @return array
     */
    public function lock($contract_id)
    {
        $services = $this->get($contract_id);

        if (! empty($services)) {
            foreach ($services as $service) {
                //TODO: Lock the services. This function is reserved for future use.

                return [
                    "status" => "success",
                ];
            }
        }

        return [
            "status" => "false",
        ];
    }

    /**
     * This function is called when an expired service is reactivated. A
     * reactivation happens if a product has been locked due to an overdue invoice
     * but the invoice is payed within the grace period. Unlocking a product 
     * makes it available without any dataloss again. If you don't want the 
     * grace-period to apply to the product, just call $this->add($order) here.
     * 
     * @param $contract_id
     * 
     * @return array
     */
    public function unlock($contract_id)
    {
        $services = $this->get($contract_id);

        if (! empty($services)) {
            foreach ($services as $service) {
                //TODO: Unlock the services. This function is reserved for future use.

                return [
                    "status" => "success",
                ];
            }
        }

        return [
            "status" => "false",
        ];
    }

    /**
     * This function is called when an expired service cannot be reactivated anymore 
     * due to an expired grace period. Either an overdue invoice has not been paid in 
     * time of the grace-period or the product was a prepaid product and has not been 
     * reactivated.
     * 
     * @param $contract_id
     * 
     * @return array
     */
    public function delete($contract_id)
    {
        $services = $this->get($contract_id);
        
        if (! empty($services)) {
            foreach ($services as $service) {
                //TODO: Delete the services.

                return [
                    "status" => "success",
                ];
            }
        }
        
        return [
            "status" => "false",
        ];
    }

    /**
     * This function provides templates for adding new forms. It can provide
     * provide multiple form templates as well.
     * 
     * @return object[]
     */
    public function forms()
    {
        return [
            (object) [
                'form_name' => 'Test Form',
                'form_desc' => 'My awesome test form',
                'product_type' => 'sample',
                'needs_approval' => true,
                'fields' => [
                    (object) [
                        'type' => 'text',
                        'configuration' => (object) [
                            'label' => 'Textfield Test',
                            'placeholder' => 'Test Input',
                            'name' => 'textfield_test',
                            'value' => 'Test 123',
                            'minlength' => 5,
                            'maxlength' => 20,
                            'price' => 23.99,
                            'required' => false,
                        ],
                    ],
                    (object) [
                        'type' => 'number',
                        'configuration' => (object) [
                            'label' => 'Numberfield Test',
                            'name' => 'numberfield_test',
                            'value' => 33,
                            'step' => 0.5,
                            'min' => 10,
                            'max' => 50,
                            'price' => 9.99,
                            'required' => true,
                        ],
                    ],
                    (object) [
                        'type' => 'range',
                        'configuration' => (object) [
                            'label' => 'Rangefield Test',
                            'name' => 'rangefield_test',
                            'value' => 22,
                            'step' => 0.5,
                            'min' => 5,
                            'max' => 45,
                            'price' => 12.99,
                            'required' => true,
                        ],
                    ],
                    (object) [
                        'type' => 'radio',
                        'configuration' => (object) [
                            'label' => 'Radiofield Test',
                            'name' => 'Radiofield_test',
                            'required' => true,
                        ],
                        'options' => [
                            (object) [
                                'label' => 'Radio Option 1',
                                'value' => 'ro1_sel',
                                'price' => 7.99
                            ],
                            (object) [
                                'label' => 'Radio Option 2',
                                'value' => 'ro2_sel',
                                'price' => 3.99
                            ],
                        ],
                    ],
                    (object) [
                        'type' => 'select',
                        'configuration' => (object) [
                            'label' => 'Selectfield Test',
                            'name' => 'selectfield_test',
                            'required' => false,
                        ],
                        'options' => [
                            (object) [
                                'label' => 'Select Option 1',
                                'value' => 'ro1_sel',
                                'price' => 2.99
                            ],
                            (object) [
                                'label' => 'Select Option 2',
                                'value' => 'ro2_sel',
                                'price' => 8.99
                            ],
                        ],
                    ],
                    (object) [
                        'type' => 'hidden',
                        'configuration' => (object) [
                            'name' => 'hiddenfield_test',
                            'value' => 'Test Hidden 123',
                            'price' => 22.99,
                        ],
                    ],
                ],
            ],
        ];
    }
}