sasilen/sensors

Sensors plugin for CakePHP 4

dev-master 2020-11-29 13:57 UTC

This package is auto-updated.

Last update: 2024-03-29 03:31:56 UTC


README

Installation

You can install this plugin into your CakePHP application using composer.

The recommended way to install composer packages is:

composer config repositories.sensors git https://github.com/sasilen/cakephp-plugin-sensors.git
composer require sasilen/sensors

Configuration

Load required modules with routes

./bin/cake plugin load Sasilen/Sensors

Migrate database schema

./bin/cake migrations migrate -p Sensors

Add templates (main app)

# /src/View/AppView.php
public function initialize(): void
{
    parent::initialize();
    $this->loadHelper('CakeDC/Users.AuthLink');
    $this->loadHelper('Paginator', ['templates' => 'templates-paginator']);
    $this->loadHelper('Form', ['templates' => 'templates-form']);
}

Triggers

If you want to update sensor_id automatically from the sensors list when sensor_value is inserted you can create these two trigger

CREATE TRIGGER sensor_values_sensor_id_updater
BEFORE UPDATE ON sensor_values
    FOR EACH ROW
          SET new.sensor_id = (select id from sensors where name=new.name);

CREATE TRIGGER sensor_values_sensor_id_inserter
BEFORE INSERT ON sensor_values
    FOR EACH ROW
          SET new.sensor_id = (select id from sensors where name=new.name);

FIX missing:
UPDATE sensor_values SET sensor_values.sensor_id = (SELECT sensors.id FROM sensors WHERE sensors.name = sensor_values.name ) WHERE sensor_values.sensor_id = '';