<?php
/*
This class is responsible for controlling input data for create and update operations. 
*/
class datacontroller
{
    // check whether the current user has the permission to create new records
    public static function check_create_permission($class)
    {
    }

    // check whether the current user has the permission to update existing records. some users can only update records created by themselves
    public static function check_update_permission($class)
    {
    }

    // validate user inputs using predefined validators 
    public static function validate_inputs($input, $validators)
    {
        $warnings = [];

        foreach ($validators as $v) {
            if (method_exists("validator", $v)) {
                $validation = validator::$v($input);
                if (!$validation["success"]) {
                    $warnings = array_merge($warnings, $validation["warnings"]); // Merging not needed if validation stops at the first unsuccessful validator
                    //break; // stop further valiidation checks
                }
            }
        }

        return $response;
    }
}
