/** * Generate a product label and return it as HTML string * @param array * @param string * @param object * @param array * @return string */ public function generate($row, $label, $dc, $args) { foreach ($GLOBALS['TL_DCA'][$dc->table]['list']['label']['fields'] as $i => $field) { if ($field == 'name' && $row['fallback']) { $args[$i] = sprintf('%s <span style="color:#b3b3b3; padding-left:3px;">[%s]</span>', $row['name'], Format::dcaLabel($dc->table, 'fallback')); } else { $args[$i] = Format::dcaValue($dc->table, $field, $row[$field]); } } return $args; }
/** * Generate a product label and return it as HTML string * @param array * @param string * @param object * @param array * @return string */ public function generate($row, $label, $dc, $args) { $objProduct = Product::findByPk($row['id']); foreach ($GLOBALS['TL_DCA'][$dc->table]['list']['label']['fields'] as $i => $field) { switch ($field) { // Add an image case 'images': $arrImages = deserialize($objProduct->images); $args[$i] = ' '; if (is_array($arrImages) && !empty($arrImages)) { foreach ($arrImages as $image) { $strImage = 'isotope/' . strtolower(substr($image['src'], 0, 1)) . '/' . $image['src']; if (!is_file(TL_ROOT . '/' . $strImage)) { continue; } $size = @getimagesize(TL_ROOT . '/' . $strImage); $args[$i] = sprintf('<a href="%s" onclick="Backend.openModalImage({\'width\':%s,\'title\':\'%s\',\'url\':\'%s\'});return false"><img src="%s" alt="%s" align="left"></a>', $strImage, $size[0], str_replace("'", "\\'", $objProduct->name), $strImage, \Image::get($strImage, 50, 50, 'proportional'), $image['alt']); break; } } break; case 'name': $args[$i] = $objProduct->name; /** @var \Isotope\Model\ProductType $objProductType */ if ($row['pid'] == 0 && ($objProductType = ProductType::findByPk($row['type'])) !== null && $objProductType->hasVariants()) { // Add a variants link $args[$i] = sprintf('<a href="%s" title="%s">%s</a>', ampersand(\Environment::get('request')) . '&id=' . $row['id'], specialchars($GLOBALS['TL_LANG'][$dc->table]['showVariants']), $args[$i]); } break; case 'price': $objPrice = ProductPrice::findPrimaryByProductId($row['id']); if (null !== $objPrice) { /** @var \Isotope\Model\TaxClass $objTax */ $objTax = $objPrice->getRelated('tax_class'); $strTax = null === $objTax ? '' : ' (' . $objTax->getName() . ')'; $args[$i] = $objPrice->getValueForTier(1) . $strTax; } break; case 'variantFields': $attributes = array(); foreach ($GLOBALS['TL_DCA'][$dc->table]['list']['label']['variantFields'] as $variantField) { $attributes[] = '<strong>' . Format::dcaLabel($dc->table, $variantField) . ':</strong> ' . Format::dcaValue($dc->table, $variantField, $objProduct->{$variantField}); } $args[$i] = ($args[$i] ? $args[$i] . '<br>' : '') . implode(', ', $attributes); break; } } return $args; }
/** * Send the news message * @param integer * @return boolean */ public function sendNewsMessage($intId) { $objNews = \NewsModel::findByPk($intId); if ($objNews === null) { return false; } $objArchive = $objNews->getRelated('pid'); if ($objArchive === null || !$objArchive->newsletter || !$objArchive->newsletter_channel || !$objArchive->nc_notification) { return false; } $objNotification = \NotificationCenter\Model\Notification::findByPk($objArchive->nc_notification); if ($objNotification === null) { return false; } $objRecipients = \NewsletterRecipientsModel::findBy(array("pid=? AND active=1"), $objArchive->newsletter_channel); if ($objRecipients === null) { return false; } $arrTokens = array(); // Generate news archive tokens foreach ($objArchive->row() as $k => $v) { $arrTokens['news_archive_' . $k] = \Haste\Util\Format::dcaValue('tl_news_archive', $k, $v); } // Generate news tokens foreach ($objNews->row() as $k => $v) { $arrTokens['news_' . $k] = \Haste\Util\Format::dcaValue('tl_news', $k, $v); } $arrTokens['news_text'] = ''; $objElement = \ContentModel::findPublishedByPidAndTable($objNews->id, 'tl_news'); // Generate news text if ($objElement !== null) { while ($objElement->next()) { $arrTokens['news_text'] .= $this->getContentElement($objElement->id); } } // Generate news URL $objPage = \PageModel::findWithDetails($objNews->getRelated('pid')->jumpTo); $arrTokens['news_url'] = ($objPage->rootUseSSL ? 'https://' : 'http://') . ($objPage->domain ?: \Environment::get('host')) . TL_PATH . '/' . $objPage->getFrontendUrl(($GLOBALS['TL_CONFIG']['useAutoItem'] && !$GLOBALS['TL_CONFIG']['disableAlias'] ? '/' : '/items/') . (!$GLOBALS['TL_CONFIG']['disableAlias'] && $objNews->alias != '' ? $objNews->alias : $objNews->id), $objPage->language); // Administrator e-mail $arrTokens['admin_email'] = $GLOBALS['TL_ADMIN_EMAIL']; while ($objRecipients->next()) { $arrTokens['recipient_email'] = $objRecipients->email; $objNotification->send($arrTokens); } // Set the newsletter flag $objNews->newsletter = 1; $objNews->save(); return true; }
/** * Auto-format model data based on DCA config * @param \Model * @param callable * @return \ArrayObject */ public static function generate(\Model $objModel = null, $varCallable = null) { if (null === $objModel) { return new \ArrayObject(array(), \ArrayObject::ARRAY_AS_PROPS); } $strTable = $objModel->getTable(); $objDca = new \DcaExtractor($strTable); $arrRelations = $objDca->getRelations(); $arrData = array(); \System::loadLanguageFile($strTable); \Controller::loadDataContainer($strTable); $arrFields =& $GLOBALS['TL_DCA'][$strTable]['fields']; foreach ($objModel->row() as $strField => $varValue) { $arrAdditional = array(); $strLabel = Format::dcaLabel($strTable, $strField); if (isset($arrRelations[$strField])) { $objRelated = $objModel->getRelated($strField); if ($objRelated == null) { $arrData[$strField] = new Plain('', $strLabel, $arrAdditional); } elseif ($objRelated instanceof \Model\Collection) { $arrCollection = array(); foreach ($objRelated as $objRelatedModel) { $arrCollection[] = new Relation($objRelatedModel, '', array(), $varCallable); } $arrData[$strField] = new Collection($arrCollection, $strLabel); } else { $arrData[$strField] = new Relation($objRelated, $strLabel, array(), $varCallable); } continue; } $arrAdditional['formatted'] = Format::dcaValue($strTable, $strField, $varValue); if (in_array($arrFields[$strField]['eval']['rgxp'], array('date', 'datim', 'time'))) { $arrData[$strField] = new Timestamp($varValue, $strLabel, $arrAdditional); } else { $arrData[$strField] = new Plain($varValue, $strLabel, $arrAdditional); } } if (null !== $varCallable) { call_user_func_array($varCallable, array($objModel, &$arrData)); } return new \ArrayObject($arrData, \ArrayObject::ARRAY_AS_PROPS); }
/** * Generate header fields for product or variant * @param array * @param \Contao\DataContainer */ public function headerFields($arrFields, $dc) { $t = Product::getTable(); $arrNew = array(); $objProduct = Product::findByPk($dc->id); if (null === $objProduct) { return $arrFields; } $arrAttributes = array('name', 'alias', 'sku'); if ($objProduct->isVariant()) { $arrAttributes = array_merge($arrAttributes, array_intersect(array_merge($objProduct->getAttributes(), $objProduct->getVariantAttributes()), Attribute::getVariantOptionFields())); } foreach ($arrAttributes as $field) { $v = $objProduct->{$field}; if ($v != '') { $arrNew[Format::dcaLabel($t, $field)] = Format::dcaValue($t, $field, $v); } } // Add fields that have potentially been added through the DCA, but do not allow to override the core fields return array_merge($arrNew, array_diff_key($arrFields, $arrNew)); }
/** * Send the personal data change e-mail * @param object * @param array * @param object */ public function sendPersonalDataEmail($objUser, $arrData, $objModule) { if (!$objModule->nc_notification) { return; } $arrTokens = array(); $arrTokens['admin_email'] = $GLOBALS['TL_ADMIN_EMAIL']; $arrTokens['domain'] = \Environment::get('host'); // Support newsletters if (in_array('newsletter', $this->Config->getActiveModules())) { if (!is_array($arrData['newsletter'])) { if ($arrData['newsletter'] != '') { $objChannels = \Database::getInstance()->execute("SELECT title FROM tl_newsletter_channel WHERE id IN(" . implode(',', array_map('intval', (array) $arrData['newsletter'])) . ")"); $arrTokens['member_newsletter'] = implode("\n", $objChannels->fetchEach('title')); } else { $arrTokens['member_newsletter'] = ''; } } } // Translate/format old values foreach ($_SESSION['PERSONAL_DATA'] as $strFieldName => $strFieldValue) { $arrTokens['member_old_' . $strFieldName] = \Haste\Util\Format::dcaValue('tl_member', $strFieldName, $strFieldValue); } // Translate/format new values foreach ($arrData as $strFieldName => $strFieldValue) { $arrTokens['member_' . $strFieldName] = \Haste\Util\Format::dcaValue('tl_member', $strFieldName, $strFieldValue); } $objNotification = \NotificationCenter\Model\Notification::findByPk($objModule->nc_notification); if ($objNotification !== null) { $objNotification->send($arrTokens); } }
/** * Replace {{dca_value::*}} insert tag * * use case: * * {{dca_value::table::field::value}} * * @param array $arrTag * * @return string */ private function replaceDcaValue($arrTag) { $strTable = $arrTag[1]; $strField = $arrTag[2]; $varValue = $arrTag[3]; return Format::dcaValue($strTable, $strField, $varValue); }
/** * Generate a list of tiers for a wizard in products * @param object * @param string * @return string */ public function generateWizardList($objRecords, $strId) { $strReturn = ' <table class="tl_listing showColumns"> <thead> <td class="tl_folder_tlist">' . Format::dcaLabel('tl_iso_product_price', 'price_tiers') . '</td> <td class="tl_folder_tlist">' . Format::dcaLabel('tl_iso_product_price', 'tax_class') . '</td> <td class="tl_folder_tlist">' . Format::dcaLabel('tl_iso_product_price', 'config_id') . '</td> <td class="tl_folder_tlist">' . Format::dcaLabel('tl_iso_product_price', 'member_group') . '</td> <td class="tl_folder_tlist">' . Format::dcaLabel('tl_iso_product_price', 'start') . '</td> <td class="tl_folder_tlist">' . Format::dcaLabel('tl_iso_product_price', 'stop') . '</td> </thead> <tbody>'; while ($objRecords->next()) { $arrTiers = array(); $objTiers = \Database::getInstance()->execute("SELECT * FROM tl_iso_product_pricetier WHERE pid={$objRecords->id} ORDER BY min"); while ($objTiers->next()) { $arrTiers[] = "{$objTiers->min}={$objTiers->price}"; } $strReturn .= ' <tr> <td class="tl_file_list">' . implode(', ', $arrTiers) . '</td> <td class="tl_file_list">' . (Format::dcaValue('tl_iso_product_price', 'tax_class', $objRecords->tax_class) ?: '-') . '</td> <td class="tl_file_list">' . (Format::dcaValue('tl_iso_product_price', 'config_id', $objRecords->config_id) ?: '-') . '</td> <td class="tl_file_list">' . (Format::dcaValue('tl_iso_product_price', 'member_group', $objRecords->member_group) ?: '-') . '</td> <td class="tl_file_list">' . (Format::dcaValue('tl_iso_product_price', 'member_group', $objRecords->start) ?: '-') . '</td> <td class="tl_file_list">' . (Format::dcaValue('tl_iso_product_price', 'member_group', $objRecords->stop) ?: '-') . '</td> </tr> '; } $strReturn .= ' </tbody> </table>'; return $strReturn; }
/** * Get the results * * @return array */ protected function getResults() { $arrResults = array(); $objResults = \Database::getInstance()->prepare(implode(' ', $this->arrQueryProcedure))->execute($this->arrQueryValues); while ($objResults->next()) { $arrRow = $objResults->row(); $strKey = $arrRow[$this->foreignTable . '_id']; $arrResults[$strKey]['rowId'] = $arrRow[$this->foreignTable . '_id']; $arrResults[$strKey]['rawData'] = $arrRow; // Mark checked if not ajax call if (!$this->blnIsAjaxRequest) { $arrResults[$strKey]['isChecked'] = $this->optionChecked($arrRow[$this->foreignTable . '_id'], $this->varValue); } foreach ($this->arrListFields as $strField) { list($strTable, $strColumn) = explode('.', $strField); $strFieldKey = str_replace('.', '_', $strField); $arrResults[$strKey]['formattedData'][$strFieldKey] = \Haste\Util\Format::dcaValue($strTable, $strColumn, $arrRow[$strFieldKey]); } } return $arrResults; }
/** * Generate HTML markup of product data for this attribute * * @param IsotopeProduct $objProduct * @param array $arrOptions * * @return string */ public function generate(IsotopeProduct $objProduct, array $arrOptions = array()) { $varValue = $this->getValue($objProduct); if (is_array($varValue) && !array_is_assoc($varValue) && is_array($varValue[0])) { // Generate a HTML table for associative arrays $strBuffer = $this->generateTable($varValue, $objProduct); } elseif (is_array($varValue)) { // Generate ul/li listing for simple arrays foreach ($varValue as &$v) { $v = Format::dcaValue('tl_iso_product', $this->field_name, $v); } $strBuffer = $this->generateList($varValue); } else { $strBuffer = Format::dcaValue('tl_iso_product', $this->field_name, $varValue); } return $strBuffer; }
/** * Retrieve the array of notification data for parsing simple tokens * * @param int $intNotification * * @return array */ public function getNotificationTokens($intNotification) { /** @type \Isotope\Model\Config $objConfig */ $objConfig = $this->getRelated('config_id'); $arrTokens = deserialize($this->email_data, true); $arrTokens['uniqid'] = $this->uniqid; $arrTokens['order_status_id'] = $this->order_status; $arrTokens['order_status'] = $this->getStatusLabel(); $arrTokens['recipient_email'] = $this->getEmailRecipient(); $arrTokens['order_id'] = $this->id; $arrTokens['order_items'] = $this->sumItemsQuantity(); $arrTokens['order_products'] = $this->countItems(); $arrTokens['order_subtotal'] = Isotope::formatPriceWithCurrency($this->getSubtotal(), false); $arrTokens['order_total'] = Isotope::formatPriceWithCurrency($this->getTotal(), false); $arrTokens['document_number'] = $this->document_number; $arrTokens['cart_html'] = ''; $arrTokens['cart_text'] = ''; $arrTokens['document'] = ''; // Add all the collection fields foreach ($this->row() as $k => $v) { $arrTokens['collection_' . $k] = $v; } // Add billing/customer address fields if (($objAddress = $this->getBillingAddress()) !== null) { foreach ($objAddress->row() as $k => $v) { $arrTokens['billing_address_' . $k] = Format::dcaValue($objAddress->getTable(), $k, $v); // @deprecated (use ##billing_address_*##) $arrTokens['billing_' . $k] = $arrTokens['billing_address_' . $k]; } $arrTokens['billing_address'] = $objAddress->generate($objConfig->getBillingFieldsConfig()); // @deprecated (use ##billing_address##) $arrTokens['billing_address_text'] = $arrTokens['billing_address']; } // Add shipping address fields if (($objAddress = $this->getShippingAddress()) !== null) { foreach ($objAddress->row() as $k => $v) { $arrTokens['shipping_address_' . $k] = Format::dcaValue($objAddress->getTable(), $k, $v); // @deprecated (use ##billing_address_*##) $arrTokens['shipping_' . $k] = $arrTokens['shipping_address_' . $k]; } $arrTokens['shipping_address'] = $objAddress->generate($objConfig->getShippingFieldsConfig()); // Shipping address equals billing address // @deprecated (use ##shipping_address##) if ($objAddress->id == $this->getBillingAddress()->id) { $arrTokens['shipping_address_text'] = $this->requiresPayment() ? $GLOBALS['TL_LANG']['MSC']['useBillingAddress'] : $GLOBALS['TL_LANG']['MSC']['useCustomerAddress']; } else { $arrTokens['shipping_address_text'] = $arrTokens['shipping_address']; } } // Add payment method info if ($this->hasPayment() && ($objPayment = $this->getPaymentMethod()) !== null) { $arrTokens['payment_id'] = $objPayment->id; $arrTokens['payment_label'] = $objPayment->getLabel(); $arrTokens['payment_note'] = $objPayment->note; } // Add shipping method info if ($this->hasShipping() && ($objShipping = $this->getShippingMethod()) !== null) { $arrTokens['shipping_id'] = $objShipping->id; $arrTokens['shipping_label'] = $objShipping->getLabel(); $arrTokens['shipping_note'] = $objShipping->note; } // Add config fields if ($this->getRelated('config_id') !== null) { foreach ($this->getRelated('config_id')->row() as $k => $v) { $arrTokens['config_' . $k] = Format::dcaValue($this->getRelated('config_id')->getTable(), $k, $v); } } // Add member fields if ($this->member > 0 && $this->getRelated('member') !== null) { foreach ($this->getRelated('member')->row() as $k => $v) { $arrTokens['member_' . $k] = Format::dcaValue($this->getRelated('member')->getTable(), $k, $v); } } if ($intNotification > 0 && ($objNotification = Notification::findByPk($intNotification)) !== null) { $objTemplate = new \Isotope\Template($objNotification->iso_collectionTpl); $objTemplate->isNotification = true; $this->addToTemplate($objTemplate, array('gallery' => $objNotification->iso_gallery, 'sorting' => $this->getItemsSortingCallable($objNotification->iso_orderCollectionBy))); $arrTokens['cart_html'] = Haste::getInstance()->call('replaceInsertTags', array($objTemplate->parse(), false)); $objTemplate->textOnly = true; $arrTokens['cart_text'] = strip_tags(Haste::getInstance()->call('replaceInsertTags', array($objTemplate->parse(), true))); // Generate and "attach" document /** @var \Isotope\Interfaces\IsotopeDocument $objDocument */ if ($objNotification->iso_document > 0 && ($objDocument = Document::findByPk($objNotification->iso_document)) !== null) { $strFilePath = $objDocument->outputToFile($this, TL_ROOT . '/system/tmp'); $arrTokens['document'] = str_replace(TL_ROOT . '/', '', $strFilePath); } } // !HOOK: add custom email tokens if (isset($GLOBALS['ISO_HOOKS']['getOrderNotificationTokens']) && is_array($GLOBALS['ISO_HOOKS']['getOrderNotificationTokens'])) { foreach ($GLOBALS['ISO_HOOKS']['getOrderNotificationTokens'] as $callback) { $objCallback = \System::importStatic($callback[0]); $arrTokens = $objCallback->{$callback}[1]($this, $arrTokens); } } return $arrTokens; }
/** * Format product configuration using \Haste\Data * * @param array $arrConfig * @param IsotopeProduct|Product $objProduct * * @return array */ public static function formatProductConfiguration(array $arrConfig, IsotopeProduct $objProduct) { Product::setActive($objProduct); $strTable = $objProduct->getTable(); foreach ($arrConfig as $k => $v) { /** @type \Isotope\Model\Attribute $objAttribute */ if (($objAttribute = $GLOBALS['TL_DCA'][$strTable]['attributes'][$k]) !== null && $objAttribute instanceof IsotopeAttributeWithOptions) { /** @type \Widget $strClass */ $strClass = $objAttribute->getFrontendWidget(); $arrField = $strClass::getAttributesFromDca($GLOBALS['TL_DCA'][$strTable]['fields'][$k], $k, $v, $k, $strTable, $objProduct); $arrOptions = array(); $values = $v; if (!empty($arrField['options']) && is_array($arrField['options'])) { if (!is_array($values)) { $values = array($values); } $arrOptions = array_filter($arrField['options'], function (&$option) use(&$values) { if (($pos = array_search($option['value'], $values)) !== false) { $option = $option['label']; unset($values[$pos]); return true; } return false; }); if (!empty($values)) { $arrOptions = array_merge($arrOptions, $values); } } $formatted = implode(', ', $arrOptions); } else { $formatted = Format::dcaValue($strTable, $k, $v); } $arrConfig[$k] = new Plain($v, Format::dcaLabel($strTable, $k), array('formatted' => Haste::getInstance()->call('replaceInsertTags', array($formatted)))); } Product::unsetActive(); return $arrConfig; }
/** * Compile the list of hCard tokens for this address * * @param array $arrFields * * @return array */ public function getTokens($arrFields = null) { global $objPage; if (!is_array($arrFields)) { $arrFields = Isotope::getConfig()->getBillingFieldsConfig(); } $arrTokens = array('outputFormat' => $objPage->outputFormat); foreach ($arrFields as $arrField) { $strField = $arrField['value']; // Set an empty value for disabled fields, otherwise the token would not be replaced if (!$arrField['enabled']) { $arrTokens[$strField] = ''; continue; } if ($strField == 'subdivision' && $this->subdivision != '') { $arrSubdivisions = \Isotope\Backend::getSubdivisions(); list($country, $subdivion) = explode('-', $this->subdivision); $arrTokens['subdivision'] = $arrSubdivisions[strtolower($country)][$this->subdivision]; $arrTokens['subdivision_abbr'] = $subdivion; continue; } $arrTokens[$strField] = Format::dcaValue(static::$strTable, $strField, $this->{$strField}); } /** * Generate hCard fields * See http://microformats.org/wiki/hcard */ // Set "fn" (full name) to company if no first- and lastname is given if ($arrTokens['company'] != '') { $fn = $arrTokens['company']; $fnCompany = ' fn'; } else { $fn = trim($arrTokens['firstname'] . ' ' . $arrTokens['lastname']); $fnCompany = ''; } $street = implode($objPage->outputFormat == 'html' ? '<br>' : '<br />', array_filter(array($this->street_1, $this->street_2, $this->street_3))); $arrTokens += array('hcard_fn' => $fn ? '<span class="fn">' . $fn . '</span>' : '', 'hcard_n' => $arrTokens['firstname'] || $arrTokens['lastname'] ? '1' : '', 'hcard_honorific_prefix' => $arrTokens['salutation'] ? '<span class="honorific-prefix">' . $arrTokens['salutation'] . '</span>' : '', 'hcard_given_name' => $arrTokens['firstname'] ? '<span class="given-name">' . $arrTokens['firstname'] . '</span>' : '', 'hcard_family_name' => $arrTokens['lastname'] ? '<span class="family-name">' . $arrTokens['lastname'] . '</span>' : '', 'hcard_org' => $arrTokens['company'] ? '<div class="org' . $fnCompany . '">' . $arrTokens['company'] . '</div>' : '', 'hcard_email' => $arrTokens['email'] ? '<a href="mailto:' . $arrTokens['email'] . '">' . $arrTokens['email'] . '</a>' : '', 'hcard_tel' => $arrTokens['phone'] ? '<div class="tel">' . $arrTokens['phone'] . '</div>' : '', 'hcard_adr' => $street | $arrTokens['city'] || $arrTokens['postal'] || $arrTokens['subdivision'] || $arrTokens['country'] ? '1' : '', 'hcard_street_address' => $street ? '<div class="street-address">' . $street . '</div>' : '', 'hcard_locality' => $arrTokens['city'] ? '<span class="locality">' . $arrTokens['city'] . '</span>' : '', 'hcard_region' => $arrTokens['subdivision'] ? '<span class="region">' . $arrTokens['subdivision'] . '</span>' : '', 'hcard_region_abbr' => $arrTokens['subdivision_abbr'] ? '<abbr class="region" title="' . $arrTokens['subdivision'] . '">' . $arrTokens['subdivision_abbr'] . '</abbr>' : '', 'hcard_postal_code' => $arrTokens['postal'] ? '<span class="postal-code">' . $arrTokens['postal'] . '</span>' : '', 'hcard_country_name' => $arrTokens['country'] ? '<div class="country-name">' . $arrTokens['country'] . '</div>' : ''); return $arrTokens; }
public function generate(IsotopeProduct $objProduct, array $arrOptions = array()) { $varValue = $objProduct->{$this->field_name}; // Generate a HTML table for associative arrays if (is_array($varValue) && !array_is_assoc($varValue) && is_array($varValue[0])) { $strBuffer = $this->generateTable($varValue, $objProduct); } elseif (is_array($varValue)) { $strBuffer = $this->generateList($varValue); } else { $strBuffer = Format::dcaValue('tl_iso_product', $this->field_name, $varValue); } return $strBuffer; }
/** * Generate HTML markup of product data for this attribute * * @param IsotopeProduct $objProduct * @param array $arrOptions * * @return string */ public function generate(IsotopeProduct $objProduct, array $arrOptions = array()) { $varValue = $this->getValue($objProduct); if (!is_array($varValue)) { return Format::dcaValue('tl_iso_product', $this->field_name, $varValue); } // Generate a HTML table for associative arrays if (!array_is_assoc($varValue) && is_array($varValue[0])) { return $arrOptions['noHtml'] ? $varValue : $this->generateTable($varValue, $objProduct); } if ($arrOptions['noHtml']) { $result = array(); foreach ($varValue as $v) { $result[$v] = Format::dcaValue('tl_iso_product', $this->field_name, $v); } return $result; } // Generate ul/li listing for simple arrays foreach ($varValue as &$v) { $v = Format::dcaValue('tl_iso_product', $this->field_name, $v); } return $this->generateList($varValue); }
/** * Get rows * * @param \Database_Result $objRecords * * @return array */ public function getRows($objRecords) { if (!$objRecords->numRows) { return array(); } $arrRows = array(); $objRecords->reset(); while ($objRecords->next()) { $arrField = $objRecords->row(); foreach ($this->fields as $field) { $arrField[$field] = Format::dcaValue($this->foreignTable, $field, $objRecords->{$field}); } $arrRows[] = $arrField; } return $arrRows; }
/** * Generate address details amd return it as string * @param Address * @return string */ protected function generateAddressData(Address $objAddress = null) { if (null === $objAddress) { return '<div class="tl_gerror">No address data available.</div>'; } \System::loadLanguageFile($objAddress->getTable()); $this->loadDataContainer($objAddress->getTable()); $strBuffer = ' <div> <table cellpadding="0" cellspacing="0" class="tl_show" summary="Table lists all details of an entry" style="width:650px"> <tbody>'; $i = 0; foreach ($GLOBALS['TL_DCA'][$objAddress->getTable()]['fields'] as $k => $v) { if (!isset($objAddress->{$k})) { continue; } $v = $objAddress->{$k}; $strClass = ++$i % 2 ? '' : ' class="tl_bg"'; $strBuffer .= ' <tr> <td' . $strClass . ' style="vertical-align:top"><span class="tl_label">' . Format::dcaLabel($objAddress->getTable(), $k) . ': </span></td> <td' . $strClass . '>' . Format::dcaValue($objAddress->getTable(), $k, $v) . '</td> </tr>'; } $strBuffer .= ' </tbody></table> </div>'; return $strBuffer; }
/** * Format options label and value * * @param array $arrData * @param string $strTable * @param bool $blnSkipEmpty * * @return array */ public static function formatOptions(array $arrData, $strTable = 'tl_iso_product', $blnSkipEmpty = true) { $arrOptions = array(); foreach ($arrData as $field => $value) { if ($blnSkipEmpty && ($value == '' || $value == '-')) { continue; } $arrOptions[$field] = array('label' => Format::dcaLabel($strTable, $field), 'value' => Haste::getInstance()->call('replaceInsertTags', Format::dcaValue($strTable, $field, $value))); } return $arrOptions; }
/** * Export the file * @param object * @param boolean * @param boolean */ protected function exportFile(\Haste\IO\Writer\WriterInterface $objWriter, $blnHeaderFields, $blnRawData) { $objMembers = \MemberModel::findAll(); // Reload if there are no members if ($objMembers === null) { $this->reload(); } $objReader = new \Haste\IO\Reader\ModelCollectionReader($objMembers); // Set header fields if ($blnHeaderFields) { $arrHeaderFields = array(); foreach ($GLOBALS['TL_DCA']['tl_member']['fields'] as $strField => $arrField) { $arrHeaderFields[] = $blnRawData || !$arrField['label'][0] ? $strField : $arrField['label'][0]; } $objReader->setHeaderFields($arrHeaderFields); $objWriter->enableHeaderFields(); } // Format the values if (!$blnRawData) { $objWriter->setRowCallback(function ($arrRow) { foreach ($arrRow as $k => $v) { $arrRow[$k] = \Haste\Util\Format::dcaValue('tl_member', $k, $v); } return $arrRow; }); } $objWriter->writeFrom($objReader); $objFile = new \File($objWriter->getFilename()); $objFile->sendToBrowser(); }