Exemple #1
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'];
 }
Exemple #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 '{}';
     }
 }
Exemple #3
0
 /**
  * Retourne au format JSON la liste des produits
  * @param $limit
  */
 private function json_listing_product($limit)
 {
     $pager = new magixglobal_model_pager();
     $max = $limit;
     $offset = $pager->setPaginationOffset($limit, $this->getpage);
     $role = new backend_model_role();
     $sort = 'idcatalog';
     if (parent::s_catalog($this->getlang, $role->sql_arg(), $limit, $max, $offset, $sort) != null) {
         foreach (parent::s_catalog($this->getlang, $role->sql_arg(), $limit, $max, $offset, $sort) as $key) {
             if ($key['desccatalog'] != null) {
                 $content = 1;
             } else {
                 $content = 0;
             }
             if ($key['imgcatalog'] != null) {
                 $img = 1;
             } else {
                 $img = 0;
             }
             if ($key['price'] != null) {
                 $price = number_format($key['price'], 2, ',', '.');
             } else {
                 $price = 0;
             }
             $json_data[] = '{"idcatalog":' . json_encode($key['idcatalog']) . ',"urlcatalog":' . json_encode($key['urlcatalog']) . ',"titlecatalog":' . json_encode($key['titlecatalog']) . ',"content":' . json_encode($content) . ',"price":' . json_encode($price) . ',"img":' . json_encode($img) . ',"iso":' . json_encode($key['iso']) . ',"pseudo":' . json_encode($key['pseudo_admin']) . '}';
         }
         print '[' . implode(',', $json_data) . ']';
     } else {
         print '{}';
     }
 }