/**
 * 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);
}
Esempio n. 2
0
 /**
  * Retourne la liste des news au format JSON
  * @param $limit
  */
 private function json_list_news($limit)
 {
     $role = new backend_model_role();
     $pager = new magixglobal_model_pager();
     $max = $limit;
     $offset = $pager->setPaginationOffset($limit, $this->getpage);
     $limit = $max;
     if (parent::s_news_list($this->getlang, $limit, $max, $offset) != null) {
         foreach (parent::s_news_list($this->getlang, $limit, $max, $offset) as $key) {
             if ($key['n_content'] != null) {
                 $content = 1;
             } else {
                 $content = 0;
             }
             if ($key['n_image'] != null) {
                 $image = 1;
             } else {
                 $image = 0;
             }
             $json[] = '{"idnews":' . json_encode($key['idnews']) . ',"n_image":' . json_encode($image) . ',"n_title":' . json_encode($key['n_title']) . ',"n_content":' . json_encode($content) . ',"pseudo":' . json_encode($key['pseudo_admin']) . ',"date_register":' . json_encode($key['date_register']) . ',"date_publish":' . json_encode($key['date_publish']) . ',"published":' . json_encode($key['published']) . '}';
         }
         print '[' . implode(',', $json) . ']';
     } else {
         print '{}';
     }
 }
Esempio n. 3
0
 /**
  * Retourne les données sql sur base des paramètres passés en paramète
  * @param array $custom
  * @param array $current
  * @return array|null
  */
 public function getData($custom, $current)
 {
     if (!is_array($custom)) {
         return null;
     }
     if (!array_key_exists('news', $current)) {
         return null;
     }
     $ModelPager = new magixglobal_model_pager();
     // set default values for query
     $data['conf'] = array('id' => $current['news']['tag']['id'], 'type' => null, 'limit' => 10, 'offset' => $ModelPager->setPaginationOffset(10, $current['news']['pagination']['id']), 'lang' => $current['lang']['iso'], 'level' => 'all');
     $current = $current['news'];
     // set data selection conf
     if (isset($custom['select'])) {
         if ($custom['select'] == 'current') {
             if ($current['tag']['id'] != null) {
                 $data['conf']['id'] = $current['tag']['id'];
                 $data['conf']['type'] = 'collection';
             }
         } elseif (is_array($custom['select'])) {
             if (array_key_exists($data['conf']['lang'], $custom['select'])) {
                 $data['conf']['id'] = $custom['select'][$data['conf']['lang']];
                 $data['conf']['type'] = 'collection';
             }
         }
     } elseif (isset($custom['exclude'])) {
         if (is_array($custom['exclude'])) {
             if (array_key_exists($current['lang']['iso'], $custom['exclude'])) {
                 $data['conf']['id'] = $custom['exclude'][$data['conf']['lang']];
                 $data['conf']['type'] = 'exclude';
             }
         }
     }
     // set number of line to return (with pagination)
     if (isset($custom['limit'])) {
         $data['conf']['limit'] = $custom['limit'];
         $data['conf']['offset'] = $ModelPager->setPaginationOffset($data['conf']['limit'], $current['pagination']['id']);
     }
     // set kind of data
     if (isset($custom['level'])) {
         switch ($custom['level']) {
             case 'last-news':
                 $data['conf']['level'] = 'last-news';
                 break;
             case 'tag':
                 $data['conf']['level'] = 'tag';
                 break;
         }
     }
     // *** Run - load data
     if ($data['conf']['level'] == 'last-news') {
         if (isset($data['conf']['type'])) {
             $data['src'] = parent::s_news_in_tag($data['conf']['lang'], $data['conf']['id'], $data['conf']['type'], $data['conf']['limit']);
         } else {
             $data['src'] = parent::s_news($data['conf']['lang'], $data['conf']['limit'], 0, null);
         }
     } elseif ($data['conf']['level'] == 'tag') {
         $data['src'] = parent::s_tag_all($data['conf']['lang']);
     } elseif (isset($data['conf']['id'])) {
         $data['src'] = parent::s_news_in_tag($data['conf']['lang'], $data['conf']['id'], $data['conf']['type'], $data['conf']['limit']);
     } else {
         $data['src'] = parent::s_news($data['conf']['lang'], $data['conf']['limit'], $data['conf']['offset']);
         $data['src']['total'] = array_shift(parent::s_news_lang_total($data['conf']['lang']));
         $data['src']['limit'] = $data['conf']['limit'];
     }
     return $data['src'];
 }
/**
 * 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;
}
Esempio n. 5
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;
 }
Esempio n. 6
0
 /**
  * Retourne la pagination pour les produits
  * @param $limit
  * @return null|string
  */
 private function product_pagination($limit)
 {
     $dbcatalog = parent::s_catalog_count($this->getlang);
     $total = $dbcatalog['total'];
     // *** Set pagination
     $dataPager = null;
     if (isset($total) and isset($limit)) {
         $lib_rewrite = new magixglobal_model_rewrite();
         $basePath = '/' . PATHADMIN . '/catalog.php?section=product&amp;getlang=' . $this->getlang . '&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;
 }