<?php
/**
 * Subito partial copy page range validator trait
 *
 * Copyright (C) 2020 Leipzig University Library
 *
 * PHP Version 7
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 as
 * published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along
 * with this program; if not, write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 *
 * @category VuFind
 * @package  Validator
 * @author   Alexander Purr <purr@ub.uni-leipzig.de>
 * @license  http://opensource.org/licenses/gpl-2.0.php GNU GPLv2
 * @link     https://vufind.org/wiki/development Wiki
 */
namespace fid\Validator;

use fid\Controller\RecordController;

/**
 * Subito partial copy page range validator trait
 *
 * @category VuFind
 * @package  Validator
 * @author   Alexander Purr <purr@ub.uni-leipzig.de>
 * @license  http://opensource.org/licenses/gpl-2.0.php GNU GPLv2
 * @link     https://vufind.org/wiki/development Wiki
 */
trait SubitoPartialCopyPageRangeValidatorTrait
{
    private $_pageStart = null;

    private $_pageEnd = null;

    /**
     * Extract start and end page of a page range (string like '12-123')
     *
     * @param string $value From to page range
     *
     * @return void
     */
    private function _extractPages(string $value)
    {
        preg_match(RecordController::PAGE_RANGE_PATTERN, $value, $matches);
        $this->_pageStart = (int)$matches[1];
        $this->_pageEnd = (int)$matches[2];
    }
}