src/Rhyme/WMassArtsHub/Model/Submission/Venue.php line 168

Open in your IDE?
  1. <?php
  2. /**
  3.  * Copyright (c) 2021 Rhyme Digital LLC (https://rhyme.digital)
  4.  *
  5.  * @license LGPL-3.0-or-later
  6.  */
  7. namespace Rhyme\WMassArtsHub\Model\Submission;
  8. use Contao\Controller;
  9. use Contao\Date;
  10. use Contao\FrontendTemplate;
  11. use Contao\Model;
  12. use Contao\Model\Collection;
  13. use Contao\ModuleModel;
  14. use Contao\PageModel;
  15. use Contao\StringUtil;
  16. use Contao\System;
  17. use Rhyme\WMassArtsHub\Helper\ProfileHelper;
  18. use Rhyme\WMassArtsHub\Helper\SubmissionHelper;
  19. /**
  20.  * Class Venue
  21.  * @package Rhyme\WMassArtsHub\Model\Submission
  22.  */
  23. class Venue extends Model implements SubmissionInterface
  24. {
  25.     /**
  26.      * @var string
  27.      */
  28.     protected static $strTable 'tl_artshub_submission_venue';
  29.     /**
  30.      * Get the alias key
  31.      * @return string
  32.      */
  33.     public static function getAliasKey()
  34.     {
  35.         return 'venueitem';
  36.     }
  37.     /**
  38.      * @return int|mixed|null
  39.      */
  40.     public function getDateSubmitted()
  41.     {
  42.         return $this->submissionDate;
  43.     }
  44.     /**
  45.      * @return string
  46.      */
  47.     public function getClass()
  48.     {
  49.         return 'venue';
  50.     }
  51.     /**
  52.      * @return string
  53.      */
  54.     public function getTitle()
  55.     {
  56.         return $this->title;
  57.     }
  58.     /**
  59.      * @return string
  60.      */
  61.     public function getPageTitle()
  62.     {
  63.         return $this->title ' | ArtsHub of Western Mass';
  64.     }
  65.     /**
  66.      * @param ModuleModel $objModule
  67.      * @return string|void
  68.      */
  69.     public function generate($objModule)
  70.     {
  71.         $t $this->getTable();
  72.         $strTemplate $objModule->venue_template;
  73.         $objTemplate = new FrontendTemplate($strTemplate);
  74.         $venue $this->row();
  75.         $objTemplate->setData($venue);
  76.         $objTemplate->model $this;
  77.         $link $this->venue_url;
  78.         //Also add related data if we have it
  79.         $relatedProfiles $this->getRelated('profiles');
  80.         if($relatedProfiles !== null) {
  81.             $objTemplate->hasProfiles true;
  82.             $objTemplate->profiles $relatedProfiles;
  83.             if($relatedProfiles->count() === 1) {
  84.                 //If there is one related profile we can use some of its data if it is missing here
  85.                 $link $this->venue_url ?: $relatedProfiles->website;
  86.                 $objTemplate->venue_phone $this->venue_phone ?: $relatedProfiles->phone;
  87.                 $objTemplate->venue_email $this->venue_email ?: $relatedProfiles->email;
  88.             }
  89.         }
  90.         $objTemplate->short_description '<p>' Controller::replaceInsertTags(StringUtil::substr(strip_tags(str_replace(['<br>''<p>''</p>'], ' '$this->description)), 200)) . '</p>';
  91.         $objTemplate->description str_replace('[nbsp]''&nbsp;'Controller::replaceInsertTags($this->description));
  92.         $objTemplate->link =            $link;
  93.         $objTemplate->link_absolute =   $link;
  94.         $objTemplate->getContactInfo = function ($blnIncludeWebsite=false)  { return  $this->getFormattedContactInfo($blnIncludeWebsite); };
  95.         $objTemplate->getAddress = function ()  { return  $this->getAddress(true); };
  96.         SubmissionHelper::addImageMethodsToTemplate($this$objModule$objTemplate);
  97.         System::loadLanguageFile($this->getTable());
  98.         $objTemplate->requestType $GLOBALS['TL_LANG'][$t][$objTemplate->venue_type];
  99.         return $objTemplate->parse();
  100.     }
  101.     /**
  102.      * Get the formatted contact info
  103.      * @return string
  104.      */
  105.     public function getFormattedContactInfo($blnIncludeWebsite=false) {
  106.         $emailLink '<a href="mailto:' StringUtil::encodeEmail($this->venue_email) . '" target="_blank" rel="noreferrer noopener">' StringUtil::encodeEmail($this->venue_email) . '</a>';
  107.         $urlLink '<a href="' $this->venue_url '" target="_blank" rel="noreferrer noopener">' $this->venue_url '</a>';
  108.         $strContact $this->venue_phone '<li><span class="label phone">Phone: </span><span class="value">' $this->venue_phone '</span></li>' '';
  109.         $strContact .= $this->venue_email '<li><span class="label email">Email: </span><span class="value">' $emailLink '</span></li>' '';
  110.         if($blnIncludeWebsite) {
  111.             $strContact .= $this->venue_url '<li><span class="label website">Link: </span><span class="value">' $urlLink '</span></li>' '';
  112.         }
  113.         return strlen($strContact) ? '<ul>' $strContact '</ul>' '';
  114.     }
  115.     /**
  116.      * Get the address
  117.      * @param bool $blnFormatLines
  118.      * @return string
  119.      */
  120.     public function getAddress($blnFormatLines false)
  121.     {
  122.         $street trim($this->street) === 'private' '' $this->street;
  123.         return ProfileHelper::formatAddress($street''$this->city$this->state$this->postal$blnFormatLines);
  124.     }
  125.     /**
  126.      * @param PageModel $objPage
  127.      * @return string|void
  128.      */
  129.     public function generateUrl($objPage){
  130.         $objModule ModuleModel::findOneByType('artshub_submission_combinedlister');
  131.         return SubmissionHelper::generateSubmissionUrlFromModule($this$objModule);
  132.     }
  133.     /**
  134.      * Find all published
  135.      * @param array $arrOptions An optional options array
  136.      *
  137.      * @return Venue|Collection|null The model or null if there is none
  138.      */
  139.     public static function findAllPublished(array $arrOptions=array())
  140.     {
  141.         $t = static::$strTable;
  142.         $time Date::floorToMinute();
  143.         $arrColumns = array("($t.start='' OR $t.start<='$time') AND ($t.stop='' OR $t.stop>'" . ($time 60) . "') AND $t.published='1'");
  144.         return static::findBy($arrColumns, array(), $arrOptions);
  145.     }
  146.     /**
  147.      * Find an event post by its ID or alias
  148.      *
  149.      * @param mixed $varId      The numeric ID or alias name
  150.      * @param array $arrOptions An optional options array
  151.      *
  152.      * @return Venue|null The model or null if there is no event
  153.      */
  154.     public static function findPublishedByIdOrAlias($varId, array $arrOptions=array())
  155.     {
  156.         $t = static::$strTable;
  157.         $arrColumns = !is_numeric($varId) ? array("$t.alias=?") : array("$t.id=?");
  158.         if (!static::isPreviewMode($arrOptions))
  159.         {
  160.             $time Date::floorToMinute();
  161.             $arrColumns[] = "($t.start='' OR $t.start<='$time') AND ($t.stop='' OR $t.stop>'" . ($time 60) . "') AND $t.published='1'";
  162.         }
  163.         return static::findOneBy($arrColumns$varId$arrOptions);
  164.     }
  165. }