<?php

namespace KupShop\ElninoBundle\Old;

class Photos extends \PhotosBase
{
    use \DatabaseCommunication;

    public static function checkLeadPhoto($table, $id_field, $id)
    {
        if ($table == 'photos_products_relation') {
            (new \AbraElnino())->checkLeadProductPhoto($id);
        } else {
            sqlQuery("SELECT @i := -1; UPDATE {$table} SET position = (select @i := @i + 1) WHERE {$id_field}=:id ORDER BY position, id_photo", ['id' => $id]);

            sqlQuery("UPDATE {$table} SET show_in_lead=IF(position=0, 'Y', 'N') WHERE {$id_field}=:id", ['id' => $id]);
        }
    }
}
