Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added email sending after creating/editing/deleting a message and cre…

…ating a comment
  • Loading branch information...
commit 2ebb87b8313daa47d5e1e717da9ea385c70abec8 1 parent 4e8c8bb
filo authored
View
2  apps/fe/config/app.yml
@@ -10,3 +10,5 @@ all:
sf_guard_plugin:
remember_key_expiration_age: 2592000 # 30 days in seconds
remember_cookie_name: phpcollabRememberMe
+ mail:
+ from: no_reply@example.com
View
23 apps/fe/config/factories.yml
@@ -4,6 +4,21 @@ prod:
param:
level: err
loggers: ~
+ mailer:
+ class: sfMailer
+ param:
+ logging: %SF_LOGGING_ENABLED%
+ charset: %SF_CHARSET%
+ delivery_strategy: none
+# delivery_strategy: realtime
+# transport:
+# class: Swift_SmtpTransport
+# param:
+# host: localhost
+# port: 25
+# encryption: ~
+# username: ~
+# password: ~
demo:
storage:
@@ -42,6 +57,14 @@ all:
param:
generate_shortest_url: true
extra_parameters_as_query_string: true
+ mailer:
+ class: sfMailer
+ param:
+ logging: %SF_LOGGING_ENABLED%
+ charset: %SF_CHARSET%
+ delivery_strategy: none
+ transport:
+ class: Swift_NullTransport
#all:
# controller:
View
BIN  data/phpcollab_unit_test.db
Binary file not shown
View
12 plugins/CommentPlugin/lib/model/doctrine/PluginfdComment.class.php
@@ -10,4 +10,16 @@ public function getUser()
return Doctrine::getTable('fdComment')->getUserForComment($this->user_id);
}
+ public function getRelatedUsers()
+ {
+ $method = 'findOneby'.$this->getModelField();
+ $object = Doctrine::getTable($this->getModel())->$method($this->getModelFieldValue());
+
+ if (method_exists($object, 'getRelatedUsers'))
+ {
+ return $object->getRelatedUsers();
+ }
+
+ return array();
+ }
}
View
17 plugins/CommentPlugin/modules/fd_comment/actions/actions.class.php
@@ -8,7 +8,7 @@
* @author Your name here
* @version SVN: $Id: actions.class.php 12474 2008-10-31 10:41:27Z fabien $
*/
-class fd_commentActions extends sfActions
+class fd_commentActions extends collabActions
{
public function preExecute()
{
@@ -77,10 +77,10 @@ public function executeCreate(sfWebRequest $request)
$this->form = new fdCommentForm(new $object_model_class, $request->getParameter('model_field'), $request->getParameter('model_field_value'));
- if ($request->isXmlHttpRequest())
- {
- return $this->processAjaxForm($request, $this->form);
- }
+// if ($request->isXmlHttpRequest())
+// {
+// return $this->processAjaxForm($request, $this->form);
+// }
$this->processForm($request, $this->form);
}
@@ -138,6 +138,13 @@ protected function processForm(sfWebRequest $request, sfForm $form)
if ($form->isValid())
{
$fd_comment = $form->save();
+ $this->sendEmail($fd_comment,
+ $this->getPartial('idProject/mail', array('object' => $fd_comment,
+ 'action' => 'created',
+ 'user' => $this->getUser()->getGuardUser(),
+ 'show' => true)),
+ 'created'
+ );
$this->redirect($this->redirect_to);
}
View
26 plugins/idProjectManagementPlugin/lib/actions/collabActions.class.php
@@ -0,0 +1,26 @@
+<?php
+
+class collabActions extends sfActions
+{
+ protected function sendEmail($object, $body, $action)
+ {
+ $to = array();
+ foreach($object->getRelatedUsers() as $user)
+ {
+ $to[] = $user->email_address;
+ }
+
+ if (empty($to))
+ {
+ return;
+ }
+
+ $from = sfConfig::get('app_mail_from');
+ $mail = $this->getMailer()->compose($from,
+ $to,
+ get_class($object).' '.$object->title.' '.$action,
+ $body);
+ $mail->setContentType('text/html');
+ $this->getMailer()->send($mail);
+ }
+}
View
5 plugins/idProjectManagementPlugin/lib/model/doctrine/PluginMessage.class.php
@@ -19,4 +19,9 @@ public function getLastCommentDate()
}
return $this->created_at;
}
+
+ public function getRelatedUsers()
+ {
+ return $this->getProject()->getUsers();
+ }
}
View
16 plugins/idProjectManagementPlugin/modules/idMessage/actions/actions.class.php
@@ -8,7 +8,7 @@
* @author Your name here
* @version SVN: $Id: actions.class.php 12474 2008-10-31 10:41:27Z fabien $
*/
-class idMessageActions extends sfActions
+class idMessageActions extends collabActions
{
public function preExecute()
{
@@ -78,6 +78,12 @@ public function executeDelete(sfWebRequest $request)
$this->forward404Unless($message->project_id == $request->getParameter('project_id'));
$message->delete();
+ $this->sendEmail($message,
+ $this->getPartial('idProject/mail', array('object' => $message,
+ 'action' => 'deleted',
+ 'user' => $this->getUser()->getGuardUser())),
+ 'deleted'
+ );
$this->getUser()->setFlash('notice', 'Message deleted successfully');
$this->redirect('@index_messages?project_id='.$request->getParameter('project_id'));
@@ -101,6 +107,14 @@ protected function processForm(sfWebRequest $request, sfForm $form)
$operation = 'create';
}
+ $this->sendEmail($message,
+ $this->getPartial('idProject/mail', array('object' => $message,
+ 'action' => $operation.'d',
+ 'user' => $this->getUser()->getGuardUser(),
+ 'show' => true)),
+ $operation.'d'
+ );
+
$this->getUser()->setFlash('notice', 'Object '.$operation.'d successfully');
$this->redirect('@edit_message?project_id='.$request->getParameter('project_id').'&message_id='.$message->getId());
}
View
12 plugins/idProjectManagementPlugin/modules/idProject/templates/_mail.php
@@ -0,0 +1,12 @@
+Hi, this is your collab installation mail system.<br/>
+A <?php echo strtolower(get_class($object)) ?> has been <?php echo $action ?>.<br/>
+<br/>
+<?php echo get_class($object) ?> <?php echo $object->title ?> has been <?php echo $action ?> by <?php echo $user->getUsername() ?> on <?php echo date('Y-m-d') ?>
+<br/>
+<?php if (isset($show) && $show === true): ?>
+<h3><?php echo $object->title ?></h3>
+<?php echo $object->body ?>
+<?php endif; ?>
+<br/>
+See you soon,
+phpCollab3
View
7 test/functional/fe/idProjectMessageCommentCreateTest.php
@@ -23,6 +23,13 @@
end()->
click('Leave a comment', array('fd_comment' => array('title' => 'comment title', 'body' => 'comment body: your message rocks!!' )))->
+ with('mailer')->begin()->
+ checkHeader('Subject', '/fdComment .* created/')->
+ checkHeader('To', '/example3@example.com/')->
+ checkHeader('To', '/example5@example.com/')->
+ checkBody('/comment title/')->
+ checkBody('/comment body: your message rocks/')->
+ end()->
followRedirect()->
with('request')->begin()->
View
9 test/functional/fe/idProjectMessageCreateTest.php
@@ -23,6 +23,15 @@
end()->
click('Save', array('message' => array('title' => 'Terzo', 'body' => 'body terzo' )))->
+
+ with('mailer')->begin()->
+ checkHeader('Subject', '/Message .* created/')->
+ checkHeader('To', '/example3@example.com/')->
+ checkHeader('To', '/example5@example.com/')->
+ checkBody('/A message has been created/')->
+ checkBody('/Terzo/')->
+ checkBody('/body terzo/')->
+ end()->
followRedirect()->
with('request')->begin()->
View
8 test/functional/fe/idProjectMessageDeleteTest.php
@@ -22,6 +22,14 @@
click('Delete')->
+ with('mailer')->begin()->
+ checkHeader('Subject', '/Message .* deleted/')->
+ checkHeader('To', '/example3@example.com/')->
+ checkHeader('To', '/example5@example.com/')->
+ checkBody('/Hi, this is your collab installation mail system/')->
+ checkBody('/A message has been deleted/')->
+ checkBody('/has been deleted by puser on/')->
+ end()->
followRedirect()->
with('request')->begin()->
View
8 test/functional/fe/idProjectMessageEditTest.php
@@ -23,6 +23,14 @@
end()->
click('Save', array('message' => array('title' => 'Primo primo', 'body' => 'body primo primo' )))->
+ with('mailer')->begin()->
+ checkHeader('Subject', '/Message .* updated/')->
+ checkHeader('To', '/example3@example.com/')->
+ checkHeader('To', '/example5@example.com/')->
+ checkBody('/A message has been updated/')->
+ checkBody('/Primo primo/')->
+ checkBody('/body primo primo/')->
+ end()->
followRedirect()->
with('request')->begin()->
Please sign in to comment.
Something went wrong with that request. Please try again.