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

source: OpenPNE3/plugins/opDiaryPlugin/trunk/lib/model/Diary.php @ 10513

Last change on this file since 10513 was 10513, checked in by ebihara, 13 years ago

added support for truncate titles of the opDiaryPlugin

File size: 2.4 KB
Line 
1<?php
2
3/**
4 * This file is part of the OpenPNE package.
5 * (c) OpenPNE Project (http://www.openpne.jp/)
6 *
7 * For the full copyright and license information, please view the LICENSE
8 * file and the NOTICE file that were distributed with this source code.
9 */
10
11class Diary extends BaseDiary
12{
13  protected $previous, $next;
14
15  public function getPublicFlagLabel()
16  {
17    $publicFlags = DiaryPeer::getPublicFlags();
18    return $publicFlags[$this->getPublicFlag()];
19  }
20
21  public function getDiaryCommentsCriteria()
22  {
23    $criteria = new Criteria();
24    $criteria->add(DiaryCommentPeer::DIARY_ID, $this->getId());
25
26    return $criteria;
27  }
28
29  public function getPrevious()
30  {
31    if (is_null($this->previous))
32    {
33      $criteria = new Criteria();
34      $criteria->add(DiaryPeer::MEMBER_ID, $this->getMemberId());
35      $criteria->add(DiaryPeer::ID, $this->getId(), Criteria::LESS_THAN);
36      $criteria->addDescendingOrderByColumn(DiaryPeer::ID);
37
38      $this->previous = DiaryPeer::doSelectOne($criteria);
39    }
40
41    return $this->previous;
42  }
43
44  public function getNext()
45  {
46    if (is_null($this->next))
47    {
48      $criteria = new Criteria();
49      $criteria->add(DiaryPeer::MEMBER_ID, $this->getMemberId());
50      $criteria->add(DiaryPeer::ID, $this->getId(), Criteria::GREATER_THAN);
51      $criteria->addAscendingOrderByColumn(DiaryPeer::ID);
52
53      $this->next = DiaryPeer::doSelectOne($criteria);
54    }
55
56    return $this->next;
57  }
58
59  public function getDiaryImages($criteria = null, PropelPDO $con = null)
60  {
61    if (is_null($criteria))
62    {
63      $criteria = new Criteria();
64      $criteria->addAscendingOrderByColumn(DiaryImagePeer::NUMBER);
65    }
66
67    $images = parent::getDiaryImages($criteria, $con);
68
69    $result = array();
70    foreach ($images as $image)
71    {
72      $result[$image->getNumber()] = $image;
73    }
74
75    return $result;
76  }
77
78  public function hasImages()
79  {
80    return (bool)$this->getHasImages();
81  }
82
83  public function updateHasImages()
84  {
85    $this->clearDiaryImages();
86    $hasImages = (bool)$this->countDiaryImages();
87
88    if ($hasImages != $this->getHasImages())
89    {
90      $this->setHasImages($hasImages);
91      $this->save();
92    }
93  }
94
95  public function isAuthor($memberId)
96  {
97    return ($this->getMemberId() === $memberId);
98  }
99
100  public function isViewable($memberId)
101  {
102    $flags = DiaryPeer::getViewablePublicFlags(DiaryPeer::getPublicFlagByMemberId($this->getMemberId(), $memberId));
103
104    return in_array($this->getPublicFlag(), $flags);
105  }
106}
Note: See TracBrowser for help on using the repository browser.