Ejemplo n.º 1
0
    /**
     * Return a select menu to limit results
     * @param boolean
     * @return string
     */
    protected function limitMenu($blnOptional = false)
    {
        $session = $this->Session->getData();
        $filter = \Input::get('id') ? $this->strTable . '_' . CURRENT_ID : $this->strTable;
        $fields = '';
        // Set limit from user input
        if (\Input::post('FORM_SUBMIT') == 'tl_filters' || \Input::post('FORM_SUBMIT') == 'tl_filters_limit') {
            $strLimit = \Input::post('tl_limit');
            if ($strLimit == 'tl_limit') {
                unset($session['filter'][$filter]['limit']);
            } else {
                // Validate the user input (thanks to aulmn) (see #4971)
                if ($strLimit == 'all' || preg_match('/^[0-9]+,[0-9]+$/', $strLimit)) {
                    $session['filter'][$filter]['limit'] = $strLimit;
                }
            }
            $this->Session->setData($session);
            if (\Input::post('FORM_SUBMIT') == 'tl_filters_limit') {
                \Controller::reload();
            }
        } else {
            $this->limit = $session['filter'][$filter]['limit'] != '' ? $session['filter'][$filter]['limit'] == 'all' ? null : $session['filter'][$filter]['limit'] : '0,' . $GLOBALS['TL_CONFIG']['resultsPerPage'];
            $query = "SELECT COUNT(*) AS count FROM " . $this->strTable;
            if (\Input::get('id')) {
                $this->procedure[] = "pid=?";
                $this->values[] = \Input::get('id');
            } else {
                $this->procedure[] = "pid=0";
            }
            if (!empty($this->root) && is_array($this->root)) {
                $this->procedure[] = 'id IN(' . implode(',', $this->root) . ')';
            }
            if (!empty($this->procedure)) {
                $query .= " WHERE " . implode(' AND ', $this->procedure);
            }
            $objTotal = $this->Database->prepare($query)->execute($this->values);
            $total = $objTotal->count;
            $options_total = 0;
            $blnIsMaxResultsPerPage = false;
            // Overall limit
            if ($total > $GLOBALS['TL_CONFIG']['maxResultsPerPage'] && ($this->limit === null || preg_replace('/^.*,/', '', $this->limit) == $GLOBALS['TL_CONFIG']['maxResultsPerPage'])) {
                if ($this->limit === null) {
                    $this->limit = '0,' . $GLOBALS['TL_CONFIG']['maxResultsPerPage'];
                }
                $blnIsMaxResultsPerPage = true;
                $GLOBALS['TL_CONFIG']['resultsPerPage'] = $GLOBALS['TL_CONFIG']['maxResultsPerPage'];
                $session['filter'][$filter]['limit'] = $GLOBALS['TL_CONFIG']['maxResultsPerPage'];
            }
            $options = '';
            // Build options
            if ($total > 0) {
                $options = '';
                $options_total = ceil($total / $GLOBALS['TL_CONFIG']['resultsPerPage']);
                // Reset limit if other parameters have decreased the number of results
                if ($this->limit !== null && ($this->limit == '' || preg_replace('/,.*$/', '', $this->limit) > $total)) {
                    $this->limit = '0,' . $GLOBALS['TL_CONFIG']['resultsPerPage'];
                }
                // Build options
                for ($i = 0; $i < $options_total; $i++) {
                    $this_limit = $i * $GLOBALS['TL_CONFIG']['resultsPerPage'] . ',' . $GLOBALS['TL_CONFIG']['resultsPerPage'];
                    $upper_limit = $i * $GLOBALS['TL_CONFIG']['resultsPerPage'] + $GLOBALS['TL_CONFIG']['resultsPerPage'];
                    if ($upper_limit > $total) {
                        $upper_limit = $total;
                    }
                    $options .= '
  <option value="' . $this_limit . '"' . \Widget::optionSelected($this->limit, $this_limit) . '>' . ($i * $GLOBALS['TL_CONFIG']['resultsPerPage'] + 1) . ' - ' . $upper_limit . '</option>';
                }
                if (!$blnIsMaxResultsPerPage) {
                    $options .= '
  <option value="all"' . \Widget::optionSelected($this->limit, null) . '>' . $GLOBALS['TL_LANG']['MSC']['filterAll'] . '</option>';
                }
            }
            // Return if there is only one page
            if ($blnOptional && ($total < 1 || $options_total < 2)) {
                return '';
            }
            $fields = '
<select name="tl_limit" class="tl_select' . ($session['filter'][$filter]['limit'] != 'all' && $total > $GLOBALS['TL_CONFIG']['resultsPerPage'] ? ' active' : '') . '" onchange="this.form.submit()">
  <option value="tl_limit">' . $GLOBALS['TL_LANG']['MSC']['filterRecords'] . '</option>' . $options . '
</select> ';
        }
        return '

<div class="tl_limit tl_subpanel">
<strong>' . $GLOBALS['TL_LANG']['MSC']['showOnly'] . ':</strong> ' . $fields . '
</div>';
    }
Ejemplo n.º 2
0
 /**
  * Return a "selected" attribute if the option is selected
  *
  * @param string $strOption The option to check
  * @param mixed  $varValues One or more values to check against
  *
  * @return string The attribute or an empty string
  *
  * @deprecated Use Widget::optionSelected() instead
  */
 public static function optionSelected($strOption, $varValues)
 {
     return \Widget::optionSelected($strOption, $varValues);
 }
Ejemplo n.º 3
0
 /**
  * Only check against the unit values (see #7246)
  *
  * @param array $arrOption The options array
  *
  * @return string The "selected" attribute or an empty string
  */
 protected function isSelected($arrOption)
 {
     if (empty($this->varValue) && empty($_POST) && $arrOption['default']) {
         return parent::optionSelected(1, 1);
     }
     if (empty($this->varValue) || !is_array($this->varValue)) {
         return '';
     }
     return parent::optionSelected($arrOption['value'], $this->varValue['unit']);
 }
Ejemplo n.º 4
0
    /**
     * Return a select menu to limit results
     * @param boolean
     * @return string
     */
    protected function limitMenu($blnOptional = false)
    {
        $session = $this->Session->getData();
        $filter = $GLOBALS['TL_DCA'][$this->strTable]['list']['sorting']['mode'] == 4 ? $this->strTable . '_' . CURRENT_ID : strlen($this->strFormKey) ? $this->strFormKey : $this->strTable;
        $fields = '';
        if (is_array($this->procedure)) {
            $this->procedure = array_unique($this->procedure);
        }
        if (is_array($this->values)) {
            $this->values = array_unique($this->values);
        }
        // Set limit from user input
        if (\Input::post('FORM_SUBMIT') == 'tl_filters' || \Input::post('FORM_SUBMIT') == 'tl_filters_limit') {
            if (\Input::post('tl_limit') != 'tl_limit') {
                $session['filter'][$filter]['limit'] = \Input::post('tl_limit');
            } else {
                unset($session['filter'][$filter]['limit']);
            }
            $this->Session->setData($session);
            if (\Input::post('FORM_SUBMIT') == 'tl_filters_limit') {
                \Controller::reload();
            }
        } else {
            $this->limit = strlen($session['filter'][$filter]['limit']) ? $session['filter'][$filter]['limit'] == 'all' ? null : $session['filter'][$filter]['limit'] : '0,' . $GLOBALS['TL_CONFIG']['resultsPerPage'];
            $sqlQuery = '';
            $sqlSelect = '';
            $sqlDetailFields = '';
            $sqlWhere = '';
            if (!empty($this->procedure)) {
                $arrProcedure = $this->procedure;
                foreach ($arrProcedure as $kProc => $vProc) {
                    $arrParts = preg_split('/[\\s=><\\!]/si', $vProc);
                    $strProcField = $arrParts[0];
                    if (in_array($strProcField, $this->arrDetailFields)) {
                        $arrProcedure[$kProc] = "(SELECT value FROM tl_formdata_details WHERE ff_name='" . $strProcField . "' AND pid=f.id)=?";
                    }
                }
                $sqlWhere = " WHERE " . implode(' AND ', $arrProcedure);
            }
            $sqlSelect = "SELECT COUNT(*) AS count FROM " . $this->strTable . " f";
            $sqlQuery = $sqlSelect . $sqlWhere;
            $objTotal = \Database::getInstance()->prepare($sqlQuery)->execute($this->values);
            $total = $objTotal->count;
            $options_total = 0;
            $blnIsMaxResultsPerPage = false;
            // Overall limit
            if ($total > $GLOBALS['TL_CONFIG']['maxResultsPerPage'] && ($this->limit === null || preg_replace('/^.*,/', '', $this->limit) == $GLOBALS['TL_CONFIG']['maxResultsPerPage'])) {
                if ($this->limit === null) {
                    $this->limit = '0,' . $GLOBALS['TL_CONFIG']['maxResultsPerPage'];
                }
                $blnIsMaxResultsPerPage = true;
                $GLOBALS['TL_CONFIG']['resultsPerPage'] = $GLOBALS['TL_CONFIG']['maxResultsPerPage'];
                $session['filter'][$filter]['limit'] = $GLOBALS['TL_CONFIG']['maxResultsPerPage'];
            }
            $options = '';
            // Build options
            if ($total > 0) {
                $options = '';
                $options_total = ceil($total / $GLOBALS['TL_CONFIG']['resultsPerPage']);
                // Reset limit if other parameters have decreased the number of results
                if ($this->limit !== null && ($this->limit == '' || preg_replace('/,.*$/', '', $this->limit) > $total)) {
                    $this->limit = '0,' . $GLOBALS['TL_CONFIG']['resultsPerPage'];
                }
                // Build options
                for ($i = 0; $i < $options_total; $i++) {
                    $this_limit = $i * $GLOBALS['TL_CONFIG']['resultsPerPage'] . ',' . $GLOBALS['TL_CONFIG']['resultsPerPage'];
                    $upper_limit = $i * $GLOBALS['TL_CONFIG']['resultsPerPage'] + $GLOBALS['TL_CONFIG']['resultsPerPage'];
                    if ($upper_limit > $total) {
                        $upper_limit = $total;
                    }
                    $options .= '
  <option value="' . $this_limit . '"' . \Widget::optionSelected($this->limit, $this_limit) . '>' . ($i * $GLOBALS['TL_CONFIG']['resultsPerPage'] + 1) . ' - ' . $upper_limit . '</option>';
                }
                if (!$blnIsMaxResultsPerPage) {
                    $options .= '
  <option value="all"' . \Widget::optionSelected($this->limit, null) . '>' . $GLOBALS['TL_LANG']['MSC']['filterAll'] . '</option>';
                }
            }
            // Return if there is only one page
            if ($blnOptional && ($total < 1 || $options_total < 2)) {
                return '';
            }
            $fields = '
<select name="tl_limit" class="tl_select' . ($session['filter'][$filter]['limit'] != 'all' && $total > $GLOBALS['TL_CONFIG']['resultsPerPage'] ? ' active' : '') . '" onchange="this.form.submit()">
  <option value="tl_limit">' . $GLOBALS['TL_LANG']['MSC']['filterRecords'] . '</option>' . $options . '
</select> ';
        }
        return '

<div class="tl_limit tl_subpanel">
<strong>' . $GLOBALS['TL_LANG']['MSC']['showOnly'] . ':</strong> ' . $fields . '
</div>';
    }