Exemplo n.º 1
0
 /**
  * Get the static instance.
  *
  * @static
  * @return MetaModelController
  */
 public static function getInstance()
 {
     if (self::$objInstance == null) {
         self::$objInstance = new self();
     }
     return self::$objInstance;
 }
Exemplo n.º 2
0
 protected function handleStandalone($arrDCA)
 {
     $objMetaModel = MetaModelFactory::byId($arrDCA['pid']);
     $strModuleName = 'metamodel_' . $objMetaModel->getTableName();
     $strTableCaption = $objMetaModel->getName();
     // determine image to use.
     if ($arrDCA['backendicon'] && file_exists(TL_ROOT . '/' . $arrDCA['backendicon'])) {
         $strIcon = MetaModelController::getImage(MetaModelController::urlEncode($arrDCA['backendicon']), 16, 16);
     } else {
         $strIcon = 'system/modules/metamodels/html/metamodels.png';
     }
     $strSection = trim($arrDCA['backendsection']) ? $arrDCA['backendsection'] : 'metamodels';
     $GLOBALS['BE_MOD'][$strSection][$strModuleName] = array('tables' => array($objMetaModel->getTableName()), 'icon' => $strIcon, 'callback' => 'MetaModelBackendModule');
     $arrCaption = array($strTableCaption);
     foreach (deserialize($arrDCA['backendcaption'], true) as $arrLangEntry) {
         if ($arrLangEntry['label'] != '' && $arrLangEntry['langcode'] == self::getUser()->language) {
             $arrCaption = array($arrLangEntry['label'], $arrLangEntry['description']);
         }
     }
     $GLOBALS['TL_LANG']['MOD'][$strModuleName] = $arrCaption;
 }
Exemplo n.º 3
0
 public function getBackendIcon($strBackendIcon)
 {
     // determine image to use.
     if ($strBackendIcon && file_exists(TL_ROOT . '/' . $strBackendIcon)) {
         return MetaModelController::getImage(MetaModelController::urlEncode($strBackendIcon), 16, 16);
     } else {
         return 'system/modules/metamodels/html/metamodels.png';
     }
 }
Exemplo n.º 4
0
 /**
  * Build the jumpTo link for use in templates.
  *
  * The returning array will hold the following keys:
  * * params - the url parameter (only if a valid filter setting could be determined).
  * * deep   - boolean true, if parameters are non empty, false otherwise.
  * * page   - id of the jumpTo page.
  * * url    - the complete generated url
  *
  * @param IMetaModelRenderSettings $objSettings The render settings to use.
  *
  * @return array
  */
 public function buildJumpToLink($objSettings)
 {
     if (!$objSettings) {
         return null;
     }
     // Get the right jumpto.
     $strDesiredLanguage = $this->getMetaModel()->getActiveLanguage();
     $strFallbackLanguage = $this->getMetaModel()->getFallbackLanguage();
     $intJumpTo = 0;
     $intFilterSettings = 0;
     foreach ((array) $objSettings->get('jumpTo') as $arrJumpTo) {
         // If either desired language or fallback, keep the result.
         if (!$this->getMetaModel()->isTranslated() || $arrJumpTo['langcode'] == $strDesiredLanguage || $arrJumpTo['langcode'] == $strFallbackLanguage) {
             $intJumpTo = $arrJumpTo['value'];
             $intFilterSettings = $arrJumpTo['filter'];
             // If the desired language, break. Otherwise try to get the desired one until all have been evaluated.
             if ($strDesiredLanguage == $arrJumpTo['langcode']) {
                 break;
             }
         }
     }
     // Apply jumpTo urls based upon the filter defined in the render settings.
     $objPage = MetaModelController::getPageDetails($intJumpTo);
     if (!$objPage) {
         return null;
     }
     $arrJumpTo = array();
     $strParams = '';
     if ($intFilterSettings) {
         $objFilterSettings = MetaModelFilterSettingsFactory::byId($intFilterSettings);
         $arrParams = $objFilterSettings->generateFilterUrlFrom($this, $objSettings);
         foreach ($arrParams as $strKey => $strValue) {
             if ($strKey == 'auto_item') {
                 $strParams = '/' . $strValue . $strParams;
             } else {
                 $strParams .= sprintf('/%s/%s', $strKey, $strValue);
             }
         }
         $arrJumpTo['params'] = $arrParams;
         $arrJumpTo['deep'] = strlen($strParams) > 0;
         if (isset($GLOBALS['TL_LANG']['MSC'][$this->getMetaModel()->getTableName()][$objSettings->get('id')]['details'])) {
             $arrJumpTo['label'] = $GLOBALS['TL_LANG']['MSC'][$this->getMetaModel()->getTableName()][$objSettings->get('id')]['details'];
         } elseif (isset($GLOBALS['TL_LANG']['MSC'][$this->getMetaModel()->getTableName()]['details'])) {
             $arrJumpTo['label'] = $GLOBALS['TL_LANG']['MSC'][$this->getMetaModel()->getTableName()]['details'];
         } else {
             $arrJumpTo['label'] = $GLOBALS['TL_LANG']['MSC']['details'];
         }
     }
     $arrJumpTo['page'] = $intJumpTo;
     $arrJumpTo['url'] = MetaModelController::generateFrontendUrl($objPage->row(), $strParams);
     return $arrJumpTo;
 }
Exemplo n.º 5
0
 /**
  * Makes all protected methods from class Controller callable publically.
  */
 public function __call($strMethod, $arrArgs)
 {
     return call_user_func_array(array(MetaModelController::getInstance(), $strMethod), $arrArgs);
 }
 /**
  * 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 bool  $blnAutoSubmit Determines if the generated options/widgets shall perform auto submitting
  *                             or not.
  *
  * @return array
  */
 protected function prepareFrontendFilterWidget($arrWidget, $arrFilterUrl, $arrJumpTo, MetaModelFrontendFilterOptions $objFrontendFilterOptions)
 {
     $strClass = $GLOBALS['TL_FFL'][$arrWidget['inputType']];
     // No widget? no output! that's it.
     if (!$strClass) {
         return array();
     }
     // Determine current value.
     $arrWidget['value'] = $arrFilterUrl[$arrWidget['eval']['urlparam']];
     $arrData = MetaModelController::getInstance()->prepareForWidget($arrWidget, $arrWidget['eval']['urlparam'], $arrWidget['value']);
     if ($objFrontendFilterOptions->isAutoSubmit() && TL_MODE == 'FE') {
         $GLOBALS['TL_JAVASCRIPT']['metamodels'] = 'system/modules/metamodels/html/metamodels.js';
     }
     /** @var Widget $objWidget */
     $objWidget = new $strClass($arrData);
     $strField = $objWidget->generate();
     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' => $arrWidget['count'], 'showCount' => $objFrontendFilterOptions->isShowCountValues(), 'autosubmit' => $objFrontendFilterOptions->isAutoSubmit(), 'urlvalue' => array_key_exists('urlvalue', $arrWidget) ? $arrWidget['urlvalue'] : $arrWidget['value']);
 }
 /**
  * Replace all insert tags in the query string.
  *
  * @param string $strSQL    SQL to parse
  *
  * @param array  $arrParams Query param stack
  *
  * @return string Parsed SQL
  */
 protected function parseInsertTags($strSQL, array &$arrParams)
 {
     return MetaModelController::getInstance()->replaceInsertTags($strSQL);
 }
Exemplo n.º 8
0
 /**
  * Process all folders and resolve to a valid file list.
  *
  * @return ToolboxFile
  */
 public function resolveFiles()
 {
     // Step 1.: fetch all files.
     $this->collectFiles();
     // TODO: check if downloading is allowed and send file to browser then
     // see https://github.com/MetaModels/attribute_file/issues/6
     if (!$this->getShowImages() && ($strFile = Input::getInstance()->get('file')) && in_array($strFile, $this->foundFiles)) {
         MetaModelController::getInstance()->sendFileToBrowser($strFile);
     }
     // Step 2.: Fetch all meta data for the found files.
     $this->parseMetafiles();
     // Step 3.: fetch additional information like modification time etc. and prepare the output buffer.
     $this->fetchAdditionalData();
     return $this;
 }