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 a7dd459..1794268 100644 Binary files a/locale/en/admin.mo and b/locale/en/admin.mo differ 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 6afb018..eae563e 100644 Binary files a/locale/en/default.mo and b/locale/en/default.mo differ 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 78bcaac..234d2d3 100644 Binary files a/locale/fa/admin.mo and b/locale/fa/admin.mo differ 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 b6b0882..5e2955c 100644 Binary files a/locale/fa/default.mo and b/locale/fa/default.mo differ diff --git a/locale/fa/default.po b/locale/fa/default.po index 42d26e3..1cb44d3 100644 --- a/locale/fa/default.po +++ b/locale/fa/default.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" @@ -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 "سوال یافت نشد" @@ -100,15 +101,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 "امکان پرسیدن سوال فعال نیست" @@ -149,9 +166,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 "پاسخ" @@ -206,12 +223,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 "در انتظار تایید" @@ -248,6 +268,8 @@ msgid "" "Displayed in search Engine result pages as Title : between 10 to 70 " "character. If empty, will be popuated automaticaly by main title value" msgstr "" +"Displayed in search Engine result pages as Title : between 10 to 70 " +"character. If empty, will be popuated automaticaly by main title value" #: src/Form/ProjectForm.php:153 src/Form/UpdateForm.php:161 msgid "Meta Keywords" @@ -258,6 +280,8 @@ msgid "" "Not used anymore by search engines : between 5 to 12 words / left it empty, " "it will be automaticaly populated with main title values" msgstr "" +"Not used anymore by search engines : between 5 to 12 words / left it empty, " +"it will be automaticaly populated with main title values" #: src/Form/ProjectForm.php:166 src/Form/UpdateForm.php:174 msgid "Meta Description" @@ -268,6 +292,8 @@ msgid "" "Displayed in search Engine result pages : quick summary to incitate user to " "click, between 80 to 160 character" msgstr "" +"Displayed in search Engine result pages : quick summary to incitate user to " +"click, between 80 to 160 character" #: src/Form/UpdateForm.php:129 msgid "Project" @@ -290,7 +316,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 "ویرایش" @@ -311,25 +338,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 "تایید در حال انجام است" @@ -337,28 +369,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 "تماس با مدیر پروژه" @@ -376,14 +399,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/src/Api/Question.php b/src/Api/Question.php index 111da4a..02bef49 100644 --- a/src/Api/Question.php +++ b/src/Api/Question.php @@ -83,11 +83,11 @@ public function canonizeQuestion($question) $question['user']['profileUrl'] = Pi::url(Pi::service('user')->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')); -