Changeset 9599 for OpenPNE3/trunk/lib/form/CommunityForm.class.php
- Timestamp:
- Dec 19, 2008, 9:17:33 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
OpenPNE3/trunk/lib/form/CommunityForm.class.php
r9589 r9599 4 4 * Community form. 5 5 * 6 * @package form7 * @subpackage community8 * @ version SVN: $Id: sfPropelFormTemplate.php 6174 2007-11-27 06:22:40Z fabien $6 * @package OpenPNE 7 * @subpackage form 8 * @author Kousuke Ebihara <ebihara@tejimaya.com> 9 9 */ 10 10 class CommunityForm extends BaseCommunityForm … … 12 12 public function configure() 13 13 { 14 unset($this['created_at'], $this['updated_at']); 14 $this->setWidget('file', new sfWidgetFormInputFile()); 15 16 unset($this['created_at'], $this['updated_at'], $this['file_id']); 15 17 16 18 $this->setValidator('config', new sfValidatorPass()); 19 $this->setValidator('file', new opValidatorImageFile(array('required' => false))); 17 20 } 18 21 … … 20 23 { 21 24 $community = parent::save($con); 22 $tainted_values = $this->getTaintedValues(); 23 $community_config_array = $tainted_values['config']; 25 $oldFile = $community->getFile(); 26 $this->saveImageFile($community); 27 $community->save(); 24 28 25 if ($this->isNew()) { 26 $communityMember = new CommunityMember(); 27 $communityMember->setPosition('admin'); 28 $communityMember->setMemberId(sfContext::getInstance()->getUser()->getMemberId()); 29 $communityMember->setCommunityId($community->getId()); 30 $communityMember->save(); 31 32 foreach ($community_config_array as $community_config_key => $community_config_value) 33 { 34 $community_config = new CommunityConfig(); 35 $community_config->setCommunityId($community->getId()); 36 $community_config->setName($community_config_key); 37 $community_config->setValue($community_config_value); 38 $community_config->save(); 39 } 40 } 41 else 29 if ($oldFile && $oldFile->getName() !== $community->getFile()->getName()) 42 30 { 43 foreach ($community_config_array as $community_config_key => $community_config_value) 44 { 45 $community_config = CommunityConfigPeer::retrieveByNameAndCommunityId($community_config_key, $community->getId()); 46 $community_config->setValue($community_config_value); 47 $community_config->save(); 48 } 31 $oldFile->delete(); 49 32 } 50 33 51 34 return $community; 52 35 } 36 37 public function updateObject($values = null) 38 { 39 $object = parent::updateObject($values); 40 41 $this->saveMember($object); 42 $this->saveConfig($object); 43 44 return $object; 45 } 46 47 public function saveConfig(Community $community) 48 { 49 $configs = $this->getValue('config'); 50 if (!$configs) 51 { 52 return false; 53 } 54 55 foreach ($configs as $key => $value) 56 { 57 $config = CommunityConfigPeer::retrieveByNameAndCommunityId($key, $community->getId()); 58 if (!$config) 59 { 60 $config->setCommunity($community); 61 $config->setName($key); 62 } 63 $config->setValue($value); 64 } 65 } 66 67 public function saveMember(Community $community) 68 { 69 if ($this->isNew()) 70 { 71 $member = new CommunityMember(); 72 $member->setPosition('admin'); 73 $member->setMemberId(sfContext::getInstance()->getUser()->getMemberId()); 74 $member->setCommunity($community); 75 } 76 } 77 78 public function saveImageFile(Community $community) 79 { 80 if (!$this->getValue('file')) 81 { 82 return false; 83 } 84 85 $file = new File(); 86 $file->setFromValidatedFile($this->getValue('file')); 87 $file->setName('c_'.$community->getId().'_'.$file->getName()); 88 $community->setFile($file); 89 90 return true; 91 } 53 92 }
Note: See TracChangeset
for help on using the changeset viewer.