Skip to content

Commit

Permalink
(refs #158)post a topic comment with images
Browse files Browse the repository at this point in the history
  • Loading branch information
tunn committed Jul 14, 2010
1 parent 1726cbd commit 700df9d
Show file tree
Hide file tree
Showing 5 changed files with 238 additions and 150 deletions.
109 changes: 55 additions & 54 deletions apps/pc_frontend/modules/communityTopic/templates/showSuccess.php
@@ -1,54 +1,55 @@
<?php use_helper('Date'); ?>
<?php $acl = opCommunityTopicAclBuilder::buildCollection($community, array($sf_user->getMember())) ?>

<div class="dparts topicDetailBox"><div class="parts">
<div class="partsHeading">
<h3><?php echo '['.$community->getName().'] '.__('Topic') ?></h3>
</div>
<dl>
<dt><?php echo nl2br(op_format_date($communityTopic->getCreatedAt(), 'XDateTimeJaBr')) ?></dt>
<dd>
<div class="title">
<p><?php echo $communityTopic->getName() ?></p>
</div>
<div class="name">
<p><?php if ($_member = $communityTopic->getMember()) : ?><?php echo link_to($_member->getName(), 'member/profile?id='.$_member->getId()) ?><?php endif; ?></p>
</div>
<div class="body">
<?php if (count($images = $communityTopic->getImages()) != 0): ?>
<ul class="photo">
<?php foreach ($images as $image): ?>
<li><a href="<?php echo sf_image_path($image->File) ?>" target="_blank"><?php echo image_tag_sf_image($image->File, array('size' => '120x120')) ?></a></li>
<?php endforeach; ?>
</ul>
<?php endif; ?>
<p class="text">
<?php echo op_url_cmd(nl2br($communityTopic->getBody())) ?>
</p>
</div>
</dd>
</dl>
<?php if ($communityTopic->isEditable($sf_user->getMemberId())): ?>
<div class="operation">
<form action="<?php echo url_for('communityTopic_edit', $communityTopic) ?>" method="get">
<ul class="moreInfo button">
<li><input class="input_submit" type="submit" value="<?php echo __('Edit') ?>" /></li>
</ul>
</form>
</div>
<?php endif; ?>
</div>
</div>

<?php include_component('communityTopicComment', 'list', array('communityTopic' => $communityTopic)) ?>

<?php if ($communityTopic->isCreatableCommunityTopicComment($sf_user->getMemberId())): ?>
<?php
$options = array();
$options['title'] = __('Post a new topic comment');
$options['url'] = url_for('communityTopic_comment_create', $communityTopic);
op_include_form('formCommunityTopicComment', $form, $options);
?>
<?php endif; ?>

<?php op_include_line('linkLine', link_to('['.$community->getName().'] '.__('Community Top Page'), 'community/home?id='.$community->getId())) ?>
<?php use_helper('Date'); ?>
<?php $acl = opCommunityTopicAclBuilder::buildCollection($community, array($sf_user->getMember())) ?>

<div class="dparts topicDetailBox"><div class="parts">
<div class="partsHeading">
<h3><?php echo '['.$community->getName().'] '.__('Topic') ?></h3>
</div>
<dl>
<dt><?php echo nl2br(op_format_date($communityTopic->getCreatedAt(), 'XDateTimeJaBr')) ?></dt>
<dd>
<div class="title">
<p><?php echo $communityTopic->getName() ?></p>
</div>
<div class="name">
<p><?php if ($_member = $communityTopic->getMember()) : ?><?php echo link_to($_member->getName(), 'member/profile?id='.$_member->getId()) ?><?php endif; ?></p>
</div>
<div class="body">
<?php if (count($images = $communityTopic->getImages()) != 0): ?>
<ul class="photo">
<?php foreach ($images as $image): ?>
<li><a href="<?php echo sf_image_path($image->File) ?>" target="_blank"><?php echo image_tag_sf_image($image->File, array('size' => '120x120')) ?></a></li>
<?php endforeach; ?>
</ul>
<?php endif; ?>
<p class="text">
<?php echo op_url_cmd(nl2br($communityTopic->getBody())) ?>
</p>
</div>
</dd>
</dl>
<?php if ($communityTopic->isEditable($sf_user->getMemberId())): ?>
<div class="operation">
<form action="<?php echo url_for('communityTopic_edit', $communityTopic) ?>" method="get">
<ul class="moreInfo button">
<li><input class="input_submit" type="submit" value="<?php echo __('Edit') ?>" /></li>
</ul>
</form>
</div>
<?php endif; ?>
</div>
</div>

<?php include_component('communityTopicComment', 'list', array('communityTopic' => $communityTopic)) ?>

<?php if ($communityTopic->isCreatableCommunityTopicComment($sf_user->getMemberId())): ?>
<?php
$options = array();
$options['title'] = __('Post a new topic comment');
$options['url'] = url_for('communityTopic_comment_create', $communityTopic);
$options['isMultipart'] = true;
op_include_form('formCommunityTopicComment', $form, $options);
?>
<?php endif; ?>

<?php op_include_line('linkLine', link_to('['.$community->getName().'] '.__('Community Top Page'), 'community/home?id='.$community->getId())) ?>
82 changes: 45 additions & 37 deletions apps/pc_frontend/modules/communityTopicComment/templates/_list.php
@@ -1,37 +1,45 @@
<?php if ($commentPager->getNbResults()) : ?>
<div class="dparts commentList"><div class="parts">
<div class="partsHeading">
<h3><?php echo __('Comments', array(), 'form_community') ?></h3>
</div>

<?php ob_start() ?>
<?php op_include_pager_navigation($commentPager, '@communityTopic_show?page=%d&id='.$communityTopic->getId()); ?>
<?php $pagerNavi = ob_get_contents() ?>
<?php ob_end_flush() ?>

<?php foreach ($commentPager->getResults() as $comment): ?>
<dl>
<dt><?php echo nl2br(op_format_date($comment->getCreatedAt(), 'XDateTimeJaBr')) ?></dt>
<dd>
<div class="title">
<p class="heading"><strong><?php echo $comment->getNumber() ?></strong>:
<?php if ($_member = $comment->getMember()) : ?> <?php echo link_to($_member->getName(), 'member/profile?id='.$_member->getId()) ?><?php endif; ?>
<?php if ($comment->isDeletable($sf_user->getMemberId())): ?>
<?php echo link_to(__('Delete'), '@communityTopic_comment_delete_confirm?id='.$comment->getId()) ?>
<?php endif; ?>
</p>
</div>
<div class="body">
<p class="text">
<?php echo op_url_cmd(nl2br($comment->getBody())) ?>
</p>
</div>
</dd>
</dl>
<?php endforeach; ?>

<?php echo $pagerNavi ?>

</div>
</div>
<?php endif; ?>
<?php if ($commentPager->getNbResults()) : ?>
<div class="dparts commentList"><div class="parts">
<div class="partsHeading">
<h3><?php echo __('Comments', array(), 'form_community') ?></h3>
</div>

<?php ob_start() ?>
<?php op_include_pager_navigation($commentPager, '@communityTopic_show?page=%d&id='.$communityTopic->getId()); ?>
<?php $pagerNavi = ob_get_contents() ?>
<?php ob_end_flush() ?>

<?php foreach ($commentPager->getResults() as $comment): ?>
<dl>
<dt><?php echo nl2br(op_format_date($comment->getCreatedAt(), 'XDateTimeJaBr')) ?></dt>
<dd>
<div class="title">
<p class="heading"><strong><?php echo $comment->getNumber() ?></strong>:
<?php if ($_member = $comment->getMember()) : ?> <?php echo link_to($_member->getName(), 'member/profile?id='.$_member->getId()) ?><?php endif; ?>
<?php if ($comment->isDeletable($sf_user->getMemberId())): ?>
<?php echo link_to(__('Delete'), '@communityTopic_comment_delete_confirm?id='.$comment->getId()) ?>
<?php endif; ?>
</p>
</div>
<div class="body">
<?php $images = $comment->getCommunityTopicCommentImagesJoinFile() ?>
<?php if (0 < count($images)): ?>
<ul class="photo">
<?php foreach ($images as $image): ?>
<li><a href="<?php echo sf_image_path($image->File) ?>" target="_blank"><?php echo image_tag_sf_image($image->File, array('size' => '120x120')) ?></a></li>
<?php endforeach; ?>
</ul>
<?php endif; ?>
<p class="text">
<?php echo op_url_cmd(nl2br($comment->getBody())) ?>
</p>
</div>
</dd>
</dl>
<?php endforeach; ?>

<?php echo $pagerNavi ?>

</div>
</div>
<?php endif; ?>
Expand Up @@ -49,7 +49,8 @@ public function executeCreate($request)
$this->form = new CommunityTopicCommentForm();
$this->form->getObject()->setMemberId($this->getUser()->getMemberId());
$this->form->getObject()->setCommunityTopic($this->communityTopic);
$this->form->bind($request->getParameter($this->form->getName()));
$this->form->bind($request->getParameter($this->form->getName()), $request->getFiles($this->form->getName()));

if ($this->form->isValid())
{
$this->form->save();
Expand Down
134 changes: 89 additions & 45 deletions lib/form/doctrine/PluginCommunityTopicCommentForm.class.php
@@ -1,45 +1,89 @@
<?php

/**
* This file is part of the OpenPNE package.
* (c) OpenPNE Project (http://www.openpne.jp/)
*
* For the full copyright and license information, please view the LICENSE
* file and the NOTICE file that were distributed with this source code.
*/

/**
* PluginCommunityTopicComment form.
*
* @package opCommunityTopicPlugin
* @subpackage form
* @author masabon
* @author Kousuke Ebihara <ebihara@tejimaya.com>
* @author Rimpei Ogawa <ogawa@tejimaya.com>
* @author Eitarow Fukamachi <fukamachi@tejimaya.net>
*/
abstract class PluginCommunityTopicCommentForm extends BaseCommunityTopicCommentForm
{
public function setup()
{
parent::setup();

unset($this['id']);
unset($this['community_topic_id']);
unset($this['member_id']);
unset($this['number']);
unset($this['created_at']);
unset($this['updated_at']);

$this->widgetSchema->setLabel('body', sfContext::getInstance()->getI18N()->__('Comment'));
$this->setValidator('body', new opValidatorString(array('rtrim' => true)));
}

public function save($con = null)
{
$communityTopicComment = parent::save($con);
$communityTopic = $communityTopicComment->getCommunityTopic();
$communityTopic->setUpdatedAt($communityTopicComment->getCreatedAt());
$communityTopic->save();
}
}
<?php

/**
* This file is part of the OpenPNE package.
* (c) OpenPNE Project (http://www.openpne.jp/)
*
* For the full copyright and license information, please view the LICENSE
* file and the NOTICE file that were distributed with this source code.
*/

/**
* PluginCommunityTopicComment form.
*
* @package opCommunityTopicPlugin
* @subpackage form
* @author masabon
* @author Kousuke Ebihara <ebihara@tejimaya.com>
* @author Rimpei Ogawa <ogawa@tejimaya.com>
* @author Eitarow Fukamachi <fukamachi@tejimaya.net>
*/
abstract class PluginCommunityTopicCommentForm extends BaseCommunityTopicCommentForm
{
public function setup()
{
parent::setup();

unset($this['id']);
unset($this['community_topic_id']);
unset($this['member_id']);
unset($this['number']);
unset($this['created_at']);
unset($this['updated_at']);

if (sfConfig::get('community_topic_comment_is_upload_images', true))
{
$images = array();
if (!$this->isNew())
{
$images = $this->getObject()->getImagesWithNumber();
}

$max = (int)sfConfig::get('community_topic_comment_max_image_file_num', 3);
for ($i = 1; $i <= $max; $i++)
{
$key = 'photo_'.$i;

if (isset($images[$i]))
{
$image = $images[$i];
}
else
{
$image = new CommunityTopicCommentImage();
$image->setCommunityTopicComment($this->getObject());
$image->setNumber($i);
}
$imageForm = new CommunityTopicCommentImageForm($image);
$imageForm->getWidgetSchema()->setFormFormatterName('list');
$this->embedForm($key, $imageForm, '<ul id="community_topic_comment_'.$key.'">%content%</ul>');
}
}

$this->widgetSchema->setLabel('body', sfContext::getInstance()->getI18N()->__('Comment'));
$this->setValidator('body', new opValidatorString(array('rtrim' => true)));
}

public function updateObject($values = null)
{
$object = parent::updateObject($values);

foreach ($this->embeddedForms as $key => $form)
{
if (!($form->getObject() && $form->getObject()->File != null))
{
unset($this->embeddedForms[$key]);
}
}

return $object;
}

public function save($con = null)
{
$communityTopicComment = parent::save($con);
$communityTopic = $communityTopicComment->getCommunityTopic();
$communityTopic->setUpdatedAt($communityTopicComment->getCreatedAt());
$communityTopic->save();
}
}
60 changes: 47 additions & 13 deletions lib/form/doctrine/PluginCommunityTopicCommentImageForm.class.php
@@ -1,13 +1,47 @@
<?php

/**
* PluginCommunityTopicCommentImage form.
*
* @package ##PROJECT_NAME##
* @subpackage form
* @author ##AUTHOR_NAME##
* @version SVN: $Id: sfDoctrineFormPluginTemplate.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $
*/
abstract class PluginCommunityTopicCommentImageForm extends BaseCommunityTopicCommentImageForm
{
}
<?php

/**
* PluginCommunityTopicCommentImage form.
*
* @package ##PROJECT_NAME##
* @subpackage form
* @author ##AUTHOR_NAME##
* @version SVN: $Id: sfDoctrineFormPluginTemplate.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $
*/
abstract class PluginCommunityTopicCommentImageForm extends BaseCommunityTopicCommentImageForm
{
public function setup()
{
parent::setup();

unset($this['id']);
$this->useFields();

$key = 'photo';

$options = array(
'file_src' => '',
'is_image' => true,
'label' => false,
'edit_mode' => false,
);

$this->setWidget($key, new sfWidgetFormInputFileEditable($options, array('size' => 40)));
$this->setValidator($key, new opValidatorImageFile(array('required' => false)));
}

public function updateObject($values = null)
{
if ($values['photo'] instanceof sfValidatedFile)
{
$file = new File();
$file->setFromValidatedFile($values['photo']);

$this->getObject()->setFile($file);
}
else
{
$this->getObject()->setFile(null);
}
}
}

0 comments on commit 700df9d

Please sign in to comment.