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

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
Line 
1<?php
2
3/**
4 * This file is part of the OpenPNE package.
5 * (c) OpenPNE Project (http://www.openpne.jp/)
6 *
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.
9 */
10
11/**
12 * Community form.
13 *
14 * @package    OpenPNE
15 * @subpackage form
16 * @author     Kousuke Ebihara <ebihara@tejimaya.com>
17 */
18class CommunityForm extends BaseCommunityForm
19{
20  protected $configForm;
21
22  public function configure()
23  {
24    unset($this['created_at'], $this['updated_at'], $this['file_id']);
25    unset($this->widgetSchema['id']);
26
27    $this->setValidator('name', new sfValidatorString(array('max_length' => 64, 'trim' => true)));
28
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(
35      'model'       => 'CommunityCategory',
36      'add_empty'   => false,
37      'peer_method' => 'retrieveAllChildren',
38      'criteria'    => $c,
39    )));
40    $this->widgetSchema->setLabel('community_category_id', 'Community Category');
41    $this->widgetSchema->getFormFormatter()->setTranslationCatalogue('form_community');
42
43    $this->mergePostValidator(new sfValidatorCallback(array('callback' => array($this, 'checkCreatable'))));
44  }
45
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    }
64  }
65
66  public function checkCreatable($validator, $value)
67  {
68    $category = CommunityCategoryPeer::retrieveByPk($value['community_category_id']);
69    if ($category->getIsAllowMemberCommunity())
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  }
81}
Note: See TracBrowser for help on using the repository browser.