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

Changeset 10130


Ignore:
Timestamp:
Jan 14, 2009, 6:58:41 PM (11 years ago)
Author:
ShogoKawahara
Message:

#3440:renamed ApplicationSetting? model to MemberApplicationSetting? model and added new ApplicationSetting? model

Location:
OpenPNE3/plugins/opOpenSocialPlugin/trunk
Files:
3 added
8 edited

Legend:

Unmodified
Added
Removed
  • OpenPNE3/plugins/opOpenSocialPlugin/trunk/apps/pc_frontend/modules/application/actions/actions.class.php

    r10014 r10130  
    152152    $this->appName = $memberApp->getApplication()->getTitle();
    153153
    154     $applicationSettingForm = new ApplicationSettingForm();
     154    $applicationSettingForm = new MemberApplicationSettingForm();
    155155    $memberId = $this->getUser()->getMember()->getId();
    156156    $applicationSettingForm->setConfigWidgets($memberId, $modId);
     
    160160    if (!$memberApp->getIsHomeWidget())
    161161    {
    162       $memberApplicationSettingForm = new MemberApplicationSettingForm($memberApp);
    163       $this->forms[] = $memberApplicationSettingForm;
     162      $memberApplicationForm = new MemberApplicationForm($memberApp);
     163      $this->forms[] = $memberApplicationForm;
    164164    }
    165165
     
    169169      if (!$memberApp->getIsHomeWidget())
    170170      {
    171         $memberApplicationSettingForm->bind($request->getParameter('member_app_setting'));
    172         if ($memberApplicationSettingForm->isValid())
     171        $memberApplicationForm->bind($request->getParameter('member_app_setting'));
     172        if ($memberApplicationForm->isValid())
    173173        {
    174           $memberApplicationSettingForm->save();
     174          $memberApplicationForm->save();
    175175        }
    176176        else
  • OpenPNE3/plugins/opOpenSocialPlugin/trunk/apps/pc_frontend/modules/application/actions/components.class.php

    r10014 r10130  
    7171      'url'       => $url,
    7272    );
    73     $criteria = new Criteria();
    74     $criteria->add(ApplicationSettingPeer::MEMBER_APPLICATION_ID, $modId);
    75     $app_settings = ApplicationSettingPeer::doSelect($criteria);
     73
     74    $app_settings = MemberApplicationSettingPeer::getSettingsByMemberApplicationId($modId);
     75
    7676    $userpref_param_prefix = Config::get('userpref_param_prefix','up_');
    7777    foreach ($app_settings as $app_setting)
  • OpenPNE3/plugins/opOpenSocialPlugin/trunk/apps/pc_frontend/modules/prefs/actions/actions.class.php

    r10014 r10130  
    4040      $modId = $token->getModuleId();
    4141      $viewer = $token->getViewerId();
    42       $criteria = new Criteria(ApplicationSettingPeer::DATABASE_NAME);
    43       $criteria->add(ApplicationSettingPeer::MEMBER_APPLICATION_ID,$modId);
    44       $criteria->add(ApplicationSettingPeer::NAME,$key);
    45       $appSetting = ApplicationSettingPeer::doSelectOne($criteria);
     42     
     43      $appSetting = MemberApplicationSettingPeer::retrieveByMemberApplicationIdAndName($modId, $key);
     44
    4645      if (empty($appSetting))
    4746      {
    48         $appSetting = new ApplicationSetting();
     47        $appSetting = new MemberApplicationSetting();
    4948        $appSetting->setMemberApplicationId($modId);
    5049        $appSetting->setName($key);
  • OpenPNE3/plugins/opOpenSocialPlugin/trunk/config/schema.yml

    r9762 r10130  
    3939  application_setting:
    4040    id: ~
     41    application_id: { type: integer, foreignTable: application, foreignReference: id, onDelete: cascade }
     42    name: { type: varchar(128), required: true }
     43    value: { type: varchar(255), required: true }
     44
     45  member_application_setting:
     46    id: ~
    4147    member_application_id: { type: integer, foreignTable: member_application, foreignReference: id, onDelete: cascade }
    4248    name: { type: varchar(128), required: true }
  • OpenPNE3/plugins/opOpenSocialPlugin/trunk/lib/form/ApplicationSettingForm.class.php

    r10014 r10130  
    1212 * ApplicationSetting form.
    1313 *
    14  * @package    OpenPNE
     14 * @package    ##PROJECT_NAME##
    1515 * @subpackage form
    16  * @author     Shogo Kawahara <kawahara@tejimaya.net>
     16 * @author     ##AUTHOR_NAME##
     17 * @version    SVN: $Id: sfPropelFormTemplate.php 10377 2008-07-21 07:10:32Z dwhittle $
    1718 */
    18 class ApplicationSettingForm extends OpenPNEFormAutoGenerate
     19class ApplicationSettingForm extends BaseApplicationSettingForm
    1920{
    20   public function __construct($appSetting = array(),$options = array(), $CSRFSecret = null)
    21   {
    22     parent::__construct(array(), $options, $CSRFSecret);
    23 
    24     foreach ($appSetting as $setting)
    25     {
    26       $this->setDefault($setting->getName(), $setting->getValue());
    27     }
    28   }
    29 
    3021  public function configure()
    3122  {
    32     $this->widgetSchema->setNameFormat('setting[%s]');
    33   }
    34 
    35   public function setConfigWidgets($memberId, $modId)
    36   {
    37     $memberApp = MemberApplicationPeer::retrieveByPk($modId);
    38     if (!$memberApp)
    39     {
    40       return false;
    41     }
    42 
    43     if ($memberApp->getMemberId() != $memberId)
    44     {
    45       return false;
    46     }
    47 
    48     if (!$memberApp->getApplication()->hasSetting())
    49     {
    50       return false;
    51     }
    52 
    53     $settings = $memberApp->getApplication()->getSettings();
    54 
    55     foreach ($settings as $key => $setting)
    56     {
    57       $param   = array();
    58       $choices = array();
    59       $param['IsRequired'] = false;
    60       $param['Caption'] = $setting['displayName'];
    61       if (empty($setting['type']) || $setting['type'] == 'HIDDEN')
    62       {
    63         continue;
    64       }
    65       switch ($setting['type'])
    66       {
    67         case 'BOOL' :
    68           $param['FormType']  = 'radio';
    69           $choices = array('1' => 'Yes', '0' => 'No');
    70           break;
    71         case 'ENUM' :
    72           $param['FormType'] = 'select';
    73           $choices = $setting['enumValues'];
    74           break;
    75         default :
    76           $param['FormType']  = 'textarea';
    77           $param['ValueType'] = '';
    78       }
    79       $this->widgetSchema[$key] = $this->generateWidget($param, $choices);
    80       $this->validatorSchema[$key] = $this->generateValidator($param, array_keys($choices));
    81 
    82       if ($setting['default'])
    83       {
    84         $this->setDefault($key, $setting['default']);
    85       }
    86     }
    87 
    88     $criteria = new Criteria();
    89     $criteria->add(ApplicationSettingPeer::MEMBER_APPLICATION_ID, $modId);
    90     $appSettings = ApplicationSettingPeer::doSelect($criteria);
    91 
    92     foreach($appSettings as $appSetting)
    93     {
    94       $this->setDefault($appSetting->getName(), $appSetting->getValue());
    95     }
    96 
    97     return true;
    98   }
    99  
    100   public function save($modId)
    101   {
    102     $values = $this->getValues();
    103 
    104     foreach ($values as $name => $value)
    105     {
    106       $appSetting = ApplicationSettingPeer::retrieveByMemberApplicationIdAndName($modId, $name);
    107       if (!$appSetting)
    108       {
    109         $appSetting = new ApplicationSetting();
    110         $appSetting->setMemberApplicationId($modId);
    111         $appSetting->setName($name);
    112       }
    113       $appSetting->setValue($value);
    114       $appSetting->save();
    115     }
    11623  }
    11724}
  • OpenPNE3/plugins/opOpenSocialPlugin/trunk/lib/form/MemberApplicationForm.class.php

    r10014 r10130  
    1212 * MemberApplication form.
    1313 *
    14  * @package    form
    15  * @subpackage member_application
    16  * @version    SVN: $Id: sfPropelFormTemplate.php 6174 2007-11-27 06:22:40Z fabien $
     14 * @package    OpenPNE3
     15 * @subpackage form
     16 * @author     Shogo Kawahara <kawahara@tejimaya.net>
    1717 */
    1818class MemberApplicationForm extends BaseMemberApplicationForm
     
    2020  public function configure()
    2121  {
     22    $this->setWidgets(array(
     23      'is_disp_other' => new sfWidgetFormInputCheckbox(),
     24      'is_disp_home'  => new sfWidgetFormInputCheckbox(),
     25    ));
     26
     27    $this->setValidators(array(
     28      'is_disp_other' => new sfValidatorBoolean(array('required' => false)),
     29      'is_disp_home'  => new sfValidatorBoolean(array('required' => false)),
     30    ));
     31
     32    $this->widgetSchema->setLabels(array(
     33      'is_disp_other' => '他のメンバーによる閲覧を許可する',
     34      'is_disp_home'  => 'ホーム/プロフィールに表示する',
     35    ));
     36
     37    $this->widgetSchema->setNameFormat('member_app_setting[%s]');
    2238  }
    2339}
  • OpenPNE3/plugins/opOpenSocialPlugin/trunk/lib/form/MemberApplicationSettingForm.class.php

    r10014 r10130  
    1010
    1111/**
    12  * MemberApplication form.
     12 * MemberApplicationSetting form.
    1313 *
    14  * @package    OpenPNE3
     14 * @package    OpenPNE
    1515 * @subpackage form
    16  * @author     Shogo Kawahara<kawahara@tejimaya.net>
     16 * @author     Shogo Kawahara <kawahara@tejimaya.net>
    1717 */
    18 class MemberApplicationSettingForm extends BaseMemberApplicationForm
     18class MemberApplicationSettingForm extends sfForm
    1919{
     20  public function __construct($appSetting = array(),$options = array(), $CSRFSecret = null)
     21  {
     22    parent::__construct(array(), $options, $CSRFSecret);
     23
     24    foreach ($appSetting as $setting)
     25    {
     26      $this->setDefault($setting->getName(), $setting->getValue());
     27    }
     28  }
     29
    2030  public function configure()
    2131  {
    22     $this->setWidgets(array(
    23       'is_disp_other' => new sfWidgetFormInputCheckbox(),
    24       'is_disp_home'  => new sfWidgetFormInputCheckbox(),
    25     ));
     32    $this->widgetSchema->setNameFormat('setting[%s]');
     33  }
    2634
    27     $this->setValidators(array(
    28       'is_disp_other' => new sfValidatorBoolean(array('required' => false)),
    29       'is_disp_home'  => new sfValidatorBoolean(array('required' => false)),
    30     ));
     35  public function setConfigWidgets($memberId, $modId)
     36  {
     37    $memberApp = MemberApplicationPeer::retrieveByPk($modId);
     38    if (!$memberApp)
     39    {
     40      return false;
     41    }
    3142
    32     $this->widgetSchema->setLabels(array(
    33       'is_disp_other' => '他のメンバーによる閲覧を許可する',
    34       'is_disp_home'  => 'ホーム/プロフィールに表示する',
    35     ));
     43    if ($memberApp->getMemberId() != $memberId)
     44    {
     45      return false;
     46    }
    3647
    37     $this->widgetSchema->setNameFormat('member_app_setting[%s]');
     48    if (!$memberApp->getApplication()->hasSetting())
     49    {
     50      return false;
     51    }
     52
     53    $settings = $memberApp->getApplication()->getSettings();
     54
     55    foreach ($settings as $key => $setting)
     56    {
     57      $param   = array();
     58      $choices = array();
     59      $param['IsRequired'] = false;
     60      $param['Caption'] = $setting['displayName'];
     61      if (empty($setting['type']) || $setting['type'] == 'HIDDEN')
     62      {
     63        continue;
     64      }
     65      switch ($setting['type'])
     66      {
     67        case 'BOOL' :
     68          $param['FormType']  = 'radio';
     69          $choices = array('1' => 'Yes', '0' => 'No');
     70          break;
     71        case 'ENUM' :
     72          $param['FormType'] = 'select';
     73          $choices = $setting['enumValues'];
     74          break;
     75        default :
     76          $param['FormType']  = 'textarea';
     77          $param['ValueType'] = '';
     78      }
     79      $this->widgetSchema[$key] = opFormItemGenerator::generateWidget($param, $choices);
     80      $this->validatorSchema[$key] = opFormItemGenerator::generateValidator($param, array_keys($choices));
     81
     82      if ($setting['default'])
     83      {
     84        $this->setDefault($key, $setting['default']);
     85      }
     86    }
     87
     88    $appSettings = MemberApplicationSettingPeer::getSettingsByMemberApplicationId($modId);
     89
     90    foreach($appSettings as $appSetting)
     91    {
     92      $this->setDefault($appSetting->getName(), $appSetting->getValue());
     93    }
     94
     95    return true;
     96  }
     97 
     98  public function save($modId)
     99  {
     100    $values = $this->getValues();
     101
     102    foreach ($values as $name => $value)
     103    {
     104      $appSetting = MemberApplicationSettingPeer::retrieveByMemberApplicationIdAndName($modId, $name);
     105      if (!$appSetting)
     106      {
     107        $appSetting = new MemberApplicationSetting();
     108        $appSetting->setMemberApplicationId($modId);
     109        $appSetting->setName($name);
     110      }
     111      $appSetting->setValue($value);
     112      $appSetting->save();
     113    }
    38114  }
    39115}
  • OpenPNE3/plugins/opOpenSocialPlugin/trunk/lib/model/ApplicationSettingPeer.php

    r10014 r10130  
    1313 *
    1414 *
    15  *
    1615 * @package plugins.opOpenSocialPlugin.lib.model
     16 * @author  Shogo Kawahara <kawahara@tejimaya.net>
    1717 */
    1818class ApplicationSettingPeer extends BaseApplicationSettingPeer
    1919{
    20   public static function retrieveByMemberApplicationIdAndName($memberApplicationId, $name)
     20  public static function getSettingsByApplicationId($applicationId)
    2121  {
    2222    $criteria = new Criteria();
    23     $criteria->add(self::MEMBER_APPLICATION_ID, $memberApplicationId);
    24     $criteria->add(self::NAME, $name);
    25     return self::doSelectOne($criteria);
     23    $criteria->add(self::APPLICATION_ID, $memberApplicationId);
     24    return self::doSelect($criteria);
    2625  }
    2726}
Note: See TracChangeset for help on using the changeset viewer.