src/Rhyme/WMassArtsHub/Model/Submission/CallsForArt.php line 93

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\SubmissionHelper;
  18. /**
  19.  * Class CallsForArt
  20.  * @package Rhyme\WMassArtsHub\Model\Submission
  21.  */
  22. class CallsForArt extends Model implements SubmissionInterface
  23. {
  24.     /**
  25.      * @var string
  26.      */
  27.     protected static $strTable 'tl_artshub_submission_callsforart';
  28.     /**
  29.      * Get the alias key
  30.      * @return string
  31.      */
  32.     public static function getAliasKey()
  33.     {
  34.         return 'callsforartitem';
  35.     }
  36.     /**
  37.      * @return int|mixed|null
  38.      */
  39.     public function getDateSubmitted()
  40.     {
  41.         return $this->submissionDate;
  42.     }
  43.     /**
  44.      * @return string
  45.      */
  46.     public function getClass()
  47.     {
  48.         return 'callforart';
  49.     }
  50.     /**
  51.      * @return string
  52.      */
  53.     public function getTitle()
  54.     {
  55.         return $this->title;
  56.     }
  57.     /**
  58.      * @return string
  59.      */
  60.     public function getPageTitle()
  61.     {
  62.         return $this->title ' | ArtsHub of Western Mass';
  63.     }
  64.     /**
  65.      * @param ModuleModel $objModule
  66.      * @return string|void
  67.      */
  68.     public function generate($objModule)
  69.     {
  70.         $t $this->getTable();
  71.         $strTemplate $objModule->callsforart_template;
  72.         $objTemplate = new FrontendTemplate($strTemplate);
  73.         $callforart $this->row();
  74.         $objTemplate->setData($callforart);
  75.         $objTemplate->model $this;
  76.         $objTemplate->short_description '<p>' Controller::replaceInsertTags(StringUtil::substr(strip_tags($this->description), 200)) . '</p>';
  77.         $objTemplate->description str_replace('[nbsp]''&nbsp;'Controller::replaceInsertTags($objTemplate->description));
  78.         $objTemplate->link =            SubmissionHelper::generateSubmissionUrlFromModule($this$objModule);
  79.         $objTemplate->link_absolute =   SubmissionHelper::generateSubmissionUrlFromModule($this$objModuletrue);
  80.         $objTemplate->getContactInfo = function ()  { return  $this->getFormattedContactInfo(); };
  81.         SubmissionHelper::addImageMethodsToTemplate($this$objModule$objTemplate);
  82.         System::loadLanguageFile($this->getTable());
  83.         $objTemplate->requestType $GLOBALS['TL_LANG'][$t][$objTemplate->request_type];
  84.         return $objTemplate->parse();
  85.     }
  86.     /**
  87.      * Get the formatted contact info
  88.      * @return string
  89.      */
  90.     public function getFormattedContactInfo() {
  91.         $emailLink '<a href="mailto:' StringUtil::encodeEmail($this->contact_email) . '" target="_blank">' StringUtil::encodeEmail($this->contact_email) . '</a>';
  92.         $urlLink '<a href="' $this->contact_url '" target="_blank">' $this->contact_url '</a>';
  93.         $strContact $this->contact_name '<li><span class="label name">Contact: </span><span class="value">' $this->contact_name '</span></li>' '';
  94.         $strContact .= $this->contact_phone '<li><span class="label phone">Phone: </span><span class="value">' $this->contact_phone '</span></li>' '';
  95.         $strContact .= $this->contact_email '<li><span class="label email">Email: </span><span class="value">' $emailLink '</span></li>' '';
  96.         $strContact .= $this->contact_url '<li><span class="label email">Link: </span><span class="value">' $urlLink '</span></li>' '';
  97.         return strlen($strContact) ? '<ul>' $strContact '</ul>' '';
  98.     }
  99.     /**
  100.      * @param PageModel $objPage
  101.      * @return string|void
  102.      */
  103.     public function generateUrl($objPage){
  104.         $objModule ModuleModel::findOneByType('artshub_submission_combinedlister');
  105.         return SubmissionHelper::generateSubmissionUrlFromModule($this$objModule);
  106.     }
  107.     /**
  108.      * Find all published
  109.      * @param array $arrOptions An optional options array
  110.      *
  111.      * @return CallsForArt|Collection|null The model or null if there is none
  112.      */
  113.     public static function findAllPublished(array $arrOptions=array())
  114.     {
  115.         $t = static::$strTable;
  116.         $time Date::floorToMinute();
  117.         $arrColumns = array("($t.start='' OR $t.start<='$time') AND ($t.stop='' OR $t.stop>'" . ($time 60) . "') AND $t.published='1'");
  118.         return static::findBy($arrColumns, array(), $arrOptions);
  119.     }
  120.     /**
  121.      * Find an event post by its ID or alias
  122.      *
  123.      * @param mixed $varId      The numeric ID or alias name
  124.      * @param array $arrOptions An optional options array
  125.      *
  126.      * @return CallsForArt|null The model or null if there is no event
  127.      */
  128.     public static function findPublishedByIdOrAlias($varId, array $arrOptions=array())
  129.     {
  130.         $t = static::$strTable;
  131.         $arrColumns = !is_numeric($varId) ? array("$t.alias=?") : array("$t.id=?");
  132.         if (!static::isPreviewMode($arrOptions))
  133.         {
  134.             $time Date::floorToMinute();
  135.             $arrColumns[] = "($t.start='' OR $t.start<='$time') AND ($t.stop='' OR $t.stop>'" . ($time 60) . "') AND $t.published='1'";
  136.         }
  137.         return static::findOneBy($arrColumns$varId$arrOptions);
  138.     }
  139. }