/**
 * Smarty plugin
 * @package     Smarty
 * @subpackage  plugins
 * Type:        function
 * Name:        widget_news_display
 * date:        25/12/2013
 * Update:      10/03/2013
 * Examples:    {widget_news_display}
 * @author      Sire Sam (sire-sam.be)
 * @link        htt://www.sire-sam.be, http://www.magix-dev.be
 * @author      Gerits Aurelien
 * @version     1.1
 * @param       array
 * @param       Smarty
 * @return      string
 */
function smarty_function_widget_news_data($params, $template)
{
    $ModelSystem = new magixglobal_model_system();
    $ModelRewrite = new magixglobal_model_rewrite();
    $ModelNews = new frontend_model_news();
    $ModelPager = new magixglobal_model_pager();
    // Set and load data
    $current = $ModelSystem->setCurrentId();
    $conf = is_array($params['conf']) ? $params['conf'] : array();
    $override = $params['conf']['plugins']['override'] ? $params['conf']['plugins']['override'] : '';
    $data = $ModelNews->getData($conf, $current, $override);
    $newrow = is_array($params['conf']['plugins']['item']) ? $params['conf']['plugins']['item'] : array();
    // Set Pagination
    $pagination = array();
    if (isset($data['total']) and isset($data['limit'])) {
        $pagination = $ModelPager->setPaginationData($data['total'], $data['limit'], '/' . $current['lang']['iso'] . $ModelRewrite->mod_news_lang($current['lang']['iso']), $current['news']['pagination']['id'], '/');
        unset($data['total']);
        unset($data['limit']);
    }
    $current = $current['news'];
    // Format data
    $items = array();
    if ($data != null) {
        foreach ($data as $row) {
            if (isset($row['idnews'])) {
                $items[] = $ModelNews->setItemData($row, $current, $newrow);
            } elseif (isset($row['name_tag'])) {
                $items[] = array('id' => $row['name_tag'], 'name' => $row['name_tag'], 'iso' => $row['iso'], 'url' => magixglobal_model_rewrite::filter_news_tag_url($row['iso'], urlencode($row['name_tag']), true));
            }
        }
    }
    $assign = isset($params['assign']) ? $params['assign'] : 'data';
    $template->assign($assign, $items);
    $assignPager = isset($params['assignPagination']) ? $params['assignPagination'] : 'paginationData';
    $template->assign($assignPager, $pagination);
}
Exemplo n.º 2
0
 /**
  * Retourne la pagination pour les actualités
  * @param $limit
  * @return null|string
  */
 private function news_pagination($limit)
 {
     $role = new backend_model_role();
     $db = parent::s_count_max_news($this->getlang);
     $total = $db['total'];
     // *** Set pagination
     $dataPager = null;
     if (isset($total) and isset($limit)) {
         $lib_rewrite = new magixglobal_model_rewrite();
         $basePath = '/' . PATHADMIN . '/news.php?getlang=' . $this->getlang . '&action=list&';
         $dataPager = magixglobal_model_pager::setPaginationData($total, $limit, $basePath, $this->getpage, '=');
         $pagination = null;
         if ($dataPager != null) {
             $pagination = '<ul class="pagination">';
             foreach ($dataPager as $row) {
                 switch ($row['name']) {
                     case 'first':
                         $name = '<<';
                         break;
                     case 'previous':
                         $name = '<';
                         break;
                     case 'next':
                         $name = '>';
                         break;
                     case 'last':
                         $name = '>>';
                         break;
                     default:
                         $name = $row['name'];
                 }
                 $classItem = $name == $this->getpage ? ' class="active"' : null;
                 $pagination .= '<li' . $classItem . '>';
                 $pagination .= '<a href="' . $row['url'] . '" title="' . $name . '" >';
                 $pagination .= $name;
                 $pagination .= '</a>';
                 $pagination .= '</li>';
             }
             $pagination .= '</ul>';
         }
         unset($total);
         unset($limit);
     }
     return $pagination;
 }
/**
 * Smarty plugin
 * @package     Smarty
 * @subpackage  plugins
 * Type:        function
 * Name:        widget_news_display
 * date:        25/12/2013
 * Update:      10/03/2013
 * Examples:    {widget_news_display}
 * @author      Sire Sam (sire-sam.be)
 * @link        htt://www.sire-sam.be, http://www.magix-dev.be
 * @author      Gerits Aurelien
 * @version     1.1
 * @param       array
 * @param       Smarty
 * @return      string
 */
function smarty_function_widget_news_display($params, $template)
{
    $ModelSystem = new magixglobal_model_system();
    $ModelRewrite = new magixglobal_model_rewrite();
    $ModelConstructor = new magixglobal_model_constructor();
    $ModelNews = new frontend_model_news();
    $ModelPager = new magixglobal_model_pager();
    $Debug = new magixcjquery_debug_magixfire();
    // Set and load data
    $current = $ModelSystem->setCurrentId();
    $conf = is_array($params['conf']) ? $params['conf'] : array();
    $data = $ModelNews->getData($conf, $current);
    // Set Pagination
    $pagination['html'] = null;
    if (isset($data['total']) and isset($data['limit'])) {
        $pagination['src'] = $ModelPager->setPaginationData($data['total'], $data['limit'], '/' . $current['lang']['iso'] . $ModelRewrite->mod_news_lang($current['lang']['iso']), $current['news']['pagination']['id'], '/');
        $pagination['html'] = $ModelConstructor->formatPaginationHtml($pagination['src'], $current['news']['pagination']['id']);
        unset($data['total']);
        unset($data['limit']);
    }
    $current = $current['news'];
    // Format data
    $html = null;
    if ($data != null) {
        $pattern['default'] = patternNews();
        $pattern['custom'] = null;
        if ($params['pattern']) {
            $pattern['custom'] = is_array($params['pattern']) ? $params['pattern'] : patternNews($params['pattern']);
        }
        $pattern['global'] = $ModelConstructor->mergeHtmlPattern($pattern['default'], $pattern['custom']);
        $i = 0;
        $items['html'] = null;
        foreach ($data as $row) {
            $i++;
            $itemData = $ModelNews->setItemData($row, $current);
            // *** set item html structure & var
            $pattern['global']['is_active'] = $itemData['active'] === true ? 1 : 0;
            $pattern['global']['id'] = isset($itemData['id']) ? $itemData['id'] : 0;
            $pattern['global']['url'] = isset($itemData['uri']) ? $itemData['uri'] : '#';
            $pattern['item'] = $ModelConstructor->setItemPattern($pattern['global'], $i);
            // *** Reset iteration if item is last of the line
            if ($pattern['item']['is_last'] == 1) {
                $i = 0;
            }
            // *** in case diplay is null, we take default value
            if ($pattern['item']['display'][1] == null) {
                $pattern['item']['display'][1] = $pattern['default']['display'][1];
            }
            $imgSize = isset($pattern['item']['img']['size']) ? $pattern['item']['img']['size'] : 'small';
            if (isset($itemData['imgSrc'][$imgSize])) {
                $itemData['imgSrc'] = $itemData['imgSrc'][$imgSize];
            } else {
                $itemData['imgSrc'] = $itemData['imgSrc']['default'];
            }
            // *** format item loop (foreach element)
            $itemHtml = null;
            foreach ($pattern['item']['display'][1] as $elem_type) {
                $pattern['elem'] = $pattern['item'][$elem_type];
                if (array_search($elem_type, $pattern['item']['display'][1])) {
                    switch ($elem_type) {
                        case 'name':
                            $elem = $itemData['name'];
                            break;
                        case 'img':
                            $elem = '<img src="' . $itemData['imgSrc'] . '" alt="' . $itemData['name'] . '"/>';
                            break;
                        case 'descr':
                            $elem = magixcjquery_form_helpersforms::inputCleanTruncate(magixcjquery_form_helpersforms::inputTagClean($itemData['content']), $pattern['item']['descr']['lenght'], $pattern['item']['descr']['delemiter']);
                            break;
                        case 'date':
                            $elem = $ModelConstructor->formatDateHtml($itemData['date']['publish'], $pattern['item']);
                            break;
                        case 'tag':
                            $elem = $itemData['tag'];
                            break;
                        default:
                            $elem = null;
                    }
                    if ($elem != null or isset($pattern['elem']['before']) or isset($pattern['elem']['after'])) {
                        $itemHtml .= $pattern['elem']['before'];
                        $itemHtml .= $elem;
                        $itemHtml .= $pattern['elem']['after'];
                    }
                }
            }
            // *** item construct
            $items['html'] .= $pattern['item']['item']['before'];
            $items['html'] .= $itemHtml;
            $items['html'] .= $pattern['item']['item']['after'];
        }
        // *** container construct
        $html = isset($params['title']) ? $params['title'] : '';
        $html .= $pattern['global']['container']['before'];
        $html .= isset($params['prepend']) ? $params['prepend'] : null;
        $html .= $items['html'];
        $html .= isset($params['append']) ? $params['append'] : null;
        $html .= $pattern['global']['container']['after'];
        $html .= $pagination['html'];
    }
    return $html;
}
Exemplo n.º 4
0
 /**
  * @param $max
  * @return string
  */
 private function paginationList($limit)
 {
     $data = parent::fetchOrder(array('fetch' => 'count'));
     $total = $data['total'];
     // *** Set pagination
     $dataPager = null;
     if (isset($total) and isset($limit)) {
         $lib_rewrite = new magixglobal_model_rewrite();
         $basePath = $this->template->pluginUrl() . '&amp;';
         $dataPager = magixglobal_model_pager::setPaginationData($total, $limit, $basePath, $this->getpage, '=');
         $pagination = null;
         if ($dataPager != null) {
             $pagination = '<ul class="pagination">';
             foreach ($dataPager as $row) {
                 switch ($row['name']) {
                     case 'first':
                         $name = '<<';
                         break;
                     case 'previous':
                         $name = '<';
                         break;
                     case 'next':
                         $name = '>';
                         break;
                     case 'last':
                         $name = '>>';
                         break;
                     default:
                         $name = $row['name'];
                 }
                 $classItem = $name == $this->getpage ? ' class="active"' : null;
                 $pagination .= '<li' . $classItem . '>';
                 $pagination .= '<a href="' . $row['url'] . '" title="' . $name . '" >';
                 $pagination .= $name;
                 $pagination .= '</a>';
                 $pagination .= '</li>';
             }
             $pagination .= '</ul>';
         }
         unset($total);
         unset($limit);
     }
     return $pagination;
 }