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

Changeset 10089


Ignore:
Timestamp:
Jan 11, 2009, 6:03:15 PM (14 years ago)
Author:
ebihara
Message:

#3432:changed the MemberProfileForm::save() method for it has three saving patterns: "for multiple select", "for singleselect" and "for other"

Location:
OpenPNE3/trunk/lib
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • OpenPNE3/trunk/lib/form/MemberProfileForm.class.php

    r10087 r10089  
    5454      $memberProfile = MemberProfilePeer::makeRoot($memberId, $profile->getId());
    5555
    56       if ($formType === 'checkbox')
     56      if ($profile->isMultipleSelect())
    5757      {
    58         if (!is_array($value))
     58        $ids = array();
     59        $_values = array();
     60        if ('date' === $formType)
    5961        {
    60           continue;
     62          $_values = explode('-', $value);
     63          $c = new Criteria();
     64          $c->addAscendingOrderByColumn(ProfileOptionPeer::SORT_ORDER);
     65          $options = $profile->getProfileOptions($c);
     66          foreach ($options as $option)
     67          {
     68            $ids[] = $option->getId();
     69          }
    6170        }
    62 
    63         foreach ($value as $v)
     71        else
    6472        {
    65           MemberProfilePeer::createChild($memberProfile, $memberId, $profile->getId(), $v);
     73          $ids = $value;
    6674        }
    67       }
    68       elseif ($formType === 'date')
    69       {
    70         $pieces = explode('-', $value);
    71 
    72         $c = new Criteria();
    73         $c->addAscendingOrderByColumn(ProfileOptionPeer::SORT_ORDER);
    74         $options = $profile->getProfileOptions($c);
    75         foreach ($options as $i => $option)
    76         {
    77           $_value = null;
    78           if (isset($pieces[$i]))
    79           {
    80             $_value = (int)$pieces[$i];
    81           }
    82           MemberProfilePeer::createChild($memberProfile, $memberId, $profile->getId(), $option->getId(), $_value);
    83         }
     75        MemberProfilePeer::createChild($memberProfile, $memberId, $profile->getId(), $ids, $_values);
    8476      }
    8577      else
    8678      {
    87         if ($formType === 'select' || $formType === 'radio')
     79        if ($profile->isSingleSelect())
    8880        {
    8981          $memberProfile->setProfileOptionId($value);
  • OpenPNE3/trunk/lib/model/MemberProfilePeer.php

    r10087 r10089  
    162162  }
    163163
    164   public static function createChild(MemberProfile $parent, $memberId, $profileId, $optionId, $value = null)
     164  public static function createChild(MemberProfile $parent, $memberId, $profileId, $optionIds, $values = array())
    165165  {
    166     $childProfile = new MemberProfile();
    167     $childProfile->setMemberId($memberId);
    168     $childProfile->setProfileId($profileId);
    169     $childProfile->setProfileOptionId($optionId);
    170     $childProfile->insertAsLastChildOf($parent);
    171     if ($value)
     166    foreach ($optionIds as $i => $optionId)
    172167    {
    173       $childProfile->setValue($value);
     168      $childProfile = new MemberProfile();
     169      $childProfile->setMemberId($memberId);
     170      $childProfile->setProfileId($profileId);
     171      $childProfile->setProfileOptionId($optionId);
     172      $childProfile->insertAsLastChildOf($parent);
     173      if (isset($values[$i]))
     174      {
     175        $childProfile->setValue($values[$i]);
     176      }
     177      $childProfile->save();
    174178    }
    175 
    176     $childProfile->save();
    177     return $childProfile;
    178179  }
    179180}
  • OpenPNE3/trunk/lib/model/Profile.php

    r10078 r10089  
    4444    return parent::hydrate($row, $startcol, $rehydrate);
    4545  }
     46
     47  public function isMultipleSelect()
     48  {
     49    return (bool)('date' === $this->getFormType() || 'checkbox' === $this->getFormType());
     50  }
     51
     52  public function isSingleSelect()
     53  {
     54    return (bool)('radio' === $this->getFormType() || 'select' === $this->getFormType());
     55  }
    4656}
Note: See TracChangeset for help on using the changeset viewer.