Author: fizyk
Date: 2010-03-31 22:18:56 +0200 (Wed, 31 Mar 2010)
New Revision: 28935
Modified:
plugins/vjCommentPlugin/TRUNK/config/app.yml
plugins/vjCommentPlugin/TRUNK/config/doctrine/schema.yml
plugins/vjCommentPlugin/TRUNK/lib/doctrine/extension/Commentable/Template/Commentable.php
plugins/vjCommentPlugin/TRUNK/lib/form/doctrine/PluginCommentForm.class.php
plugins/vjCommentPlugin/TRUNK/lib/model/doctrine/PluginComment.class.php
plugins/vjCommentPlugin/TRUNK/modules/comment/lib/BaseCommentComponents.class.php
plugins/vjCommentPlugin/TRUNK/modules/comment/templates/_comment.php
plugins/vjCommentPlugin/TRUNK/modules/comment/templates/_comment_infos.php
plugins/vjCommentPlugin/TRUNK/modules/comment/templates/_formComment.php
plugins/vjCommentPlugin/TRUNK/modules/comment/templates/_list.php
plugins/vjCommentPlugin/TRUNK/modules/commentAdmin/config/generator.yml
Log:
added relation between comment and user. Modified module, so taht it takes
logged users into consideration
Modified: plugins/vjCommentPlugin/TRUNK/config/app.yml
===================================================================
--- plugins/vjCommentPlugin/TRUNK/config/app.yml 2010-03-31 19:53:00 UTC
(rev 28934)
+++ plugins/vjCommentPlugin/TRUNK/config/app.yml 2010-03-31 20:18:56 UTC
(rev 28935)
@@ -1,6 +1,8 @@
all:
recaptcha:
enabled: false
+ vjCommentPlugin:
+ restricted: false
commentAdmin:
max_length: 50
gravatar:
Modified: plugins/vjCommentPlugin/TRUNK/config/doctrine/schema.yml
===================================================================
--- plugins/vjCommentPlugin/TRUNK/config/doctrine/schema.yml 2010-03-31
19:53:00 UTC (rev 28934)
+++ plugins/vjCommentPlugin/TRUNK/config/doctrine/schema.yml 2010-03-31
20:18:56 UTC (rev 28935)
@@ -8,6 +8,9 @@
record_model:
type: string(255)
notnull: true
+ user_id:
+ type: integer(4)
+ notnull: false
record_id:
type: integer
notnull: true
@@ -31,6 +34,15 @@
type: integer
relations:
Comment: { local: reply, foreign: id }
+ sfGuardUser:
+ alias: User
+ local: user_id
+ type: one
+ foreign: id
+ foreignType: many
+ foreignAlias: Comments
+
+
CommentReport:
actAs:
Timestampable:
Modified:
plugins/vjCommentPlugin/TRUNK/lib/doctrine/extension/Commentable/Template/Commentable.php
===================================================================
---
plugins/vjCommentPlugin/TRUNK/lib/doctrine/extension/Commentable/Template/Commentable.php
2010-03-31 19:53:00 UTC (rev 28934)
+++
plugins/vjCommentPlugin/TRUNK/lib/doctrine/extension/Commentable/Template/Commentable.php
2010-03-31 20:18:56 UTC (rev 28935)
@@ -34,6 +34,7 @@
public function getCommentsQuery()
{
$query = Doctrine::getTable('Comment')->createQuery('c')
+ ->leftJoin( 'c.User as u')
->where('c.record_id = ?', $this->_invoker->get('id'))
->andWhere('c.record_model = ?',
$this->_invoker->getTable()->getComponentName())
->orderBy('c.created_at ASC');
Modified:
plugins/vjCommentPlugin/TRUNK/lib/form/doctrine/PluginCommentForm.class.php
===================================================================
--- plugins/vjCommentPlugin/TRUNK/lib/form/doctrine/PluginCommentForm.class.php
2010-03-31 19:53:00 UTC (rev 28934)
+++ plugins/vjCommentPlugin/TRUNK/lib/form/doctrine/PluginCommentForm.class.php
2010-03-31 20:18:56 UTC (rev 28935)
@@ -15,13 +15,23 @@
{
parent::setup();
- unset($this['is_active'], $this['is_delete'], $this['created_at'],
$this['updated_at'], $this['edition_reason']);
+ unset($this['id'],$this['is_active'], $this['is_delete'],
$this['created_at'], $this['updated_at'], $this['edition_reason']);
$this->widgetSchema['reply_author'] = new sfWidgetFormInputText(array(),
array('readonly' => "readonly"));
$this->widgetSchema->setLabel('reply_author', __('Reply to', array(),
'vjComment'));
$this->widgetSchema->setHelp('author_email', __('Your email will never be
published', array(), 'vjComment'));
-
- if ($this->isCaptchaEnabled())
+ $this->widgetSchema['user_id'] = new sfWidgetFormInputHidden();
+
+ if( $this->isLoginRestricted() ||
sfContext::getInstance()->getUser()->isAuthenticated() )
{
+ unset( $this['author_email'], $this['author_website'],
$this['author_name'] );
+ }
+ else
+ {
+ unset( $this['user_id'] );
+ }
+
+ if ($this->isCaptchaEnabled() &&
!sfContext::getInstance()->getUser()->isAuthenticated() )
+ {
$this->addCaptcha();
}
}
@@ -44,4 +54,9 @@
{
return sfConfig::get('app_recaptcha_enabled');
}
+
+ private function isLoginRestricted()
+ {
+ return sfConfig::get('app_vjCommentPlugin_restricted');
+ }
}
\ No newline at end of file
Modified:
plugins/vjCommentPlugin/TRUNK/lib/model/doctrine/PluginComment.class.php
===================================================================
--- plugins/vjCommentPlugin/TRUNK/lib/model/doctrine/PluginComment.class.php
2010-03-31 19:53:00 UTC (rev 28934)
+++ plugins/vjCommentPlugin/TRUNK/lib/model/doctrine/PluginComment.class.php
2010-03-31 20:18:56 UTC (rev 28935)
@@ -10,4 +10,16 @@
*/
abstract class PluginComment extends BaseComment
{
+ public function getAuthor()
+ {
+ //var_dump( is_null( $this->getUserId() ) );
+ if( null !== $this->getUserId() )
+ {
+ return $this->getUser()->getUsername();
+ }
+ else
+ {
+ return $this->getAuthorName();
+ }
+ }
}
\ No newline at end of file
Modified:
plugins/vjCommentPlugin/TRUNK/modules/comment/lib/BaseCommentComponents.class.php
===================================================================
---
plugins/vjCommentPlugin/TRUNK/modules/comment/lib/BaseCommentComponents.class.php
2010-03-31 19:53:00 UTC (rev 28934)
+++
plugins/vjCommentPlugin/TRUNK/modules/comment/lib/BaseCommentComponents.class.php
2010-03-31 20:18:56 UTC (rev 28935)
@@ -18,18 +18,25 @@
$this->form->setDefault('record_id', $this->object->get('id'));
if($request->isMethod('post'))
{
- if(sfConfig::get('app_recaptcha_enabled'))
+ //preparing temporary array with sent values
+ $formValues = $request->getParameter($this->form->getName());
+
+ if(sfConfig::get('app_recaptcha_enabled') &&
$this->getUser()->isAuthenticated() )
{
$captcha = array(
'recaptcha_challenge_field' =>
$request->getParameter('recaptcha_challenge_field'),
'recaptcha_response_field' =>
$request->getParameter('recaptcha_response_field'),
);
-
$this->form->bind(array_merge($request->getParameter($this->form->getName()),
array('captcha' => $captcha)));
+ //Adding captcha
+ $formValues = array_merge( $formValues, array('captcha' => $captcha)
);
}
- else
+ if( sfConfig::get('app_vjCommentPlugin_restricted', false) ||
$this->getUser()->isAuthenticated() )
{
- $this->form->bind($request->getParameter($this->form->getName()));
+ //adding user id
+ $formValues = array_merge( $formValues, array('user_id' =>
$this->getUser()->getGuardUser()->getId() ) );
}
+
+ $this->form->bind( $formValues );
if ($this->form->isValid()){
$this->form->save();
$url = $request->getUri() . "#" .
$this->getUser()->getAttribute("nextComment");
Modified: plugins/vjCommentPlugin/TRUNK/modules/comment/templates/_comment.php
===================================================================
--- plugins/vjCommentPlugin/TRUNK/modules/comment/templates/_comment.php
2010-03-31 19:53:00 UTC (rev 28934)
+++ plugins/vjCommentPlugin/TRUNK/modules/comment/templates/_comment.php
2010-03-31 20:18:56 UTC (rev 28935)
@@ -1,7 +1,7 @@
<tbody class="comment<?php if($obj->is_delete) echo " deleted"; ?>">
<tr>
- <?php include_partial("comment/comment_author", array('website' =>
$obj->getAuthorWebsite(), 'name' => $obj->getAuthorName(), 'date' =>
$obj->getCreatedAt())) ?>
+ <?php include_partial("comment/comment_author", array('website' =>
$obj->getAuthorWebsite(), 'name' => $obj->getAuthor(), 'date' =>
$obj->getCreatedAt())) ?>
<?php include_partial("comment/comment_infos", array('obj' => $obj,
'i' => $i)) ?>
</tr>
<?php include_partial("comment/comment_body", array('obj' => $obj)) ?>
Modified:
plugins/vjCommentPlugin/TRUNK/modules/comment/templates/_comment_infos.php
===================================================================
--- plugins/vjCommentPlugin/TRUNK/modules/comment/templates/_comment_infos.php
2010-03-31 19:53:00 UTC (rev 28934)
+++ plugins/vjCommentPlugin/TRUNK/modules/comment/templates/_comment_infos.php
2010-03-31 20:18:56 UTC (rev 28935)
@@ -1,6 +1,5 @@
-
<td rowspan="2" class="infos">
- <a name="<?php echo ++$i ?>" class="ancre">#<?php echo $i ?></a>
+ <a name="<?php echo $i ?>" class="ancre">#<?php echo $i ?></a>
<?php if(!$obj->is_delete): ?>
<?php echo link_to_function(
image_tag('/vjCommentPlugin/images/comments.png') ,
Modified:
plugins/vjCommentPlugin/TRUNK/modules/comment/templates/_formComment.php
===================================================================
--- plugins/vjCommentPlugin/TRUNK/modules/comment/templates/_formComment.php
2010-03-31 19:53:00 UTC (rev 28934)
+++ plugins/vjCommentPlugin/TRUNK/modules/comment/templates/_formComment.php
2010-03-31 20:18:56 UTC (rev 28935)
@@ -4,6 +4,7 @@
<?php $sf_user->setAttribute('nextComment', $object->getNbComments()+1) ?>
<a name="top"></a>
<div class="form-comment">
+<?php if( sfConfig::get( 'app_vjCommentPlugin_restricted' ) &&
$sf_user->isAuthenticated() || !sfConfig::get( 'app_vjCommentPlugin_restricted'
) ): ?>
<form action="" method="post">
<fieldset>
<legend><?php echo __('Add new comment', array(), 'vjComment') ?></legend>
@@ -16,4 +17,7 @@
</table>
</fieldset>
</form>
+<?php else: ?>
+ <?php echo __('Please log in to comment', array(), 'vjComment') ?>
+<?php endif ?>
</div>
\ No newline at end of file
Modified: plugins/vjCommentPlugin/TRUNK/modules/comment/templates/_list.php
===================================================================
--- plugins/vjCommentPlugin/TRUNK/modules/comment/templates/_list.php
2010-03-31 19:53:00 UTC (rev 28934)
+++ plugins/vjCommentPlugin/TRUNK/modules/comment/templates/_list.php
2010-03-31 20:18:56 UTC (rev 28935)
@@ -8,7 +8,7 @@
<div><h1><?php echo __('Comments list', array(), 'vjComment') ?></h1></div>
<table class="list-comments" summary="">
<?php foreach($object->getAllComments() as $c): ?>
- <?php include_partial("comment/comment", array('obj' => $c, 'i' => $i)) ?>
+ <?php include_partial("comment/comment", array('obj' => $c, 'i' => ++$i))
?>
<?php endforeach; ?>
</table>
<?php else: ?>
Modified:
plugins/vjCommentPlugin/TRUNK/modules/commentAdmin/config/generator.yml
===================================================================
--- plugins/vjCommentPlugin/TRUNK/modules/commentAdmin/config/generator.yml
2010-03-31 19:53:00 UTC (rev 28934)
+++ plugins/vjCommentPlugin/TRUNK/modules/commentAdmin/config/generator.yml
2010-03-31 20:18:56 UTC (rev 28935)
@@ -21,7 +21,7 @@
edition_reason: { label: Reason }
list:
title: Comments list
- display: [author_name, _body, created_at]
+ display: [author, _body, created_at]
sort: [created_at, desc]
actions: {}
object_actions:
--
You received this message because you are subscribed to the Google Groups
"symfony SVN" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/symfony-svn?hl=en.