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

Changeset 5083


Ignore:
Timestamp:
Jan 29, 2008, 2:41:38 AM (12 years ago)
Author:
ebihara
Message:

#1843:MemberモデルにFriendを関連づけ、アソシエーションをなるべく使う形に

Location:
OpenPNE/branches/prj/framework/cakephp/app
Files:
1 added
5 edited

Legend:

Unmodified
Added
Removed
  • OpenPNE/branches/prj/framework/cakephp/app/app_controller.php

    r5063 r5083  
    2929            $auth = $this->Auth->user();
    3030            if ($auth) {
    31                 $this->you = $this->Member->findById($auth['Secure']['member_id']);
     31                $this->you = $this->Member->findById($auth['Secure']['member_id'], null, null, 2);
    3232            }
    3333        }
  • OpenPNE/branches/prj/framework/cakephp/app/config/sql/convert_openpne2cakepne.sql

    r5066 r5083  
    4949) ENGINE=MyISAM DEFAULT CHARSET=utf8;
    5050
     51DROP TABLE IF EXISTS `friends`;
     52CREATE TABLE `friends` (
     53  `id` int(11) NOT NULL auto_increment,
     54  `member_id` int(11) NOT NULL,
     55  `friend_member_id` int(11) NOT NULL,
     56  `intro` text NOT NULL,
     57  `created` datetime NOT NULL,
     58  `modified` datetime NOT NULL,
     59  PRIMARY KEY (`id`)
     60) ENGINE=MyISAM DEFAULT CHARSET=utf8;
     61
    5162INSERT INTO `members` (`id`, `nickname`, `birth_year`, `birth_month`, `birth_day`,
    5263`image_filename`, `access_date`, `created`, `modified`)
     
    7283     FROM `c_diary_comment`
    7384     ORDER BY `c_diary_id`);
     85
     86INSERT INTO `friends` (`member_id`, `friend_member_id`, `intro`)
     87  (SELECT `c_member_id_from`, `c_member_id_to`, `intro`
     88     FROM `c_friend`);
  • OpenPNE/branches/prj/framework/cakephp/app/controllers/members_controller.php

    r5063 r5083  
    3333            $id = $target_member['Member']['id'];
    3434        } else {
    35             $target_member = $this->Member->findById($id);
     35            $target_member = $this->Member->findById($id, null, null, 2);
    3636            if (empty($target_member)) {
    3737                return false;
     
    4040
    4141        $this->pageTitle = $target_member['Member']['nickname'] . 'さんのホーム';
    42 
    43         // メンバーの最新日記5件
    44         $member_diary = $this->Diary->findAllByMemberId($id, array('id', 'subject', 'created'), 'Diary.created DESC', 5);
    45 
    4642        $this->set('target_member', $target_member);
    47         $this->set('member_diary', $member_diary);
    4843    }
    4944
  • OpenPNE/branches/prj/framework/cakephp/app/models/member.php

    r5042 r5083  
    1212        ),
    1313    );
     14    var $hasMany = array(
     15        'Friend' => array(
     16            'className' => 'Friend',
     17            'fields' => array('id', 'friend_member_id'),
     18            'order' => 'RAND()',
     19            'conditions' => true,
     20            'dependent' => false,
     21            'foreignKey' => 'member_id',
     22            'limit' => 9,
     23        ),
     24        'Diary' => array(
     25            'className' => 'Diary',
     26            'fields' => array('id', 'created', 'subject'),
     27            'order' => 'created DESC',
     28            'conditons' => true,
     29            'dependent' => true,
     30            'foreignKey' => 'member_id',
     31            'limit' => 5,
     32        ),
     33    );
    1434}
    1535?>
  • OpenPNE/branches/prj/framework/cakephp/app/views/members/home.tpl

    r5063 r5083  
    44
    55<h3>■フレンドリスト</h3>
    6 
     6<ul>
     7({foreach from=$target_member.Friend item=value})
     8    <li><a href="({$html->url('/members/home/')})({$value.Member.id})">({$value.Member.nickname})</a></li>
     9({/foreach})
     10</ul>
    711<hr>
    812
     
    1418<h4>最新日記</h4>
    1519<ul>
    16 ({foreach from=$member_diary item=value})
    17     <li>({$value.Diary.created|date_format:"%Y/%m/%d"})&nbsp;…&nbsp;<a href="({$html->url('/diaries/view/')})({$value.Diary.id})">({$value.Diary.subject})</a></li>
     20({foreach from=$target_member.Diary item=value})
     21    <li>({$value.created|date_format:"%Y/%m/%d"})&nbsp;…&nbsp;<a href="({$html->url('/diaries/view/')})({$value.id})">({$value.subject})</a></li>
    1822({/foreach})
    1923</ul>
Note: See TracChangeset for help on using the changeset viewer.