# booktics/1.0.0/core/extensions/controllers/module-controller.php

Booktics – Appointment Booking Calendar for Service Businesses, version 1.0.0. 246 lines.

- Page: https://pluginprobe.com/plugins/booktics/1.0.0/code/core/extensions/controllers/module-controller.php
- Raw: https://pluginprobe.com/plugins/booktics/1.0.0/raw/core/extensions/controllers/module-controller.php
- Modified: 2025-07-03T16:48:18+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/booktics/1.0.0/code/core/extensions/controllers/module-controller.php#L10-L20`.

```php
<?php

namespace Booktics\Extensions\Controllers;

use Booktics\Abstracts\Base_Rest_Controller;
use Arraytics\ToolsSdk\Extension as ExtensionManager;
use WP_REST_Request;
use Booktics\Extensions\Extension_Icon;

/**
 * Module Controller
 *
 * @package Booktics/Module
 */
class Module_Controller extends Base_Rest_Controller {
    /**
     * The namespace of this controller's route.
     *
     * @since 1.0.0
     * @var string
     */
    protected $namespace = 'booktics/v1';

    /**
     * The base of this controller's route.
     *
     * @since 1.0.0
     * @var string
     */
    protected $rest_base = 'module';

    /**
     * Extension manager instance
     *
     * @var ExtensionManager
     */
    protected $extensions;

    /**
     * Initialize the class and set its properties.
     */
    public function __construct() {
        $available_modules = [
            'stripe-addon' => [
                'name'          => 'stripe-addon',
                'slug'          => 'stripe-addon',
                'type'          => 'module',
                'upgrade'       => true,
                'upgrade_link'  => 'https://themewinter.com/purchase-history',
                'status'        => 'off',
                'is_pro'        => false,
                'title'         => __( 'Stripe Addon', 'booktics' ),
                'description'   => __( 'It allows you to use stripe payment.', 'booktics' ),
                'icon'          => Extension_Icon::get( 'booktics-stripe-addon' ),
                'notice'        => '',
                'demo_link'     => 'https://support.themewinter.com/docs/plugins/plugin-docs/integration/booktics-stripe-addon',
                'settings_link' => '',
                'doc_link'      => 'https://support.themewinter.com/docs/plugins/plugin-docs/integration/booktics-stripe-addon',
                'download_link' => 'https://products.arraytics.com/booktics-addons/booktics-stripe-addon-1.0.0.zip',
            ],
            'google-calendar' => [
                'name'          => 'google-calendar',
                'slug'          => 'google-calendar',
                'type'          => 'module',
                'upgrade'       => true,
                'upgrade_link'  => 'https://themewinter.com/purchase-history',
                'status'        => 'off',
                'is_pro'        => false,
                'title'         => __( 'Google Calendar', 'booktics' ),
                'description'   => __( 'It allows you to use google calendar.', 'booktics' ),
                'icon'          => Extension_Icon::get( 'booktics-google-calendar' ),
                'notice'        => '',
                'demo_link'     => 'https://support.themewinter.com/docs/plugins/plugin-docs/integration/booktics-google-calendar',
                'settings_link' => '',
                'doc_link'      => 'https://support.themewinter.com/docs/plugins/plugin-docs/integration/booktics-google-calendar',
                'download_link' => 'https://products.arraytics.com/booktics-addons/booktics-google-calendar-1.0.0.zip',
            ],
        ];
        $available_modules = apply_filters('booktics_available_modules', $available_modules);

        $this->extensions = new ExtensionManager('booktics_extension_settings', $available_modules);
    }

    /**
     * Register the routes for the objects of the controller.
     *
     * @since 1.0.0
     *
     * @return void
     */
    public function register_routes(): void {
        register_rest_route($this->namespace, '/' . $this->rest_base, [
            [
                'methods'             => \WP_REST_Server::READABLE,
                'callback'            => [$this, 'get_items'],
                'permission_callback' => [$this, 'get_items_permissions_check'],
                'args'                => [
                    'type' => [
                        'description' => __('Type of extensions to retrieve (module, addon, plugin, all).', 'booktics'),
                        'type'        => 'string',
                        'enum'        => ['module', 'addon', 'plugin', 'all'],
                        'default'     => 'all',
                    ],
                ],
            ],
            [
                'methods'             => \WP_REST_Server::EDITABLE,
                'callback'            => [$this, 'update_item'],
                'permission_callback' => [$this, 'update_item_permissions_check'],
            ],
        ]);
    }

    /**
     * Check if a given request has permission to get items.
     *
     * @since 1.0.0
     *
     * @param WP_REST_Request $request Full data about the request.
     * @return bool True if the request has read access, false otherwise.
     */
    public function get_items_permissions_check($request) {
        return current_user_can('manage_options');
    }

    /**
     * Check if a given request has permission to update items.
     *
     * @since 1.0.0
     *
     * @param WP_REST_Request $request Full data about the request.
     * @return bool True if the request has update access, false otherwise.
     */
    public function update_item_permissions_check($request) {
        return current_user_can('manage_options');
    }

    /**
     * Get all extensions
     *
     * @since 1.0.0
     *
     * @param WP_REST_Request $request Full data about the request.
     * @return WP_HTTP_Response Response object on success, or WP_Error object on failure.
     */
    public function get_items($request) {
        $type = !empty($request['type']) ? $request['type'] : 'all';
        
        $types = [
            'module' => $this->extensions->get_modules(),
            'addon'  => $this->extensions->get_addons(),
            'plugin' => $this->extensions->get_plugins(),
            'all'    => $this->extensions->get()
        ];

        if (!isset($types[$type])) {
            return $this->error(
                __('Invalid extension type', 'booktics'),
                400,
                'invalid_extension_type'
            );
        }

        foreach ($types[$type] as $data) {
            $modules_list[] = $data;
        }

        return $this->response($modules_list);
    }

    /**
     * Update extension status
     *
     * @since 1.0.0
     *
     * @param WP_REST_Request $request Full data about the request.
     * @return WP_HTTP_Response Response object on success, or WP_Error object on failure.
     */
    public function update_item($request) {
        $params = json_decode($request->get_body(), true);
        
        $name   = isset($params['name']) ? sanitize_text_field($params['name']) : '';
        $status = isset($params['status']) ? sanitize_text_field($params['status']) : '';
        
        $valid_statuses = ['off', 'on', 'install', 'activate', 'deactivate'];

        if (empty($name)) {
            return $this->error(
                __('Please enter extension name', 'booktics'),
                422,
                'extension_name_error'
            );
        }

        if (empty($status)) {
            return $this->error(
                /* translators: %s: extension name */
                sprintf(__('Please provide status for extension %s', 'booktics'), $name),
                422,
                'extension_status_error'
            );
        }

        if (!in_array($status, $valid_statuses, true)) {
            return $this->error(
                /* translators: %s: extension status */
                sprintf(__('Invalid status %s provided', 'booktics'), $status),
                422,
                'invalid_status'
            );
        }

        $extension = $this->extensions->find($name);
        
        if (!$extension) {
            return $this->error(
                /* translators: %s: extension name */
                sprintf(__('Extension %s not found', 'booktics'), $name),
                404,
                'extension_not_found'
            );
        }

        $result = $this->extensions->update($name, $status);

        if (false === $result) {
            return $this->error(
                /* translators: %s: extension name */
                sprintf(__('Could not %s the extension', 'booktics'), $status),
                500,
                'operation_failed'
            );
        }

        return $this->response([
            'name'   => $name,
            'status' => $status,
        ],
        /* translators: %s: extension name */ 
        sprintf(__('Extension %s successfully', 'booktics'), $status)
        );
    }
}



```
