Ejemplo n.º 1
0
/**
 * Apply tablesorter is enabled
 *
 * @param WikiParser_PluginMatcher $matches
 * @param Search_Query $query
 * @return array
 */
function applyTablesorter(WikiParser_PluginMatcher $matches, Search_Query $query)
{
    $ret = ['max' => false, 'tsOn' => false];
    $parser = new WikiParser_PluginArgumentParser();
    foreach ($matches as $match) {
        $name = $match->getName();
        if ($name == 'tablesorter') {
            $tsargs = $parser->parse($match->getArguments());
            $ajax = !empty($tsargs['server']) && $tsargs['server'] === 'y';
            $ret['tsOn'] = Table_Check::isEnabled($ajax);
            if (!$ret['tsOn']) {
                TikiLib::lib('errorreport')->report(tra('List plugin: Feature "jQuery Sortable Tables" (tablesorter) is not enabled'));
                return $ret;
            }
            if (isset($tsargs['tsortcolumns'])) {
                $tsc = Table_Check::parseParam($tsargs['tsortcolumns']);
            }
            if (isset($tsargs['tspaginate'])) {
                $tsp = Table_Check::parseParam($tsargs['tspaginate']);
                if (isset($tsp[0]['max']) && $ajax) {
                    $ret['max'] = (int) $tsp[0]['max'];
                }
            }
        }
    }
    foreach ($matches as $match) {
        $name = $match->getName();
        if ($name == 'column') {
            $cols[] = $match;
            $args[] = $parser->parse($match->getArguments());
        }
    }
    if (Table_Check::isSort()) {
        foreach ($_GET['sort'] as $key => $dir) {
            $n = '';
            switch ($tsc[$key]['type']) {
                case 'digit':
                case 'currency':
                case 'percent':
                case 'time':
                case strpos($tsc[$key]['type'], 'date') !== false:
                    $n = 'n';
                    break;
            }
            $query->setOrder($args[$key]['field'] . '_' . $n . Table_Check::$dir[$dir]);
        }
    }
    if (Table_Check::isFilter()) {
        foreach ($_GET['filter'] as $key => $filter) {
            $query->filterContent($filter, $args[$key]['field']);
        }
    }
    return $ret;
}
Ejemplo n.º 2
0
 /**
  * To be used within plugin program to convert user parameter settings into the settings array
  * that can be used by Table_Factory to generate the necessary jQuery
  *
  * @param null   $id				//html element id for table and surrounding div
  * @param string $sortable			//see params above
  * @param null   $sortList			//see params above
  * @param string $tsortcolumns		//see params above
  * @param null   $tsfilters			//see params above
  * @param null   $tsfilteroptions	//see params above
  * @param null   $tspaginate		//see params above
  * @param null   $ajaxurl			//only needed if ajax will be used to pull partial record sets
  * @param null   $totalrows			//only needed if ajax will be used to pull partial record sets
  */
 public function setSettings($id = null, $server = 'n', $sortable = 'n', $sortList = null, $tsortcolumns = null, $tsfilters = null, $tsfilteroptions = null, $tspaginate = null, $tscolselect = null, $ajaxurl = null, $totalrows = null, $tsmathoptions = null)
 {
     $s = array();
     //id
     if (!empty($id)) {
         $s['id'] = $id;
     }
     //sortable
     switch ($sortable) {
         case 'y':
         case 'server':
             $s['sorts']['type'] = true;
             break;
         case 'n':
             $s['sorts']['type'] = false;
             break;
         default:
             $sp = Table_Check::parseParam($sortable);
             if (isset($sp[0]['type'])) {
                 $s['sorts']['type'] = $sp[0]['type'];
             }
     }
     //sortlist
     if (!empty($sortList) && (!isset($s['sorts']['type']) || $s['sorts']['type'] !== false)) {
         $crop = substr($sortList, 1);
         $crop = substr($crop, 0, -1);
         $slarray = explode('],[', $crop);
         if (is_array($slarray)) {
             foreach ($slarray as $l) {
                 $lpieces = explode(',', $l);
                 if (isset($lpieces[1])) {
                     switch ($lpieces[1]) {
                         case '0':
                             $dir = 'asc';
                             break;
                         case '1':
                             $dir = 'desc';
                             break;
                         case 'y':
                             $dir = true;
                             break;
                         case 'n':
                             $dir = false;
                             break;
                         default:
                             if ($s['sorts']['type'] !== false) {
                                 $dir = true;
                             } else {
                                 $dir = false;
                             }
                     }
                     if ($dir === false || $dir === true) {
                         $s['columns'][$lpieces[0]]['sort']['type'] = $dir;
                     } else {
                         $s['columns'][$lpieces[0]]['sort']['dir'] = $dir;
                     }
                 }
             }
         }
     }
     if (!empty($tsortcolumns)) {
         $tsc = Table_Check::parseParam($tsortcolumns);
         if (is_array($tsc)) {
             foreach ($tsc as $col => $sortinfo) {
                 if (isset($s['columns'][$col]['sort'])) {
                     $s['columns'][$col]['sort'] = $s['columns'][$col]['sort'] + $sortinfo;
                 } else {
                     $s['columns'][$col]['sort'] = $sortinfo;
                 }
             }
             ksort($s['columns']);
         }
     } else {
         $s['sorts']['group'] = false;
     }
     //tsfilters
     if (!empty($tsfilters)) {
         switch ($tsfilters) {
             case 'y':
                 $s['filters']['type'] = 'text';
                 break;
             case 'n':
                 $s['filters']['type'] = false;
                 break;
             default:
                 $tsf = Table_Check::parseParam($tsfilters);
                 if (is_array($tsf)) {
                     foreach ($tsf as $col => $filterinfo) {
                         if (isset($filterinfo) && $filterinfo['type'] === 'dropdown' && !empty($filterinfo['options'])) {
                             foreach ($filterinfo['options'] as $key => $value) {
                                 $filterinfo['options'][$key] = str_replace('=', '|', $value);
                             }
                         }
                         if (isset($s['columns'][$col]['filter'])) {
                             $s['columns'][$col]['filter'] = $s['columns'][$col]['filter'] + $filterinfo;
                         } else {
                             $s['columns'][$col]['filter'] = $filterinfo;
                         }
                     }
                 }
         }
     }
     //tsfilteroptions
     if (!empty($tsfilteroptions) && !empty($s['filters']['type'])) {
         $tsfo = Table_Check::parseParam($tsfilteroptions);
         switch ($tsfo[0]['type']) {
             case 'reset':
                 $s['filters']['type'] = 'reset';
                 break;
             case 'hide':
                 $s['filters']['hide'] = true;
                 break;
         }
     }
     //tspaginate
     if (empty($tspaginate)) {
         $tspaginate = $server === 'y' ? 'y' : '';
     }
     if (!empty($tspaginate)) {
         $tsp = Table_Check::parseParam($tspaginate);
         //pagination must be on if server side processing is on ($server == 'y')
         if (is_array($tsp[0]) || $tsp[0] !== 'n' || $tsp[0] === 'n' && $server === 'y') {
             if (is_array($tsp[0])) {
                 $s['pager'] = $tsp[0];
                 if (isset($s['pager']['expand']) && is_array($s['pager']['expand'])) {
                     if (isset($s['pager']['max']) && $s['pager']['max'] > 0) {
                         $s['pager']['expand'] = array_merge(array($s['pager']['max']), $s['pager']['expand']);
                     } else {
                         $s['pager']['max'] = min($s['pager']['expand']);
                     }
                     $s['pager']['expand'] = array_unique($s['pager']['expand']);
                     sort($s['pager']['expand']);
                 }
             }
             $s['pager']['type'] = true;
         } elseif ($tsp[0] === 'n' && $server === 'n') {
             $s['pager']['type'] = false;
         }
     }
     //tscolselect
     if (!empty($tscolselect)) {
         $tscs = Table_Check::parseParam($tscolselect);
         if (is_array($tscs)) {
             $s['colselect']['type'] = true;
             foreach ($tscs as $col => $priority) {
                 $s['columns'][$col]['priority'] = $priority;
             }
         }
     }
     //ajaxurl
     if (!empty($ajaxurl) && $server === 'y') {
         $url = $this->getAjaxurl($ajaxurl);
         $s['ajax']['url']['file'] = $url['path'];
         $s['ajax']['url']['query'] = $url['query'];
         $s['ajax']['type'] = true;
     } else {
         $s['ajax']['type'] = false;
     }
     //totalrows
     if (!empty($totalrows)) {
         $s['total'] = $totalrows;
     }
     //tsmathoptions
     if (!empty($tsmathoptions)) {
         $tsmo = Table_Check::parseParam($tsmathoptions);
         if (is_array($tsmo)) {
             //column and table totals and labels
             foreach (['col', 'table'] as $type) {
                 if (!empty($tsmo[0][$type . 'total'])) {
                     $label = !empty($tsmo[0][$type . 'label']) ? $tsmo[0][$type . 'label'] : null;
                     $tsmo[0][$type . 'total'] = $this->setTotals($tsmo[0][$type . 'total'], $label);
                 }
             }
             //ignore
             if (!empty($tsmo[0]['ignore'])) {
                 $tsmo[0]['ignore'] = explode(',', $tsmo[0]['ignore']);
             }
             $s['math'] = $tsmo[0];
         }
     }
     $this->settings = $s;
 }