From 7e7fffc39df46e447a4d1a4199e881122e40c38c Mon Sep 17 00:00:00 2001 From: voltan Date: Sat, 12 Aug 2017 10:44:29 +0430 Subject: [PATCH] Add confirm and rejext option for manager --- config/config.php | 2 +- config/module.php | 2 +- locale/en/admin.mo | Bin 412 -> 412 bytes locale/en/admin.po | 6 +- locale/en/default.mo | Bin 412 -> 412 bytes locale/en/default.po | 95 ++++++++---- locale/fa/admin.mo | Bin 2804 -> 2828 bytes locale/fa/admin.po | 32 ++-- locale/fa/default.mo | Bin 7024 -> 8167 bytes locale/fa/default.po | 101 +++++++++---- src/Api/Question.php | 6 +- src/Controller/Front/AnswerController.php | 2 +- src/Controller/Front/ProjectController.php | 11 +- src/Controller/Front/QuestionController.php | 147 +++++++++++++++++-- src/Route/Ask.php | 29 +++- template/admin/question-index.phtml | 56 ++++--- template/front/question-index.phtml | 111 -------------- template/front/question-list.phtml | 5 +- template/front/question-single.phtml | 155 ++++++++++++++++++++ 19 files changed, 522 insertions(+), 238 deletions(-) delete mode 100644 template/front/question-index.phtml create mode 100644 template/front/question-single.phtml diff --git a/config/config.php b/config/config.php index deb8b2a..b3ecca7 100644 --- a/config/config.php +++ b/config/config.php @@ -113,8 +113,8 @@ 'type' => 'select', 'options' => array( 'options' => array( - 0 => _a('All questions and answers need admin review before publish'), 1 => _a('Automatic approval all questions and answers'), + 2 => _a('All questions and answers need admin or project manager review before publish'), ), ), ), diff --git a/config/module.php b/config/module.php index 7f86b69..606c0b4 100644 --- a/config/module.php +++ b/config/module.php @@ -14,7 +14,7 @@ 'meta' => array( 'title' => _a('Ask'), 'description' => _a('Ask and Answer'), - 'version' => '0.3.0', + 'version' => '0.3.1', 'license' => 'New BSD', 'logo' => 'image/logo.png', 'readme' => 'docs/readme.txt', diff --git a/locale/en/admin.mo b/locale/en/admin.mo index a7dd459dbf5b1f1a4531e0074a63a2bc9d3fa6f4..17942682516199d904b8520d3c7dee5dec0359c5 100644 GIT binary patch delta 19 acmbQkJcoHgCWoPsf}w$xiNVG~ZAJh#76lLh delta 19 acmbQkJcoHgCWnEUf}ydMvBkzhZAJh#a0MLz diff --git a/locale/en/admin.po b/locale/en/admin.po index 6667470..e04372f 100644 --- a/locale/en/admin.po +++ b/locale/en/admin.po @@ -1,7 +1,7 @@ msgid "" msgstr "" "Project-Id-Version: \n" -"POT-Creation-Date: 2017-08-06 13:38+0430\n" +"POT-Creation-Date: 2017-08-12 10:40+0430\n" "PO-Revision-Date: \n" "Last-Translator: \n" "Language-Team: \n" @@ -80,11 +80,11 @@ msgid "Automatic approval" msgstr "" #: config/config.php:116 -msgid "All questions and answers need admin review before publish" +msgid "Automatic approval all questions and answers" msgstr "" #: config/config.php:117 -msgid "Automatic approval all questions and answers" +msgid "All questions and answers need admin or project manager review before publish" msgstr "" #: config/config.php:128 diff --git a/locale/en/default.mo b/locale/en/default.mo index 6afb018ba5751da0f4c2afd5a5051fc55863bccd..eae563e3aae2198fdd2f2fd21586bbe4480c1999 100644 GIT binary patch delta 19 acmbQkJcoHgCWoPsf}w$xiNVG~ZAJh#76lLh delta 19 acmbQkJcoHgCWnEUf}ydMvB}0lZAJh#Tm=~b diff --git a/locale/en/default.po b/locale/en/default.po index d3c65df..be2d3e0 100644 --- a/locale/en/default.po +++ b/locale/en/default.po @@ -1,7 +1,7 @@ msgid "" msgstr "" "Project-Id-Version: \n" -"POT-Creation-Date: 2017-08-06 13:34+0430\n" +"POT-Creation-Date: 2017-08-12 10:40+0430\n" "PO-Revision-Date: \n" "Last-Translator: \n" "Language-Team: \n" @@ -72,7 +72,8 @@ msgid "Answer question not active" msgstr "" #: src/Controller/Front/AnswerController.php:41 -#: src/Controller/Front/QuestionController.php:33 +#: src/Controller/Front/QuestionController.php:36 +#: src/Controller/Front/QuestionController.php:62 msgid "The question not found." msgstr "" @@ -98,15 +99,31 @@ msgid "List of all projects" msgstr "" #: src/Controller/Front/IndexController.php:53 -#: src/Controller/Front/ProjectController.php:55 +#: src/Controller/Front/ProjectController.php:65 msgid "List of all questions" msgstr "" -#: src/Controller/Front/ProjectController.php:34 +#: src/Controller/Front/ProjectController.php:37 #: src/Controller/Front/SubmitController.php:45 msgid "Project not set." msgstr "" +#: src/Controller/Front/QuestionController.php:174 +msgid "Question confirmed !" +msgstr "" + +#: src/Controller/Front/QuestionController.php:185 +msgid "Question rejected !" +msgstr "" + +#: src/Controller/Front/QuestionController.php:200 +msgid "Answer confirmed !" +msgstr "" + +#: src/Controller/Front/QuestionController.php:211 +msgid "Answer rejected !" +msgstr "" + #: src/Controller/Front/SubmitController.php:34 msgid "Ask question not active" msgstr "" @@ -144,9 +161,9 @@ msgid "List of all used tags" msgstr "" #: src/Form/AnswerForm.php:49 template/admin/question-index.phtml:26 -#: template/front/question-index.phtml:104 -#: template/front/question-index.phtml:108 #: template/front/question-list.phtml:73 +#: template/front/question-single.phtml:148 +#: template/front/question-single.phtml:152 msgid "Answer" msgstr "" @@ -201,12 +218,15 @@ msgid "Status" msgstr "" #: src/Form/ProjectForm.php:106 src/Form/UpdateForm.php:112 -#: template/admin/project-index.phtml:34 template/admin/question-index.phtml:61 +#: template/admin/project-index.phtml:34 template/admin/question-index.phtml:74 msgid "Published" msgstr "" #: src/Form/ProjectForm.php:107 src/Form/UpdateForm.php:113 -#: template/admin/project-index.phtml:35 template/admin/question-index.phtml:62 +#: template/admin/project-index.phtml:35 template/admin/question-index.phtml:75 +#: template/front/question-list.phtml:95 +#: template/front/question-single.phtml:53 +#: template/front/question-single.phtml:128 msgid "Pending review" msgstr "" @@ -285,7 +305,8 @@ msgid "View" msgstr "" #: template/admin/project-index.phtml:26 template/admin/project-index.phtml:28 -#: template/admin/question-index.phtml:53 +#: template/admin/question-index.phtml:62 +#: template/admin/question-index.phtml:64 msgid "Edit" msgstr "" @@ -306,25 +327,30 @@ msgstr "" msgid "Create" msgstr "" -#: template/admin/question-index.phtml:49 -#: template/admin/question-index.phtml:78 +#: template/admin/question-index.phtml:55 +#: template/admin/question-index.phtml:91 +#: template/front/question-single.phtml:40 +#: template/front/question-single.phtml:45 +#: template/front/question-single.phtml:116 +#: template/front/question-single.phtml:121 msgid "Reject" msgstr "" -#: template/admin/question-index.phtml:51 -#: template/admin/question-index.phtml:83 +#: template/admin/question-index.phtml:60 +#: template/admin/question-index.phtml:96 msgid "Accept" msgstr "" -#: template/admin/question-index.phtml:54 +#: template/admin/question-index.phtml:65 +#: template/admin/question-index.phtml:67 msgid "Delete" msgstr "" -#: template/admin/question-index.phtml:65 +#: template/admin/question-index.phtml:78 msgid "No question submit yet" msgstr "" -#: template/admin/question-index.phtml:72 +#: template/admin/question-index.phtml:85 msgid "Accept in process" msgstr "" @@ -332,28 +358,19 @@ msgstr "" msgid "Slug" msgstr "" -#: template/front/answer-index.phtml:19 template/front/question-index.phtml:27 -#: template/front/question-index.phtml:82 +#: template/front/answer-index.phtml:19 template/front/question-single.phtml:28 +#: template/front/question-single.phtml:106 msgid "Time" msgstr "" -#: template/front/answer-index.phtml:20 template/front/question-index.phtml:28 +#: template/front/answer-index.phtml:20 template/front/question-single.phtml:29 msgid "Read" msgstr "" -#: template/front/answer-index.phtml:20 template/front/question-index.phtml:28 +#: template/front/answer-index.phtml:20 template/front/question-single.phtml:29 msgid "Times" msgstr "" -#: template/front/question-index.phtml:13 -#: template/front/question-index.phtml:76 -msgid "View profile" -msgstr "" - -#: template/front/question-index.phtml:62 -msgid "Answers" -msgstr "" - #: template/front/question-list.phtml:20 msgid "Contact to manager" msgstr "" @@ -371,14 +388,30 @@ msgstr "" msgid "Vote" msgstr "" -#: template/front/question-list.phtml:100 +#: template/front/question-list.phtml:103 msgid "On" msgstr "" -#: template/front/question-list.phtml:102 +#: template/front/question-list.phtml:105 msgid "By" msgstr "" +#: template/front/question-single.phtml:14 +#: template/front/question-single.phtml:100 +msgid "View profile" +msgstr "" + +#: template/front/question-single.phtml:34 +#: template/front/question-single.phtml:39 +#: template/front/question-single.phtml:110 +#: template/front/question-single.phtml:115 +msgid "Confirm" +msgstr "" + +#: template/front/question-single.phtml:85 +msgid "Answers" +msgstr "" + #: template/front/submit-index.phtml:11 msgid "Roles to ask question" msgstr "" diff --git a/locale/fa/admin.mo b/locale/fa/admin.mo index 78bcaaca77e5d405c25dd9f05ed833778ef99350..234d2d3fdb11cf2e3b8df3af0890e0e5c208f73c 100644 GIT binary patch delta 848 zcmXZaOK1~O6oBC~nWU*vv`w1$YU>qD4bsxY2ioeQf(sW`YN0FLL@5O!tqpEOAyl-9 zP$@VB1UJ4QZBewQD+>xD?Xnw%I|@P3ayapl7Q)EQ>ZchAYab03r6$(dB?TRdD9 zt}dQ-o^y`KF}xKba1FU4NxXm&9K%5@U=uDQw|pRM#}$m@XY9rw7{g>(B#H*PB}3RM zQj#7TDGGh49fznY&_Ir*Dlx5t8t7!03U;}lc6suJ`QTugaGaf;@$SG`L zemPA;S3bO15XqzNtcW}C2C@mchdS_nP=65QPf=f7!^@oBYdlDvV0NAOB+lYl)P5Fq zL+hAhe)&UVCuaC{00&TaK7|IKp`Oe~)K9U7o%kJff#EIx$G2gIyc>7nNZ>do$jhiF z`v?!=ODyf7VQF;WFVu-z2|A!1nM1Ou^*(|w^bG0(F5zyxiQG~p=(xv0zJ$8K_n5{t z)RS!l^}jJ*!-;KPdQ|&@w*DCp@Pxhj&~c~3TMs21@fx9CV%qI>(%y(W7@sJbYsHDH zqgSq*LVi3yHd?Gdaeq2qHFCZ=ci7~z{YSI)jmV^P!uVxdGk(R`7k|9W|ZRh+u zhQb?yKW!K663L?Rr@zi<)tij&HFaAfTQFKO{$2Zu23_9SMZfappGT6u|K}JG-uKTDj|PsZEWT84{^UD|%SGbP~yf2TxMbMG=-dlo#1fOUOXU z;6d=>K~@$KbP_!oq(_mg%WshcL7_`Q;l-QZx6JUH-{<}Q?eEQ7FLRMDoFtb_;ih)ke@vW9o@8)_n_sOSITL#(S4xs6XkhcU(YHEM-t zu+T*?N6>;>=-_wMi~gb>xI}(a8kp4i44q!ohMK?tHsd(b{dRym0hC1th;92l>GU4tFvl0OzGHjO{r2e cW%Gsg4YyJ}_6RnEgLsV{Up1RL>mMd^S5Itlu>b%7 diff --git a/locale/fa/admin.po b/locale/fa/admin.po index ea81255..f83eb80 100644 --- a/locale/fa/admin.po +++ b/locale/fa/admin.po @@ -1,7 +1,7 @@ msgid "" msgstr "" "Project-Id-Version: \n" -"POT-Creation-Date: 2017-08-06 13:36+0430\n" +"POT-Creation-Date: 2017-08-12 10:40+0430\n" "PO-Revision-Date: \n" "Last-Translator: \n" "Language-Team: \n" @@ -23,7 +23,7 @@ msgstr "مدیریت" msgid "Show" msgstr "نمایش" -#: config/config.php:24 config/page.php:53 +#: config/config.php:24 config/page.php:48 msgid "Question" msgstr "سوال" @@ -80,13 +80,13 @@ msgid "Automatic approval" msgstr "تایید خودکار" #: config/config.php:116 -msgid "All questions and answers need admin review before publish" -msgstr "تمام سوالات و پاسخ خا به تایید مدیر برای انتشار نیاز دارند" - -#: config/config.php:117 msgid "Automatic approval all questions and answers" msgstr "تایید خودکار پرسش و پاسخ های ارسالی" +#: config/config.php:117 +msgid "All questions and answers need admin or project manager review before publish" +msgstr "تمام سوال ها و جواب ها قبل از انتشار نیاز به تایید مدیر سایت یا مدیر پروژه دارند" + #: config/config.php:128 msgid "Show feed icon" msgstr "نمایش آیکن خوارک" @@ -136,27 +136,23 @@ msgstr "پروژه ها" msgid "New project" msgstr "پروژه جدید" -#: config/navigation.php:112 config/page.php:27 config/permission.php:51 -msgid "Tools" -msgstr "ابزار" - -#: config/page.php:35 +#: config/page.php:30 msgid "Index page" msgstr "صفحه اول" -#: config/page.php:41 +#: config/page.php:36 msgid "Project page" msgstr "صفحه پروژه" -#: config/page.php:47 config/permission.php:30 +#: config/page.php:42 config/permission.php:30 msgid "Answer" msgstr "پاسخ" -#: config/page.php:59 +#: config/page.php:54 msgid "Submit question" msgstr "ارسال سوال" -#: config/page.php:65 +#: config/page.php:60 msgid "Tag" msgstr "برچسب" @@ -168,6 +164,12 @@ msgstr "دسترسی های عمومی" msgid "Submit" msgstr "ارسال" +#~ msgid "All questions and answers need admin review before publish" +#~ msgstr "تمام سوالات و پاسخ خا به تایید مدیر برای انتشار نیاز دارند" + +#~ msgid "Tools" +#~ msgstr "ابزار" + #~ msgid "Title" #~ msgstr "عنوان" diff --git a/locale/fa/default.mo b/locale/fa/default.mo index b6b08829f4c10da08c1042e7ab7c12b25743d28e..5e2955cc00078cd707d47e089aec22f342725435 100644 GIT binary patch delta 3042 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 aO!*P6Pc4fydfQ?n32ComBI)V(getUrl('profile', array( 'id' => $question['user']['id'], ))); + // Set text_description + $question['text_description'] = Pi::service('markup')->render($question['text_description'], 'html', 'text'); // Set info for Q and A switch ($question['type']) { case 'Q': - // Set text_description - $question['text_description'] = Pi::service('markup')->render($question['text_description'], 'html', 'text'); // Set question url $question['questionUrl'] = Pi::url(Pi::service('url')->assemble('ask', array( 'module' => $this->getModule(), @@ -97,8 +97,6 @@ public function canonizeQuestion($question) break; case 'A': - // Set text_description - $question['text_description'] = Pi::service('markup')->render($question['text_description'], 'html', 'text'); // Set question url $question['questionUrl'] = '#'; break; diff --git a/src/Controller/Front/AnswerController.php b/src/Controller/Front/AnswerController.php index 017b31d..d79044c 100644 --- a/src/Controller/Front/AnswerController.php +++ b/src/Controller/Front/AnswerController.php @@ -37,7 +37,7 @@ public function indexAction() // Find story $question = Pi::api('question', 'ask')->getQuestion($slug, 'slug'); // Check page - if (!$question || $question['status'] != 1) { + if (empty($question) || $question['status'] != 1) { $message = __('The question not found.'); $url = array('', 'module' => $module, 'controller' => 'index', 'action' => 'index'); $this->jump($url, $message); diff --git a/src/Controller/Front/ProjectController.php b/src/Controller/Front/ProjectController.php index 19fd387..ac5122c 100644 --- a/src/Controller/Front/ProjectController.php +++ b/src/Controller/Front/ProjectController.php @@ -10,6 +10,7 @@ /** * @author Hossein Azizabadi */ + namespace Module\Ask\Controller\Front; use Pi; @@ -26,6 +27,8 @@ public function indexAction() $slug = $this->params('slug'); // Get config $config = Pi::service('registry')->config->read($module); + // Get user id + $uid = Pi::user()->getId(); // Get topic information from model $project = Pi::api('project', 'ask')->getProject($slug, 'slug'); // Check slug set @@ -37,6 +40,12 @@ public function indexAction() } // Set question info $where = array('status' => 1, 'type' => 'Q', 'project_id' => $project['id']); + // check is project manager + $userIsManager = false; + if ($project['manager'] == $uid && $config['auto_approval'] == 2) { + $userIsManager = true; + $where['status'] = array(1, 2); + } // Set paginator info $template = array( 'controller' => 'index', @@ -52,7 +61,7 @@ public function indexAction() $this->view()->assign('paginator', $paginator); $this->view()->assign('project', $project); $this->view()->assign('config', $config); + $this->view()->assign('userIsManager', $userIsManager); $this->view()->assign('title', __('List of all questions')); - } } \ No newline at end of file diff --git a/src/Controller/Front/QuestionController.php b/src/Controller/Front/QuestionController.php index bdea648..a6d3a2b 100644 --- a/src/Controller/Front/QuestionController.php +++ b/src/Controller/Front/QuestionController.php @@ -26,11 +26,42 @@ public function indexAction() $module = $this->params('module'); // Get Module Config $config = Pi::service('registry')->config->read($module); + // Get user id + $uid = Pi::user()->getId(); // Find question $question = Pi::api('question', 'ask')->getQuestion($slug, 'slug'); // Check status - if (!$question || $question['status'] != 1) { - $this->jump(array('', 'module' => $module, 'controller' => 'index'), __('The question not found.')); + if (empty($question)) { + $this->getResponse()->setStatusCode(404); + $this->terminate(__('The question not found.'), '', 'error-404'); + $this->view()->setLayout('layout-simple'); + return; + } + // Get project + $question['is_manager'] = false; + if ($question['project_id'] > 0) { + $question['project'] = Pi::api('project', 'ask')->getProject($question['project_id']); + if ($question['project']['user']['id'] == $question['user']['id']) { + $question['is_manager'] = true; + } + } + // Check access + $access = false; + $userIsManager = false; + if (isset($question['project']) + && $question['project']['manager'] == $uid + && in_array($question['status'], array(1, 2)) + && $config['auto_approval'] == 2) { + $access = true; + $userIsManager = true; + } elseif ($question['status'] == 1) { + $access = true; + } + if (!$access) { + $this->getResponse()->setStatusCode(404); + $this->terminate(__('The question not found.'), '', 'error-404'); + $this->view()->setLayout('layout-simple'); + return; } // Update Hits $this->getModel('question')->increment('hits', array('id' => $question['id'])); @@ -46,18 +77,14 @@ public function indexAction() 'class' => 'btn-group-vertical', ); } - // Get project - $question['is_manager'] = false; - if ($question['project_id'] > 0) { - $question['project'] = Pi::api('project', 'ask')->getProject($question['project_id']); - if ($question['project']['user']['id'] == $question['user']['id']) { - $question['is_manager'] = true; - } - } + // Get answers if ($question['answer'] > 0) { $answers = array(); $where = array('status' => 1, 'question_id' => $question['id'], 'type' => 'A'); + if ($userIsManager) { + $where['status'] = array(1, 2); + } $order = array('point DESC', 'id DESC'); $select = $this->getModel('question')->select()->where($where)->order($order); $rowset = $this->getModel('question')->selectWith($select); @@ -87,8 +114,106 @@ public function indexAction() $this->view()->headTitle($question['seo_title']); $this->view()->headDescription($question['seo_keywords'], 'set'); $this->view()->headKeywords($question['seo_description'], 'set'); - $this->view()->setTemplate('question-index'); + $this->view()->setTemplate('question-single'); $this->view()->assign('question', $question); $this->view()->assign('config', $config); + $this->view()->assign('userIsManager', $userIsManager); + } + + public function reviewAction() + { + // Get info from url + $module = $this->params('module'); + $id = $this->params('id'); + $status = $this->params('status'); + // Get Module Config + $config = Pi::service('registry')->config->read($module); + // Get user id + $uid = Pi::user()->getId(); + // Check auto approval + if ($config['auto_approval'] == 1) { + return false; + } + // Find question + $question = Pi::api('question', 'ask')->getQuestion($id); + // Check question + if (empty($question) && $question['status'] != 2) { + return false; + } + // + if ($question['type'] == 'A') { + $mainQuestion = Pi::api('question', 'ask')->getQuestion($question['question_id']); + $question['project_id'] = $mainQuestion['project_id']; + } + // Get project + $project = Pi::api('project', 'ask')->getProject($question['project_id']); + // Check question + if (empty($project) || $project['status'] != 1) { + return false; + } + // Check status + if (!in_array($status, array('confirm', 'reject'))) { + return false; + } + // Check manager + if ($project['manager'] != $uid) { + return false; + } + // Back + switch ($question['type']) { + case 'Q': + switch ($status) { + case 'confirm': + // Update status + $this->getModel('question')->update( + array('status' => 1), + array('id' => $question['id']) + ); + // Set jump + $url = $question['questionUrl']; + $message = __('Question confirmed !'); + break; + + case 'reject': + // Update status + $this->getModel('question')->update( + array('status' => 5), + array('id' => $question['id']) + ); + // Set jump + $url = $project['projectUrl']; + $message = __('Question rejected !'); + break; + } + break; + + case 'A': + switch ($status) { + case 'confirm': + // Update status + $this->getModel('question')->update( + array('status' => 1), + array('id' => $question['id']) + ); + // Set jump + $url = $mainQuestion['questionUrl']; + $message = __('Answer confirmed !'); + break; + + case 'reject': + // Update status + $this->getModel('question')->update( + array('status' => 5), + array('id' => $question['id']) + ); + // Set jump + $url = $mainQuestion['questionUrl']; + $message = __('Answer rejected !'); + break; + } + break; + } + // Set jump + $this->jump($url, $message); } } \ No newline at end of file diff --git a/src/Route/Ask.php b/src/Route/Ask.php index 86019c7..9e61526 100644 --- a/src/Route/Ask.php +++ b/src/Route/Ask.php @@ -66,7 +66,14 @@ protected function parse($path) break; case 'question': - if (!empty($parts[1])) { + if (!empty($parts[1]) && $parts[1] == 'review') { + if (isset($parts[2]) && in_array($parts[2], array('confirm', 'reject')) + && isset($parts[3]) && !empty($parts[3])) { + $matches['action'] = 'review'; + $matches['status'] = $this->decode($parts[2]); + $matches['id'] = intval($parts[3]); + } + } elseif (!empty($parts[1])) { $matches['slug'] = $this->decode($parts[1]); } break; @@ -88,7 +95,7 @@ protected function parse($path) case 'term': $matches['action'] = 'term'; if (!empty($parts[2])) { - $matches['slug'] = urldecode($parts[2]); + $matches['slug'] = $this->decode($parts[2]); } break; @@ -96,11 +103,18 @@ protected function parse($path) $matches['action'] = 'list'; break; } - break; } } + /* echo '
';
+        print_r($matches);
+        echo '
'; + + echo '
';
+        print_r($parts);
+        echo '
'; */ + return $matches; } @@ -130,15 +144,18 @@ public function assemble( if (!empty($mergedParams['action']) && $mergedParams['action'] != 'index') { $url['action'] = $mergedParams['action']; } + if (!empty($mergedParams['status'])) { + $url['status'] = $mergedParams['status']; + } if (!empty($mergedParams['slug'])) { $url['slug'] = urlencode($mergedParams['slug']); } - if (!empty($mergedParams['order'])) { - $url['order'] = 'order' . $this->paramDelimiter . $mergedParams['order']; - } if (!empty($mergedParams['id'])) { $url['id'] = $mergedParams['id']; } + if (!empty($mergedParams['order'])) { + $url['order'] = 'order' . $this->paramDelimiter . $mergedParams['order']; + } // Make url $url = implode($this->paramDelimiter, $url); diff --git a/template/admin/question-index.phtml b/template/admin/question-index.phtml index 9f003a8..060ece1 100644 --- a/template/admin/question-index.phtml +++ b/template/admin/question-index.phtml @@ -17,23 +17,26 @@ $this->js($this->assetModule('script/system-msg.js', 'system')); - - + - - + + escape($question['title']); ?> - + escape($question['title']); ?> @@ -45,13 +48,23 @@ $this->js($this->assetModule('script/system-msg.js', 'system')); escape($question['time_create_view']); ?> - - - - + + + + - - + + @@ -65,27 +78,28 @@ $this->js($this->assetModule('script/system-msg.js', 'system')); -