Skip to content

Commit aff6325

Browse files
committed
Changed post and product model edit method to add post/product content as separate parameter
1 parent 27fb8e4 commit aff6325

File tree

9 files changed

+285
-166
lines changed

9 files changed

+285
-166
lines changed

admin/controller/content/edit.php

+28-11
Original file line numberDiff line numberDiff line change
@@ -182,15 +182,17 @@ function index() {
182182
if (isset($post[$this->object . '_content'])) {
183183
foreach ($post[$this->object . '_content'] as &$content) {
184184
if (! isset($post['url'])) {
185-
$post['url'] = \Vvveb\url($route, ['slug'=> $content['slug'], 'post_id'=> $post_id] + $url);
185+
$post['url'] = \Vvveb\url($route, ['slug'=> $content['slug'], $this->object . '_id' => $post_id] + $url);
186186

187-
if (! $post['url']) {
188-
$post['url'] = \Vvveb\url($altRoute, ['slug'=> $content['slug'], 'post_id'=> $post_id] + $url);
187+
if (! $post['url'] || $post['url'] == '//' . $this->global['site_url']) {
188+
$post['url'] = \Vvveb\url($altRoute, ['slug'=> $content['slug'], $this->object . '_id' => $post_id] + $url);
189189
}
190190
}
191191
$language = [];
192192

193193
if ($content['language_id'] != $this->global['default_language_id']) {
194+
$code = 'en_US';
195+
194196
foreach ($this->view->languagesList as $code => $lang) {
195197
if ($lang['language_id'] == $content['language_id']) {
196198
break;
@@ -204,7 +206,7 @@ function index() {
204206
$content['url'] = \Vvveb\url($route, $content + $language + $url);
205207
$content['revision_count'] = 0;
206208

207-
if (! $content['url']) {
209+
if (! $content['url'] || $content['url'] == '//' . $this->global['site_url']) {
208210
$content['url'] = \Vvveb\url($altRoute, $content + $language + $url);
209211
}
210212

@@ -213,8 +215,8 @@ function index() {
213215

214216
if ($revision) {
215217
foreach ($revision[$this->object . '_content_revision'] as &$rev) {
216-
$rev['preview-url'] = $content['url'] . '?revision=preview&created_at=' . $rev['created_at'];
217-
$rev['compare-url'] = $revisionsUrl . '&created_at=' . $rev['created_at'];
218+
$rev['preview-url'] = $content['url'] . '?revision=preview&created_at=' . $rev['created_at'] . '&language_id=' . $content['language_id'];
219+
$rev['compare-url'] = $revisionsUrl . '&created_at=' . $rev['created_at'] . '&language_id=' . $content['language_id'];
218220
}
219221

220222
$content['revision_count'] = $revision['count'];
@@ -265,7 +267,7 @@ function index() {
265267

266268
$object = $this->object;
267269
$view->$object = $post;
268-
$view->status = ['publish' => 'Publish', 'draft' => 'Draft', 'pending' => 'Pending', 'private' => 'Private', 'password' => 'Password'];
270+
$view->status = ['publish' => 'Publish', 'draft' => 'Draft', 'pending' => 'Pending', 'private' => 'Private', 'password' => 'Password', 'future' => 'Future'];
269271

270272
$view->templates = Cache::getInstance()->cache(APP,'template-list.' . $this->global['site_id'],function () {
271273
return \Vvveb\getTemplateList(false, ['email']);
@@ -341,12 +343,12 @@ function save() {
341343
foreach ($tags as $tagId => $tag) {
342344
//existing tag add to post taxonomy_item list
343345
if (is_numeric($tagId)) {
344-
//$post['taxonomy_item'][] = $tagId;
346+
//$post['taxonomy_item_id'][] = $tagId;
345347
} else {
346348
//add new taxonomy_item
347349
$tagId = $this->addCategory($listId, $tag);
348350
}
349-
$post['taxonomy_item'][] = $tagId;
351+
$post['taxonomy_item_id'][] = $tagId;
350352
}
351353
}
352354
}
@@ -372,7 +374,15 @@ function save() {
372374
*/
373375

374376
$post[$this->object . '_id'] = (int)$post_id;
375-
$result = $posts->edit([$this->object => $post, $this->object . '_id' => $post_id, 'site_id' => $site_id] + $this->global);
377+
$data = [
378+
$this->object => $post,
379+
$this->object . '_id' => $post_id,
380+
$this->object . '_content' => $post[$this->object . '_content'],
381+
'taxonomy_item_id' => $post['taxonomy_item_id'] ?? [],
382+
'site_id' => $site_id,
383+
] + $this->global;
384+
385+
$result = $posts->edit($data);
376386

377387
if ($result >= 0) {
378388
$this->view->success['get'] = ucfirst($this->type) . ' ' . __('saved') . '!';
@@ -405,7 +415,14 @@ function save() {
405415
unset($post['updated_at'], $post[$this->object . '_id']);
406416
}
407417

408-
$return = $posts->add([$this->object => $post, 'site_id' => $site_id] + $this->global);
418+
$add = [
419+
$this->object => $post,
420+
$this->object . '_content' => $post[$this->object . '_content'],
421+
'taxonomy_item_id' => $post['taxonomy_item_id'] ?? [],
422+
'site_id' => $site_id,
423+
] + $this->global;
424+
425+
$return = $posts->add($add);
409426
$id = $return[$this->object] ?? false;
410427

411428
if (! $id) {

admin/controller/content/posts.php

+7-7
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,10 @@ function duplicate() {
7575

7676
if ($data) {
7777
$result = $this->posts->add([
78-
'post' => [
79-
'post_content' => $data['post_content'],
80-
'taxonomy_item' => $taxonomy_item ?? [],
81-
] + $data,
82-
'site_id' => $site_id,
78+
'post' => $data,
79+
'post_content' => $data['post_content'],
80+
'taxonomy_item' => $taxonomy_item ?? [],
81+
'site_id' => $site_id,
8382
]);
8483

8584
if ($result && isset($result['post'])) {
@@ -232,15 +231,16 @@ function index() {
232231
}
233232

234233
$url = ['module' => 'content/post', 'post_id' => $post['post_id'], 'type' => $post['type']];
235-
$admin_path = \Vvveb\adminPath();
234+
$adminPath = \Vvveb\adminPath();
236235
$template = $post['template'] ? $post['template'] : $defaultTemplate;
237236
$post['url'] = url($url);
238237
$post['edit-url'] = $post['url'];
239238
$post['admin-url'] = url(['module' => 'content/posts']) . '&filter[admin_id_text]=' . $post['username'] . ' &filter[admin_id]=' . $post['admin_id'];
240239
$post['delete-url'] = url(['module' => 'content/posts', 'action' => 'delete'] + $url + ['post_id[]' => $post['post_id']]);
241240
$post['duplicate-url'] = url(['module' => 'content/posts', 'action' => 'duplicate'] + $url + ['post_id' => $post['post_id']]);
242241
$post['view-url'] = url("content/{$this->type}/index", $post + $url + ['host' => $this->global['site_url']]);
243-
$post['design-url'] = url(['module' => 'editor/editor', 'name' => urlencode($post['name'] ?? ''), 'url' => $post['view-url'], 'template' => $template, 'host' => $this->global['site_url'] . $admin_path], false, false);
242+
$relativeUrl = url("content/{$this->type}/index", $post + $url);
243+
$post['design-url'] = url(['module' => 'editor/editor', 'name' => urlencode($post['name'] ?? ''), 'url' => $relativeUrl, 'template' => $template, 'host' => $this->global['site_url'] . $adminPath], false, false);
244244
}
245245
}
246246

admin/controller/product/products.php

+12-11
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,10 @@ function duplicate() {
7575

7676
if ($data) {
7777
$result = $this->products->add([
78-
'product' => [
79-
'product_content' => $data['product_content'],
80-
'taxonomy_item' => $taxonomy_item ?? [],
81-
] + $data,
82-
'site_id' => $site_id,
78+
'product' => $data,
79+
'product_content' => $data['product_content'],
80+
'taxonomy_item' => $taxonomy_item ?? [],
81+
'site_id' => $site_id,
8382
]);
8483

8584
if ($result && isset($result['product'])) {
@@ -174,14 +173,16 @@ function index() {
174173
}
175174
}
176175

176+
$adminPath = \Vvveb\adminPath();
177+
$url = ['module' => 'product/product', 'product_id' => $product['product_id'], 'type' => $product['type']];
177178
$template = (isset($product['template']) && $product['template']) ? $product['template'] : $defaultTemplate;
178-
$product['url'] = url(['module' => 'product/product', 'product_id' => $product['product_id'], 'type' => $product['type']]);
179+
$product['url'] = url($url);
179180
$product['edit-url'] = url(['module' => 'product/product', 'product_id' => $product['product_id'], 'type' => $product['type']]);
180-
$product['delete-url'] = url(['module' => 'product/products', 'action' => 'delete', 'product_id[]' => $product['product_id'], 'type' => $product['type']]);
181-
$product['duplicate-url'] = url(['module' => 'product/products', 'action' => 'duplicate', 'product_id' => $product['product_id'], 'type' => $product['type']]);
182-
$product['view-url'] = url('product/product/index', $product + ['host' => $this->global['site_url']]);
183-
$admin_path = \Vvveb\adminPath();
184-
$product['design-url'] = url(['module' => 'editor/editor', 'name' => urlencode($product['name'] ?? ''), 'url' => $product['view-url'], 'template' => $template, 'host' => $this->global['site_url'] . $admin_path], false, false);
181+
$product['delete-url'] = url(['module' => 'product/products', 'action' => 'delete'] + $url + ['product_id[]' => $product['product_id']]);
182+
$product['duplicate-url'] = url(['module' => 'product/products', 'action' => 'duplicate'] + $url + ['product_id' => $product['product_id']]);
183+
$product['view-url'] = url('product/product/index', $product + $url + ['host' => $this->global['site_url']]);
184+
$relativeUrl = url('product/product/index', $product + $url);
185+
$product['design-url'] = url(['module' => 'editor/editor', 'name' => urlencode($product['name'] ?? ''), 'url' => $relativeUrl, 'template' => $template, 'host' => $this->global['site_url'] . $adminPath], false, false);
185186
}
186187
}
187188

admin/sql/mysqli/post.sql

+43-35
Original file line numberDiff line numberDiff line change
@@ -3,33 +3,33 @@
33
-- get all post
44

55
CREATE PROCEDURE getAll(
6-
IN start INT,
7-
IN limit INT,
8-
IN search CHAR,
9-
IN like CHAR,
10-
IN username CHAR,
11-
IN status CHAR,
12-
IN taxonomy_item_slug CHAR,
13-
IN post_id ARRAY,
14-
IN taxonomy_item_id INT,
6+
IN start INT, -- start offset
7+
IN limit INT, -- number of posts
8+
IN search CHAR, -- filter posts by search string
9+
IN like CHAR, -- filter posts by search string using LIKE for partial search, slower
10+
IN username CHAR, -- filter by author username
11+
IN status CHAR, -- filter by author username
12+
IN taxonomy_item_slug CHAR, -- filter by taxonomy item slug
13+
IN post_id ARRAY, -- include only posts with post_id
14+
IN taxonomy_item_id INT, -- filter by taxonomy item id
1515
-- global
16-
IN type CHAR,
17-
IN site_id INT,
18-
IN admin_id INT,
19-
IN language_id INT,
16+
IN type CHAR, -- post type, default 'post'
17+
IN site_id INT, -- filter by site_id
18+
IN admin_id INT, -- filter by admin_id
19+
IN language_id INT, -- filter by site_id
2020
-- comment
21-
IN comment_count INT,
22-
IN comment_status INT,
21+
IN comment_count INT, -- flag to include comment count
22+
IN comment_status INT, -- flag to include comment status
2323
-- archive
24-
IN year INT,
25-
IN month INT,
24+
IN year INT, -- filter by year
25+
IN month INT, -- filter by month
2626
-- taxonomy
27-
IN categories INT,
28-
IN tags INT,
29-
IN taxonomy CHAR,
27+
IN categories INT, -- flag to include post categories
28+
IN tags INT, -- flag to include post tags
29+
IN taxonomy CHAR, -- flag to include post taxonomy
3030

31-
IN order_by CHAR,
32-
IN direction CHAR,
31+
IN order_by CHAR, -- sort by column
32+
IN direction CHAR, -- sort order, asc/desc
3333

3434
-- return array of posts for posts query
3535
OUT fetch_all,
@@ -277,10 +277,11 @@
277277
IN admin_id INT,
278278
IN type CHAR,
279279

280-
OUT fetch_row,
281-
OUT fetch_row,
282-
OUT fetch_all,
283-
OUT fetch_all,
280+
OUT fetch_row, -- post
281+
OUT fetch_all, -- content
282+
OUT fetch_all, -- meta
283+
OUT fetch_all, -- post_to_site
284+
OUT fetch_all, -- post_to_taxonomy_item
284285
)
285286
BEGIN
286287

@@ -363,6 +364,8 @@
363364

364365
CREATE PROCEDURE add(
365366
IN post ARRAY,
367+
IN post_content ARRAY,
368+
IN taxonomy_item_id ARRAY,
366369
IN site_id ARRAY,
367370
OUT insert_id,
368371
OUT insert_id,
@@ -381,17 +384,17 @@
381384

382385
VALUES ( :post_data );
383386

384-
:post.post_content = @FILTER(:post.post_content, post_content, false, true)
387+
:post_content = @FILTER(:post_content, post_content, false, true)
385388

386389

387-
@EACH(:post.post_content)
390+
@EACH(:post_content)
388391
INSERT INTO post_content
389392

390393
( @KEYS(:each), post_id)
391394

392395
VALUES ( :each, @result.post);
393396

394-
@EACH(:post.taxonomy_item)
397+
@EACH(:taxonomy_item_id)
395398
INSERT INTO post_to_taxonomy_item
396399

397400
( taxonomy_item_id, post_id)
@@ -412,15 +415,22 @@
412415

413416
CREATE PROCEDURE edit(
414417
IN post ARRAY,
418+
IN post_content ARRAY,
419+
IN taxonomy_item_id ARRAY,
415420
IN post_id INT,
416421
IN site_id ARRAY,
422+
OUT insert_id,
423+
OUT affected_rows,
424+
OUT insert_id,
425+
OUT affected_rows,
426+
OUT insert_id,
417427
OUT affected_rows
418428
)
419429
BEGIN
420430

421-
:post.post_content = @FILTER(:post.post_content, post_content, false, true)
431+
:post_content = @FILTER(:post_content, post_content, false, true)
422432

423-
@EACH(:post.post_content)
433+
@EACH(:post_content)
424434
INSERT INTO post_content
425435

426436
( @KEYS(:each), post_id)
@@ -429,12 +439,12 @@
429439
ON DUPLICATE KEY UPDATE @LIST(:each);
430440

431441

432-
@IF isset(:post.taxonomy_item)
442+
@IF isset(:taxonomy_item_id)
433443
THEN
434444
DELETE FROM post_to_taxonomy_item WHERE post_id = :post_id
435445
END @IF;
436446

437-
@EACH(:post.taxonomy_item)
447+
@EACH(:taxonomy_item_id)
438448
INSERT INTO post_to_taxonomy_item
439449

440450
( taxonomy_item_id, post_id)
@@ -468,7 +478,6 @@
468478
END @IF;
469479

470480

471-
472481
END
473482

474483
-- Edit post content
@@ -495,7 +504,6 @@
495504

496505
CREATE PROCEDURE delete(
497506
IN post_id ARRAY,
498-
IN site_id INT,
499507
OUT affected_rows,
500508
OUT affected_rows,
501509
OUT affected_rows,

0 commit comments

Comments
 (0)