@@ -31,10 +31,10 @@ class ModelBlogPost extends Model
3131 public function getPost ($ post_id )
3232 {
3333 $ post = new NewsClass ((int ) $ post_id , (int ) $ this ->context ->language ->id , $ this ->context ->shop ->id );
34-
3534 return array (
3635 'id ' => $ post ->id ,
3736 'title ' => $ post ->title ,
37+ 'datePublished ' => $ post ->date ,
3838 'description ' => html_entity_decode ($ post ->content , ENT_QUOTES , 'UTF-8 ' ),
3939 'shortDescription ' => strip_tags (html_entity_decode ($ post ->paragraph , ENT_QUOTES , 'UTF-8 ' )),
4040 'image ' => $ this ->getImage ($ post ->id ),
@@ -45,16 +45,26 @@ public function getPost($post_id)
4545
4646 public function getImage ($ post_id )
4747 {
48- $ uri = __PS_BASE_URI__ . 'modules/prestablog/views/img/ ' . Configuration::get ('prestablog_theme ' ) .
48+ if (file_exists (_PS_ROOT_DIR_ . '/modules/prestablog/views/img/ ' . Configuration::get ('prestablog_theme ' ) .
49+ '/up-img/ ' . $ post_id . '.jpg ' )) {
50+ $ uri = __PS_BASE_URI__ . 'modules/prestablog/views/img/ ' . Configuration::get ('prestablog_theme ' ) .
4951 '/up-img/ ' . $ post_id . '.jpg ' ;
50- return $ this ->context ->link ->protocol_content . Tools::getMediaServer ($ uri ) . $ uri ;
52+ return $ this ->context ->link ->protocol_content . Tools::getMediaServer ($ uri ) . $ uri ;
53+ } else {
54+ return '' ;
55+ }
5156 }
5257
5358 public function getImageLazy ($ post_id )
5459 {
55- $ uri = __PS_BASE_URI__ . 'modules/prestablog/views/img/ ' . Configuration::get ('prestablog_theme ' ) .
60+ if (file_exists (_PS_ROOT_DIR_ . '/modules/prestablog/views/img/ ' . Configuration::get ('prestablog_theme ' ) .
61+ '/up-img/thumb_ ' . $ post_id . '.jpg ' )) {
62+ $ uri = __PS_BASE_URI__ . 'modules/prestablog/views/img/ ' . Configuration::get ('prestablog_theme ' ) .
5663 '/up-img/thumb_ ' . $ post_id . '.jpg ' ;
57- return $ this ->context ->link ->protocol_content . Tools::getMediaServer ($ uri ) . $ uri ;
64+ return $ this ->context ->link ->protocol_content . Tools::getMediaServer ($ uri ) . $ uri ;
65+ } else {
66+ return '' ;
67+ }
5868 }
5969
6070 public function getPosts ($ data = array ())
@@ -138,4 +148,34 @@ public function getTotalPosts($data = array())
138148 $ result = Db::getInstance (_PS_USE_SQL_SLAVE_ )->getRow ($ sql );
139149 return $ result ['count(*) ' ];
140150 }
151+
152+ public function getNextPost ($ post_id )
153+ {
154+ $ sql = new DbQuery ();
155+ $ sql ->select ('* ' );
156+ $ sql ->from ('prestablog_news ' , 'pn ' );
157+ $ sql ->leftJoin ('prestablog_news_lang ' , 'pnl ' , 'pnl.`id_prestablog_news` = pn.`id_prestablog_news` ' );
158+ $ sql ->where ('pn.`actif` = 1 ' );
159+ $ sql ->where ('pnl.`id_lang` = ' . (int ) $ this ->context ->language ->id );
160+ $ sql ->orderBy ('pn.date ASC ' );
161+ $ sql ->where ("pn.id_prestablog_news > ' " . (int )$ post_id . "' " );
162+ $ result = Db::getInstance (_PS_USE_SQL_SLAVE_ )->getRow ($ sql );
163+
164+ return $ result ;
165+ }
166+ public function getPrevPost ($ post_id )
167+ {
168+ $ sql = new DbQuery ();
169+ $ sql ->select ('* ' );
170+ $ sql ->from ('prestablog_news ' , 'pn ' );
171+ $ sql ->leftJoin ('prestablog_news_lang ' , 'pnl ' , 'pnl.`id_prestablog_news` = pn.`id_prestablog_news` ' );
172+ $ sql ->where ('pn.`actif` = 1 ' );
173+ $ sql ->where ('pnl.`id_lang` = ' . (int ) $ this ->context ->language ->id );
174+ $ sql ->orderBy ('pn.id_prestablog_news DESC ' );
175+ $ sql ->where ("pn.id_prestablog_news < ' " . (int )$ post_id . "' " );
176+
177+ $ result = Db::getInstance (_PS_USE_SQL_SLAVE_ )->getRow ($ sql );
178+
179+ return $ result ;
180+ }
141181}
0 commit comments