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

Changeset 9852


Ignore:
Timestamp:
Jan 2, 2009, 5:49:33 PM (11 years ago)
Author:
ogawa
Message:

#3344:added public_flag to the Diary

Location:
OpenPNE3/plugins/opDiaryPlugin/trunk
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • OpenPNE3/plugins/opDiaryPlugin/trunk/apps/mobile_frontend/i18n/messages.ja.xml

    r9811 r9852  
    3535        <target>コメントを書く</target>
    3636      </trans-unit>
     37      <trans-unit id="28">
     38        <source>My Friends</source>
     39        <target>マイフレンドまで公開</target>
     40      </trans-unit>
    3741    </body>
    3842  </file>
  • OpenPNE3/plugins/opDiaryPlugin/trunk/apps/mobile_frontend/modules/diary/templates/showSuccess.php

    r9810 r9852  
    1313<?php endforeach; ?>
    1414
    15 (<?php echo __('Public') ?>)<br>
     15(<?php echo $diary->getPublicFlagLabel() ?>)<br>
    1616
    1717<?php $comments = $diary->getDiaryComments() ?>
  • OpenPNE3/plugins/opDiaryPlugin/trunk/apps/pc_frontend/modules/diary/templates/showSuccess.php

    r9810 r9852  
    33<div class="dparts diaryDetailBox"><div class="parts">
    44<div class="partsHeading"><h3><?php echo __('Diary of %1%', array('%1%' => $diary->getMember()->getName())) ?></h3>
    5 <p class="public">(<?php echo __('Public') ?>)</p></div>
     5<p class="public">(<?php echo $diary->getPublicFlagLabel() ?>)</p></div>
    66<dl>
    77<dt><?php echo format_datetime($diary->getCreatedAt(), 'f') ?></dt>
  • OpenPNE3/plugins/opDiaryPlugin/trunk/config/schema.yml

    r9731 r9852  
    66    title: { type: longvarchar, required: true }
    77    body: { type: longvarchar, required: true }
     8    public_flag: { type: tinyint, required: true, default: 1 }
    89    created_at: ~
    910    updated_at: ~
  • OpenPNE3/plugins/opDiaryPlugin/trunk/i18n/messages.ja.xml

    r9811 r9852  
    9999        <target>コメントを書く</target>
    100100      </trans-unit>
     101      <trans-unit id="25">
     102        <source>Public flag</source>
     103        <target>公開範囲</target>
     104      </trans-unit>
     105      <trans-unit id="26">
     106        <source>All Users on the Web</source>
     107        <target>Web全体に公開</target>
     108      </trans-unit>
     109      <trans-unit id="27">
     110        <source>All Members</source>
     111        <target>全員に公開</target>
     112      </trans-unit>
     113      <trans-unit id="28">
     114        <source>My Friends</source>
     115        <target>マイフレンドまで公開</target>
     116      </trans-unit>
     117      <trans-unit id="29">
     118        <source>Private</source>
     119        <target>公開しない</target>
     120      </trans-unit>
    101121    </body>
    102122  </file>
  • OpenPNE3/plugins/opDiaryPlugin/trunk/lib/action/opDiaryPluginDiaryActions.class.php

    r9847 r9852  
    6161    $this->member = MemberPeer::retrieveByPk($memberId);
    6262    $this->forward404unless($this->member);
    63     $this->pager = DiaryPeer::getMemberDiaryPager($memberId, $request->getParameter('page'), 20);
     63    $this->pager = DiaryPeer::getMemberDiaryPager($memberId, $request->getParameter('page'), 20, $this->getUser()->getMemberId());
    6464  }
    6565
  • OpenPNE3/plugins/opDiaryPlugin/trunk/lib/action/opDiaryPluginDiaryComponents.class.php

    r9645 r9852  
    1212  public function executeMyDiaryList()
    1313  {
    14     $this->diaryList = DiaryPeer::getMemberDiaryList($this->getUser()->getMemberId(), 5);
     14    $this->diaryList = DiaryPeer::getMemberDiaryList($this->getUser()->getMemberId(), 5, $this->getUser()->getMemberId());
    1515  }
    1616
     
    2323  {
    2424    $this->memberId = $request->getParameter('id', $this->getUser()->getMemberId());
    25     $this->diaryList = DiaryPeer::getMemberDiaryList($this->memberId, 5);
     25    $this->diaryList = DiaryPeer::getMemberDiaryList($this->memberId, 5, $this->getUser()->getMemberId());
    2626  }
    2727}
  • OpenPNE3/plugins/opDiaryPlugin/trunk/lib/form/DiaryForm.class.php

    r9612 r9852  
    1717    unset($this['created_at']);
    1818    unset($this['updated_at']);
     19
     20    $this->widgetSchema['public_flag'] = new sfWidgetFormChoice(array(
     21      'choices'  => DiaryPeer::getPublicFlags(),
     22      'expanded' => true,
     23    ));
     24    $this->validatorSchema['public_flag'] = new sfValidatorChoice(array(
     25      'choices' => array_keys(DiaryPeer::getPublicFlags()),
     26    ));
    1927
    2028    $this->mergeForm(new DiaryImageForm());
  • OpenPNE3/plugins/opDiaryPlugin/trunk/lib/model/Diary.php

    r9522 r9852  
    33class Diary extends BaseDiary
    44{
     5  public function getPublicFlagLabel()
     6  {
     7    $publicFlags = DiaryPeer::getPublicFlags();
     8    return $publicFlags[$this->getPublicFlag()];
     9  }
    510}
  • OpenPNE3/plugins/opDiaryPlugin/trunk/lib/model/DiaryPeer.php

    r9551 r9852  
    33class DiaryPeer extends BaseDiaryPeer
    44{
    5   public static function getDiaryPager($page = 1, $size = 20)
     5  const PUBLIC_FLAG_OPEN    = 4;
     6  const PUBLIC_FLAG_SNS     = 1;
     7  const PUBLIC_FLAG_FRIEND  = 2;
     8  const PUBLIC_FLAG_PRIVATE = 3;
     9
     10  protected static $publicFlags = array(
     11    self::PUBLIC_FLAG_OPEN    => 'All Users on the Web',
     12    self::PUBLIC_FLAG_SNS     => 'All Members',
     13    self::PUBLIC_FLAG_FRIEND  => 'My Friends',
     14    self::PUBLIC_FLAG_PRIVATE => 'Private',
     15  );
     16
     17  public static function getPublicFlags()
    618  {
    7     $c = new Criteria();
    8     $c->addDescendingOrderByColumn(self::CREATED_AT);
     19    if (!sfConfig::get('app_op_diary_plugin_is_open', false))
     20    {
     21      unset(self::$publicFlags[self::PUBLIC_FLAG_OPEN]);
     22    }
    923
     24    return array_map(array(sfContext::getInstance()->getI18N(), '__'), self::$publicFlags);
     25  }
     26
     27  public static function getDiaryPager($page = 1, $size = 20, $publicFlag = self::PUBLIC_FLAG_SNS)
     28  {
     29    $c = self::getOrderdCriteria();
     30    self::addPublicFlagCriteria($c, $publicFlag);
     31
     32    return self::getPager($c, $page, $size);
     33  }
     34
     35  public static function getMemberDiaryList($memberId, $limit = 5, $myMemberId = null, $publicFlag = null)
     36  {
     37    $c = self::getOrderdCriteria();
     38    $c->add(self::MEMBER_ID, $memberId);
     39    self::addPublicFlagCriteria($c, self::getPublicFlagByMemberId($memberId, $myMemberId, $publicFlag));
     40    $c->setLimit($limit);
     41
     42    return self::doSelect($c);
     43  }
     44
     45  public static function getMemberDiaryPager($memberId, $page = 1, $size = 20, $myMemberId = null, $publicFlag = null)
     46  {
     47    $c = self::getOrderdCriteria();
     48    $c->add(self::MEMBER_ID, $memberId);
     49    self::addPublicFlagCriteria($c, self::getPublicFlagByMemberId($memberId, $myMemberId, $publicFlag));
     50
     51    return self::getPager($c, $page, $size);
     52  }
     53
     54  public static function getFriendDiaryList($memberId, $limit = 5)
     55  {
     56    $c = self::getOrderdCriteria();
     57    self::addFriendCriteria($c, $memberId);
     58    $c->setLimit($limit);
     59
     60    return self::doSelect($c);
     61  }
     62
     63  public static function getFriendDiaryPager($memberId, $page = 1, $size = 20)
     64  {
     65    $c = self::getOrderdCriteria();
     66    self::addFriendCriteria($c, $memberId);
     67
     68    return self::getPager($c, $page, $size);
     69  }
     70
     71  protected static function getPager(Criteria $c, $page, $size)
     72  {
    1073    $pager = new sfPropelPager('Diary', $size);
    1174    $pager->setCriteria($c);
     
    1679  }
    1780
    18   public static function getMemberDiaryList($memberId, $limit = 5)
     81  protected static function getOrderdCriteria()
    1982  {
    2083    $c = new Criteria();
    21     $c->add(self::MEMBER_ID, $memberId);
    2284    $c->addDescendingOrderByColumn(self::CREATED_AT);
    23     $c->setLimit($limit);
    24     return self::doSelect($c);
     85   
     86    return $c;
    2587  }
    2688
    27   public static function getMemberDiaryPager($memberId, $page = 1, $size = 20)
    28   {
    29     $c = new Criteria();
    30     $c->add(self::MEMBER_ID, $memberId);
    31     $c->addDescendingOrderByColumn(self::CREATED_AT);
    32 
    33     $pager = new sfPropelPager('Diary', $size);
    34     $pager->setCriteria($c);
    35     $pager->setPage($page);
    36     $pager->init();
    37 
    38     return $pager;
    39   }
    40 
    41   public static function getFriendDiaryList($memberId, $limit = 5)
     89  protected static function addFriendCriteria(Criteria $c, $memberId)
    4290  {
    4391    $friendIds = MemberRelationshipPeer::getFriendMemberIds($memberId, 5);
    4492
    45     $c = new Criteria();
    4693    $c->add(self::MEMBER_ID, $friendIds, Criteria::IN);
    47     $c->addDescendingOrderByColumn(self::CREATED_AT);
    48     $c->setLimit($limit);
    49     return self::doSelect($c);
     94    self::addPublicFlagCriteria($c, self::PUBLIC_FLAG_FRIEND);
     95
     96    return $c;
    5097  }
    5198
    52   public static function getFriendDiaryPager($memberId, $page = 1, $size = 20)
     99  protected static function addPublicFlagCriteria(Criteria $c, $flag)
    53100  {
    54     $friendIds = MemberRelationshipPeer::getFriendMemberIds($memberId, 5);
     101    $flags = array();
     102    switch ($flag)
     103    {
     104      case self::PUBLIC_FLAG_FRIEND:
     105        $flags[] = self::PUBLIC_FLAG_FRIEND;
     106      case self::PUBLIC_FLAG_SNS:
     107        $flags[] = self::PUBLIC_FLAG_SNS;
     108      case self::PUBLIC_FLAG_OPEN:
     109        $flags[] = self::PUBLIC_FLAG_OPEN;
     110        break;
    55111
    56     $c = new Criteria();
    57     $c->add(self::MEMBER_ID, $friendIds, Criteria::IN);
    58     $c->addDescendingOrderByColumn(self::CREATED_AT);
     112      case self::PUBLIC_FLAG_PRIVATE:
     113      default:
     114        return $c;
     115    }
    59116
    60     $pager = new sfPropelPager('Diary', $size);
    61     $pager->setCriteria($c);
    62     $pager->setPage($page);
    63     $pager->init();
     117    if (1 === count($flags))
     118    {
     119      $c->add(self::PUBLIC_FLAG, array_shift($flags));
     120    }
     121    else
     122    {
     123      $c->add(self::PUBLIC_FLAG, $flags, Criteria::IN);
     124    }
    64125
    65     return $pager;
     126    return $c;
     127  }
     128
     129  protected static function getPublicFlagByMemberId($memberId, $myMemberId, $forceFlag = null)
     130  {
     131    if ($forceFlag)
     132    {
     133      return $forceFlag;
     134    }
     135
     136    if ($memberId == $myMemberId)
     137    {
     138      return self::PUBLIC_FLAG_PRIVATE;
     139    }
     140
     141    $relation = MemberRelationshipPeer::retrieveByFromAndTo($myMemberId, $memberId);
     142    if ($relation && $relation->isFriend())
     143    {
     144      return self::PUBLIC_FLAG_FRIEND;
     145    }
     146    else
     147    {
     148      return self::PUBLIC_FLAG_SNS;
     149    }
    66150  }
    67151}
Note: See TracChangeset for help on using the changeset viewer.