<?php

namespace Litecms\BCategory;

use User;

class BCategory
{
    /**
     * $b_category object.
     */
    protected $b_category;    /**
     * $b_category object.
     */
    protected $b_category;

    /**
     * Constructor.
     */
    public function __construct(\Litecms\BCategory\Interfaces\BCategoryRepositoryInterface $b_category,        \Litecms\BCategory\Interfaces\BCategoryRepositoryInterface $b_category)
    {
        $this->b_category = $b_category;        $this->b_category = $b_category;
    }

    /**
     * Returns count of b_category.
     *
     * @param array $filter
     *
     * @return int
     */
    public function count()
    {
        return  0;
    }

    /**
     * Make gadget View
     *
     * @param string $view
     *
     * @param int $count
     *
     * @return View
     */
    public function gadget($view = 'admin.b_category.gadget', $count = 10)
    {

        if (User::hasRole('user')) {
            $this->b_category->pushCriteria(new \Litepie\Litecms\Repositories\Criteria\BCategoryUserCriteria());
        }

        $b_category = $this->b_category->scopeQuery(function ($query) use ($count) {
            return $query->orderBy('id', 'DESC')->take($count);
        })->all();

        return view('b_category::' . $view, compact('b_category'))->render();
    }    /**
     * Make gadget View
     *
     * @param string $view
     *
     * @param int $count
     *
     * @return View
     */
    public function gadget($view = 'admin.b_category.gadget', $count = 10)
    {

        if (User::hasRole('user')) {
            $this->b_category->pushCriteria(new \Litepie\Litecms\Repositories\Criteria\BCategoryUserCriteria());
        }

        $b_category = $this->b_category->scopeQuery(function ($query) use ($count) {
            return $query->orderBy('id', 'DESC')->take($count);
        })->all();

        return view('b_category::' . $view, compact('b_category'))->render();
    }
}