<?php
/**
 * @author  Magediary
 * @package Magediary_ProductQuestion
 */

namespace Magediary\ProductQuestion\Block\Question;

use Magediary\ProductQuestion\Block\Product\View;

class ListView extends View
{
    /**
     * Unused class property
     * @var false
     */
    protected $_forceHasOptions = false;

    /**
     * Get product id
     *
     * @return int|null
     */
    public function getProductId()
    {
        $product = $this->_coreRegistry->registry('product');
        return $product ? $product->getId() : null;
    }

    /**
     * Get answer trigger URL for ajax call
     *
     * @return string
     */
    public function getAnswerTriggerUrl()
    {
        return $this->getUrl(
            'question/answer/trigger',
            [
                '_secure' => $this->getRequest()->isSecure(),
            ]
        );
    }

    /**
     * Get answer list URL for ajax call
     *
     * @return string
     */
    public function getAnswerListUrl()
    {
        return $this->getUrl(
            'question/answer/listAction',
            [
                '_secure' => $this->getRequest()->isSecure(),
            ]
        );
    }

    /**
     * Prepare product question list toolbar
     *
     * @return $this
     */
    protected function _prepareLayout()
    {
        parent::_prepareLayout();

        $toolbar = $this->getLayout()->getBlock('product_question_list.toolbar');
        if ($toolbar) {
            $toolbar->setCollection($this->getQuestionsCollection());
            $this->setChild('toolbar', $toolbar);
        }

        return $this;
    }
}
