Advertisement
Guest User

Untitled

a guest
Jan 17th, 2019
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.82 KB | None | 0 0
  1. <?php
  2. /**
  3.  * Created by e-spin Berlin.
  4.  * User: Ingolf Steinhardt <info@e-spin.de>
  5.  * Date: 17.01.2019
  6.  * Time: 17:11
  7.  */
  8.  
  9. namespace AppBundle\Forms;
  10.  
  11. use MetaModels\Filter\Rules\SearchAttribute;
  12. use MetaModels\IFactory;
  13. use MetaModels\Item;
  14.  
  15. /**
  16.  * Class MmForms
  17.  *
  18.  * Load after 'notification_center'.
  19.  */
  20. class MmForms
  21. {
  22.     /**
  23.      * MmForms constructor.
  24.      *
  25.      * @param IFactory $factory
  26.      */
  27.     public function __construct(IFactory $factory)
  28.     {
  29.         $this->factory = $factory;
  30.     }
  31.  
  32.     /**
  33.      * @param $arrPost
  34.      * @param $arrForm
  35.      * @param $arrFiles
  36.      * @param $arrLabels
  37.      * @param $objForm
  38.      */
  39.     public function onProcessFormData($arrPost, $arrForm, $arrFiles, $arrLabels, $objForm)
  40.     {
  41.         // Constraint at form 'GJB - Stammdaten Gastro ' with id 13.
  42.         if ('13' === $arrForm['id']) {
  43.             // Debug.
  44.             if (function_exists('dump')) {
  45.                 //dump($arrPost, $arrForm, $arrFiles, $arrLabels, $objForm);die();
  46.             }
  47.  
  48.             // Only if user logged in.
  49.             if (!FE_USER_LOGGED_IN) {
  50.                 $objForm->reload();
  51.             }
  52.            
  53.             $member   = \FrontendUser::getInstance();
  54.             $memberId = $member->id;
  55.  
  56.             // Get MetaModel and retrieve items.
  57.             $model  = $this->factory->getMetaModel('mm_gastro');
  58.             $filter = $model->getEmptyFilter();
  59.             $filter->addFilterRule(new SearchAttribute($model->getAttribute('member_id'), $memberId, $model->getAvailableLanguages()));
  60.             $item   = $model->findByFilter($filter);
  61.  
  62.             // Check if new or update
  63.             $statusNew = true;
  64.             if (empty($item->getCount())) {
  65.                 $item = new Item($model, []);
  66.             } else {
  67.                 $statusNew = false;
  68.             }
  69.  
  70.             // get new one
  71.             if ($statusNew) {
  72.                 // Set attribute name and firstname
  73.             }
  74.  
  75.             // Save form values.
  76.             // Simple attributes.
  77.             $item->set('company_name', $arrPost['company_name']);
  78.             $item->set('alias', \StringUtil::generateAlias($arrPost['company_name']));
  79.             $item->set('street', $arrPost['street']);
  80.             $item->set('plz', $arrPost['plz']);
  81.             $item->set('city', $arrPost['city']);
  82.             $country = $model->getAttribute('country');
  83.             $item->set('country', $country->widgetToValue($arrPost['country'], 0));
  84.             $item->set('website', $arrPost['website']);
  85.             $item->set('email', $arrPost['email']);
  86.             $item->set('phone', $arrPost['phone']);
  87.             $item->set('fax', $arrPost['fax']);
  88.             $item->set('slogan', $arrPost['slogan']);
  89.             $item->set('description', $arrPost['description']);
  90.  
  91.             // Invoice
  92.             $item->set('invoice_address', $arrPost['invoice_address']);
  93.             $item->set('invoice_street', $arrPost['invoice_address'] ? $arrPost['invoice_street'] : $arrPost['street']);
  94.             $item->set('invoice_zip', $arrPost['invoice_address'] ? $arrPost['invoice_zip'] : $arrPost['zip']);
  95.             $item->set('invoice_city', $arrPost['invoice_address'] ? $arrPost['invoice_city'] : $arrPost['city']);
  96.             $item->set('invoice_country', $arrPost['invoice_address'] ? $country->widgetToValue($arrPost['invoice_country'], 0) : $country->widgetToValue($arrPost['country'], 0));
  97.  
  98.             // Files.
  99.             /*
  100.             if ($arrFiles['abstract_file']['uuid']) {
  101.                 $objAttrImage = $objMetaModelPres->getAttribute('abstract_file');
  102.                 $objItemPres->set('abstract_file', $objAttrImage->widgetToValue($arrFiles['abstract_file']['uuid'], 0));
  103.             }
  104.             */
  105.  
  106.             // Save.
  107.             $item->save();
  108.  
  109.         }
  110.     }
  111. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement