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

Changeset 11260


Ignore:
Timestamp:
Apr 9, 2009, 9:55:34 PM (11 years ago)
Author:
ebihara
Message:

#3765:imported some code to Doctrine's Form Classes from Propel's Form Classes

Location:
OpenPNE3/branches/goto_doctrine
Files:
16 edited
3 copied

Legend:

Unmodified
Added
Removed
  • OpenPNE3/branches/goto_doctrine/apps/pc_backend/modules/community/actions/actions.class.php

    r11248 r11260  
    3535  public function executeCategoryList(sfWebRequest $request)
    3636  {
    37     $this->categories = CommunityCategoryPeer::retrieveAllRoots();
     37    $this->categories = Doctrine::getTable('CommunityCategory')->retrieveAllRoots();
    3838    $this->rootForm = new CommunityCategoryForm();
    3939    $this->deleteForm = new sfForm();
  • OpenPNE3/branches/goto_doctrine/lib/form/doctrine/AdminUserForm.class.php

    r11208 r11260  
    11<?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 */
    210
    311/**
    412 * AdminUser form.
    513 *
    6  * @package    form
    7  * @subpackage AdminUser
    8  * @version    SVN: $Id: sfDoctrineFormTemplate.php 6174 2007-11-27 06:22:40Z fabien $
     14 * @package    OpenPNE
     15 * @subpackage form
     16 * @author     Kousuke Ebihara <ebihara@tejimaya.com>
    917 */
    1018class AdminUserForm extends BaseAdminUserForm
     
    1220  public function configure()
    1321  {
     22    $this->setWidgets(array(
     23      'username' => new sfWidgetFormInput(),
     24      'password' => new sfWidgetFormInputPassword(),
     25    ));
     26
     27    $this->setValidators(array(
     28      'username' => new sfValidatorString(array('max_length' => 64, 'trim' => true)),
     29      'password' => new sfValidatorString(array('max_length' => 40, 'trim' => true)),
     30    ));
     31
     32    $this->widgetSchema->setNameFormat('admin_user[%s]');
     33
     34    $this->errorSchema = new sfValidatorErrorSchema($this->validatorSchema);
     35
     36    $this->widgetSchema->setLabels(array(
     37      'username' => 'アカウント名',
     38      'password' => 'パスワード',
     39    ));
     40
     41    $this->mergePostValidator(new sfValidatorDoctrineUnique(array(
     42      'model' => 'AdminUser', 'column' => array('username')
     43    )));
    1444  }
    1545}
  • OpenPNE3/branches/goto_doctrine/lib/form/doctrine/BlacklistForm.class.php

    r11208 r11260  
    11<?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 */
    210
    311/**
    412 * Blacklist form.
    513 *
    6  * @package    form
    7  * @subpackage Blacklist
    8  * @version    SVN: $Id: sfDoctrineFormTemplate.php 6174 2007-11-27 06:22:40Z fabien $
     14 * @package    OpenPNE
     15 * @subpackage form
     16 * @author     Kousuke Ebihara <ebihara@tejimaya.com>
    917 */
    1018class BlacklistForm extends BaseBlacklistForm
     
    1220  public function configure()
    1321  {
     22    $this->setValidator('uid', new opValidatorHash());
    1423  }
    1524}
  • OpenPNE3/branches/goto_doctrine/lib/form/doctrine/CommunityCategoryForm.class.php

    r11208 r11260  
    11<?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 */
    210
    311/**
    412 * CommunityCategory form.
    513 *
    6  * @package    form
    7  * @subpackage CommunityCategory
    8  * @version    SVN: $Id: sfDoctrineFormTemplate.php 6174 2007-11-27 06:22:40Z fabien $
     14 * @package    OpenPNE
     15 * @subpackage form
     16 * @author     Kousuke Ebihara <ebihara@tejimaya.com>
    917 */
    1018class CommunityCategoryForm extends BaseCommunityCategoryForm
     
    1220  public function configure()
    1321  {
     22    unset($this['id'], $this['sort_order'], $this['lft_key'], $this['rht_key'], $this->widgetSchema['tree_key']);
     23
     24    $obj = $this->isNew() ? $this->getOption('category') : $this->getObject();
     25    if ($obj instanceof CommunityCategory)
     26    {
     27      $this->setWidget('tree_key', new sfWidgetFormInputHidden(array('default' => $obj->getTreeKey())));
     28    }
     29
     30    $this->widgetSchema->getFormFormatter()->setTranslationCatalogue('form_community');
    1431  }
    1532}
  • OpenPNE3/branches/goto_doctrine/lib/form/doctrine/CommunityConfigForm.class.php

    r11208 r11260  
    11<?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 */
    210
    311/**
    412 * CommunityConfig form.
    513 *
    6  * @package    form
    7  * @subpackage CommunityConfig
    8  * @version    SVN: $Id: sfDoctrineFormTemplate.php 6174 2007-11-27 06:22:40Z fabien $
     14 * @package    OpenPNE
     15 * @subpackage form
     16 * @author     Kousuke Ebihara <ebihara@tejimaya.com>
    917 */
    1018class CommunityConfigForm extends BaseCommunityConfigForm
    1119{
     20  protected
     21    $configSettings = array(),
     22    $category = '',
     23    $community,
     24    $isNew = false,
     25    $isAutoGenerate = true;
     26
     27  public function __construct($defaults = array(), $options = array(), $CSRFSecret = null)
     28  {
     29    return parent::__construct($defaults, $options, false);
     30  }
     31
    1232  public function configure()
    1333  {
     34    $this->setCommunity($this->getOption('community'));
     35
     36    $this->setConfigSettings();
     37
     38    if ($this->isAutoGenerate)
     39    {
     40      $this->generateConfigWidgets();
     41    }
     42
     43    $this->widgetSchema->setNameFormat('community_config[%s]');
     44    $this->widgetSchema->getFormFormatter()->setTranslationCatalogue('form_community');
     45
     46    $this->errorSchema = new sfValidatorErrorSchema($this->validatorSchema);
     47  }
     48
     49  public function setCommunity($community)
     50  {
     51    if (!($community instanceof Community))
     52    {
     53      $community = new Community();
     54    }
     55    $this->community = $community;
     56  }
     57
     58  public function generateConfigWidgets()
     59  {
     60    foreach ($this->configSettings as $key => $value)
     61    {
     62      $this->setConfigWidget($key);
     63    }
     64  }
     65
     66  public function setConfigWidget($name)
     67  {
     68    $config = $this->configSettings[$name];
     69    $this->widgetSchema[$name] = opFormItemGenerator::generateWidget($config);
     70    $this->widgetSchema->setLabel($name, $config['Caption']);
     71    $communityConfig = Doctrine::getTable('CommunityConfig')->retrieveByNameAndCommunityId($name, $this->community->getId());
     72    if ($communityConfig)
     73    {
     74      $this->setDefault($name, $communityConfig->getValue());
     75    }
     76    $this->validatorSchema[$name] = opFormItemGenerator::generateValidator($config);
     77  }
     78
     79  public function setConfigSettings($category = '')
     80  {
     81    $categories = sfConfig::get('openpne_community_category');
     82    $configs = sfConfig::get('openpne_community_config');
     83
     84    if (!$category)
     85    {
     86      $this->configSettings = $configs;
     87      return true;
     88    }
     89
     90    foreach ($categories[$category] as $value)
     91    {
     92      $this->configSettings[$value] = $configs[$value];
     93    }
     94  }
     95
     96  public function save()
     97  {
     98    foreach ($this->getValues() as $key => $value)
     99    {
     100      $config = Doctrine::getTable('CommunityConfig')->retrieveByNameAndCommunityId($key, $this->community->getId());
     101      if (!$config)
     102      {
     103        $config = new CommunityConfig();
     104        $config->setCommunity($this->community);
     105        $config->setName($key);
     106      }
     107      $config->setValue($value);
     108      $config->save();
     109    }
    14110  }
    15111}
  • OpenPNE3/branches/goto_doctrine/lib/form/doctrine/CommunityForm.class.php

    r11208 r11260  
    11<?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 */
    210
    311/**
    412 * Community form.
    513 *
    6  * @package    form
    7  * @subpackage Community
    8  * @version    SVN: $Id: sfDoctrineFormTemplate.php 6174 2007-11-27 06:22:40Z fabien $
     14 * @package    OpenPNE
     15 * @subpackage form
     16 * @author     Kousuke Ebihara <ebihara@tejimaya.com>
    917 */
    1018class CommunityForm extends BaseCommunityForm
    1119{
     20  protected $configForm;
     21
    1222  public function configure()
    1323  {
     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    $q = Doctrine::getTable('CommunityCategory')->createQuery();
     30    if (1 != sfContext::getInstance()->getUser()->getMemberId())
     31    {
     32      $q->where('is_allow_member_community' = 1);
     33    }
     34    $this->setWidget('community_category_id', new sfWidgetFormDoctrineChoice(array(
     35      'model'       => 'CommunityCategory',
     36      'add_empty'   => false,
     37      'method' => 'retrieveAllChildren',
     38      'query'    => $q,
     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 = Doctrine::getTable('CommunityCategory')->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');
    1480  }
    1581}
  • OpenPNE3/branches/goto_doctrine/lib/form/doctrine/GadgetConfigForm.class.php

    r11208 r11260  
    11<?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 */
    210
    311/**
    412 * GadgetConfig form.
    513 *
    6  * @package    form
    7  * @subpackage GadgetConfig
    8  * @version    SVN: $Id: sfDoctrineFormTemplate.php 6174 2007-11-27 06:22:40Z fabien $
     14 * @package    OpenPNE
     15 * @subpackage form
     16 * @author     Kousuke Ebihara <ebihara@tejimaya.com>
    917 */
    10 class GadgetConfigForm extends BaseGadgetConfigForm
     18class GadgetConfigForm extends sfForm
    1119{
    12   public function configure()
     20  protected $gadget;
     21
     22  public function __construct(Gadget $gadget, $options = array(), $CSRFSecret = null)
    1323  {
     24    $this->gadget = $gadget;
     25
     26    parent::__construct(array(), $options, $CSRFSecret);
     27
     28    $config = Doctrine::getTable('Gadget')->getGadgetConfigListByType($options['type']);
     29    if (empty($config[$gadget->getName()]['config']))
     30    {
     31      throw new RuntimeException('The gadget has not registered or it doesn\'t have any configuration items.');
     32    }
     33
     34    $gadgetConfig = $config[$gadget->getName()]['config'];
     35    foreach ($gadgetConfig as $key => $value)
     36    {
     37      $this->setWidget($key, opFormItemGenerator::generateWidget($value));
     38      $this->setValidator($key, opFormItemGenerator::generateValidator($value));
     39
     40      $config = Doctrine::getTable('GadgetConfig')->retrieveByGadgetIdAndName($gadget->getId(), $key);
     41      if ($config)
     42      {
     43        $this->setDefault($key, $config->getValue());
     44      }
     45    }
     46
     47    $this->widgetSchema->setNameFormat('gadget_config[%s]');
     48  }
     49
     50  public function save()
     51  {
     52    foreach ($this->values as $key => $value)
     53    {
     54      $gadgetConfig = Doctrine::getTable('GadgetConfig')->retrieveByGadgetIdAndName($this->gadget->getId(), $key);
     55      if (!$gadgetConfig)
     56      {
     57        $gadgetConfig = new GadgetConfig();
     58        $gadgetConfig->setGadget($this->gadget);
     59        $gadgetConfig->setName($key);
     60      }
     61      $gadgetConfig->setValue($value);
     62      $gadgetConfig->save();
     63    }
    1464  }
    1565}
  • OpenPNE3/branches/goto_doctrine/lib/form/doctrine/InviteForm.class.php

    r11208 r11260  
    5555    }
    5656
    57     if (!empty($values['mobile_address']) && MemberConfigPeer::retrieveByNameAndValue('mobile_address', $values['mobile_address']))
     57    if (!empty($values['mobile_address']) && Doctrine::getTable('MemberConfig')->retrieveByNameAndValue('mobile_address', $values['mobile_address']))
    5858    {
    5959      throw new sfValidatorError($validator, 'invalid');
    6060    }
    61     if (!empty($values['pc_address']) && MemberConfigPeer::retrieveByNameAndValue('pc_address', $values['pc_address']))
     61    if (!empty($values['pc_address']) && Doctrine::getTable('MemberConfig')->retrieveByNameAndValue('pc_address', $values['pc_address']))
    6262    {
    6363      throw new sfValidatorError($validator, 'invalid');
     
    7272    {
    7373      $this->savePreConfig($name, $value);
    74       $memberConfig = MemberConfigPeer::retrieveByNameAndMemberId($name.'_token', $this->member->getId(), true);
     74      $memberConfig = Doctrine::getTable('MemberConfig')->retrieveByNameAndMemberId($name.'_token', $this->member->getId(), true);
    7575      $token = $memberConfig->getValue();
    7676      $this->sendConfirmMail($token, $value, array(
     
    116116      $fromMemberId = $user->getMemberId();
    117117      $toMemberId = $this->member->getId();
    118       $relation = MemberRelationshipPeer::retrieveByFromAndTo($fromMemberId, $toMemberId);
     118      $relation = Doctrine::getTable('MemberRelationship')->retrieveByFromAndTo($fromMemberId, $toMemberId);
    119119      if (!$relation)
    120120      {
  • OpenPNE3/branches/goto_doctrine/lib/form/doctrine/InvitelistForm.class.php

    r11208 r11260  
    11<?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 */
    210
    311/**
     
    614 * @package    OpenPNE
    715 * @subpackage form
    8  * @author     Your name here
    9  * @version    SVN: $Id: sfPropelFormTemplate.php 10377 2008-07-21 07:10:32Z dwhittle $
     16 * @author     Kousuke Ebihara <ebihara@tejimaya.com>
    1017 */
    1118class InvitelistForm extends sfForm
  • OpenPNE3/branches/goto_doctrine/lib/form/doctrine/MemberConfigForm.class.php

    r11208 r11260  
    11<?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 */
    210
    311/**
     
    513 *
    614 * @package    form
    7  * @subpackage MemberConfig
    8  * @version    SVN: $Id: sfDoctrineFormTemplate.php 6174 2007-11-27 06:22:40Z fabien $
     15 * @subpackage member_config
     16 * @author     Kousuke Ebihara <ebihara@tejimaya.com>
    917 */
    10 class MemberConfigForm extends BaseMemberConfigForm
     18class MemberConfigForm extends sfForm
    1119{
    12   public function configure()
     20  protected $memberConfigSettings = array();
     21  protected $category = '';
     22  protected $member;
     23  protected $isNew = false;
     24  protected $isAutoGenerate = true;
     25
     26  public function __construct(Member $member = null, $options = array(), $CSRFSecret = null)
    1327  {
     28    $this->setMemberConfigSettings();
     29
     30    $this->member = $member;
     31    if (is_null($this->member)) {
     32      $this->isNew = true;
     33      $this->member = new Member();
     34      $this->member->setIsActive(false);
     35    } elseif (!$this->member->getIsActive()) {
     36      $this->isNew = true;
     37    }
     38
     39    parent::__construct(array(), $options, $CSRFSecret);
     40
     41    if ($this->isAutoGenerate) {
     42      $this->generateConfigWidgets();
     43    }
     44
     45    $this->widgetSchema->setNameFormat('member_config[%s]');
     46  }
     47
     48  public function generateConfigWidgets()
     49  {
     50    foreach ($this->memberConfigSettings as $key => $value) {
     51      if ($this->isNew && $value['IsRegist'] || !$this->isNew && $value['IsConfig']) {
     52        $this->setMemberConfigWidget($key);
     53      }
     54    }
     55  }
     56
     57  public function setMemberConfigSettings()
     58  {
     59    $categories = sfConfig::get('openpne_member_category');
     60    $configs = sfConfig::get('openpne_member_config');
     61
     62    if (!$this->category) {
     63      $this->memberConfigSettings = $configs;
     64      return true;
     65    }
     66
     67    foreach ($categories[$this->category] as $value)
     68    {
     69      $this->memberConfigSettings[$value] = $configs[$value];
     70    }
     71  }
     72
     73  public function setMemberConfigWidget($name)
     74  {
     75    $config = $this->memberConfigSettings[$name];
     76    $this->widgetSchema[$name] = opFormItemGenerator::generateWidget($config);
     77    $this->widgetSchema->setLabel($name, $config['Caption']);
     78    $memberConfig = Doctrine::getTable('MemberConfig')->retrieveByNameAndMemberId($name, $this->member->getId());
     79    if ($memberConfig) {
     80      $this->setDefault($name, $memberConfig->getValue());
     81    }
     82    $this->validatorSchema[$name] = opFormItemGenerator::generateValidator($config);
     83
     84    if (!empty($config['IsConfirm'])) {
     85      $this->validatorSchema[$name.'_confirm'] = $this->validatorSchema[$name];
     86      $this->widgetSchema[$name.'_confirm'] = $this->widgetSchema[$name];
     87      $this->widgetSchema->setLabel($name.'_confirm', $config['Caption'].' (Confirm)');
     88
     89      $this->mergePostValidator(new sfValidatorSchemaCompare($name, '==', $name.'_confirm'));
     90    }
     91
     92    if (!empty($config['IsUnique'])) {
     93      $this->mergePostValidator(new sfValidatorCallback(array(
     94        'callback' => array($this, 'isUnique'),
     95        'arguments' => array('name' => $name),
     96      )));
     97    }
     98  }
     99
     100  public function isUnique($validator, $value, $arguments = array())
     101  {
     102    if (empty($arguments['name'])) {
     103      throw new InvalidArgumentException('Invalid argument');
     104    }
     105
     106    $name = $arguments['name'];
     107    $data = Doctrine::getTable('MemberConfig')->retrieveByNameAndValue($name, $value[$name]);
     108    if (!$data || !$data->getMember()->getIsActive() || $data->getMember()->getId() == $this->member->getId()) {
     109      return $value;
     110    }
     111
     112    throw new sfValidatorError($validator, 'This '.$name.' address already exists.');
     113  }
     114
     115  public function isValid()
     116  {
     117    opActivateBehavior::disable();
     118
     119    foreach ($this->getValues() as $key => $value)
     120    {
     121      if (!empty($this->memberConfigSettings[$key]['IsUnique']))
     122      {
     123        $memberConfig = Doctrine::getTable('MemberConfig')->retrieveByNameAndValue($key.'_pre', $value);
     124        if ($memberConfig)
     125        {
     126          $member = $memberConfig->getMember();
     127          if (!$member->getIsActive())
     128          {
     129            $this->member = $member;
     130          }
     131        }
     132      }
     133    }
     134
     135    opActivateBehavior::enable();
     136    return parent::isValid();
     137  }
     138
     139  public function save()
     140  {
     141    foreach ($this->getValues() as $key => $value)
     142    {
     143      if (strrpos($key, '_confirm'))
     144      {
     145        continue;
     146      }
     147
     148      $this->saveConfig($key, $value);
     149    }
     150
     151    return true;
     152  }
     153
     154  public function saveConfig($name, $value)
     155  {
     156    $memberConfig = Doctrine::getTable('MemberConfig')->retrieveByNameAndMemberId($name, $this->member->getId());
     157    if (!$memberConfig) {
     158      $memberConfig = new MemberConfig();
     159      $memberConfig->setName($name);
     160      $memberConfig->setMember($this->member);
     161    }
     162    $memberConfig->setValue($value);
     163
     164    $memberConfig->save();
     165  }
     166
     167  public function savePreConfig($name, $value)
     168  {
     169    $memberConfig = Doctrine::getTable('MemberConfig')->retrieveByNameAndMemberId($name.'_pre', $this->member->getId());
     170    if (!$memberConfig) {
     171      $memberConfig = new MemberConfig();
     172      $memberConfig->setName($name);
     173      $memberConfig->setMember($this->member);
     174    }
     175
     176    $memberConfig->setValue($value);
     177    $memberConfig->savePre();
     178    $memberConfig->saveToken();
    14179  }
    15180}
  • OpenPNE3/branches/goto_doctrine/lib/form/doctrine/MemberForm.class.php

    r11208 r11260  
    11<?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 */
    210
    311/**
     
    513 *
    614 * @package    form
    7  * @subpackage Member
    8  * @version    SVN: $Id: sfDoctrineFormTemplate.php 6174 2007-11-27 06:22:40Z fabien $
     15 * @subpackage member
     16 * @author     Kousuke Ebihara <ebihara@tejimaya.com>
    917 */
    1018class MemberForm extends BaseMemberForm
     
    1220  public function configure()
    1321  {
     22    $this->setWidgets(array(
     23      'name' => new sfWidgetFormInput(),
     24    ));
     25
     26    $this->setValidators(array(
     27      'name' => new sfValidatorString(array('max_length' => 64, 'trim' => true)),
     28    ));
     29
     30    $this->widgetSchema->setNameFormat('member[%s]');
     31    $this->widgetSchema->getFormFormatter()->setTranslationCatalogue('form_member');
     32  }
     33
     34  protected function doSave($con = null)
     35  {
     36    if ($this->isNew()) {
     37      $this->object->setIsActive(false);
     38    }
     39
     40    parent::doSave($con);
    1441  }
    1542}
  • OpenPNE3/branches/goto_doctrine/lib/form/doctrine/MemberImageForm.class.php

    r11208 r11260  
    22
    33/**
    4  * MemberImage form.
     4 * This file is part of the OpenPNE package.
     5 * (c) OpenPNE Project (http://www.openpne.jp/)
    56 *
    6  * @package    form
    7  * @subpackage MemberImage
    8  * @version    SVN: $Id: sfDoctrineFormTemplate.php 6174 2007-11-27 06:22:40Z fabien $
     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.
    99 */
    10 class MemberImageForm extends BaseMemberImageForm
     10
     11/**
     12 * MemberImageForm
     13 *
     14 * @package    OpenPNE
     15 * @subpackage form
     16 * @author     Kousuke Ebihara <ebihara@tejimaya.com>
     17 */
     18class MemberImageForm extends sfForm
    1119{
    1220  public function configure()
    1321  {
     22    $this->member = $this->getOption('member');
     23    $this->setWidget('file', new sfWidgetFormInputFile());
     24    $this->setValidator('file', new opValidatorImageFile());
     25    $this->widgetSchema->setNameFormat('member_image[%s]');
     26  }
     27
     28  public function bindAndSave(array $taintedValues = null, array $taintedFiles = null)
     29  {
     30    $this->bind($taintedValues, $taintedFiles);
     31    if ($this->isValid())
     32    {
     33      return $this->save();
     34    }
     35    return false;
     36  }
     37
     38  public function save()
     39  {
     40    $count = $this->member->countMemberImages();
     41    if ($count >= 3)
     42    {
     43      throw new opRuntimeException('Cannot add an image any more.');
     44    }
     45
     46    $file = new File();
     47    $file->setFromValidatedFile($this->getValue('file'));
     48    $file->setName('m_'.$this->member->getId().'_'.$file->getName());
     49
     50    $memberImage = new MemberImage();
     51    $memberImage->setMember($this->member);
     52    $memberImage->setFile($file);
     53    if (!$count)
     54    {
     55      $memberImage->setIsPrimary(true);
     56    }
     57    return $memberImage->save();
    1458  }
    1559}
  • OpenPNE3/branches/goto_doctrine/lib/form/doctrine/MemberProfileForm.class.php

    r11208 r11260  
    11<?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 */
    210
    311/**
    412 * MemberProfile form.
    513 *
    6  * @package    form
    7  * @subpackage MemberProfile
    8  * @version    SVN: $Id: sfDoctrineFormTemplate.php 6174 2007-11-27 06:22:40Z fabien $
     14 * @package    OpenPNE
     15 * @subpackage form
     16 * @author     Kousuke Ebihara <ebihara@tejimaya.com>
    917 */
    10 class MemberProfileForm extends BaseMemberProfileForm
     18class MemberProfileForm extends sfForm
    1119{
     20  public function __construct($profileMember = array(), $options = array(), $CSRFSecret = null)
     21  {
     22    parent::__construct(array(), $options, $CSRFSecret);
     23
     24    $profiles = Doctrine::getTable('Profile')->createQuery()->execute();
     25
     26    foreach ($profileMember as $profile)
     27    {
     28      $this->setDefault($profile->getName(), array(
     29        'value' => $profile->getValue(),
     30        'public_flag' => $profile->getPublicFlag()
     31      ));
     32    }
     33  }
     34
    1235  public function configure()
    1336  {
     37    $this->widgetSchema->setNameFormat('profile[%s]');
     38  }
     39
     40  public function save($memberId)
     41  {
     42    $values = $this->getValues();
     43
     44    foreach ($values as $key => $value)
     45    {
     46      $profile = Doctrine::getTable('Profile')->retrieveByName($key);
     47      if (!$profile)
     48      {
     49        continue;
     50      }
     51
     52      $formType = $profile->getFormType();
     53
     54      $memberProfile = MemberDoctrine::getTable('Profile')->retrieveByMemberIdAndProfileId($memberId, $profile->getId());
     55      if ($memberProfile)
     56      {
     57        $memberProfile->clearChildren();
     58      }
     59      $memberProfile = MemberDoctrine::getTable('Profile')->makeRoot($memberId, $profile->getId());
     60
     61      if ($profile->isMultipleSelect())
     62      {
     63        $ids = array();
     64        $_values = array();
     65        if ('date' === $formType)
     66        {
     67          $_values = explode('-', $value['value']);
     68          $options = $profile->getProfileOptions();
     69          foreach ($options as $option)
     70          {
     71            $ids[] = $option->getId();
     72          }
     73        }
     74        else
     75        {
     76          $ids = $value['value'];
     77        }
     78        MemberDoctrine::getTable('Profile')->createChild($memberProfile, $memberId, $profile->getId(), $ids, $_values);
     79      }
     80      else
     81      {
     82        $memberProfile->setValue($value['value']);
     83      }
     84     
     85      $memberProfile->setPublicFlag($memberProfile->getProfile()->getDefaultPublicFlag());
     86      if (isset($value['public_flag']))
     87      {
     88        $memberProfile->setPublicFlag($value['public_flag']);
     89      }
     90
     91      $memberProfile->save();
     92    }
     93
     94    return true;
     95  }
     96
     97  public function setRegisterWidgets()
     98  {
     99    $profiles = Doctrine::getTable('Profile')->retrieveByIsDispRegist();
     100    $this->setProfileWidgets($profiles);
     101  }
     102
     103  public function setConfigWidgets()
     104  {
     105    $profiles = Doctrine::getTable('Profile')->retrieveByIsDispConfig();
     106    $this->setProfileWidgets($profiles);
     107  }
     108
     109  public function setSearchWidgets()
     110  {
     111    $profiles = Doctrine::getTable('Profile')->retrieveByIsDispSearch();
     112    $this->setProfileWidgets($profiles);
     113  }
     114
     115  public function setAllWidgets()
     116  {
     117    $profiles = Doctrine::getTable('Profile')->retrievesAll();
     118    $this->setProfileWidgets($profiles);
     119  }
     120
     121  protected function setProfileWidgets($profiles)
     122  {
     123    foreach ($profiles as $profile)
     124    {
     125      $profile_i18n = $profile->getProfileI18ns();
     126      $profileWithI18n = $profile->toArray() + $profile_i18n[0]->toArray();
     127
     128      $widgetOptions = array(
     129        'widget' => opFormItemGenerator::generateWidget($profileWithI18n, $this->getFormOptionsValue($profile->getId())),
     130      );
     131      $validatorOptions = array(
     132        'validator' => opFormItemGenerator::generateValidator($profileWithI18n, $this->getFormOptions($profile->getId())),
     133      );
     134
     135      if ($profile->getIsEditPublicFlag())
     136      {
     137        $widgetOptions['is_edit_public_flag'] = $validatorOptions['is_edit_public_flag'] = true;
     138        if (!$this->getDefault($profile->getName()))
     139        {
     140          $this->setDefault($profile->getName(), array('public_flag' => $profile->getDefaultPublicFlag()));
     141        }
     142       
     143      }
     144
     145      $this->widgetSchema[$profile->getName()] = new opWidgetFormProfile($widgetOptions);
     146      $this->validatorSchema[$profile->getName()] = new opValidatorProfile($validatorOptions);
     147    }
     148  }
     149
     150  private function getFormOptions($profileId)
     151  {
     152    $result = array();
     153    $options = Doctrine::getTable('ProfileOption')->retrieveByProfileId($profileId);
     154
     155    foreach ($options as $option)
     156    {
     157      $result[] = $option->getId();
     158    }
     159
     160    return $result;
     161  }
     162
     163  private function getFormOptionsValue($profileId)
     164  {
     165    $result = array();
     166    $options = Doctrine::getTable('ProfileOption')->retrieveByProfileId($profileId);
     167
     168    foreach ($options as $option)
     169    {
     170      $result[$option->getId()] = $option->getValue();
     171    }
     172
     173    return $result;
     174  }
     175
     176  private function updateDefaultsFromObject($obj)
     177  {
     178    $this->setDefaults(array_merge($this->getDefaults(), $obj->toArray()));
    14179  }
    15180}
  • OpenPNE3/branches/goto_doctrine/lib/form/doctrine/NavigationForm.class.php

    r11208 r11260  
    1212  public function configure()
    1313  {
     14    $this->setWidgets(array(
     15      'id' => new sfWidgetFormInputHidden(),
     16      'uri' => new sfWidgetFormInput(),
     17      'type' => new sfWidgetFormInputHidden(),
     18    ));
     19
     20    $this->widgetSchema->setNameFormat('nav[%s]');
     21    $this->embedI18n(array('ja_JP'));
     22  }
     23
     24  public function updateObject($values = null)
     25  {
     26    $nav = parent::updateObject($values);
     27
     28    if (!$nav->getSortOrder())
     29    {
     30      $maxSortOrder = 0;
     31
     32      $navs = Doctrine::getTable('Navigation')->retrieveByType($nav->getType());
     33      $finalNav = array_pop($navs);
     34      if ($finalNav)
     35      {
     36        $maxSortOrder = $finalNav->getSortOrder();
     37      }
     38
     39      $nav->setSortOrder($maxSortOrder + 10);
     40    }
     41
     42    return $nav;
    1443  }
    1544}
  • OpenPNE3/branches/goto_doctrine/lib/form/doctrine/ProfileForm.class.php

    r11208 r11260  
    11<?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 */
    210
    311/**
    412 * Profile form.
    513 *
    6  * @package    form
    7  * @subpackage Profile
    8  * @version    SVN: $Id: sfDoctrineFormTemplate.php 6174 2007-11-27 06:22:40Z fabien $
     14 * @package    OpenPNE
     15 * @subpackage form
     16 * @author     Kousuke Ebihara <ebihara@tejimaya.com>
    917 */
    1018class ProfileForm extends BaseProfileForm
     
    1220  public function configure()
    1321  {
     22    $isDispOption = array('choices' => array('1' => '表示する', '0' => '表示しない'));
     23    $this->setWidgets(array(
     24      'name' => new sfWidgetFormInput(),
     25      'is_edit_public_flag' => new sfWidgetFormSelectRadio(array('choices' => array('0' => '固定', '1' => 'メンバー選択'))),
     26      'default_public_flag' => new sfWidgetFormSelect(array('choices' => Doctrine::getTable('Profile')->getPublicFlags())),
     27      'is_disp_regist' => new sfWidgetFormSelectRadio($isDispOption),
     28      'is_disp_config' => new sfWidgetFormSelectRadio($isDispOption),
     29      'is_disp_search' => new sfWidgetFormSelectRadio($isDispOption),
     30      'form_type' => new sfWidgetFormSelect(array('choices' => array(
     31        'input'    => 'テキスト',
     32        'textarea' => 'テキスト(複数行)',
     33        'select'   => '単一選択(プルダウン)',
     34        'radio'    => '単一選択(ラジオボタン)',
     35        'checkbox' => '複数選択(チェックボックス)',
     36        'date'     => '日付',
     37      ))),
     38      'value_type' => new sfWidgetFormSelect(array('choices' => array(
     39        'string' => '文字列',
     40        'integer' => '数値',
     41        'email' => 'メールアドレス',
     42        'url' => 'URL',
     43        'regexp' => '正規表現',
     44      ))),
     45      'is_unique' => new sfWidgetFormSelectRadio(array('choices' => array('0' => '重複可', '1' => '重複不可'))),
     46      'sort_order' => new sfWidgetFormInputHidden(),
     47    ) + $this->getWidgetSchema()->getFields());
     48
     49    $this->widgetSchema->setNameFormat('profile[%s]');
     50
     51    $this->validatorSchema->setPostValidator(
     52      new sfValidatorDoctrineUnique(array('model' => 'Profile', 'column' => array('name')))
     53    );
     54
     55    $this->mergePostValidator(new sfValidatorCallback(array('callback' => array('ProfileForm', 'advancedValidator'))));
     56    $this->setValidator('default_public_flag', new sfValidatorChoice(array('choices' => array_keys(Doctrine::getTable('Profile')->getPublicFlags()))));
     57    $this->setValidator('value_min', new sfValidatorPass());
     58    $this->setValidator('value_max', new sfValidatorPass());
     59    $this->setValidator('value_type', new sfValidatorString(array('required' => false, 'empty_value' => 'string')));
     60
     61    $this->widgetSchema->setLabels(array(
     62      'name' => '識別名',
     63      'is_required' => '必須',
     64      'is_edit_public_flag' => '公開設定の選択',
     65      'default_public_flag' => '公開設定デフォルト値',
     66      'is_unique' => '重複の可否',
     67      'form_type' => 'フォームタイプ',
     68      'value_type' => '入力値タイプ',
     69      'value_regexp' => '正規表現',
     70      'value_min' => '最小値',
     71      'value_max' => '最大値',
     72      'is_disp_regist' => '新規登録',
     73      'is_disp_config' => 'プロフィール変更',
     74      'is_disp_search' => 'メンバー検索'
     75   ));
     76
     77    $this->setDefaults($this->getDefaults() + array(
     78      'is_unique' => '0',
     79      'is_disp_regist' => '1',
     80      'is_disp_config' => '1',
     81      'is_disp_search' => '1',
     82    ));
     83
     84    $this->embedI18n(array('ja_JP'));
     85  }
     86
     87  static public function advancedValidator($validator, $values)
     88  {
     89    if ($values['form_type'] === 'input' || $values['form_type'] === 'textarea')
     90    {
     91      $validator = new sfValidatorInteger(array('required' => false));
     92      $values['value_min'] = $validator->clean($values['value_min']);
     93      $values['value_max'] = $validator->clean($values['value_max']);
     94    }
     95    elseif ($values['form_type'] === 'date')
     96    {
     97      $validator = new opValidatorDate(array('required' => false));
     98      $validator->clean($values['value_min']);
     99      $validator->clean($values['value_max']);
     100    }
     101    elseif ($values['value_min'] || $values['value_max'])
     102    {
     103      throw new sfValidatorError($validator, 'invalid');
     104    }
     105
     106    return $values;
     107  }
     108
     109  public function save($con = null)
     110  {
     111    $profile  = parent::save($con);
     112
     113    $values = $this->getValues();
     114    if (!$values['is_edit_public_flag'])
     115    {
     116      Doctrine_Query::create()
     117        ->update('MemberProfile')
     118        ->set('public_flag', $values['default_public_flag'])
     119        ->where('lft_key = 1')
     120        ->andWhere('profile_id = ?', $profile->getId())
     121        ->execute();
     122    }
    14123  }
    15124}
  • OpenPNE3/branches/goto_doctrine/lib/form/doctrine/ProfileOptionForm.class.php

    r11208 r11260  
    11<?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 */
    210
    311/**
    412 * ProfileOption form.
    513 *
    6  * @package    form
    7  * @subpackage ProfileOption
    8  * @version    SVN: $Id: sfDoctrineFormTemplate.php 6174 2007-11-27 06:22:40Z fabien $
     14 * @package    OpenPNE
     15 * @subpackage form
     16 * @author     Kousuke Ebihara <ebihara@tejimaya.com>
    917 */
    1018class ProfileOptionForm extends BaseProfileOptionForm
     
    1220  public function configure()
    1321  {
     22    $options = array();
     23    if ($this->object && $this->object->getId()) {
     24      $options['id_format'] = '%s' . $this->object->getId();
     25    }
     26
     27    $this->setWidgets(array(
     28      'id'         => new sfWidgetFormInputHidden(),
     29      'profile_id' => new sfWidgetFormInputHidden(),
     30      'sort_order' => new sfWidgetFormInputHidden(),
     31    ));
     32
     33    $this->setValidators(array(
     34      'id'         => new sfValidatorDoctrineChoice(array('model' => 'ProfileOption', 'column' => 'id', 'required' => false)),
     35      'profile_id' => new sfValidatorDoctrineChoice(array('model' => 'Profile', 'column' => 'id', 'required' => true)),
     36      'sort_order' => new sfValidatorInteger(array('required' => false)),
     37    ));
     38
     39    $this->widgetSchema->setNameFormat('profile_option[%s]');
     40
     41    $this->embedI18n(array('ja_JP'));
    1442  }
    1543}
  • OpenPNE3/branches/goto_doctrine/lib/form/doctrine/SnsConfigForm.class.php

    r11208 r11260  
    11<?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 */
    210
    311/**
    412 * SnsConfig form.
    513 *
    6  * @package    form
    7  * @subpackage SnsConfig
    8  * @version    SVN: $Id: sfDoctrineFormTemplate.php 6174 2007-11-27 06:22:40Z fabien $
     14 * @package    OpenPNE
     15 * @subpackage form
     16 * @author     Kousuke Ebihara <ebihara@tejimaya.com>
    917 */
    10 class SnsConfigForm extends BaseSnsConfigForm
     18class SnsConfigForm extends sfForm
    1119{
    1220  public function configure()
    1321  {
     22    $snsConfig = sfConfig::get('openpne_sns_config');
     23    $category = sfConfig::get('openpne_sns_category');
     24    if (empty($category[$this->getOption('category')]))
     25    {
     26      return false;
     27    }
     28
     29    foreach ($category[$this->getOption('category')] as $configName)
     30    {
     31      if (empty($snsConfig[$configName]))
     32      {
     33        continue;
     34      }
     35
     36      $this->setWidget($configName, opFormItemGenerator::generateWidget($snsConfig[$configName]));
     37      $this->setValidator($configName, opFormItemGenerator::generateValidator($snsConfig[$configName]));
     38      $this->widgetSchema->setLabel($configName, $snsConfig[$configName]['Caption']);
     39      if (isset($snsConfig[$configName]['Help']))
     40      {
     41        $this->widgetSchema->setHelp($configName, $snsConfig[$configName]['Help']);
     42      }
     43      $this->setDefault($configName, opConfig::get($configName));
     44    }
     45
     46    $this->widgetSchema->setNameFormat('sns_config[%s]');
     47  }
     48
     49  public function save()
     50  {
     51    $config = sfConfig::get('openpne_sns_config');
     52    foreach ($this->getValues() as $key => $value)
     53    {
     54      $snsConfig = Doctrine::getTable('SnsConfig')->retrieveByName($key);
     55      if (!$snsConfig)
     56      {
     57        $snsConfig = new SnsConfig();
     58        $snsConfig->setName($key);
     59      }
     60      $snsConfig->setValue($value);
     61      $snsConfig->save();
     62    }
    1463  }
    1564}
  • OpenPNE3/branches/goto_doctrine/lib/model/doctrine/CommunityCategoryTable.class.php

    r11249 r11260  
    1919  {
    2020    return $this->createQuery()
    21       ->where('left_col = 1')
     21      ->where('lft_key = 1')
    2222      ->execute();
    2323  }
     
    2626  {
    2727    return $this->createQuery()
    28       ->where('left_col > 1')
     28      ->where('lft_key > 1')
    2929      ->execute();
    3030  }
Note: See TracChangeset for help on using the changeset viewer.