diff --git a/locale/en/mail/answer_question_admin.txt b/locale/en/mail/answer_question_admin.txt
new file mode 100644
index 0000000..aa1bfa2
--- /dev/null
+++ b/locale/en/mail/answer_question_admin.txt
@@ -0,0 +1,20 @@
+[comment]answer question admin[/comment]
+
+[format]html[/format]
+
+[subject]%site_name% - Answer question[/subject]
+
+[body]
+
+
Dear %site_name% admin
+
New answer on %title% question on %time% by %user% submitted on website. Status is : %status%
+
%description%
+
+
Dont reply to this email
+
+
+[/body]
\ No newline at end of file
diff --git a/locale/en/mail/answer_question_manager.txt b/locale/en/mail/answer_question_manager.txt
new file mode 100644
index 0000000..9622a07
--- /dev/null
+++ b/locale/en/mail/answer_question_manager.txt
@@ -0,0 +1,20 @@
+[comment]answer question manager[/comment]
+
+[format]html[/format]
+
+[subject]%site_name% - Answer question[/subject]
+
+[body]
+
+
Dear %user%
+
New answer on %title% question on %time% by %user% submitted on website. Status is : %status%
+
%description%
+
+
Dont reply to this email
+
+
+[/body]
\ No newline at end of file
diff --git a/locale/en/mail/answer_question_questioner.txt b/locale/en/mail/answer_question_questioner.txt
new file mode 100644
index 0000000..99a4077
--- /dev/null
+++ b/locale/en/mail/answer_question_questioner.txt
@@ -0,0 +1,20 @@
+[comment]answer question questioner[/comment]
+
+[format]html[/format]
+
+[subject]%site_name% - Answer question[/subject]
+
+[body]
+
+
Dear %questioner%
+
New answer on %title% question on %time% by %user% submitted on website. Status is : %status%
+
%description%
+
+
Dont reply to this email
+
+
+[/body]
\ No newline at end of file
diff --git a/locale/en/mail/answer_question_user.txt b/locale/en/mail/answer_question_user.txt
new file mode 100644
index 0000000..e4b5b10
--- /dev/null
+++ b/locale/en/mail/answer_question_user.txt
@@ -0,0 +1,20 @@
+[comment]answer question user[/comment]
+
+[format]html[/format]
+
+[subject]%site_name% - Answer question[/subject]
+
+[body]
+
+
Dear %user%
+
You submit new answer on %title% question on %time%. Status is : %status%
+
%description%
+
+
Dont reply to this email
+
+
+[/body]
\ No newline at end of file
diff --git a/locale/en/mail/ask_question_admin.txt b/locale/en/mail/ask_question_admin.txt
new file mode 100644
index 0000000..4d8f473
--- /dev/null
+++ b/locale/en/mail/ask_question_admin.txt
@@ -0,0 +1,20 @@
+[comment]ask question admin[/comment]
+
+[format]html[/format]
+
+[subject]%site_name% - Ask question[/subject]
+
+[body]
+
+
Dear %site_name% admin
+
New question by %title% title on %time% by %user% submitted on website. Status is : %status%
+
%description%
+
+
Dont reply to this email
+
+
+[/body]
\ No newline at end of file
diff --git a/locale/en/mail/ask_question_manager.txt b/locale/en/mail/ask_question_manager.txt
new file mode 100644
index 0000000..80f4d8a
--- /dev/null
+++ b/locale/en/mail/ask_question_manager.txt
@@ -0,0 +1,20 @@
+[comment]ask question manager[/comment]
+
+[format]html[/format]
+
+[subject]%site_name% - Ask question[/subject]
+
+[body]
+
+
Dear %site_name% manager
+
New question by %title% title on %time% by %user% submitted on website. Status is : %status%
+
%description%
+
+
Dont reply to this email
+
+
+[/body]
\ No newline at end of file
diff --git a/locale/en/mail/ask_question_user.txt b/locale/en/mail/ask_question_user.txt
new file mode 100644
index 0000000..da42c52
--- /dev/null
+++ b/locale/en/mail/ask_question_user.txt
@@ -0,0 +1,20 @@
+[comment]ask question user[/comment]
+
+[format]html[/format]
+
+[subject]%site_name% - Ask question[/subject]
+
+[body]
+
+
Dear %user%
+
You submit question by %title% title on %time% by %user%. Status is : %status%
+
%description%
+
+
Dont reply to this email
+
+
+[/body]
\ No newline at end of file
diff --git a/locale/en/mail/review_question_admin.txt b/locale/en/mail/review_question_admin.txt
new file mode 100644
index 0000000..61aa412
--- /dev/null
+++ b/locale/en/mail/review_question_admin.txt
@@ -0,0 +1,20 @@
+[comment]review question admin[/comment]
+
+[format]html[/format]
+
+[subject]%site_name% - Review question / answer[/subject]
+
+[body]
+
+
Dear %site_name% admin
+
Question / answer by %title% title on %time% by %user% reviewed on website. Status is : %status%
+
%description%
+
+
Dont reply to this email
+
+
+[/body]
\ No newline at end of file
diff --git a/locale/en/mail/review_question_questioner.txt b/locale/en/mail/review_question_questioner.txt
new file mode 100644
index 0000000..e29c26a
--- /dev/null
+++ b/locale/en/mail/review_question_questioner.txt
@@ -0,0 +1,20 @@
+[comment]review question questioner[/comment]
+
+[format]html[/format]
+
+[subject]%site_name% - Review question / answer[/subject]
+
+[body]
+
+
Dear %questioner%
+
Answer on %title% question on %time% by %user% reviewed on website. Status is : %status%
+
%description%
+
+
Dont reply to this email
+
+
+[/body]
\ No newline at end of file
diff --git a/locale/en/mail/review_question_user.txt b/locale/en/mail/review_question_user.txt
new file mode 100644
index 0000000..3933b0a
--- /dev/null
+++ b/locale/en/mail/review_question_user.txt
@@ -0,0 +1,20 @@
+[comment]review question user[/comment]
+
+[format]html[/format]
+
+[subject]%site_name% - Review question / answer[/subject]
+
+[body]
+
+
Dear %user%
+
Your submited question / answer by %title% title on %time% reviewed on website. Status is : %status%
+
%description%
+
+
Dont reply to this email
+
+
+[/body]
\ No newline at end of file
diff --git a/locale/fa/mail/answer_question_admin.txt b/locale/fa/mail/answer_question_admin.txt
new file mode 100644
index 0000000..36fd525
--- /dev/null
+++ b/locale/fa/mail/answer_question_admin.txt
@@ -0,0 +1,20 @@
+[comment]answer question admin[/comment]
+
+[format]html[/format]
+
+[subject]%site_name% - پاسخ به سوال[/subject]
+
+[body]
+
+
مدیر وب سایت %site_name%
+
یک پاسخ جدید به سوال %title% در تاریخ %time% توسط %user% در وب سایت ارسال شد : وضعیت %status%
+
%description%
+
+
لطفا به این پیام پاسخی ندهید
+
+
+[/body]
\ No newline at end of file
diff --git a/locale/fa/mail/answer_question_manager.txt b/locale/fa/mail/answer_question_manager.txt
new file mode 100644
index 0000000..3abf6a8
--- /dev/null
+++ b/locale/fa/mail/answer_question_manager.txt
@@ -0,0 +1,20 @@
+[comment]answer question manager[/comment]
+
+[format]html[/format]
+
+[subject]%site_name% - پاسخ به سوال[/subject]
+
+[body]
+
+
مدیر پروژه عزیز در وب سایت %site_name%
+
یک پاسخ جدید به سوال %title% در تاریخ %time% توسط %user% در وب سایت ارسال شد : وضعیت %status%
+
%description%
+
+
لطفا به این پیام پاسخی ندهید
+
+
+[/body]
\ No newline at end of file
diff --git a/locale/fa/mail/answer_question_questioner.txt b/locale/fa/mail/answer_question_questioner.txt
new file mode 100644
index 0000000..a9d19f6
--- /dev/null
+++ b/locale/fa/mail/answer_question_questioner.txt
@@ -0,0 +1,20 @@
+[comment]answer question questioner[/comment]
+
+[format]html[/format]
+
+[subject]%site_name% - پاسخ به سوال[/subject]
+
+[body]
+
+
%questioner% عزیز
+
یک پاسخ جدید به سوال %title% در تاریخ %time% توسط %user% در وب سایت ارسال شد : وضعیت %status%
+
%description%
+
+
لطفا به این پیام پاسخی ندهید
+
+
+[/body]
\ No newline at end of file
diff --git a/locale/fa/mail/answer_question_user.txt b/locale/fa/mail/answer_question_user.txt
new file mode 100644
index 0000000..d85cefb
--- /dev/null
+++ b/locale/fa/mail/answer_question_user.txt
@@ -0,0 +1,20 @@
+[comment]answer question user[/comment]
+
+[format]html[/format]
+
+[subject]%site_name% - پاسخ به سوال[/subject]
+
+[body]
+
+
%user% عزیز
+
پاسخ شما به سوال %title% در تاریخ %time% در وب سایت ارسال شد : وضعیت %status%
+
%description%
+
+
لطفا به این پیام پاسخی ندهید
+
+
+[/body]
\ No newline at end of file
diff --git a/locale/fa/mail/ask_question_admin.txt b/locale/fa/mail/ask_question_admin.txt
new file mode 100644
index 0000000..d8c0642
--- /dev/null
+++ b/locale/fa/mail/ask_question_admin.txt
@@ -0,0 +1,20 @@
+[comment]ask question admin[/comment]
+
+[format]html[/format]
+
+[subject]%site_name% - ارسال سوال[/subject]
+
+[body]
+
+
مدیر وب سایت %site_name%
+
یک سوال جدید با عنوان %title% در تاریخ %time% توسط %user% در وب سایت ارسال شد : وضعیت %status%
+
%description%
+
+
لطفا به این پیام پاسخی ندهید
+
+
+[/body]
\ No newline at end of file
diff --git a/locale/fa/mail/ask_question_manager.txt b/locale/fa/mail/ask_question_manager.txt
new file mode 100644
index 0000000..4ea32b2
--- /dev/null
+++ b/locale/fa/mail/ask_question_manager.txt
@@ -0,0 +1,20 @@
+[comment]ask question manager[/comment]
+
+[format]html[/format]
+
+[subject]%site_name% - ارسال سوال[/subject]
+
+[body]
+
+
مدیر پروژه عزیز در وب سایت %site_name%
+
یک سوال جدید با عنوان %title% در تاریخ %time% توسط %user% در وب سایت ارسال شد : وضعیت %status%
+
%description%
+
+
لطفا به این پیام پاسخی ندهید
+
+
+[/body]
\ No newline at end of file
diff --git a/locale/fa/mail/ask_question_user.txt b/locale/fa/mail/ask_question_user.txt
new file mode 100644
index 0000000..57c1112
--- /dev/null
+++ b/locale/fa/mail/ask_question_user.txt
@@ -0,0 +1,20 @@
+[comment]ask question user[/comment]
+
+[format]html[/format]
+
+[subject]%site_name% - ارسال سوال[/subject]
+
+[body]
+
+
%user% عزیز
+
سوال شما با عنوان %title% در تاریخ %time% در وب سایت ارسال شد : وضعیت %status%
+
%description%
+
+
لطفا به این پیام پاسخی ندهید
+
+
+[/body]
\ No newline at end of file
diff --git a/locale/fa/mail/review_question_admin.txt b/locale/fa/mail/review_question_admin.txt
new file mode 100644
index 0000000..dc80005
--- /dev/null
+++ b/locale/fa/mail/review_question_admin.txt
@@ -0,0 +1,20 @@
+[comment]review question admin[/comment]
+
+[format]html[/format]
+
+[subject]%site_name% - بررسی سوال / پاسخ[/subject]
+
+[body]
+
+
مدیر وب سایت %site_name%
+
سوال / پاسخ با عنوان %title% ارسال شده در تاریخ %time% توسط %user% در وب سایت بررسی شد. نتیجه بررسی : %status%
+
%description%
+
+
لطفا به این پیام پاسخی ندهید
+
+
+[/body]
\ No newline at end of file
diff --git a/locale/fa/mail/review_question_questioner.txt b/locale/fa/mail/review_question_questioner.txt
new file mode 100644
index 0000000..f988af5
--- /dev/null
+++ b/locale/fa/mail/review_question_questioner.txt
@@ -0,0 +1,20 @@
+[comment]review question questioner[/comment]
+
+[format]html[/format]
+
+[subject]%site_name% - بررسی سوال / پاسخ[/subject]
+
+[body]
+
+
%questioner% عزیز
+
پاسخ به پرسش شما با عنوان %title% ارسال شده در تاریخ %time% توسط %user% در وب سایت بررسی شد. نتیجه بررسی : %status%
+
%description%
+
+
لطفا به این پیام پاسخی ندهید
+
+
+[/body]
\ No newline at end of file
diff --git a/locale/fa/mail/review_question_user.txt b/locale/fa/mail/review_question_user.txt
new file mode 100644
index 0000000..d7e771f
--- /dev/null
+++ b/locale/fa/mail/review_question_user.txt
@@ -0,0 +1,20 @@
+[comment]review question user[/comment]
+
+[format]html[/format]
+
+[subject]%site_name% - بررسی سوال / پاسخ[/subject]
+
+[body]
+
+
%user% عزیز
+
سوال / پاسخ ارسالی شما با عنوان %title% ارسال شده در تاریخ %time% در وب سایت بررسی شد. نتیجه بررسی : %status%
+
%description%
+
+
لطفا به این پیام پاسخی ندهید
+
+
+[/body]
\ No newline at end of file
diff --git a/src/Api/Notification.php b/src/Api/Notification.php
new file mode 100644
index 0000000..8a2f8c5
--- /dev/null
+++ b/src/Api/Notification.php
@@ -0,0 +1,183 @@
+
+ */
+
+namespace Module\Ask\Api;
+
+use Pi;
+use Pi\Application\Api\AbstractApi;
+
+/*
+ * Pi::api('notification', 'ask')->askQuestion();
+ * Pi::api('notification', 'ask')->answerQuestion();
+ * Pi::api('notification', 'ask')->reviewQuestion();
+ */
+
+class Notification extends AbstractApi
+{
+ public function askQuestion($question, $project)
+ {
+ // Set information
+ $information = array(
+ 'title' => $question['title'],
+ 'description' => $question['text_description'],
+ 'user' => $question['user']['name'],
+ 'time' => $question['time_create_view'],
+ 'url' => $question['questionUrl'],
+ 'status' => $question['status'] == 1 ? __('Published'): __('Pending review'),
+ );
+
+ // Send notification to admin
+ Pi::service('notification')->send(
+ array(
+ Pi::config('adminmail') => Pi::config('adminname'),
+ ),
+ 'ask_question_admin',
+ $information,
+ Pi::service('module')->current()
+ );
+
+ // Send notification to project manager
+ if (!empty($project)) {
+ Pi::service('notification')->send(
+ array(
+ $project['user']['email'] => $project['user']['name'],
+ ),
+ 'ask_question_manager',
+ $information,
+ Pi::service('module')->current(),
+ $project['user']['id']
+ );
+ }
+
+ // Send notification to user
+ Pi::service('notification')->send(
+ array(
+ $question['user']['email'] => $question['user']['name'],
+ ),
+ 'ask_question_user',
+ $information,
+ Pi::service('module')->current(),
+ $question['user']['id']
+ );
+ }
+
+ public function answerQuestion($question, $answer, $project)
+ {
+ // Set information
+ $information = array(
+ 'title' => $question['title'],
+ 'description' => $answer['text_description'],
+ 'questioner' => $question['user']['name'],
+ 'user' => $answer['user']['name'],
+ 'time' => $answer['time_create_view'],
+ 'url' => $question['questionUrl'],
+ 'status' => $answer['status'] == 1 ? __('Published'): __('Pending review'),
+ );
+
+ // Send notification to admin
+ Pi::service('notification')->send(
+ array(
+ Pi::config('adminmail') => Pi::config('adminname'),
+ ),
+ 'answer_question_admin',
+ $information,
+ Pi::service('module')->current()
+ );
+
+ // Send notification to project manager
+ if (!empty($project)) {
+ Pi::service('notification')->send(
+ array(
+ $project['user']['email'] => $project['user']['name'],
+ ),
+ 'answer_question_manager',
+ $information,
+ Pi::service('module')->current(),
+ $project['user']['id']
+ );
+ }
+
+ // Send notification to user
+ Pi::service('notification')->send(
+ array(
+ $answer['user']['email'] => $answer['user']['name'],
+ ),
+ 'answer_question_user',
+ $information,
+ Pi::service('module')->current(),
+ $answer['user']['id']
+ );
+
+ // Send notification to questioner
+ if ($answer['uid'] != $question['uid']) {
+ Pi::service('notification')->send(
+ array(
+ $question['user']['email'] => $question['user']['name'],
+ ),
+ 'answer_question_questioner',
+ $information,
+ Pi::service('module')->current(),
+ $question['user']['id']
+ );
+ }
+ }
+
+ public function reviewQuestion($status, $project, $question, $mainQuestion)
+ {
+ // Set information
+ $information = array(
+ 'title' => !empty($mainQuestion) ? $mainQuestion['title'] : $question['title'],
+ 'description' => !empty($mainQuestion) ? $mainQuestion['text_description'] : $question['text_description'],
+ 'questioner' => !empty($mainQuestion) ? $mainQuestion['user']['name'] : '',
+ 'user' => !empty($mainQuestion) ? $mainQuestion['user']['name'] : $question['user']['name'],
+ 'time' => !empty($mainQuestion) ? $mainQuestion['time_create_view'] : $question['time_create_view'],
+ 'url' => !empty($mainQuestion) ? $mainQuestion['questionUrl'] : $question['questionUrl'],
+ 'status' => $status == 'confirm' ? __('Confirmed'): __('Rejected'),
+
+ );
+
+ // Send notification to admin
+ Pi::service('notification')->send(
+ array(
+ Pi::config('adminmail') => Pi::config('adminname'),
+ ),
+ 'review_question_admin',
+ $information,
+ Pi::service('module')->current()
+ );
+
+ // Send notification to user
+ Pi::service('notification')->send(
+ array(
+ $question['user']['email'] => $question['user']['name'],
+ ),
+ 'review_question_user',
+ $information,
+ Pi::service('module')->current(),
+ $question['user']['id']
+ );
+
+ // Send notification to questioner
+ if (!empty($mainQuestion)) {
+ Pi::service('notification')->send(
+ array(
+ $mainQuestion['user']['email'] => $mainQuestion['user']['name'],
+ ),
+ 'review_question_questioner',
+ $information,
+ Pi::service('module')->current(),
+ $mainQuestion['user']['id']
+ );
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/Controller/Front/AnswerController.php b/src/Controller/Front/AnswerController.php
index d79044c..3f06a42 100644
--- a/src/Controller/Front/AnswerController.php
+++ b/src/Controller/Front/AnswerController.php
@@ -42,6 +42,19 @@ public function indexAction()
$url = array('', 'module' => $module, 'controller' => 'index', 'action' => 'index');
$this->jump($url, $message);
}
+ // Check project
+ $project = array();
+ if ($config['project_active'] && $question['project_id']) {
+ // Get topic information from model
+ $project = Pi::api('project', 'ask')->getProject($question['project_id']);
+ // Check slug set
+ if (empty($project) || $project['status'] != 1) {
+ $this->getResponse()->setStatusCode(404);
+ $this->terminate(__('Project not set.'), '', 'error-404');
+ $this->view()->setLayout('layout-simple');
+ return;
+ }
+ }
// get info
$form = new AnswerForm('Answer');
if ($this->request->isPost()) {
@@ -75,6 +88,7 @@ public function indexAction()
$values['uid'] = Pi::user()->getId();
$values['status'] = $this->config('auto_approval');
$values['type'] = 'A';
+ $values['project_id'] = $project['id'];
// Update answer
$this->getModel('question')->update(
array('answer' => $question['answer'] + 1),
@@ -84,6 +98,10 @@ public function indexAction()
$row = $this->getModel('question')->createRow();
$row->assign($values);
$row->save();
+ // Set question
+ $answer = Pi::api('question', 'ask')->canonizeQuestion($row);
+ // Send notification
+ Pi::api('notification', 'ask')->askQuestion($question, $answer, $project);
// Check it save or not
if ($this->config('auto_approval')) {
$message = __('Your new answer to this question save successfully, and show under question');
diff --git a/src/Controller/Front/QuestionController.php b/src/Controller/Front/QuestionController.php
index a6d3a2b..3fb2aff 100644
--- a/src/Controller/Front/QuestionController.php
+++ b/src/Controller/Front/QuestionController.php
@@ -141,6 +141,7 @@ public function reviewAction()
return false;
}
//
+ $mainQuestion = array();
if ($question['type'] == 'A') {
$mainQuestion = Pi::api('question', 'ask')->getQuestion($question['question_id']);
$question['project_id'] = $mainQuestion['project_id'];
@@ -213,6 +214,8 @@ public function reviewAction()
}
break;
}
+ //
+ Pi::api('notification', 'ask')->reviewQuestion($status, $project, $question, $mainQuestion);
// Set jump
$this->jump($url, $message);
}
diff --git a/src/Controller/Front/SubmitController.php b/src/Controller/Front/SubmitController.php
index c7f50db..a6945ab 100644
--- a/src/Controller/Front/SubmitController.php
+++ b/src/Controller/Front/SubmitController.php
@@ -36,6 +36,7 @@ public function indexAction()
// Check user is login or not
Pi::service('authentication')->requireLogin();
// Check project
+ $project = array();
if ($config['project_active'] && !empty($slug)) {
// Get topic information from model
$project = Pi::api('project', 'ask')->getProject($slug, 'slug');
@@ -99,6 +100,10 @@ public function indexAction()
if (isset($tag) && is_array($tag) && Pi::service('module')->isActive('tag')) {
Pi::service('tag')->add($this->params('module'), $row->id, '', $tag);
}
+ // Set question
+ $question = Pi::api('question', 'ask')->canonizeQuestion($row);
+ // Send notification
+ Pi::api('notification', 'ask')->askQuestion($question, $project);
// Check it save or not
if ($this->config('auto_approval')) {
$message = __('Your ask new question successfully, Other users can view and answer it');