public static function getJoinTablesAndConditions($intExporter) { $arrTables = array(); $objJoins = \HeimrichHannot\FieldPalette\FieldPaletteModel::findPublishedByPidAndTableAndField($intExporter, 'tl_exporter', 'joinTables'); while ($objJoins->next()) { $arrTables[] = array('table' => $objJoins->joinTable, 'condition' => $objJoins->joinCondition); } return $arrTables; }
public static function addSubscriptions(Order $objOrder, $arrTokens) { $strEmail = $objOrder->getBillingAddress()->email; $objAddress = $objOrder->getShippingAddress() ?: $objOrder->getBillingAddress(); $arrItems = $objOrder->getItems(); $objSession = \Session::getInstance(); if (!($intModule = $objSession->get('isotopeCheckoutModuleIdSubscriptions'))) { return true; } $objSession->remove('isotopeCheckoutModuleIdSubscriptions'); $objModule = \ModuleModel::findByPk($intModule); foreach ($arrItems as $item) { switch ($objModule->iso_direct_checkout_product_mode) { case 'product_type': $objFieldpalette = FieldPaletteModel::findBy('iso_direct_checkout_product_type', Standard::findAvailableByIdOrAlias($item->product_id)->type); break; default: $objFieldpalette = FieldPaletteModel::findBy('iso_direct_checkout_product', $item->product_id); break; } if ($objFieldpalette !== null && $objFieldpalette->iso_addSubscription) { if ($objFieldpalette->iso_subscriptionArchive && (!$objFieldpalette->iso_addSubscriptionCheckbox || \Input::post('subscribeToProduct_' . $item->product_id))) { $objSubscription = Subscription::findOneBy(array('email=?', 'pid=?', 'activation!=?', 'disable=?'), array($strEmail, $objFieldpalette->iso_subscriptionArchive, '', 1)); if (!$objSubscription) { $objSubscription = new Subscription(); } if ($objFieldpalette->iso_addActivation) { $strToken = md5(uniqid(mt_rand(), true)); $objSubscription->disable = true; $objSubscription->activation = $strToken; if (($objNotification = Notification::findByPk($objFieldpalette->iso_activationNotification)) !== null) { if ($objFieldpalette->iso_activationJumpTo && ($objPageRedirect = \PageModel::findByPk($objFieldpalette->iso_activationJumpTo)) !== null) { $arrTokens['link'] = \Environment::get('url') . '/' . \Controller::generateFrontendUrl($objPageRedirect->row()) . '?token=' . $strToken; } $objNotification->send($arrTokens, $GLOBALS['TL_LANGUAGE']); } } $arrAddressFields = \Config::get('iso_addressFields'); if ($arrAddressFields === null) { $arrAddressFields = serialize(array_keys(static::getIsotopeAddressFields())); } foreach (deserialize($arrAddressFields, true) as $strName) { $objSubscription->{$strName} = $objAddress->{$strName}; } $objSubscription->email = $strEmail; $objSubscription->pid = $objFieldpalette->iso_subscriptionArchive; $objSubscription->tstamp = $objSubscription->dateAdded = time(); $objSubscription->quantity = \Input::post('quantity'); $objSubscription->order_id = $objOrder->id; $objSubscription->save(); } } } return true; }
/** * 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 modifyFieldPalette() { if (($objFieldPalette = \HeimrichHannot\FieldPalette\FieldPaletteModel::findByPk(\Input::get('id'))) === null) { return; } $objModule = \ModuleModel::findByPk($objFieldPalette->pid); $arrDca =& $GLOBALS['TL_DCA']['tl_fieldpalette']; switch ($objModule->type) { case 'iso_direct_checkout': if (in_array('isotope_plus', \ModuleLoader::getActive())) { $arrDca['subpalettes']['iso_addSubscription'] = str_replace('iso_subscriptionArchive', 'iso_subscriptionArchive,iso_addSubscriptionCheckbox', $arrDca['subpalettes']['iso_addSubscription']); } // no break! // no break! case 'iso_checkout': if ($objFieldPalette->iso_addActivation) { $arrDca['subpalettes']['iso_addSubscription'] = str_replace('iso_addActivation', 'iso_addActivation,iso_activationNotification,iso_activationJumpTo', $arrDca['subpalettes']['iso_addSubscription']); } break; } }
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; }
protected function exportAfterSubmission() { $objExportConfigs = FieldPaletteModel::findPublishedByPidAndTableAndField($this->objModule->id, 'tl_module', 'formHybridExportConfigs'); if ($objExportConfigs !== null) { while ($objExportConfigs->next()) { $objConfig = ExporterModel::findByPk($objExportConfigs->formhybrid_formHybridExportConfigs_config); if ($objConfig !== null) { $objConfig->type = Exporter::TYPE_ITEM; $objConfig->linkedTable = $this->strTable; // prepare fields for exporter $arrExportFields = array(); foreach ($this->arrFields as $objWidget) { $arrData = $GLOBALS['TL_DCA'][$this->strTable]['fields'][$objWidget->name]; $arrExportFields[$objWidget->name] = array('raw' => $this->objActiveRecord->{$objWidget->name}, 'inputType' => $arrData['inputType'], 'formatted' => FormSubmission::prepareSpecialValueForPrint($this->objActiveRecord->{$objWidget->name}, $arrData, $this->strTable, $this)); if ($arrData['inputType'] != 'explanation') { $arrExportFields[$objWidget->name]['label'] = $this->dca['fields'][$objWidget->name]['label'][0] ?: $objWidget->name; } if ($objWidget->subName) { foreach ($this->arrSubFields[$objWidget->subName] as $objSubWidget) { $arrData = $GLOBALS['TL_DCA'][$this->strTable][$objSubWidget->name]; $arrExportFields[$objSubWidget->name] = array('raw' => $this->objActiveRecord->{$objSubWidget->name}, 'inputType' => $arrData['inputType'], 'formatted' => FormSubmission::prepareSpecialValueForPrint($this->objActiveRecord->{$objSubWidget->name}, $arrData, $this->strTable, $this)); if ($arrData['inputType'] != 'explanation') { $arrExportFields[$objSubWidget->name]['label'] = $this->dca['fields'][$objSubWidget->name]['label'][0] ?: $objSubWidget->name; } } } } $objExporter = ModuleExporter::export($objConfig, $this->objActiveRecord, $arrExportFields); if ($objExportConfigs->formhybrid_formHybridExportConfigs_entityField) { $objFile = FilesModel::findByPath($objExporter->getFileDir() . '/' . $objExporter->getFilename()); $this->objActiveRecord->{$objExportConfigs->formhybrid_formHybridExportConfigs_entityField} = $objFile->uuid; $this->objActiveRecord->save(); } } } } }
/** * @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(); } } } } }
public static function getParentTable($objModel, $intId) { if ($objModel->ptable == \Config::get('fieldpalette_table')) { $objModel = \HeimrichHannot\FieldPalette\FieldPaletteModel::findByPk($objModel->pid); if ($objModel === null) { throw new \Exception(sprintf($GLOBALS['TL_LANG']['ERR']['fieldPaletteNestedParentTableDoesNotExist'], $intId)); } return static::getParentTable($objModel, $intId); } return $objModel->ptable; }
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(); }
protected function prepareParameter($act) { $arrParameters = array('do' => $this->do, 'ptable' => $this->ptable, 'table' => $this->table, 'act' => $this->act, 'pid' => $this->pid, 'id' => $this->id, $this->fieldpaletteKey => $this->fieldpalette, 'popup' => $this->popup); $arrAllowed = array_keys($arrParameters); switch ($act) { case 'create': $arrAllowed = array('do', 'ptable', 'table', 'act', 'pid', 'fieldpalette', 'popup', 'popupReferer'); // nested fieldpalettes if ($this->ptable == \Config::get('fieldpalette_table') && ($objModel = FieldPaletteModel::findByPk($this->pid)) !== null) { $arrParameters['table'] = FieldPalette::getParentTable($objModel, $objModel->id); } break; case 'toggle': $arrAllowed = array('do', 'table', 'state', 'tid', 'id'); $arrParameters['id'] = $this->pid; break; case 'edit': $arrAllowed = array('do', 'table', 'act', 'id', 'popup', 'popupReferer'); break; case 'copy': $arrAllowed = array('do', 'table', 'act', 'id', 'popup', 'popupReferer'); break; case 'show': $arrAllowed = array('do', 'table', 'act', 'id', 'popup', 'popupReferer'); break; case 'delete': $arrAllowed = array('do', 'table', 'act', 'id'); break; } $arrParameters = array_intersect_key($arrParameters, array_flip($arrAllowed)); return $arrParameters; }