ここの情報は古いです。ご理解頂いた上でお取り扱いください。

source: OpenPNE3/trunk/lib/form/CommunityForm.class.php @ 11046

Last change on this file since 11046 was 11046, checked in by ebihara, 14 years ago

#3219:replaced "is_allow_user_community" to "is_allow_member_community"

File size: 2.2 KB
RevLine 
[7858]1<?php
2
3/**
[10003]4 * This file is part of the OpenPNE package.
5 * (c) OpenPNE Project (http://www.openpne.jp/)
[10000]6 *
[10003]7 * For the full copyright and license information, please view the LICENSE
8 * file and the NOTICE file that were distributed with this source code.
[10000]9 */
10
11/**
[7858]12 * Community form.
13 *
[9599]14 * @package    OpenPNE
15 * @subpackage form
16 * @author     Kousuke Ebihara <ebihara@tejimaya.com>
[7858]17 */
18class CommunityForm extends BaseCommunityForm
19{
[9613]20  protected $configForm;
21
[7858]22  public function configure()
23  {
[10467]24    unset($this['created_at'], $this['updated_at'], $this['file_id']);
25    unset($this->widgetSchema['id']);
[9599]26
[9815]27    $this->setValidator('name', new sfValidatorString(array('max_length' => 64, 'trim' => true)));
28
[11045]29    $c = new Criteria();
30    if (1 != sfContext::getInstance()->getUser()->getMemberId())
31    {
32      $c->add(CommunityCategoryPeer::IS_ALLOW_USER_COMMUNITY, 1);
33    }
34    $this->setWidget('community_category_id', new sfWidgetFormPropelChoice(array(
[11044]35      'model'       => 'CommunityCategory',
36      'add_empty'   => false,
[11045]37      'peer_method' => 'retrieveAllChildren',
38      'criteria'    => $c,
[11044]39    )));
40    $this->widgetSchema->setLabel('community_category_id', 'Community Category');
[10458]41    $this->widgetSchema->getFormFormatter()->setTranslationCatalogue('form_community');
[11045]42
43    $this->mergePostValidator(new sfValidatorCallback(array('callback' => array($this, 'checkCreatable'))));
[7858]44  }
[7861]45
[9599]46  public function updateObject($values = null)
47  {
48    $object = parent::updateObject($values);
49
50    $this->saveMember($object);
51
52    return $object;
53  }
54
55  public function saveMember(Community $community)
56  {
57    if ($this->isNew())
58    {
59      $member = new CommunityMember();
60      $member->setPosition('admin');
61      $member->setMemberId(sfContext::getInstance()->getUser()->getMemberId());
62      $member->setCommunity($community);
63    }
[7861]64  }
[11045]65
66  public function checkCreatable($validator, $value)
67  {
68    $category = CommunityCategoryPeer::retrieveByPk($value['community_category_id']);
[11046]69    if ($category->getIsAllowMemberCommunity())
[11045]70    {
71      return $value;
72    }
73
74    if (1 == sfContext::getInstance()->getUser()->getMemberId())
75    {
76      return $value;
77    }
78
79    throw new sfValidatorError($validator, 'invalid');
80  }
[7858]81}
Note: See TracBrowser for help on using the repository browser.