forked from niryuu/opCommunityTopicPlugin-100628
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(refs #158) fixed bugs: the topic's images are not displayed correctly
- Loading branch information
Showing
3 changed files
with
156 additions
and
147 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
} | ||
} |