Skip to content

Commit

Permalink
(refs #158) fixed bugs: the topic's images are not displayed correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
tunn committed Jul 14, 2010
1 parent 700df9d commit 47e1590
Show file tree
Hide file tree
Showing 3 changed files with 156 additions and 147 deletions.
Expand Up @@ -15,7 +15,7 @@
<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): ?>
<?php if (count($images = $communityTopic->getCommunityTopicImagesJoinFile()) != 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>
Expand Down
158 changes: 79 additions & 79 deletions lib/form/doctrine/PluginCommunityTopicForm.class.php
@@ -1,79 +1,79 @@
<?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.
*/

/**
* PluginCommunityTopic form.
*
* @package opCommunityTopicPlugin
* @subpackage form
* @author masabon
* @author Kousuke Ebihara <ebihara@tejimaya.com>
* @author Rimpei Ogawa <ogawa@tejimaya.com>
*/
abstract class PluginCommunityTopicForm extends BaseCommunityTopicForm
{
public function setup()
{
parent::setup();

unset($this['id']);
unset($this['community_id']);
unset($this['member_id']);
unset($this['created_at']);
unset($this['updated_at']);
unset($this['topic_updated_at']);

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

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

if (isset($images[$i]))
{
$image = $images[$i];
}
else
{
$image = new CommunityTopicImage();
$image->setCommunityTopic($this->getObject());
$image->setNumber($i);
}
$imageForm = new CommunityTopicImageForm($image);
$imageForm->getWidgetSchema()->setFormFormatterName('list');
$this->embedForm($key, $imageForm, '<ul id="community_topic_'.$key.'">%content%</ul>');
}
}
$this->setWidget('name', new sfWidgetFormInput());
$this->widgetSchema->getFormFormatter()->setTranslationCatalogue('community_topic_form');
}

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;
}
}
<?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.
*/

/**
* PluginCommunityTopic form.
*
* @package opCommunityTopicPlugin
* @subpackage form
* @author masabon
* @author Kousuke Ebihara <ebihara@tejimaya.com>
* @author Rimpei Ogawa <ogawa@tejimaya.com>
*/
abstract class PluginCommunityTopicForm extends BaseCommunityTopicForm
{
public function setup()
{
parent::setup();

unset($this['id']);
unset($this['community_id']);
unset($this['member_id']);
unset($this['created_at']);
unset($this['updated_at']);
unset($this['topic_updated_at']);

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

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

if (isset($images[$i]))
{
$image = $images[$i];
}
else
{
$image = new CommunityTopicImage();
$image->setCommunityTopic($this->getObject());
$image->setNumber($i);
}
$imageForm = new CommunityTopicImageForm($image);
$imageForm->getWidgetSchema()->setFormFormatterName('list');
$this->embedForm($key, $imageForm, '<ul id="community_topic_'.$key.'">%content%</ul>');
}
}
$this->setWidget('name', new sfWidgetFormInput());
$this->widgetSchema->getFormFormatter()->setTranslationCatalogue('community_topic_form');
}

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;
}
}
143 changes: 76 additions & 67 deletions lib/model/doctrine/PluginCommunityTopic.class.php
@@ -1,67 +1,76 @@
<?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.
*/

/**
* PluginCommunityTopic
*
* @package opCommunityTopicPlugin
* @subpackage CommunityTopic
* @author Kousuke Ebihara <ebihara@tejimaya.com>
*/
abstract class PluginCommunityTopic extends BaseCommunityTopic
{
public function isEditable($memberId)
{
if (!$this->getCommunity()->isPrivilegeBelong($memberId))
{
return false;
}

return ($this->getMemberId() === $memberId || $this->getCommunity()->isAdmin($memberId));
}

public function isCreatableCommunityTopicComment($memberId)
{
return $this->getCommunity()->isPrivilegeBelong($memberId);
}

public function isTopicModified()
{
$modified = $this->getModified();
return (isset($modified['name']) || isset($modified['body']));
}

public function preSave($event)
{
$modified = $this->getModified();
if ($this->isTopicModified() && empty($modified['topic_updated_at']))
{
$this->setTopicUpdatedAt(date('Y-m-d H:i:s', time()));
}
}

// for pager
public function getImageFilename()
{
$this->getCommunity()->getImageFilename();
}

public function getImagesWithNumber()
{
$images = $this->getImages();
$result = array();
foreach ($images as $image)
{
$result[$image->number] = $image;
}

return $result;
}
}
<?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.
*/

/**
* PluginCommunityTopic
*
* @package opCommunityTopicPlugin
* @subpackage CommunityTopic
* @author Kousuke Ebihara <ebihara@tejimaya.com>
*/
abstract class PluginCommunityTopic extends BaseCommunityTopic
{
public function isEditable($memberId)
{
if (!$this->getCommunity()->isPrivilegeBelong($memberId))
{
return false;
}

return ($this->getMemberId() === $memberId || $this->getCommunity()->isAdmin($memberId));
}

public function isCreatableCommunityTopicComment($memberId)
{
return $this->getCommunity()->isPrivilegeBelong($memberId);
}

public function isTopicModified()
{
$modified = $this->getModified();
return (isset($modified['name']) || isset($modified['body']));
}

public function preSave($event)
{
$modified = $this->getModified();
if ($this->isTopicModified() && empty($modified['topic_updated_at']))
{
$this->setTopicUpdatedAt(date('Y-m-d H:i:s', time()));
}
}

// for pager
public function getImageFilename()
{
$this->getCommunity()->getImageFilename();
}

public function getImagesWithNumber()
{
$images = $this->getImages();
$result = array();
foreach ($images as $image)
{
$result[$image->number] = $image;
}

return $result;
}

public function getCommunityTopicImagesJoinFile()
{
$q = Doctrine::getTable('CommunityTopicImage')->createQuery()
->leftJoin('CommunityTopicImage.File')
->where('post_id = ?', $this->id);

return $q->execute();
}
}

0 comments on commit 47e1590

Please sign in to comment.