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

Changeset 10336


Ignore:
Timestamp:
Jan 23, 2009, 3:18:06 PM (14 years ago)
Author:
ebihara
Message:

#3111:moved the code for creating feeds and entries to the action

Location:
OpenPNE3/plugins/opWebAPIPlugin/trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • OpenPNE3/plugins/opWebAPIPlugin/trunk/apps/api/modules/feeds/actions/actions.class.php

    r10328 r10336  
    5656    $this->result = $this->api->entry();
    5757    $this->forward404Unless($this->result);
    58     return $this->renderText($this->result);
     58    $entry = $this->api->createEntryByInstance($this->result);
     59    return $this->renderText($entry->publish());
    5960  }
    6061
     
    6667  public function executeInsertEntry($request)
    6768  {
    68     $this->result = $this->api->insert();
     69    $this->result = $this->api->insert($this->api->getEntryXMLFromRequestBody());
    6970    $this->forward404Unless($this->result);
    7071
    7172    $this->getResponse()->setStatusCode(201);
    72     return $this->renderText($this->result);
     73    $entry = $this->api->createEntryByInstance($this->result);
     74    return $this->renderText($entry->publish());
    7375  }
    7476
     
    8082  public function executeUpdateEntry($request)
    8183  {
    82     $this->result = $this->api->update();
     84    $this->result = $this->api->update($this->api->getEntryXMLFromRequestBody());
    8385    $this->forward404Unless($this->result);
    84     return $this->renderText($this->result);
     86    $entry = $this->api->createEntryByInstance($this->result);
     87    return $this->renderText($entry->publish());
    8588  }
    8689
  • OpenPNE3/plugins/opWebAPIPlugin/trunk/lib/api/opAPI.class.php

    r10334 r10336  
    6565  }
    6666
    67   protected function createEntryByInstance(BaseObject $obj, SimpleXMLElement $entry = null)
     67  public function createEntryByInstance(BaseObject $obj, SimpleXMLElement $entry = null)
    6868  {
    6969    $entry = new opAtomPubDocumentEntry($entry);
     
    7575  }
    7676
    77   protected function getEntryXMLFromRequestBody()
     77  public function getEntryXMLFromRequestBody()
    7878  {
    7979    $input = file_get_contents('php://input');
  • OpenPNE3/plugins/opWebAPIPlugin/trunk/lib/api/opAPICommunityTopic.class.php

    r10334 r10336  
    4949    $id = $this->getRequiredParameter('id');
    5050    $topic = CommunityTopicPeer::retrieveByPk($id);
    51     if (!$topic)
    52     {
    53       return false;
    54     }
    55 
    56     $entry = $this->createEntryByInstance($topic);
    57     return $entry->publish();
     51    return $topic;
    5852  }
    5953
    60   public function insert()
     54  public function insert(SimpleXMLElement $xml)
    6155  {
    62     $elements = $this->getEntryXMLFromRequestBody();
    6356    $communityId = $this->getRequiredParameter('community_id');
    6457
    6558    $community = CommunityPeer::retrieveByPk($communityId);
    66     $member = MemberPeer::retrieveByPk($elements->author->id);
     59    $member = MemberPeer::retrieveByPk($xml->author->id);
    6760    if (!$community || !$member)
    6861    {
     
    7366    $topic->setMember($member);
    7467    $topic->setCommunity($community);
    75     $topic->setName($elements->title);
     68    $topic->setName($xml->title);
    7669    $topic->save();
    7770
    78     $responseEntry = $this->createEntryByInstance($topic);
    79     return $responseEntry->publish();
     71    return $topic;
    8072  }
    8173
    82   public function update()
     74  public function update(SimpleXMLElement $xml)
    8375  {
    84     $elements = $this->getEntryXMLFromRequestBody();
    85 
    8676    $id = $this->getRequiredParameter('id');
    8777    $topic = CommunityTopicPeer::retrieveByPk($id);
    8878
    89     if (!$topic || $this->generateEntryId($topic) != $elements->id)
     79    if (!$topic || $this->generateEntryId($topic) != $xml->id)
    9080    {
    9181      return false;
    9282    }
    9383
    94     $topic->setName($elements->title);
     84    $topic->setName($xml->title);
    9585    $topic->save();
    9686
    97     $responseEntry = $this->createEntryByInstance($topic);
    98     return $responseEntry->publish();
     87    return $topic;
    9988  }
    10089
     
    112101  }
    113102
    114   protected function createEntryByInstance(BaseObject $topic, SimpleXMLElement $entry = null)
     103  public function createEntryByInstance(BaseObject $topic, SimpleXMLElement $entry = null)
    115104  {
    116105    $entry = parent::createEntryByInstance($topic, $entry);
  • OpenPNE3/plugins/opWebAPIPlugin/trunk/lib/api/opAPICommunityTopicComment.class.php

    r10334 r10336  
    4949    $id = $this->getRequiredParameter('id');
    5050    $comment = CommunityTopicCommentPeer::retrieveByPk($id);
    51     if (!$comment)
    52     {
    53       return false;
    54     }
    55 
    56     $entry = $this->createEntryByInstance($comment);
    57     return $entry->publish();
     51    return $comment;
    5852  }
    5953
    60   public function insert()
     54  public function insert(SimpleXMLElement $xml)
    6155  {
    62     $elements = $this->getEntryXMLFromRequestBody();
    6356    $communityTopicId = $this->getRequiredParameter('topic_id');
    6457
    6558    $communityTopic = CommunityTopicPeer::retrieveByPk($communityTopicId);
    66     $member = MemberPeer::retrieveByPk($elements->author->id);
     59    $member = MemberPeer::retrieveByPk($xml->author->id);
    6760    if (!$communityTopic || !$member)
    6861    {
     
    7063    }
    7164
    72     $elements = $this->getEntryXMLFromRequestBody();
    73 
    7465    $comment = new CommunityTopicComment();
    7566    $comment->setMember($member);
    7667    $comment->setCommunityTopic($communityTopic);
    77     $comment->setBody($elements->content);
     68    $comment->setBody($xml->content);
    7869    $comment->save();
    7970
    80     $responseEntry = $this->createEntryByInstance($comment);
    81     return $responseEntry->publish();
     71    return $comment;
    8272  }
    8373
    84   public function update()
     74  public function update(SimpleXMLElement $xml)
    8575  {
    86     $elements = $this->getEntryXMLFromRequestBody();
    87 
    8876    $id = $this->getRequiredParameter('id');
    8977    $comment = CommunityTopicCommentPeer::retrieveByPk($id);
    90     if (!$comment || $this->generateEntryId($comment) != $elements->id)
     78    if (!$comment || $this->generateEntryId($comment) != $xml->id)
    9179    {
    9280      return false;
    9381    }
    9482
    95     $comment->setBody($elements->content);
     83    $comment->setBody($xml->content);
    9684    $comment->save();
    9785
    98     $responseEntry = $this->createEntryByInstance($comment);
    99     return $responseEntry->publish();
     86    return $comment;
    10087  }
    10188
     
    113100  }
    114101
    115   protected function createEntryByInstance(BaseObject $comment, SimpleXMLElement $entry = null)
     102  public function createEntryByInstance(BaseObject $comment, SimpleXMLElement $entry = null)
    116103  {
    117104    $entry = parent::createEntryByInstance($comment, $entry);
  • OpenPNE3/plugins/opWebAPIPlugin/trunk/lib/api/opAPIDiary.class.php

    r10334 r10336  
    4949    $id = $this->getRequiredParameter('id');
    5050    $diary = DiaryPeer::retrieveByPk($id);
    51     if (!$diary)
    52     {
    53       return false;
    54     }
    55 
    56     $entry = $this->createEntryByInstance($diary);
    57     return $entry->publish();
     51    return $diary;
    5852  }
    5953
    60   public function insert()
     54  public function insert(SimpleXMLElement $xml)
    6155  {
    62     $elements = $this->getEntryXMLFromRequestBody();
    63     $member = MemberPeer::retrieveByPk($elements->author->id);
     56    $member = MemberPeer::retrieveByPk($xml->author->id);
    6457    if (!$member)
    6558    {
     
    6861
    6962    $diary = new Diary();
    70     $diary->setTitle($elements->title);
    71     $diary->setBody($elements->content);
     63    $diary->setTitle($xml->title);
     64    $diary->setBody($xml->content);
    7265    $diary->setMember($member);
    7366    $diary->save();
    7467
    75     $responseEntry = $this->createEntryByInstance($diary);
    76     return $responseEntry->publish();
     68    return $diary;
    7769  }
    7870
    79   public function update()
     71  public function update(SimpleXMLElement $xml)
    8072  {
    81     $elements = $this->getEntryXMLFromRequestBody();
    82 
    8373    $id = $this->getRequiredParameter('id');
    8474    $diary = DiaryPeer::retrieveByPk($id);
    85     if (!$diary || $this->generateEntryId($diary) != $elements->id)
     75    if (!$diary || $this->generateEntryId($diary) != $xml->id)
    8676    {
    8777      return false;
    8878    }
    8979
    90     $diary->setTitle($elements->title);
    91     $diary->setBody($elements->content);
     80    $diary->setTitle($xml->title);
     81    $diary->setBody($xml->content);
    9282    $diary->save();
    9383
    94     $responseEntry = $this->createEntryByInstance($diary);
    95     return $responseEntry->publish();
     84    return $diary;
    9685  }
    9786
     
    10998  }
    11099
    111   protected function createEntryByInstance(BaseObject $diary, SimpleXMLElement $entry = null)
     100  public function createEntryByInstance(BaseObject $diary, SimpleXMLElement $entry = null)
    112101  {
    113102    $entry = parent::createEntryByInstance($diary, $entry);
  • OpenPNE3/plugins/opWebAPIPlugin/trunk/lib/api/opAPIInterface.class.php

    r10328 r10336  
    2020  public function feed();
    2121  public function entry();
    22   public function insert();
    23   public function update();
     22  public function insert(SimpleXMLElement $xml);
     23  public function update(SimpleXMLElement $xml);
    2424  public function delete();
    2525}
Note: See TracChangeset for help on using the changeset viewer.