/** * Generate the widget and return it as string * * @return string */ public function generate() { $this->reviseTable(); $this->objModels = FieldPaletteModel::findByPidAndTableAndField($this->currentRecord, $this->strTable, $this->strName); $this->arrButtonDefaults = array('do' => \Input::get('do'), 'ptable' => $this->strTable, 'table' => \Config::get('fieldpalette_table'), 'pid' => $this->currentRecord, 'fieldpalette' => $this->strName, 'fieldpaletteKey' => FieldPalette::$strPaletteRequestKey, 'popup' => true, 'syncId' => 'ctrl_' . $this->strId, 'pfield' => $this->strId); $objT = new \FrontendTemplate($this->getViewTemplate('fieldpalette_wizard')); $objT->buttons = $this->generateGlobalButtons(); $objT->listView = $this->generateListView(); $objT->strId = $this->strId; $varValue = array(); if ($this->objModels !== null) { $varValue = $this->objModels->fetchEach('id'); } $objT->value = $varValue; $objT->strName = $this->strName; return $objT->parse(); }
public function modifyDC(&$arrDca = null) { // get the product switch ($this->iso_direct_checkout_product_mode) { case 'product_type': if (($objTypes = FieldPaletteModel::findByPidAndTableAndField($this->objModule->id, 'tl_module', 'iso_direct_checkout_product_types')) !== null) { while ($objTypes->next()) { $arrColumns = array('type=?'); $arrValues = array($objTypes->iso_direct_checkout_product_type); if ($this->iso_listingSortField) { $arrSorting = array($this->iso_listingSortField => $this->iso_listingSortDirection == 'DESC' ? Sort::descending() : Sort::ascending()); } else { $arrSorting = array(); } $objProducts = Product::findPublishedBy($arrColumns, $arrValues, array('sorting' => $arrSorting)); if ($objProducts->count() > 0) { $objProduct = $objProducts->current(); $this->arrProducts[] = array('product' => $objProduct, 'useQuantity' => $objTypes->iso_use_quantity); $this->addProductFields($objProduct, $objTypes->iso_use_quantity, $objTypes->iso_addSubscriptionCheckbox, $arrDca); } } } break; default: if (($objProducts = FieldPaletteModel::findByPidAndTableAndField($this->objModule->id, 'tl_module', 'iso_direct_checkout_products')) !== null) { while ($objProducts->next()) { $objProduct = Product::findByPk($objProducts->iso_direct_checkout_product); $this->arrProducts[] = array('product' => $objProduct, 'useQuantity' => $objProducts->iso_use_quantity); $this->addProductFields($objProduct, $objProducts->iso_use_quantity, $objProducts->iso_addSubscriptionCheckbox, $arrDca); } } break; } // add address fields \Controller::loadDataContainer('tl_iso_address'); \System::loadLanguageFile('tl_iso_address'); $arrAddressFields = deserialize(Config::findByPk($this->iso_config_id)->address_fields, true); // add billing address fields foreach ($arrAddressFields as $strName => $arrAddressField) { $arrData = $GLOBALS['TL_DCA']['tl_iso_address']['fields'][$strName]; if (!is_array($arrData) || $arrAddressField['billing'] == 'disabled') { continue; } $arrData['eval']['mandatory'] = $arrAddressField['billing'] == 'mandatory'; $this->arrBillingAddressFields[] = $strName; $this->addEditableField($strName, $arrData); } if ($this->iso_use_notes) { $this->addEditableField('notes', array('label' => &$GLOBALS['TL_LANG']['MSC']['iso_note'], 'exclude' => true, 'inputType' => 'textarea', 'eval' => array('tl_class' => 'clr w50'), 'sql' => "text NULL")); } $this->addEditableField('shippingaddress', array('label' => array($GLOBALS['TL_LANG']['MSC']['differentShippingAddress'], $GLOBALS['TL_LANG']['MSC']['differentShippingAddress']), 'inputType' => 'checkbox', 'eval' => array('submitOnChange' => true))); // add shipping address fields $arrShippingAddressFields = array(); foreach ($arrAddressFields as $strName => $arrAddressField) { $arrData = $GLOBALS['TL_DCA']['tl_iso_address']['fields'][$strName]; if (!is_array($arrData) || $arrAddressField['shipping'] == 'disabled') { continue; } $arrData['eval']['mandatory'] = $arrAddressField['shipping'] == 'mandatory'; $this->addEditableField('shippingaddress_' . $strName, $arrData); $arrShippingAddressFields[] = 'shippingaddress_' . $strName; } $this->dca['palettes']['__selector__'][] = 'shippingaddress'; $this->dca['subpalettes']['shippingaddress'] = implode(',', $arrShippingAddressFields); $this->arrShippingAddressFields = $arrShippingAddressFields; }
/** * @param $intPid int The id of the former parent record * @param $intNewId int the id of the new parent record just copied from the former record * @param $strTable string The parent table * @param $arrDcaFields array A dca array of fields */ public static function recursivelyCopyFieldPaletteRecords($intPid, $intNewId, $strTable, array $arrDcaFields) { foreach ($arrDcaFields as $strField => $arrData) { if ($arrData['inputType'] == 'fieldpalette') { if (isset($arrData['fieldpalette']['fields']) && !$arrData['eval']['doNotCopy']) { $objFieldPaletteRecords = FieldPaletteModel::findByPidAndTableAndField($intPid, $strTable, $strField); if ($objFieldPaletteRecords === null) { continue; } while ($objFieldPaletteRecords->next()) { $objFieldpalette = new FieldPaletteModel(); // get existing data except id $arrFieldData = $objFieldPaletteRecords->row(); unset($arrFieldData['id']); $objFieldpalette->setRow($arrFieldData); // set new data $objFieldpalette->tstamp = time(); $objFieldpalette->pid = $intNewId; $objFieldpalette->published = true; if (isset($arrData['eval']['fieldpalette']['copy_callback']) && is_array($arrData['eval']['fieldpalette']['copy_callback'])) { foreach ($arrData['eval']['fieldpalette']['copy_callback'] as $arrCallback) { if (is_array($arrCallback)) { \System::importStatic($arrCallback[0]); $arrCallback[0]::$arrCallback[1]($objFieldpalette, $intPid, $intNewId, $strTable, $arrData); } elseif (is_callable($arrCallback)) { $arrCallback($objFieldpalette, $intPid, $intNewId, $strTable, $arrData); } } } $objFieldpalette->save(); static::recursivelyCopyFieldPaletteRecords($objFieldPaletteRecords->id, $objFieldpalette->id, \Config::get('fieldpalette_table'), $arrData['fieldpalette']['fields']); } } } else { if ($strTable == \Config::get('fieldpalette_table')) { $objFieldPaletteRecords = FieldPaletteModel::findByPidAndTableAndField($intPid, $strTable, $strField); if ($objFieldPaletteRecords === null) { continue; } while ($objFieldPaletteRecords->next()) { $objFieldpalette = new FieldPaletteModel(); $objFieldpalette->setRow($objFieldPaletteRecords->row()); // set new data $objFieldpalette->tstamp = time(); $objFieldpalette->pid = $intNewId; $objFieldpalette->published = true; if (isset($arrData['eval']['fieldpalette']['copy_callback']) && is_array($arrData['eval']['fieldpalette']['copy_callback'])) { foreach ($arrData['eval']['fieldpalette']['copy_callback'] as $arrCallback) { if (is_array($arrCallback)) { \System::importStatic($arrCallback[0]); $arrCallback[0]::$arrCallback[1]($objFieldpalette, $intPid, $intNewId, $strTable, $arrData); } elseif (is_callable($arrCallback)) { $arrCallback($objFieldpalette, $intPid, $intNewId, $strTable, $arrData); } } } $objFieldpalette->save(); } } } } }
protected function doExport($objEntity = null, array $arrFields = array()) { switch ($this->type) { case Exporter::TYPE_ITEM: $arrMargins = deserialize($this->pdfMargins, true); if (count($arrMargins) > 0) { $objPdf = new PdfTemplate('A4', PdfTemplate::ORIENTATION_PORTRAIT, $arrMargins['left'], $arrMargins['right'], $arrMargins['top'], $arrMargins['bottom']); } else { $objPdf = new PdfTemplate(); } // template if ($this->pdfBackground) { $objPdf->addTemplatePdf(Files::getPathFromUuid($this->objConfig->pdfBackground)); } // fonts if (($objPdfFonts = FieldPaletteModel::findByPidAndTableAndField($this->objConfig->id, 'tl_exporter', 'pdfFonts')) !== null) { while ($objPdfFonts->next()) { switch ($objPdfFonts->exporter_pdfFonts_fontWeight) { case 'B': $strMethod = 'addBoldFont'; break; case 'I': $strMethod = 'addItalicFont'; break; case 'BI': $strMethod = 'addBoldItalicFont'; break; default: $strMethod = 'addRegularFont'; } $objPdf->{$strMethod}($objPdfFonts->exporter_pdfFonts_fontName, Files::getPathFromUuid($objPdfFonts->exporter_pdfFonts_file)); } } $objTemplate = new \FrontendTemplate($this->pdfTemplate ?: 'exporter_pdf_item_default'); $objTemplate->raw = $objEntity->row(); foreach ($objEntity->row() as $strName => $arrValue) { $objTemplate->{$strName} = $arrValue; } // skip fields $arrSkipFields = array_map(function ($val) { list($strTable, $strField) = explode('.', $val); return $strField; }, deserialize($this->skipFields, true)); foreach ($arrSkipFields as $strName) { unset($arrFields[$strName]); } // skip labels $arrSkipLabels = array_map(function ($val) { list($strTable, $strField) = explode('.', $val); return $strField; }, deserialize($this->skipLabels, true)); foreach ($arrSkipLabels as $strName) { unset($arrFields[$strName]['label']); } $objTemplate->fields = $arrFields; // css $arrCss = deserialize($this->pdfCss, true); $strCss = ''; if (!empty($arrCss)) { $strCss = implode('', array_map(function ($val) { return file_get_contents(Files::getPathFromUuid($val)); }, $arrCss)); } $objPdf->writeHtml($objTemplate->parse(), $strCss); return $objPdf; break; case Exporter::TYPE_LIST: break; } }
/** * Update the parent field with its tl_fieldpalette item ids * * @param DataContainer $dc * * @return bool */ public function updateParentField($objCurrentRecord, $intDelete = 0) { $strClass = \Model::getClassFromTable($objCurrentRecord->ptable); if (!class_exists($strClass)) { return false; } /** @var \Model $strClass */ $objParent = $strClass::findByPk($objCurrentRecord->pid); if ($objParent === null) { return false; } $objItems = \HeimrichHannot\FieldPalette\FieldPaletteModel::findByPidAndTableAndField($objCurrentRecord->pid, $objCurrentRecord->ptable, $objCurrentRecord->pfield); $varValue = array(); if ($objItems !== null) { $varValue = $objItems->fetchEach('id'); // ondelete_callback support if ($intDelete > 0 && ($key = array_search($intDelete, $varValue)) !== false) { unset($varValue[$key]); } } if (empty($varValue)) { \Controller::loadDataContainer($objCurrentRecord->ptable); $arrData = $GLOBALS['TL_DCA'][$objCurrentRecord->ptable]['fields'][$objCurrentRecord->pfield]; if (isset($arrData['sql'])) { $varValue = \Widget::getEmptyValueByFieldType($arrData['sql']); } } $objParent->{$objCurrentRecord->pfield} = $varValue; $objParent->save(); }