<?php

namespace Hura8\Components\User\Controller;

use Hura8\Components\Customer\PublicController\UCustomerLoginController;
use Hura8\Components\User\AdminController\AUserController;
use Hura8\Components\User\Model\UserUploadModel;
use Hura8\System\Controller\aEntityBaseController;

class bUserUploadController extends aEntityBaseController
{
    protected $web_user_id = '';
    protected $customer_id = 0;
    protected $item_type = '';
    protected $item_id = '';

    public function __construct($item_type='', $item_id=0) {
        $this->web_user_id = AUserController::getWebUserId();
        $this->customer_id = UCustomerLoginController::getLoggedInCustomerId();

        $this->item_type = $item_type;
        $this->item_id   = $item_id;

        parent::__construct(new UserUploadModel($this->web_user_id, $this->customer_id, $item_type, $item_id));
    }

    protected function deleteFileBeforeDeleteItem($item_id): bool
    {
        // delete thumb files
        $item_info = $this->getInfo($item_id);

        if($item_info['file_path']) {
            $file_local_path = PUBLIC_DIR . "/". $item_info['file_path'];
            @unlink($file_local_path);
        }

        // ok
        return true;
    }

}
