The class functions as a wrapper for the database result set and lazy loads the result rows when they are first requested. Usage: while ($result->next()) { echo $result->name; print_r($result->row()); }
 /**
  * Convert the value ids to a result array.
  *
  * @param Result     $valueResult The database result.
  *
  * @param null|array $counter     The destination for the counter values.
  *
  * @return array
  */
 protected function convertValueIds($valueResult, &$counter = null)
 {
     $result = array();
     $aliases = array();
     $idColumn = $this->getIdColumn();
     $aliasColumn = $this->getAliasColumn();
     while ($valueResult->next()) {
         $valueId = $valueResult->{$idColumn};
         $aliases[$valueId] = $valueResult->{$aliasColumn};
         $result[] = $valueId;
     }
     if ($counter !== null && !empty($result)) {
         $objCount = $this->getDatabase()->prepare(sprintf('SELECT value_id, COUNT(value_id) as mm_count
                     FROM tl_metamodel_tag_relation
                     WHERE att_id=?
                     AND value_id IN (%s)
                     GROUP BY item_id', $this->parameterMask($result)))->execute(array_merge(array($this->get('id')), $result));
         /** @noinspection PhpUndefinedFieldInspection */
         $amount = $objCount->mm_count;
         /** @noinspection PhpUndefinedFieldInspection */
         $valueId = $objCount->value_id;
         $alias = $aliases[$valueId];
         $counter[$valueId] = $amount;
         $counter[$alias] = $amount;
     }
     return $result;
 }
 /**
  * Loop over the Result until the item id is not matching anymore the requested item id.
  *
  * @param string $itemId  The item id for which the ids shall be retrieved.
  *
  * @param Result $allTags The database result from which the ids shall be extracted.
  *
  * @return array
  */
 protected function getExistingTags($itemId, $allTags)
 {
     $thisExisting = array();
     // Determine existing tags for this item.
     /** @noinspection PhpUndefinedFieldInspection */
     if ($allTags->item_id == $itemId) {
         /** @noinspection PhpUndefinedFieldInspection */
         $thisExisting[] = $allTags->value_id;
     }
     /** @noinspection PhpUndefinedFieldInspection */
     while ($allTags->next() && $allTags->item_id == $itemId) {
         /** @noinspection PhpUndefinedFieldInspection */
         $thisExisting[] = $allTags->value_id;
     }
     return $thisExisting;
 }
Exemple #3
0
 /**
  * Compile the newsletter and send it
  *
  * @param Email                  $objEmail
  * @param Database\Result|object $objNewsletter
  * @param array                  $arrRecipient
  * @param string                 $text
  * @param string                 $html
  * @param string                 $css
  *
  * @return string
  */
 protected function sendNewsletter(Email $objEmail, Database\Result $objNewsletter, $arrRecipient, $text, $html, $css = null)
 {
     // Prepare the text content
     $objEmail->text = \StringUtil::parseSimpleTokens($text, $arrRecipient);
     if (!$objNewsletter->sendText) {
         // Default template
         if ($objNewsletter->template == '') {
             $objNewsletter->template = 'mail_default';
         }
         /** @var BackendTemplate|object $objTemplate */
         $objTemplate = new \BackendTemplate($objNewsletter->template);
         $objTemplate->setData($objNewsletter->row());
         $objTemplate->title = $objNewsletter->subject;
         $objTemplate->body = \StringUtil::parseSimpleTokens($html, $arrRecipient);
         $objTemplate->charset = \Config::get('characterSet');
         $objTemplate->recipient = $arrRecipient['email'];
         // Deprecated since Contao 4.0, to be removed in Contao 5.0
         $objTemplate->css = $css;
         // Parse template
         $objEmail->html = $objTemplate->parse();
         $objEmail->imageDir = TL_ROOT . '/';
     }
     // Deactivate invalid addresses
     try {
         $objEmail->sendTo($arrRecipient['email']);
     } catch (\Swift_RfcComplianceException $e) {
         $_SESSION['REJECTED_RECIPIENTS'][] = $arrRecipient['email'];
     }
     // Rejected recipients
     if ($objEmail->hasFailures()) {
         $_SESSION['REJECTED_RECIPIENTS'][] = $arrRecipient['email'];
     }
     // HOOK: add custom logic
     if (isset($GLOBALS['TL_HOOKS']['sendNewsletter']) && is_array($GLOBALS['TL_HOOKS']['sendNewsletter'])) {
         foreach ($GLOBALS['TL_HOOKS']['sendNewsletter'] as $callback) {
             $this->import($callback[0]);
             $this->{$callback[0]}->{$callback[1]}($objEmail, $objNewsletter, $arrRecipient, $text, $html);
         }
     }
 }
Exemple #4
0
 /**
  * Add the table tl_theme
  *
  * @param \DOMDocument           $xml
  * @param \DOMNode|\DOMElement   $tables
  * @param Database\Result|object $objTheme
  */
 protected function addTableTlTheme(\DOMDocument $xml, \DOMNode $tables, Database\Result $objTheme)
 {
     // Add the table
     $table = $xml->createElement('table');
     $table->setAttribute('name', 'tl_theme');
     $table = $tables->appendChild($table);
     // Load the DCA
     $this->loadDataContainer('tl_theme');
     // Get the order fields
     $objDcaExtractor = \DcaExtractor::getInstance('tl_theme');
     $arrOrder = $objDcaExtractor->getOrderFields();
     // Add the row
     $this->addDataRow($xml, $table, $objTheme->row(), $arrOrder);
 }
Exemple #5
0
 /**
  * Create a new collection from a database result
  *
  * @param Result $objResult The database result object
  * @param string $strTable  The table name
  *
  * @return static The model collection
  */
 public static function createFromDbResult(Result $objResult, $strTable)
 {
     $arrModels = array();
     $strClass = \Model::getClassFromTable($strTable);
     while ($objResult->next()) {
         /** @var Model $strClass */
         $objModel = \Model\Registry::getInstance()->fetch($strTable, $objResult->{$strClass::getPk()});
         if ($objModel !== null) {
             $objModel->mergeRow($objResult->row());
             $arrModels[] = $objModel;
         } else {
             $arrModels[] = new $strClass($objResult);
         }
     }
     return new static($arrModels, $strTable);
 }
 /**
  * {@inheritDoc}
  */
 public function __get($strKey)
 {
     return $this->result->__get($strKey);
 }