src/Rhyme/WMassArtsHub/Model/Submission/Funding.php line 145

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\CalendarEventsModel;
  9. use Contao\Controller;
  10. use Contao\Date;
  11. use Contao\FrontendTemplate;
  12. use Contao\Model;
  13. use Contao\Model\Collection;
  14. use Contao\ModuleModel;
  15. use Contao\PageModel;
  16. use Contao\StringUtil;
  17. use Contao\System;
  18. use Rhyme\WMassArtsHub\Helper\SubmissionHelper;
  19. /**
  20.  * Class Type
  21.  * @package Rhyme\WMassArtsHub\Model\Submission
  22.  */
  23. class Funding extends Model implements SubmissionInterface
  24. {
  25.     /**
  26.      * @var string
  27.      */
  28.     protected static $strTable 'tl_artshub_submission_funding';
  29.     /**
  30.      * Get the alias key
  31.      * @return string
  32.      */
  33.     public static function getAliasKey()
  34.     {
  35.         return 'fundingitem';
  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 'funding';
  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->funding_template;
  73.         $objTemplate = new FrontendTemplate($strTemplate);
  74.         $funding $this->row();
  75.         $objTemplate->setData($funding);
  76.         $objTemplate->model $this;
  77.         $objTemplate->short_description '<p>' Controller::replaceInsertTags(StringUtil::substr(strip_tags($this->description), 200)) . '</p>';
  78.         $objTemplate->description str_replace('[nbsp]''&nbsp;'Controller::replaceInsertTags($objTemplate->description));
  79.         $objTemplate->link =            SubmissionHelper::generateSubmissionUrlFromModule($this$objModule);
  80.         $objTemplate->link_absolute =   SubmissionHelper::generateSubmissionUrlFromModule($this$objModuletrue);
  81.         $objTemplate->getContactInfo = function ()  { return  $this->getFormattedContactInfo(); };
  82.         SubmissionHelper::addImageMethodsToTemplate($this$objModule$objTemplate);
  83.         System::loadLanguageFile($this->getTable());
  84.         $objTemplate->requestType $GLOBALS['TL_LANG'][$t][$objTemplate->funding_type];
  85.         return $objTemplate->parse();
  86.     }
  87.     /**
  88.      * Get the formatted contact info
  89.      * @return string
  90.      */
  91.     public function getFormattedContactInfo() {
  92.         $emailLink '<a href="mailto:' StringUtil::encodeEmail($this->contact_email) . '" target="_blank">' StringUtil::encodeEmail($this->contact_email) . '</a>';
  93.         $urlLink '<a href="' $this->contact_url '" target="_blank">' $this->contact_url '</a>';
  94.         $strContact $this->contact_name '<li><span class="label name">Contact: </span><span class="value">' $this->contact_name '</span></li>' '';
  95.         $strContact .= $this->contact_phone '<li><span class="label phone">Phone: </span><span class="value">' $this->contact_phone '</span></li>' '';
  96.         $strContact .= $this->contact_email '<li><span class="label email">Email: </span><span class="value">' $emailLink '</span></li>' '';
  97.         $strContact .= $this->contact_url '<li><span class="label email">Link: </span><span class="value">' $urlLink '</span></li>' '';
  98.         return strlen($strContact) ? '<ul>' $strContact '</ul>' '';
  99.     }
  100.     /**
  101.      * @param PageModel $objPage
  102.      * @return string|void
  103.      */
  104.     public function generateUrl($objPage){
  105.         $objModule ModuleModel::findOneByType('artshub_submission_combinedlister');
  106.         return SubmissionHelper::generateSubmissionUrlFromModule($this$objModule);
  107.     }
  108.     /**
  109.      * Find all published
  110.      * @param array $arrOptions An optional options array
  111.      *
  112.      * @return Funding|Collection|null The model or null if there is none
  113.      */
  114.     public static function findAllPublished(array $arrOptions=array())
  115.     {
  116.         $t = static::$strTable;
  117.         $time Date::floorToMinute();
  118.         $arrColumns = array("($t.start='' OR $t.start<='$time') AND ($t.stop='' OR $t.stop>'" . ($time 60) . "') AND $t.published='1'");
  119.         return static::findBy($arrColumns, array(), $arrOptions);
  120.     }
  121.     /**
  122.      * Find an event post by its ID or alias
  123.      *
  124.      * @param mixed $varId      The numeric ID or alias name
  125.      * @param array $arrOptions An optional options array
  126.      *
  127.      * @return Funding|null The model or null if there is no event
  128.      */
  129.     public static function findPublishedByIdOrAlias($varId, array $arrOptions=array())
  130.     {
  131.         $t = static::$strTable;
  132.         $arrColumns = !is_numeric($varId) ? array("$t.alias=?") : array("$t.id=?");
  133.         if (!static::isPreviewMode($arrOptions))
  134.         {
  135.             $time Date::floorToMinute();
  136.             $arrColumns[] = "($t.start='' OR $t.start<='$time') AND ($t.stop='' OR $t.stop>'" . ($time 60) . "') AND $t.published='1'";
  137.         }
  138.         return static::findOneBy($arrColumns$varId$arrOptions);
  139.     }
  140. }