当前位置: 首页>>代码示例>>PHP>>正文


PHP Widget::optionSelected方法代码示例

本文整理汇总了PHP中Widget::optionSelected方法的典型用法代码示例。如果您正苦于以下问题:PHP Widget::optionSelected方法的具体用法?PHP Widget::optionSelected怎么用?PHP Widget::optionSelected使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Widget的用法示例。


在下文中一共展示了Widget::optionSelected方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: limitMenu

    /**
     * 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>';
    }
开发者ID:rpquadrat,项目名称:core,代码行数:92,代码来源:DC_ProductData.php

示例2: optionSelected

 /**
  * 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);
 }
开发者ID:StephenGWills,项目名称:sample-contao-app,代码行数:14,代码来源:Controller.php

示例3: isSelected

 /**
  * 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']);
 }
开发者ID:bytehead,项目名称:contao-core,代码行数:17,代码来源:TimePeriod.php

示例4: limitMenu

    /**
     * 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>';
    }
开发者ID:byteworks-ch,项目名称:contao-efg,代码行数:98,代码来源:DC_Formdata.php


注:本文中的Widget::optionSelected方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。