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

Changeset 11535


Ignore:
Timestamp:
Apr 30, 2009, 8:14:50 AM (11 years ago)
Author:
ebihara
Message:

added some models for Doctrine

Location:
OpenPNE3/plugins/opCommunityTopicPlugin/branches/goto_doctrine/lib
Files:
12 added
9 edited

Legend:

Unmodified
Added
Removed
  • OpenPNE3/plugins/opCommunityTopicPlugin/branches/goto_doctrine/lib/model/doctrine/PluginCommunityEvent.class.php

    r11533 r11535  
    11<?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 */
    210
    311/**
    412 * PluginCommunityEvent
    513 *
    6  * This class has been auto-generated by the Doctrine ORM Framework
    7  *
    8  * @package    ##PACKAGE##
    9  * @subpackage ##SUBPACKAGE##
    10  * @author     ##NAME## <##EMAIL##>
    11  * @version    SVN: $Id: Builder.php 5441 2009-01-30 22:58:43Z jwage $
     14 * @package    opCommunityTopicPlugin
     15 * @subpackage CommunityEvent
     16 * @author     Kousuke Ebihara <ebihara@tejimaya.com>
    1217 */
    1318abstract class PluginCommunityEvent extends BaseCommunityEvent
    1419{
     20  public function isEditable($memberId)
     21  {
     22    if (!$this->getCommunity()->isPrivilegeBelong($memberId))
     23    {
     24      return false;
     25    }
    1526
     27    return ($this->getMemberId() === $memberId || $this->getCommunity()->isAdmin($memberId));
     28  }
     29
     30  public function isCreatableCommunityEventComment($memberId)
     31  {
     32    return $this->getCommunity()->isPrivilegeBelong($memberId);
     33  }
     34
     35  public function isEventMember($memberId)
     36  {
     37    return (bool)Doctrine::getTable('CommunityEventMember')->retrieveByEventIdAndMemberId($this->getId(), $memberId);
     38  }
     39
     40  public function isEventModified()
     41  {
     42    return (
     43      $this->isColumnModified(CommunityEventPeer::NAME) ||
     44      $this->isColumnModified(CommunityEventPeer::BODY)
     45    );
     46  }
     47
     48  public function preSave()
     49  {
     50    if ($this->isEventModified() && !$this->isColumnModified(CommunityEventPeer::EVENT_UPDATED_AT))
     51    {
     52      $this->setEventUpdatedAt(time());
     53    }
     54  }
     55
     56  public function toggleEventMember($memberId)
     57  {
     58    if ($this->isClosed())
     59    {
     60      throw new opCommunityEventMemberAppendableException('This event has already been finished.');
     61    }
     62
     63    if ($this->isExpired())
     64    {
     65      throw new opCommunityEventMemberAppendableException('This event has already been expired.');
     66    }
     67
     68    if ($this->isEventMember($memberId))
     69    {
     70      $eventMember = Doctrine::getTable('CommunityEventMember')->retrieveByEventIdAndMemberId($this->getId(), $memberId);
     71      $eventMember->delete();
     72    }
     73    else
     74    {
     75      if ($this->isAtCapacity())
     76      {
     77        throw new opCommunityEventMemberAppendableException('This event has already been at capacity.');
     78      }
     79
     80      $eventMember = new CommunityEventMember();
     81      $eventMember->setCommunityEventId($this->getId());
     82      $eventMember->setMemberId($memberId);
     83
     84      $this->addCommunityEventMember($eventMember);
     85    }
     86  }
     87
     88  public function isClosed()
     89  {
     90    return (time() > $this->getOpenDate('U'));
     91  }
     92
     93  public function isExpired()
     94  {
     95    return (!is_null($this->getApplicationDeadline()) && time() > $this->getApplicationDeadline('U'));
     96  }
     97
     98  public function isAtCapacity()
     99  {
     100    return (!is_null($this->getCapacity()) && $this->countCommunityEventMembers() >= $this->getCapacity());
     101  }
    16102}
  • OpenPNE3/plugins/opCommunityTopicPlugin/branches/goto_doctrine/lib/model/doctrine/PluginCommunityEventComment.class.php

    r11533 r11535  
    22
    33/**
    4  * PluginCommunityEventComment
     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
     11/**
     12 * PluginCommunityEvent
    513 *
    6  * This class has been auto-generated by the Doctrine ORM Framework
    7  *
    8  * @package    ##PACKAGE##
    9  * @subpackage ##SUBPACKAGE##
    10  * @author     ##NAME## <##EMAIL##>
    11  * @version    SVN: $Id: Builder.php 5441 2009-01-30 22:58:43Z jwage $
     14 * @package    opCommunityTopicPlugin
     15 * @subpackage CommunityEventComment
     16 * @author     Kousuke Ebihara <ebihara@tejimaya.com>
    1217 */
    1318abstract class PluginCommunityEventComment extends BaseCommunityEventComment
    1419{
     20  public function isDeletable($memberId)
     21  {
     22    return ($this->getMemberId() === $memberId || $this->getCommunityEvent()->isEditable($memberId));
     23  }
    1524
     25  public function save($event)
     26  {
     27    if ($this->isNew() && !$this->isColumnModified(CommunityEventCommentPeer::NUMBER))
     28    {
     29      $this->setNumber(Doctrine::getTable('CommunityEventComment')->getMaxNumber($this->getCommunityEventId()) + 1);
     30    }
     31  }
     32
     33  public function toggleEventMember($memberId)
     34  {
     35    $this->getCommunityEvent()->toggleEventMember($memberId);
     36  }
    1637}
  • OpenPNE3/plugins/opCommunityTopicPlugin/branches/goto_doctrine/lib/model/doctrine/PluginCommunityEventCommentTable.class.php

    r11533 r11535  
    11<?php
     2
    23/**
     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
     11/**
     12 * PluginCommunityEventCommentTable
     13 *
     14 * @package    opCommunityTopicPlugin
     15 * @subpackage CommunityEventComment
     16 * @author     Kousuke Ebihara <ebihara@tejimaya.com>
    317 */
    418class PluginCommunityEventCommentTable extends Doctrine_Table
    519{
     20  public function retrieveByCommunityEventId($communityEventId)
     21  {
     22    return $this->createQuery()
     23      ->where('community_event_id = ?', $communityEventId)
     24      ->execute();
     25  }
    626
     27  public function getCommunityEventCommentListPager($communityEventId, $page = 1, $size = 20, $order = 'DESC')
     28  {
     29    $q = $this->createQuery()
     30      ->where('community_event_id = ?', $communityEventId);
     31
     32    $pager = new sfReversibleDoctrinePager('CommunityEventComment', $size);
     33    $pager->setCriteria($q);
     34    $pager->setPage($page);
     35    $pager->setSqlOrderColumn('id');
     36    $pager->setSqlOrder($order);
     37    $pager->setListOrder(sfReversibleDoctrinePager::ASC);
     38    $pager->setMaxPerPage($size);
     39    $pager->init();
     40
     41    return $pager;
     42  }
     43
     44  public function getMaxNumber($communityEventId)
     45  {
     46    $result = $this->createQuery()
     47      ->select('number')
     48      ->where('community_event_id = ?', $communityEventId)
     49      ->orderBy('number DESC')
     50      ->fetchOne();
     51
     52    if ($result)
     53    {
     54      return (int)$result->getNumber();
     55    }
     56
     57    return 0;
     58  }
    759}
  • OpenPNE3/plugins/opCommunityTopicPlugin/branches/goto_doctrine/lib/model/doctrine/PluginCommunityEventMemberTable.class.php

    r11533 r11535  
    11<?php
     2
    23/**
     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
     11/**
     12 * PluginCommunityEventMemberTable
     13 *
     14 * @package    opCommunityTopicPlugin
     15 * @subpackage CommunityEventMember
     16 * @author     Kousuke Ebihara <ebihara@tejimaya.com>
    317 */
    418class PluginCommunityEventMemberTable extends Doctrine_Table
    519{
    6 
     20  public function retrieveByEventIdAndMemberId($eventId, $memberId)
     21  {
     22    return $this->createQuery()
     23      ->where('community_event_id = ?', $eventId)
     24      ->andWhere('member_id = ?', $memberId)
     25      ->fetchOne();
     26  }
    727}
  • OpenPNE3/plugins/opCommunityTopicPlugin/branches/goto_doctrine/lib/model/doctrine/PluginCommunityEventTable.class.php

    r11533 r11535  
    11<?php
     2
    23/**
     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
     11/**
     12 * PluginCommunityEventTable
     13 *
     14 * @package    opCommunityTopicPlugin
     15 * @subpackage CommunityEvent
     16 * @author     Kousuke Ebihara <ebihara@tejimaya.com>
    317 */
    418class PluginCommunityEventTable extends Doctrine_Table
    519{
     20  public function retrieveByCommunityId($communityId)
     21  {
     22    return $this->createQuery()
     23      ->where('community_id = ?', $communityId)
     24      ->execute();
     25  }
    626
     27  public function getEvents($communityId, $limit = 5)
     28  {
     29    return $this->createQuery()
     30      ->where('community_id = ?', $communityId)
     31      ->limit($limit)
     32      ->orderBy('updated_at')
     33      ->execute();
     34  }
     35
     36  public function getCommunityEventListPager($communityId, $page = 1, $size = 20)
     37  {
     38    $q = $this->createQuery()
     39      ->where('community_id = ?', $communityId)
     40      ->orderBy('updated_at');
     41
     42    $pager = new sfDoctrinePager('CommunityEvent', $size);
     43    $pager->setQuery($q);
     44    $pager->setPage($page);
     45    $pager->init();
     46
     47    return $pager;
     48  }
     49
     50  public function retrivesByMemberId($memberId, $limit = 5)
     51  {
     52    $communityIds = CommunityPeer::getIdsByMemberId($memberId);
     53    return $this->createQuery()
     54      ->whereIn('community_id IN (?)', $communityIds)
     55      ->limit($limit)
     56      ->orderBy('updated_at')
     57      ->execute();
     58  }
     59
     60  public function getRecentlyEventListPager($memberId, $page = 1, $size = 50)
     61  {
     62    $communityIds = CommunityPeer::getIdsByMemberId($memberId);
     63    $q = $this->createQuery()
     64      ->where('community_id IN (?)', $communityIds)
     65      ->orderBy('updated_at');
     66
     67    $pager = new sfDoctrinePager('CommunityEvent', $size);
     68    $pager->setQuery($q);
     69    $pager->setPage($page);
     70    $pager->init();
     71
     72    return $pager;
     73  }
    774}
  • OpenPNE3/plugins/opCommunityTopicPlugin/branches/goto_doctrine/lib/model/doctrine/PluginCommunityTopic.class.php

    r11533 r11535  
    11<?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 */
    210
    311/**
    412 * PluginCommunityTopic
    513 *
    6  * This class has been auto-generated by the Doctrine ORM Framework
    7  *
    8  * @package    ##PACKAGE##
    9  * @subpackage ##SUBPACKAGE##
    10  * @author     ##NAME## <##EMAIL##>
    11  * @version    SVN: $Id: Builder.php 5441 2009-01-30 22:58:43Z jwage $
     14 * @package    opCommunityTopicPlugin
     15 * @subpackage CommunityTopic
     16 * @author     Kousuke Ebihara <ebihara@tejimaya.com>
    1217 */
    1318abstract class PluginCommunityTopic extends BaseCommunityTopic
    1419{
     20  public function isEditable($memberId)
     21  {
     22    if (!$this->getCommunity()->isPrivilegeBelong($memberId))
     23    {
     24      return false;
     25    }
    1526
     27    return ($this->getMemberId() === $memberId || $this->getCommunity()->isAdmin($memberId));
     28  }
     29
     30  public function isCreatableCommunityTopicComment($memberId)
     31  {
     32    return $this->getCommunity()->isPrivilegeBelong($memberId);
     33  }
     34
     35  public function isTopicModified()
     36  {
     37    return (
     38      $this->isColumnModified(CommunityTopicPeer::NAME) ||
     39      $this->isColumnModified(CommunityTopicPeer::BODY)
     40    );
     41  }
     42
     43  public function preSave()
     44  {
     45    if ($this->isTopicModified() && !$this->isColumnModified(CommunityTopicPeer::TOPIC_UPDATED_AT))
     46    {
     47      $this->setTopicUpdatedAt(time());
     48    }
     49  }
    1650}
  • OpenPNE3/plugins/opCommunityTopicPlugin/branches/goto_doctrine/lib/model/doctrine/PluginCommunityTopicComment.class.php

    r11533 r11535  
    11<?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 */
    210
    311/**
    412 * PluginCommunityTopicComment
    513 *
    6  * This class has been auto-generated by the Doctrine ORM Framework
    7  *
    8  * @package    ##PACKAGE##
    9  * @subpackage ##SUBPACKAGE##
    10  * @author     ##NAME## <##EMAIL##>
    11  * @version    SVN: $Id: Builder.php 5441 2009-01-30 22:58:43Z jwage $
     14 * @package    opCommunityTopicPlugin
     15 * @subpackage CommunityTopicCommnet
     16 * @author     Kousuke Ebihara <ebihara@tejimaya.com>
    1217 */
    1318abstract class PluginCommunityTopicComment extends BaseCommunityTopicComment
    1419{
     20  public function isDeletable($memberId)
     21  {
     22    return ($this->getMemberId() === $memberId || $this->getCommunityTopic()->isEditable($memberId));
     23  }
    1524
     25  public function preSave()
     26  {
     27    if ($this->isNew() && !$this->isColumnModified(CommunityTopicCommentPeer::NUMBER))
     28    {
     29      $this->setTopicUpdatedAt(time());
     30      $this->setNumber(Doctrine::getTable('CommunityTopicComment')->getMaxNumber($this->getCommunityTopicId()) + 1);
     31    }
     32  }
    1633}
  • OpenPNE3/plugins/opCommunityTopicPlugin/branches/goto_doctrine/lib/model/doctrine/PluginCommunityTopicCommentTable.class.php

    r11533 r11535  
    11<?php
     2
    23/**
     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
     11/**
     12 * PluginCommunityTopicCommentTable
     13 *
     14 * @package    opCommunityTopicPlugin
     15 * @subpackage CommunityEventComment
     16 * @author     Kousuke Ebihara <ebihara@tejimaya.com>
    317 */
    418class PluginCommunityTopicCommentTable extends Doctrine_Table
    519{
     20  public function retrieveByCommunityTopicId($communityTopicId)
     21  {
     22    return $this->createQuery()
     23      ->where('community_topic_id = ?', $communityTopicId)
     24      ->execute();
     25  }
    626
     27  public function getCommunityTopicCommentListPager($communityTopicId, $page = 1, $size = 20, $order = 'DESC')
     28  {
     29    $q = $this->createQuery()
     30      ->where('community_topic_id', $communityTopicId);
     31   
     32    $pager = new sfReversibleDoctrinePager('CommunityTopicComment', $size);
     33    $pager->setQuery($q);
     34    $pager->setPage($page);
     35    $pager->setSqlOrderColumn('id');
     36    $pager->setSqlOrder($order);
     37    $pager->setListOrder(sfReversibleDoctrinePager::ASC);
     38    $pager->setMaxPerPage($size);
     39    $pager->init();
     40
     41    return $pager;
     42  }
     43
     44  public function getMaxNumber($communityTopicId)
     45  {
     46    $result = $this->createQuery()
     47      ->select('number')
     48      ->where('community_topic_id = ?', $communityTopicId)
     49      ->orderBy('number DESC')
     50      ->fetchOne();
     51
     52    if ($result)
     53    {
     54      return (int)$result->getNumber();
     55    }
     56
     57    return 0;
     58  }
    759}
  • OpenPNE3/plugins/opCommunityTopicPlugin/branches/goto_doctrine/lib/model/doctrine/PluginCommunityTopicTable.class.php

    r11533 r11535  
    11<?php
     2
    23/**
     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
     11/**
     12 * PluginCommunityTopicTable
     13 *
     14 * @package    opCommunityTopicPlugin
     15 * @subpackage CommunityTopicComment
     16 * @author     Kousuke Ebihara <ebihara@tejimaya.com>
    317 */
    418class PluginCommunityTopicTable extends Doctrine_Table
    519{
     20  public function retrieveByCommunityId($communityId)
     21  {
     22    return $this->createQuery()
     23      ->where('community_id = ?', $communityId)
     24      ->execute();
     25  }
    626
     27  public function getTopics($communityId, $limit = 5)
     28  {
     29    return $this->createQuery()
     30      ->where('community_id = ?', $communityId)
     31      ->limit($limit)
     32      ->orderBy('updated_at')
     33      ->execute();
     34  }
     35
     36  public function getCommunityTopicListPager($communityId, $page = 1, $size = 20)
     37  {
     38    $pager = new sfDoctrinePager('CommunityTopic', $size);
     39    $pager->setQuery($q);
     40    $pager->setPage($page);
     41    $pager->init();
     42
     43    return $pager;
     44  }
     45
     46  public function retrivesByMemberId($memberId, $limit = 5)
     47  {
     48    $communityIds = CommunityPeer::getIdsByMemberId($memberId);
     49    return $this->createQuery()
     50      ->whereIn('community_id IN (?)', $communityIds)
     51      ->limit($limit)
     52      ->orderBy('updated_at')
     53      ->execute();
     54  }
     55
     56  public function getRecentlyTopicListPager($memberId, $page = 1, $size = 50)
     57  {
     58    $communityIds = CommunityPeer::getIdsByMemberId($memberId);
     59    $q = $this->createQuery()
     60      ->where('community_id IN (?)', $communityIds)
     61      ->orderBy('updated_at');
     62
     63    $pager = new sfDoctrinePager('CommunityTopic', $size);
     64    $pager->setQuery($q);
     65    $pager->setPage($page);
     66    $pager->init();
     67
     68    return $pager;
     69  }
    770}
Note: See TracChangeset for help on using the changeset viewer.