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

Changeset 9394


Ignore:
Timestamp:
Nov 27, 2008, 12:40:41 PM (11 years ago)
Author:
ShogoKawahara
Message:

#2906:changed MemberProfile? model

Location:
OpenPNE3/trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • OpenPNE3/trunk/config/schema.yml

    r9275 r9394  
    5454
    5555  member_profile:
     56    _attributes: { treeMode: NestedSet }
    5657    id: ~
     58    lft_key: { type: integer, nestedSetLeftKey: true ,index: true }
     59    rht_key: { type: integer, nestedSetRightKey: true ,index: true }
     60    tree_key : { type: integer, treeScopeKey: true ,index: true }
    5761    member_id: ~
    5862    profile_id: ~
  • OpenPNE3/trunk/data/fixtures/002_import_first_member.yml

    r9199 r9394  
    77MemberProfile:
    88  first_member_profile_sex:
     9    lft_key: 1
     10    rht_key: 2
    911    member_id: first_member
    1012    profile_id: profile_sex
     
    1214
    1315  first_member_profile_self_intro:
     16    lft_key: 1
     17    rht_key: 2
    1418    member_id: first_member
    1519    profile_id: profile_self_intro
  • OpenPNE3/trunk/lib/form/MemberProfileForm.class.php

    r9060 r9394  
    3838
    3939      $memberProfile = MemberProfilePeer::retrieveByMemberIdAndProfileId($memberId, $profile->getId());
    40       if (!$memberProfile) {
     40
     41      if ($formType == 'checkbox')
     42      {
     43        if (!is_array($value))
     44        {
     45          continue;
     46        }
     47        if ($memberProfile)
     48        {
     49          $c = new Criteria();
     50          $c->add(MemberProfilePeer::TREE_KEY, $memberProfile->getTreeKey());
     51          MemberProfilePeer::doDelete($c);
     52        }
     53
    4154        $memberProfile = new MemberProfile();
     55        $memberProfile->makeRoot();
     56        $memberProfile->setMemberId($memberId);
     57        $memberProfile->setProfileId($profile->getId());
     58        $memberProfile->save();
     59        $memberProfile->setScopeIdValue($memberProfile->getId());
     60        $memberProfile->save();
     61
     62        foreach ($value as $v)
     63        {
     64          $mp = new MemberProfile();
     65          $mp->setMemberId($memberId);
     66          $mp->setProfileId($profile->getId());
     67          $mp->setProfileOptionId($v);
     68          $mp->insertAsLastChildOf($memberProfile);
     69          $mp->save();
     70        }
    4271      }
     72      else{
     73        if (!$memberProfile)
     74        {
     75          $memberProfile = new MemberProfile();
     76          $memberProfile->makeRoot();
     77        }
    4378
    44       $memberProfile->setMemberId($memberId);
    45       $memberProfile->setProfileId($profile->getId());
    46       if ($formType == 'checkbox' || $formType == 'select' || $formType == 'radio') {
    47         $memberProfile->setProfileOptionId($value);
    48       } else {
    49         $memberProfile->setValue($value);
     79        $memberProfile->setMemberId($memberId);
     80        $memberProfile->setProfileId($profile->getId());
     81        if ($formType == 'select' || $formType == 'radio') {
     82          $memberProfile->setProfileOptionId($value);
     83        } else {
     84          $memberProfile->setValue($value);
     85        }
     86        $memberProfile->save();
    5087      }
    51 
    52       $memberProfile->save();
    5388    }
    5489
  • OpenPNE3/trunk/lib/model/MemberProfile.php

    r9199 r9394  
    88 * @package lib.model
    99 */
    10 class MemberProfile extends BaseMemberProfile
     10class MemberProfile extends BaseMemberProfileNestedSet
    1111{
    1212  private $name;
     
    1515  public function __toString()
    1616  {
     17
     18    if ($this->getRhtKey() != 2) {
     19      $string = "";
     20      $children = $this->getChildren();
     21
     22      foreach ($children as $child) {
     23        if ($child->getProfileOptionId()) {
     24          $option = ProfileOptionPeer::retrieveByPk($child->getProfileOptionId());
     25          if (!empty($string)) {
     26            $string .= ", ";
     27          }
     28          $string .= $option->getValue();
     29        }
     30      }
     31
     32      return $string;
     33    }
     34
    1735    if ($this->getProfileOptionId()) {
    1836      $option = ProfileOptionPeer::retrieveByPk($this->getProfileOptionId());
     
    2543  public function getValue()
    2644  {
     45    if ($this->getRhtKey() != 2) {
     46      $children = $this->getChildren();
     47      $value = array();
     48      foreach ($children as $child) {
     49        $value[] = $child->getProfileOptionId();
     50      }
     51      return $value;
     52    }
    2753    if ($this->getProfileOptionId()) {
    2854      return $this->getProfileOptionId();
  • OpenPNE3/trunk/lib/model/MemberProfilePeer.php

    r9199 r9394  
    88 * @package lib.model
    99 */
    10 class MemberProfilePeer extends BaseMemberProfilePeer
     10class MemberProfilePeer extends BaseMemberProfileNestedSetPeer
    1111{
    1212  public static function getProfileListByMemberId($memberId)
     
    2222
    2323    $c->add(self::MEMBER_ID, $memberId);
     24    $c->add(self::LFT_KEY, 1);
    2425    $c->addJoin(ProfilePeer::ID, ProfileI18nPeer::ID);
    2526    $c->addJoin(ProfilePeer::ID, MemberProfilePeer::PROFILE_ID);
Note: See TracChangeset for help on using the changeset viewer.