<?php
/**
* Copyright (C) 2019 Rhyme Digital, LLC.
*
* @link https://rhyme.digital
* @license http://www.gnu.org/licenses/lgpl-3.0.html LGPL
*/
namespace Rhyme\WMassArtsHub\Module\Submission;
use Contao\Date;
use Contao\Input;
use Contao\Config;
use Contao\Module;
use Contao\PageModel;
use Contao\StringUtil;
use Contao\Environment;
use Contao\BackendTemplate;
use Patchwork\Utf8;
use Contao\CoreBundle\Exception\PageNotFoundException;
use Rhyme\WMassArtsHub\Model\Submission\CallsForArt;
use Rhyme\WMassArtsHub\Model\Submission\Funding;
use Rhyme\WMassArtsHub\Model\Submission\Space;
/**
* Class CallsForArtReader
* @package Rhyme\WMassArtsHub\Module\Submission
*/
class CallsForArtReader extends Module
{
/**
* Current date object
* @var Date
*/
protected $Date;
/**
* Template
* @var string
*/
protected $strTemplate = 'mod_artshub_submission_reader';
/**
* Display a wildcard in the back end
*
* @return string
*/
public function generate()
{
if (TL_MODE == 'BE') {
$objTemplate = new BackendTemplate('be_wildcard');
$objTemplate->wildcard = '### ' . Utf8::strtoupper($GLOBALS['TL_LANG']['FMD']['artshub_callsforart_reader'][0]) . ' ###';
$objTemplate->title = $this->headline;
$objTemplate->id = $this->id;
$objTemplate->link = $this->name;
$objTemplate->href = 'contao/main.php?do=themes&table=tl_module&act=edit&id=' . $this->id;
return $objTemplate->parse();
}
// Set the item from the auto_item parameter
if (!isset($_GET['callsforartitem']) && Config::get('useAutoItem') && isset($_GET['auto_item']))
{
Input::setGet('callsforartitem', Input::get('auto_item'));
}
// Return an empty string if "callsforartitem" is not set
if (!Input::get('callsforartitem'))
{
return '';
}
return parent::generate();
}
/**
* Generate the module
*/
protected function compile()
{
/** @var PageModel $objPage */
global $objPage;
$this->Template->item = '';
// Get the current submission
$objSubmission = CallsForArt::findPublishedByIdOrAlias(Input::get('callsforartitem'));
if (null === $objSubmission)
{
throw new PageNotFoundException('Page not found: ' . Environment::get('uri'));
}
// Overwrite the page title (see #2853, #4955 and #87)
if ($objPage && $objSubmission->title)
{
$objPage->pageTitle = $objSubmission->getPageTitle();
$objPage->description = 'Check out ' . $objSubmission->title . ', an artists\' studio/space opportunity in western Massachusetts.';
$objPage->description .= StringUtil::substr(strip_tags($objSubmission->description), 100);
}
$this->Template->item = $objSubmission->generate($this);
}
}