1:  2:  3:  4:  5:  6:  7:  8:  9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 
<?php

namespace Omeka\View\Model;

use Zend\View\Model\JsonModel;

/**
 * View model for JSON responses from the API.
 */
class ApiJsonModel extends JsonModel
{
    /**
     * Key that stores the API response in the view variables
     */
    const API_RESPONSE_KEY = 'api_response';

    /**
     * Key that stores the thrown exception, if any, in the view variables
     */
    const EXCEPTION_KEY = 'exception';

    /**
     * Create a new model.
     *
     * The API response object can be passed here directly as the first
     * argument.
     *
     * @param \Omeka\Api\Response $apiResponse API response object
     * @param array|Traversable $options
     */
    public function __construct($apiResponse = null, $options = null)
    {
        $variables = [self::API_RESPONSE_KEY => $apiResponse];
        parent::__construct($variables, $options);
    }

    /**
     * Get the API response object stored on the model.
     *
     * @return \Omeka\Api\Response
     */
    public function getApiResponse()
    {
        return $this->getVariable(self::API_RESPONSE_KEY);
    }

    /**
     * Set the API response object on this model.
     *
     * @param \Omeka\Api\Response $apiResponse
     */
    public function setApiResponse($apiResponse)
    {
        $this->setVariable(self::API_RESPONSE_KEY, $apiResponse);
    }

    /**
     * Get the exception stored on the model.
     *
     * @return \Exception|null
     */
    public function getException()
    {
        return $this->getVariable(self::EXCEPTION_KEY);
    }

    /**
     * Set the exception on this model.
     *
     * @param \Exception $exception
     */
    public function setException(\Exception $exception)
    {
        $this->setVariable(self::EXCEPTION_KEY, $exception);
    }
}