spotorm / spot2

Spot v2.x DataMapper built on top of Doctrine's Database Abstraction Layer
http://phpdatamapper.com
BSD 3-Clause "New" or "Revised" License
601 stars 101 forks source link

Warning: a form on this page has more than 1000 fields? [MySQL] #259

Closed pasichnyk closed 6 years ago

pasichnyk commented 6 years ago

Am I doing smth wrong?

When I opened the table on phpMyAdmin I've got next warning: ( table contains 25 rows ) 127 0 0 1 127 0 0 1 clinic2 registrations phpmyadmin 4 7 7 - google chrome

Entity

<?php

namespace App\Models;

class Registrations extends \Spot\Entity
{
    protected static $table = "registrations";
    protected static $mapper = "\App\Models\Mappers\Registrations";
    public static function fields()
    {
        return [
            "id" => ["type" => "integer", "primary" => true, "autoincrement" => true],
            "dt" => ["type" => "datetime", "required" => true],
            "dtCreated" => ["type" => "datetime", "default" => "CURRENT_TIMESTAMP", "value" => new \DateTime()],
            "patientID" => ["type" => "integer", "required" => true],
            "doctorID" => ["type" => "integer", "required" => true],
            "cabinet" => ["type" => "smallint", "unsigned" => true, "default" => null],
            "orderedServiceID" => ["type" => "integer", "required" => true],
            "performedServices" => ["type" => "json_array", "value" => []],
            "sum" => ["type" => "float", "unsigned" => true, "default" => 0],
            "paid" => ["type" => "boolean", "default" => false, "notnull" => true],
            "analysis" => ["type" => "text", "notnull" => true, "default" => ""],
            "comment" => ["type" => "text", "notnull" => true, "default" => ""],
            "pathology" => ["type" => "text", "notnull" => true, "default" => ""],
            "conclusion" => ["type" => "text", "notnull" => true, "default" => ""],
            "extraord" => ["type" => "boolean", "default" => false, "notnull" => true]            
        ];
    }
    public static function relations(\Spot\MapperInterface  $mapper, \Spot\EntityInterface $entity)
    {
        return [
            "patient" => $mapper->belongsTo($entity, "App\Models\Patients", "patientID"),
            "doctor" => $mapper->belongsTo($entity, "App\Models\Doctors", "doctorID"),
            "doctorPosition" => $mapper->belongsTo($entity, "App\Models\DctPositions", "doctorID"),
            "orderedService" => $mapper->belongsTo($entity, "App\Models\ServicesSimplified", "orderedServiceID")
        ];
    }

    public static function events(\Spot\EventEmitter $eventEmitter)
    {
        $eventEmitter->on("beforeSave", 
            function(\Spot\Entity $entity, \Spot\Mapper $mapper)
            {
                if( $entity -> isModified( "performedServices" ) )
                {
                    $performedServices = $entity -> performedServices;
                    if (!is_array($performedServices)) 
                        $performedServices = json_decode($performedServices, true);

                    if( count($performedServices) > 0 )
                    {
                        $newSum = $mapper
                            -> query("SELECT SUM(`sum`) AS `newSum` FROM `services` WHERE `id` IN ('" . implode("', '", $performedServices ) . "')")
                            -> first()
                            -> newSum;

                        $entity -> sum = $newSum;
                    }
                    else{
                        $entity -> sum = null;
                    }
                }

                if( $entity -> isModified( "doctorID" ) )
                {
                    $newCabinet = $mapper
                        -> query("SELECT cabinet FROM `doctors` WHERE `id` = '" . $entity -> doctorID . "'")
                        -> first()
                        -> cabinet;

                    $entity -> cabinet = $newCabinet;
                }
            }
        );

    }
}

Mapper

<?php

namespace App\Models\Mappers;

class Registrations extends \Spot\Mapper
{
    public function scopes()
    {
        return [
            "today" => function($query)
            {
                return $query -> where(
                    [
                        "dt >=" => new \DateTime('today 00:00:00'),
                        "dt <" => new \DateTime('tomorrow 00:00:00')
                    ]);
            },
            "yesterday" => function($query)
            {
                return $query -> where(
                    [
                        "dt >=" => new \DateTime('yesterday 00:00:00'),
                        "dt <" => new \DateTime('today 00:00:00')
                    ]);
            },
            "tomorrow" => function($query)
            {
                return $query -> where(
                    [
                        "dt >=" => new \DateTime('tomorrow 00:00:00'),
                        "dt <" => new \DateTime('+2 day 00:00:00')
                    ]);
            },
            "month" => function($query)
            {
                return $query -> where(
                    [
                        "dt >=" => new \DateTime('first day of this month 00:00:00'),
                        "dt <" => new \DateTime('first day of next month 00:00:00')
                    ]);
            },
            "prevMonth" => function($query)
            {
                return $query -> where(
                    [
                        "dt >=" => new \DateTime('first day of previous month 00:00:00'),
                        "dt <" => new \DateTime('first day of this month 00:00:00')
                    ]);
            },
            "nextMonth" => function($query)
            {
                return $query -> where(
                    [
                        "dt >=" => new \DateTime('first day of next month 00:00:00'),
                        "dt <=" => new \DateTime('last day of next month 23:59:59')
                    ]);
            }
        ];
    }
}
vlucas commented 6 years ago

Spot doesn't have anything to do with phpMyAdmin, so I am not sure what the issue is here. Seems like bad table design with tons of fields, but that would not have been created by Spot according to the entity definitions you have shown here.

lucasff commented 6 years ago

It already shows your problem. Increase your max_input_vars to 10000 or so.