Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * Created by e-spin Berlin.
- * User: Ingolf Steinhardt <info@e-spin.de>
- * Date: 17.01.2019
- * Time: 17:11
- */
- namespace AppBundle\Forms;
- use MetaModels\Filter\Rules\SearchAttribute;
- use MetaModels\IFactory;
- use MetaModels\Item;
- /**
- * Class MmForms
- *
- * Load after 'notification_center'.
- */
- class MmForms
- {
- /**
- * MmForms constructor.
- *
- * @param IFactory $factory
- */
- public function __construct(IFactory $factory)
- {
- $this->factory = $factory;
- }
- /**
- * @param $arrPost
- * @param $arrForm
- * @param $arrFiles
- * @param $arrLabels
- * @param $objForm
- */
- public function onProcessFormData($arrPost, $arrForm, $arrFiles, $arrLabels, $objForm)
- {
- // Constraint at form 'GJB - Stammdaten Gastro ' with id 13.
- if ('13' === $arrForm['id']) {
- // Debug.
- if (function_exists('dump')) {
- //dump($arrPost, $arrForm, $arrFiles, $arrLabels, $objForm);die();
- }
- // Only if user logged in.
- if (!FE_USER_LOGGED_IN) {
- $objForm->reload();
- }
- $member = \FrontendUser::getInstance();
- $memberId = $member->id;
- // Get MetaModel and retrieve items.
- $model = $this->factory->getMetaModel('mm_gastro');
- $filter = $model->getEmptyFilter();
- $filter->addFilterRule(new SearchAttribute($model->getAttribute('member_id'), $memberId, $model->getAvailableLanguages()));
- $item = $model->findByFilter($filter);
- // Check if new or update
- $statusNew = true;
- if (empty($item->getCount())) {
- $item = new Item($model, []);
- } else {
- $statusNew = false;
- }
- // get new one
- if ($statusNew) {
- // Set attribute name and firstname
- }
- // Save form values.
- // Simple attributes.
- $item->set('company_name', $arrPost['company_name']);
- $item->set('alias', \StringUtil::generateAlias($arrPost['company_name']));
- $item->set('street', $arrPost['street']);
- $item->set('plz', $arrPost['plz']);
- $item->set('city', $arrPost['city']);
- $country = $model->getAttribute('country');
- $item->set('country', $country->widgetToValue($arrPost['country'], 0));
- $item->set('website', $arrPost['website']);
- $item->set('email', $arrPost['email']);
- $item->set('phone', $arrPost['phone']);
- $item->set('fax', $arrPost['fax']);
- $item->set('slogan', $arrPost['slogan']);
- $item->set('description', $arrPost['description']);
- // Invoice
- $item->set('invoice_address', $arrPost['invoice_address']);
- $item->set('invoice_street', $arrPost['invoice_address'] ? $arrPost['invoice_street'] : $arrPost['street']);
- $item->set('invoice_zip', $arrPost['invoice_address'] ? $arrPost['invoice_zip'] : $arrPost['zip']);
- $item->set('invoice_city', $arrPost['invoice_address'] ? $arrPost['invoice_city'] : $arrPost['city']);
- $item->set('invoice_country', $arrPost['invoice_address'] ? $country->widgetToValue($arrPost['invoice_country'], 0) : $country->widgetToValue($arrPost['country'], 0));
- // Files.
- /*
- if ($arrFiles['abstract_file']['uuid']) {
- $objAttrImage = $objMetaModelPres->getAttribute('abstract_file');
- $objItemPres->set('abstract_file', $objAttrImage->widgetToValue($arrFiles['abstract_file']['uuid'], 0));
- }
- */
- // Save.
- $item->save();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement