Esempio n. 1
0
 /**
  * Returns the frontend filter widget information for the filter setting.
  *
  * The returning array will hold the following keys:
  * * class      - The CSS classes for the widget.
  * * label      - The label text for the widget.
  * * formfield  - The parsed default widget object for this filter setting.
  * * raw        - The widget information that was used for rendering "formfield" as raw array (this means
  *                prior calling prepareForWidget()).
  * * urlparam   - The URL parameter used for this widget.
  * * options    - The filter options available to be used in selects etc. see prepareFrontendFilterOptions
  *                for details on the contained array.
  * * autosubmit - True if the frontend filter shall perform auto form submitting, false otherwise.
  * * urlvalue   - The current value selected in the filtersetting. Will use "urlvalue" from $arrWidget with
  *                fallback to the value of the url param in the filter url.
  *
  * @param array                 $arrWidget                The widget information to use for generating.
  *
  * @param array                 $arrFilterUrl             The filter url parameters to use.
  *
  * @param array                 $arrJumpTo                The jumpTo page to use for URL generating - if empty, the
  *                                                        current frontend page will get used.
  *
  * @param FrontendFilterOptions $objFrontendFilterOptions The options to use.
  *
  * @return array
  *
  * @SuppressWarnings(PHPMD.Superglobals)
  * @SuppressWarnings(PHPMD.CamelCaseVariableName)
  */
 protected function prepareFrontendFilterWidget($arrWidget, $arrFilterUrl, $arrJumpTo, FrontendFilterOptions $objFrontendFilterOptions)
 {
     $strClass = $GLOBALS['TL_FFL'][$arrWidget['inputType']];
     // No widget? no output! that's it.
     if (!$strClass) {
         return array();
     }
     // Determine current value.
     $arrWidget['value'] = isset($arrFilterUrl[$arrWidget['eval']['urlparam']]) ? $arrFilterUrl[$arrWidget['eval']['urlparam']] : null;
     $dispatcher = $this->getEventDispatcher();
     $event = new GetAttributesFromDcaEvent($arrWidget, $arrWidget['eval']['urlparam']);
     $dispatcher->dispatch(ContaoEvents::WIDGET_GET_ATTRIBUTES_FROM_DCA, $event);
     if ($objFrontendFilterOptions->isAutoSubmit() && TL_MODE == 'FE') {
         $GLOBALS['TL_JAVASCRIPT']['metamodels'] = 'system/modules/metamodels/assets/js/metamodels.js';
     }
     /** @var \Widget $objWidget */
     $objWidget = new $strClass($event->getResult());
     $this->validateWidget($objWidget, $arrWidget['value']);
     $strField = $objWidget->generateWithError();
     return array('class' => sprintf('mm_%s %s%s%s', $arrWidget['inputType'], $arrWidget['eval']['urlparam'], $arrWidget['value'] !== null ? ' used' : ' unused', $objFrontendFilterOptions->isAutoSubmit() ? ' submitonchange' : ''), 'label' => $objWidget->generateLabel(), 'formfield' => $strField, 'raw' => $arrWidget, 'urlparam' => $arrWidget['eval']['urlparam'], 'options' => $this->prepareFrontendFilterOptions($arrWidget, $arrFilterUrl, $arrJumpTo, $objFrontendFilterOptions->isAutoSubmit()), 'count' => isset($arrWidget['count']) ? $arrWidget['count'] : null, 'showCount' => $objFrontendFilterOptions->isShowCountValues(), 'autosubmit' => $objFrontendFilterOptions->isAutoSubmit(), 'urlvalue' => array_key_exists('urlvalue', $arrWidget) ? $arrWidget['urlvalue'] : $arrWidget['value'], 'errors' => $objWidget->hasErrors() ? $objWidget->getErrors() : array());
 }
Esempio n. 2
0
 /**
  * Get the frontend filter options to use.
  *
  * @return FrontendFilterOptions
  */
 protected function getFrontendFilterOptions()
 {
     $objFrontendFilterOptions = new FrontendFilterOptions();
     $objFrontendFilterOptions->setAutoSubmit($this->objFilterConfig->metamodel_fef_autosubmit ? true : false);
     $objFrontendFilterOptions->setHideClearFilter($this->objFilterConfig->metamodel_fef_hideclearfilter ? true : false);
     $objFrontendFilterOptions->setShowCountValues($this->objFilterConfig->metamodel_available_values ? true : false);
     return $objFrontendFilterOptions;
 }
Esempio n. 3
0
 /**
  * {@inheritdoc}
  *
  * @SuppressWarnings(PHPMD.Superglobals)
  * @SuppressWarnings(PHPMD.CamelCaseVariableName)
  */
 public function getParameterFilterWidgets($arrIds, $arrFilterUrl, $arrJumpTo, FrontendFilterOptions $objFrontendFilterOptions, $arrCustom = array())
 {
     /* $arrCustom array with settings which makes the function more flexible to use in template
            the following keys can be set: objAttribute, forceToUseArrIds, strParamName, 
            [Widget > eval: includeBlankOption, onlyused, onlypossible, template] (only eval for now)
        */
     $strParam = !isset($arrCustom['strParamName']) ? $this->getParamName() : $arrCustom['strParamName'];
     $forceToUseArrIds = !isset($arrCustom['forceToUseArrIds']) ? false : $arrCustom['forceToUseArrIds'];
     // If defined as static, return nothing as not to be manipulated via editors.
     if (!$this->enableFEFilterWidget()) {
         return array();
     }
     $objAttribute = !isset($arrCustom['objAttribute']) ? $this->getMetaModel()->getAttributeById($this->get('attr_id')) : $arrCustom['objAttribute'];
     if (!$objAttribute) {
         return array();
     }
     $GLOBALS['MM_FILTER_PARAMS'][] = $strParam;
     $arrCount = array();
     $arrWidget = array('label' => array($this->get('label') ? $this->get('label') : $objAttribute->getName(), 'GET: ' . $strParam), 'inputType' => 'select', 'options' => $this->getParameterFilterOptions($objAttribute, $arrIds, $arrCount, $forceToUseArrIds), 'count' => $arrCount, 'showCount' => $objFrontendFilterOptions->isShowCountValues(), 'eval' => array('includeBlankOption' => $this->get('blankoption') && !$objFrontendFilterOptions->isHideClearFilter() ? true : false, 'blankOptionLabel' => &$GLOBALS['TL_LANG']['metamodels_frontendfilter']['do_not_filter'], 'colname' => $objAttribute->getColname(), 'urlparam' => $strParam, 'onlyused' => $this->get('onlyused'), 'onlypossible' => $this->get('onlypossible'), 'template' => $this->get('template')));
     if (isset($arrCustom['Widget']['eval']) && is_array($arrCustom['Widget']['eval'])) {
         $arrWidget['eval'] = array_merge($arrWidget['eval'], $arrCustom['Widget']['eval']);
     }
     return array($strParam => $this->prepareFrontendFilterWidget($arrWidget, $arrFilterUrl, $arrJumpTo, $objFrontendFilterOptions));
 }
Esempio n. 4
0
 /**
  * {@inheritdoc}
  *
  * @SuppressWarnings(PHPMD.Superglobals)
  * @SuppressWarnings(PHPMD.CamelCaseVariableName)
  */
 public function getParameterFilterWidgets($arrIds, $arrFilterUrl, $arrJumpTo, FrontendFilterOptions $objFrontendFilterOptions)
 {
     // If defined as static, return nothing as not to be manipulated via editors.
     if (!$this->enableFEFilterWidget()) {
         return array();
     }
     $objAttribute = $this->getMetaModel()->getAttributeById($this->get('attr_id'));
     if (!$objAttribute) {
         return array();
     }
     $GLOBALS['MM_FILTER_PARAMS'][] = $this->getParamName();
     $arrCount = array();
     $arrWidget = array('label' => array($this->get('label') ? $this->get('label') : $objAttribute->getName(), 'GET: ' . $this->getParamName()), 'inputType' => 'select', 'options' => $this->getParameterFilterOptions($objAttribute, $arrIds, $arrCount), 'count' => $arrCount, 'showCount' => $objFrontendFilterOptions->isShowCountValues(), 'eval' => array('includeBlankOption' => $this->get('blankoption') && !$objFrontendFilterOptions->isHideClearFilter() ? true : false, 'blankOptionLabel' => &$GLOBALS['TL_LANG']['metamodels_frontendfilter']['do_not_filter'], 'colname' => $objAttribute->getColname(), 'urlparam' => $this->getParamName(), 'onlyused' => $this->get('onlyused'), 'onlypossible' => $this->get('onlypossible'), 'template' => $this->get('template')));
     return array($this->getParamName() => $this->prepareFrontendFilterWidget($arrWidget, $arrFilterUrl, $arrJumpTo, $objFrontendFilterOptions));
 }
Esempio n. 5
0
 /**
  * {@inheritdoc}
  */
 public function getParameterFilterWidgets($arrIds, $arrFilterUrl, $arrJumpTo, FrontendFilterOptions $objFrontendFilterOptions)
 {
     // If defined as static, return nothing as not to be manipulated via editors.
     if (!$this->enableFEFilterWidget()) {
         return array();
     }
     if (!($attribute = $this->getFilteredAttribute())) {
         return array();
     }
     $arrReturn = array();
     $this->addFilterParam($this->getParamName());
     // Text search.
     $arrCount = array();
     $arrWidget = array('label' => array($this->getLabel(), 'GET: ' . $this->getParamName()), 'inputType' => 'text', 'count' => $arrCount, 'showCount' => $objFrontendFilterOptions->isShowCountValues(), 'eval' => array('colname' => $attribute->getColname(), 'urlparam' => $this->getParamName(), 'template' => $this->get('template'), 'placeholder' => $this->get('placeholder')));
     // Add filter.
     $arrReturn[$this->getParamName()] = $this->prepareFrontendFilterWidget($arrWidget, $arrFilterUrl, $arrJumpTo, $objFrontendFilterOptions);
     return $arrReturn;
 }
 /**
  * Get the widget information for the search field.
  *
  * @param FrontendFilterOptions $objFrontendFilterOptions The FE options.
  *
  * @return array
  */
 private function getSearchWidget(FrontendFilterOptions $objFrontendFilterOptions)
 {
     $arrCount = array();
     $arrWidget = array('label' => array($this->get('label') ? $this->get('label') : $this->getAttributeName(), 'GET: ' . $this->getParamName()), 'inputType' => 'text', 'count' => $arrCount, 'showCount' => $objFrontendFilterOptions->isShowCountValues(), 'eval' => array('colname' => $this->getColname(), 'urlparam' => $this->getParamName(), 'template' => $this->get('template')));
     return $arrWidget;
 }