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

Changeset 10377


Ignore:
Timestamp:
Jan 25, 2009, 3:59:03 PM (11 years ago)
Author:
ogawa
Message:

#3376:implemented edit/update action and modified schema file to add the required option

Location:
OpenPNE3/plugins/opCommunityTopicPlugin/branches/renewal
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • OpenPNE3/plugins/opCommunityTopicPlugin/branches/renewal/apps/pc_frontend/modules/communityTopic/actions/actions.class.php

    r10358 r10377  
    138138    $this->form->getObject()->setMemberId($this->getUser()->getMemberId());
    139139    $this->form->getObject()->setCommunity($this->community);
    140     $this->form->bind($request->getParameter('community_topic'));
    141     if ($this->form->isValid())
    142     {
    143       $communityTopic = $this->form->save();
     140    $this->processForm($request, $this->form);
     141
     142    $this->setTemplate('new');
     143  }
     144
     145 /**
     146  * Executes edit action
     147  *
     148  * @param sfRequest $request A request object
     149  */
     150  public function executeEdit($request)
     151  {
     152    $this->communityTopic = $this->getRoute()->getObject();
     153    $this->community = $this->communityTopic->getCommunity();
     154
     155    $this->forward404Unless(
     156         $this->community->isAdmin($this->getUser()->getMemberId())
     157      || $this->communityTopic->getMemberId() === $this->getUser()->getMemberId()
     158    );
     159
     160    $this->form = new CommunityTopicForm($this->communityTopic);
     161  }
     162
     163 /**
     164  * Executes update action
     165  *
     166  * @param sfRequest $request A request object
     167  */
     168  public function executeUpdate($request)
     169  {
     170    $this->communityTopic = $this->getRoute()->getObject();
     171    $this->community = $this->communityTopic->getCommunity();
     172
     173    $this->forward404Unless(
     174         $this->community->isAdmin($this->getUser()->getMemberId())
     175      || $this->communityTopic->getMemberId() === $this->getUser()->getMemberId()
     176    );
     177
     178    $this->form = new CommunityTopicForm($this->communityTopic);
     179    $this->processForm($request, $this->form);
     180
     181    $this->setTemplate('edit');
     182  }
     183
     184  protected function processForm(sfWebRequest $request, sfForm $form)
     185  {
     186    $form->bind(
     187      $request->getParameter($form->getName())
     188    );
     189
     190    if ($form->isValid())
     191    {
     192      $communityTopic = $form->save();
     193
    144194      $this->redirect($this->generateUrl('communityTopic_show', $communityTopic));
    145195    }
    146 
    147     $this->setTemplate('new');
    148   }
    149 
    150 
    151  /**
    152   * Executes edit action
    153   *
    154   * @param sfRequest $request A request object
    155   */
    156   public function executeEdit($request)
     196  }
     197
     198
     199 /**
     200  * Executes delete action
     201  *
     202  * @param sfRequest $request A request object
     203  */
     204  public function executeDelete($request)
    157205  {
    158206    $this->community->checkPrivilegeBelong($this->getUser()->getMemberId());
     
    162210    }
    163211
    164     $this->form = new CommunityTopicForm($this->communityTopic, array('community_id' => $this->communityId));
    165 
    166     if ($request->isMethod('post'))
    167     {
    168       $this->form->bind($request->getParameter('community_topic'));
    169       if ($this->form->isValid())
    170       {
    171         $communityTopic = $this->form->save();
    172         $this->redirect('community/home?id='.$this->communityId);
    173       }
    174     }
    175   }
    176 
    177 
    178  /**
    179   * Executes delete action
    180   *
    181   * @param sfRequest $request A request object
    182   */
    183   public function executeDelete($request)
    184   {
    185     $this->community->checkPrivilegeBelong($this->getUser()->getMemberId());
    186     if ($this->checkOwner)
    187     {
    188       $this->community->checkPrivilegeOwner($this->getUser()->getMemberId());
    189     }
    190 
    191212    $this->comments = CommunityTopicCommentPeer::retrieveByCommunityTopicId($this->communityTopicId);
    192213
  • OpenPNE3/plugins/opCommunityTopicPlugin/branches/renewal/apps/pc_frontend/modules/communityTopic/templates/_communityTopicList.php

    r10358 r10377  
    1515<li><?php echo link_to('もっと読む', 'communityTopic_list_community', $community); ?></li>
    1616<?php endif; ?>
    17 <li><?php echo link_to('トピック作成', 'communityTopic/edit?community_id='.$community->getId()); ?></li>
     17<li><?php echo link_to('トピック作成', 'communityTopic_new', $community); ?></li>
    1818</ul>
    1919</td>
  • OpenPNE3/plugins/opCommunityTopicPlugin/branches/renewal/apps/pc_frontend/modules/communityTopic/templates/editSuccess.php

    r9656 r10377  
    11<?php
    2 $options = array('form' => array($form));
    3 if ($form->isNew()) {
    4   $title = 'トピック作成';
    5   $options['url'] = 'communityTopic/edit?community_id='.$sf_params->get('community_id');
    6 } else {
    7   $title = 'トピック編集';
    8   $options['url'] = 'communityTopic/edit?id='.$communityTopic->getId();
    9 }
    10 include_box('formCommunityTopic', $title, '', $options);
     2$options = array();
     3$options['title'] = 'トピック編集';
     4$options['url'] = '@communityTopic_update?id='.$communityTopic->getId();
     5op_include_form('formCommunityTopic', $form, $options);
    116?>
  • OpenPNE3/plugins/opCommunityTopicPlugin/branches/renewal/apps/pc_frontend/modules/communityTopic/templates/newSuccess.php

    r10358 r10377  
    11<?php
    22$options = array();
    3 if ($form->isNew()) {
    4   $options['title'] = 'トピック作成';
    5   $options['url'] = '@communityTopic_create?id='.$community->getId();
    6 } else {
    7   $options['title'] = 'トピック編集';
    8   $options['url'] = 'communityTopic/edit?id='.$communityTopic->getId();
    9 }
     3$options['title'] = 'トピック作成';
     4$options['url'] = '@communityTopic_create?id='.$community->getId();
    105op_include_form('formCommunityTopic', $form, $options);
    116?>
  • OpenPNE3/plugins/opCommunityTopicPlugin/branches/renewal/apps/pc_frontend/modules/communityTopic/templates/showSuccess.php

    r10358 r10377  
    66</div>
    77
    8 <table><tbody>
    9 <tr>
    10 <th rowspan=2><?php echo format_datetime($communityTopic->getUpdatedAt(), 'f'); ?></th>
    11 <td><?php echo $communityTopic->getName(); ?></td>
    12 </tr>
    13 <tr>
    14 <td class="border-left"><?php echo $communityTopic->getMember()->getName(); ?></td>
    15 </tr>
    16 <tr>
    17 <td class="align-center" colspan=2><?php echo link_to('トピック編集', 'communityTopic/edit?id='.$communityTopic->getId()); ?></td>
    18 </tr>
    19 </tbody>
    20 </table>
     8<dl>
     9<dt><?php echo format_datetime($communityTopic->getCreatedAt(), 'f') ?></dt>
     10<dd>
     11<div class="title"><?php echo $communityTopic->getName() ?></div>
     12<div class="name"><?php echo link_to($communityTopic->getMember()->getName(), 'member/profile?id='.$communityTopic->getMember()->getId()) ?></div>
     13<div class="body"><?php echo nl2br($communityTopic->getBody()) ?></div>
     14</dd>
     15</dl>
     16
     17<div class="operation"><?php echo link_to('トピック編集', 'communityTopic/edit?id='.$communityTopic->getId()) ?></div>
    2118
    2219</div>
  • OpenPNE3/plugins/opCommunityTopicPlugin/branches/renewal/config/schema.yml

    r9512 r10377  
    11propel:
    2   _attributes: { package: plugins.opTopicPlugin.lib.model }
     2  _attributes: { package: plugins.opCommunityTopicPlugin.lib.model }
    33
    44  community_topic:
    55    id: ~
    6     community_id: { type: integer, foreignTable: community, foreignReference: id }
    7     name: { type: longvarchar }
    8     member_id: { type: integer, foreignTable: member, foreignReference: id }
     6    community_id: { type: integer, required: true, foreignTable: community, foreignReference: id }
     7    member_id: { type: integer, required: true, foreignTable: member, foreignReference: id }
     8    name: { type: longvarchar, required: true }
     9    body: { type: longvarchar, required: true }
    910    created_at: ~
    1011    updated_at: ~
     
    1213  community_topic_comment:
    1314    id: ~
    14     community_topic_id: { type: integer, foreignTable: community_topic, foreignReference: id }
    15     member_id: { type: integer, foreignTable: member, foreignReference: id }
    16     body: { type: longvarchar }
     15    community_topic_id: { type: integer, required: true, foreignTable: community_topic, foreignReference: id }
     16    member_id: { type: integer, required: true, foreignTable: member, foreignReference: id }
     17    body: { type: longvarchar, required: true }
    1718    created_at: ~
    1819    updated_at: ~
Note: See TracChangeset for help on using the changeset viewer.