Browse Source

First work on article list

Léo Serre 10 months ago
parent
commit
a3d964e9c5
3 changed files with 22 additions and 19 deletions
  1. 12
    12
      controllers/d.blog.php
  2. 9
    6
      models/d.blog.php
  3. 1
    1
      views/blocks/d.nav.html

+ 12
- 12
controllers/d.blog.php View File

@@ -31,13 +31,13 @@ switch ($controller->splitted_url[1]) {
31 31
 	case "list":
32 32
 		$blogArticles = new Kabano\BlogArticles();
33 33
 
34
-		$blogArticles->number(($user->role >= 600));
34
+		$blogArticles->number(($user->rankIsHigher("premium")));
35 35
 
36 36
 		// In case the wanted page is too big
37 37
 		if($articles_per_pages * $page >= $blogArticles->number)
38 38
 			$page = 0;
39 39
 
40
-		$blogArticles->listArticles($page*$articles_per_pages,$articles_per_pages,($user->role >= 600));
40
+		$blogArticles->listArticles($page*$articles_per_pages,$articles_per_pages,($user->rankIsHigher("premium")));
41 41
 
42 42
 		$i = 0;
43 43
 		$blogArticles_list = array();
@@ -64,7 +64,7 @@ switch ($controller->splitted_url[1]) {
64 64
 		}
65 65
 		break;
66 66
 	case "new":
67
-		if($user->role >= 800) {
67
+		if($user->rankIsHigher("moderator")) {
68 68
 			if(isset($_POST['submit'])) {
69 69
 				$blogArticle->content = $_POST['content'];
70 70
 				$blogArticle->locale = $_POST['locale'];
@@ -91,12 +91,12 @@ switch ($controller->splitted_url[1]) {
91 91
 		}
92 92
 	default:
93 93
 		// If the page exists
94
-		if ($blogArticle->checkUrl($controller->splitted_url[1],$user->role >= 600)) {
95
-			if (isset($controller->splitted_url[2]) && $controller->splitted_url[2] == "delete" && $user->role >= 800) {
94
+		if ($blogArticle->checkUrl($controller->splitted_url[1],$user->rankIsHigher("premium"))) {
95
+			if (isset($controller->splitted_url[2]) && $controller->splitted_url[2] == "delete" && $user->rankIsHigher("moderator")) {
96 96
 				$blogArticle->delete();
97 97
 				header('Location: '.$config['rel_root_folder']."blog/".$blogArticle->url);
98 98
 			}
99
-			else if (isset($controller->splitted_url[2]) && $controller->splitted_url[2] == "edit" && $user->role >= 800) {
99
+			else if (isset($controller->splitted_url[2]) && $controller->splitted_url[2] == "edit" && $user->rankIsHigher("moderator")) {
100 100
 				if(isset($_POST['submit'])) {
101 101
 					$blogArticle->content = $_POST['content'];
102 102
 					$blogArticle->locale = $_POST['locale'];
@@ -114,7 +114,7 @@ switch ($controller->splitted_url[1]) {
114 114
 			}
115 115
 			else {
116 116
 				// Manage history of an article
117
-				if($user->role >= 600) {
117
+				if($user->rankIsHigher("premium")) {
118 118
 					$blogArticles_history = new Kabano\BlogArticles();
119 119
 					$blogArticles_history->getHistory($controller->splitted_url[1]);
120 120
 
@@ -127,11 +127,11 @@ switch ($controller->splitted_url[1]) {
127 127
 					}
128 128
 				}
129 129
 				if (isset($controller->splitted_url[2]) && is_numeric($controller->splitted_url[2]))
130
-					$blogArticle->checkUrl($controller->splitted_url[1],$user->role>=600,$controller->splitted_url[2]);
130
+					$blogArticle->checkUrl($controller->splitted_url[1],$user->rankIsHigher("premium"),$controller->splitted_url[2]);
131 131
 
132 132
 				// Manage comment creation
133 133
 				if (isset($controller->splitted_url[2]) && $controller->splitted_url[2]=="new_comment") {
134
-					if (isset($_POST['submit']) && $user->role > 0) {
134
+					if (isset($_POST['submit']) && $user->rankIsHigher("registered")) {
135 135
 						$blogComment = new Kabano\BlogComment();
136 136
 						$blogComment->locale = $user->locale;
137 137
 						$blogComment->author = $user->id;
@@ -147,7 +147,7 @@ switch ($controller->splitted_url[1]) {
147 147
 						$blogComment = new Kabano\BlogComment();
148 148
 						$blogComment->id = $controller->splitted_url[3];
149 149
 						$blogComment->populate();
150
-						if ($user->role >= 800 || $user->id == $blogComment->author)
150
+						if ($user->rankIsHigher("moderator") || $user->id == $blogComment->author)
151 151
 							$blogComment->delete();
152 152
 					}
153 153
 				}
@@ -158,7 +158,7 @@ switch ($controller->splitted_url[1]) {
158 158
 						$blogComment = new Kabano\BlogComment();
159 159
 						$blogComment->id = $controller->splitted_url[3];
160 160
 						$blogComment->populate();
161
-						if ($user->role >= 800 || $user->id == $blogComment->author)
161
+						if ($user->rankIsHigher("moderator") || $user->id == $blogComment->author)
162 162
 							$blogComment->undelete();
163 163
 					}
164 164
 				}
@@ -169,7 +169,7 @@ switch ($controller->splitted_url[1]) {
169 169
 				// Manage comments
170 170
 				if ($blogArticle->comments == "t") {
171 171
 					$blogArticles_comments = new Kabano\BlogComments();
172
-					$blogArticles_comments->listComments($blogArticle->id, ($user->role>400));
172
+					$blogArticles_comments->listComments($blogArticle->id, ($user->rankIsHigher("premium")));
173 173
 
174 174
 					$i = 0;
175 175
 					foreach ($blogArticles_comments->ids as $row) {

+ 9
- 6
models/d.blog.php View File

@@ -218,7 +218,7 @@ class BlogArticle
218 218
 
219 219
 class BlogArticles
220 220
 {
221
-	public $ids = array();
221
+	public $objs = array();
222 222
 	public $number = NULL;
223 223
 
224 224
 	/*****
@@ -232,10 +232,10 @@ class BlogArticles
232 232
 
233 233
 		if ($archive == 1) {
234 234
 			// You just want one per url and the criteria is ORDER BY archives = true, time DES=C
235
-			$query = "SELECT id FROM (SELECT a.id, a.lastedit , ROW_NUMBER() OVER (PARTITION BY a.url ORDER BY CASE WHEN a.archive IS TRUE THEN 1 ELSE 0 END, a.lastedit DESC) AS r FROM blog_articles AS a) AS b WHERE r = 1 ORDER BY lastedit DESC";
235
+			$query = "SELECT * FROM (SELECT a.id, a.update_date , ROW_NUMBER() OVER (PARTITION BY a.permalink ORDER BY CASE WHEN a.is_archive IS TRUE THEN 1 ELSE 0 END, a.update_date DESC) AS r FROM contents WHERE type='blog' AS a) AS b WHERE r = 1 ORDER BY update_date DESC";
236 236
 		}
237 237
 		else {
238
-			$query = "SELECT id FROM blog_articles WHERE archive IS NOT TRUE ORDER BY lastedit DESC";
238
+			$query = "SELECT * FROM contents WHERE is_archive IS NOT TRUE AND is_public IS TRUE AND type='blog' ORDER BY update_date DESC";
239 239
 		}
240 240
 		$query .= " LIMIT $1 OFFSET $2";
241 241
 
@@ -248,9 +248,11 @@ class BlogArticles
248 248
 
249 249
 		for($i = 0; $i < pg_num_rows($result); $i++) {
250 250
 			$row = pg_fetch_assoc($result, $i);
251
-			$this->ids[$i] = $row['id'];
251
+			$this->objs[$i] = new BlogArticle;
252
+			$this->objs[$i]->populate($row);
252 253
 		}
253 254
 	}
255
+
254 256
 	/*****
255 257
 	** Return the number of articles
256 258
 	*****/
@@ -262,10 +264,10 @@ class BlogArticles
262 264
 
263 265
 		if ($archive == 1) {
264 266
 			// You just want one per url and the criteria is ORDER BY archives = true, time DES=C
265
-			$query = "SELECT id FROM (SELECT a.id, a.lastedit , ROW_NUMBER() OVER (PARTITION BY a.url ORDER BY CASE WHEN a.archive IS TRUE THEN 1 ELSE 0 END, a.lastedit DESC) AS r FROM blog_articles AS a) AS b WHERE r = 1 ORDER BY lastedit DESC";
267
+			$query = "SELECT * FROM (SELECT a.id, a.update_date , ROW_NUMBER() OVER (PARTITION BY a.permalink ORDER BY CASE WHEN a.is_archive IS TRUE THEN 1 ELSE 0 END, a.update_date DESC) AS r FROM contents WHERE type='blog' AS a) AS b WHERE r = 1 ORDER BY update_date DESC";
266 268
 		}
267 269
 		else {
268
-			$query = "SELECT id FROM blog_articles WHERE archive IS NOT TRUE ORDER BY lastedit DESC";
270
+			$query = "SELECT * FROM contents WHERE is_archive IS NOT TRUE AND is_public IS TRUE AND type='blog' ORDER BY update_date DESC";
269 271
 		}
270 272
 
271 273
 		pg_prepare($con, "prepare1", $query) 
@@ -277,6 +279,7 @@ class BlogArticles
277 279
 
278 280
 		$this->number = pg_num_rows($result);
279 281
 	}
282
+
280 283
 	/*****
281 284
 	** Return the list of archived version of a blog article
282 285
 	*****/

+ 1
- 1
views/blocks/d.nav.html View File

@@ -40,7 +40,7 @@
40 40
 						<li class="on-bar has-sub"><a class="on-bar" href="#"><i class="icon fas fa-question"></i></a>
41 41
 							<ul>
42 42
 								<li><a href="<?=$config['rel_root_folder']?>wiki/help">Aide</a></li>
43
-								<!--<li><a href="<?=$config['rel_root_folder']?>blog">Blog</a></li>-->
43
+								<li><a href="<?=$config['rel_root_folder']?>blog">Blog</a></li>
44 44
 								<li><a href="<?=$config['rel_root_folder']?>contact">Contact</a></li>
45 45
 								<li><a href="<?=$config['rel_root_folder']?>wiki/api">API Développeurs</a></li>
46 46
 								<li><a href="<?=$config['rel_root_folder']?>wiki/about">À propos</a></li>

Loading…
Cancel
Save