-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathopAPIDiary.class.php
More file actions
112 lines (96 loc) · 2.77 KB
/
opAPIDiary.class.php
File metadata and controls
112 lines (96 loc) · 2.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
<?php
/**
* This file is part of the OpenPNE package.
* (c) OpenPNE Project (http://www.openpne.jp/)
*
* For the full copyright and license information, please view the LICENSE
* file and the NOTICE file that were distributed with this source code.
*/
/**
* opAPIDiary
*
* @package OpenPNE
* @subpackage api
* @author Kousuke Ebihara <ebihara@tejimaya.com>
*/
class opAPIDiary extends opAPI implements opAPIInterface
{
public function feed()
{
if ($id = $this->getParameter('member_id'))
{
$diaries = Doctrine::getTable('Diary')->getMemberDiaryPager($id, $this->getParameter('_pg', 1));
}
else
{
$diaries = Doctrine::getTable('Diary')->getDiaryPager($this->getParameter('_pg', 1));
}
if (!$result = $diaries->getResults())
{
return false;
}
$feed = $this->getGeneralFeed('Diaries');
foreach ($result as $diary)
{
$entry = $feed->addEntry();
$this->createEntryByInstance($diary, $entry);
}
$feed->setUpdated($result[0]->getCreatedAt());
return $feed->publish();
}
public function entry()
{
$id = $this->getRequiredParameter('id');
$diary = Doctrine::getTable('Diary')->find($id);
return $diary;
}
public function insert(SimpleXMLElement $xml)
{
$member = Doctrine::getTable('Member')->find($this->getMemberIdByUrl((string)$xml->author->uri));
if (!$member)
{
return false;
}
$diary = new Diary();
$diary->setTitle($xml->title);
$diary->setBody($xml->content);
$diary->setMember($member);
$diary->save();
return $diary;
}
public function update(SimpleXMLElement $xml)
{
$id = $this->getRequiredParameter('id');
$diary = Doctrine::getTable('Diary')->find($id);
if (!$diary || $this->generateEntryId($diary) != $xml->id)
{
return false;
}
$diary->setTitle($xml->title);
$diary->setBody($xml->content);
$diary->save();
return $diary;
}
public function delete()
{
$id = $this->getRequiredParameter('id');
$diary = Doctrine::getTable('Diary')->find($id);
if (!$diary)
{
return false;
}
$diary->delete();
return true;
}
public function createEntryByInstance(Doctrine_Record $diary, SimpleXMLElement $entry = null)
{
$entry = parent::createEntryByInstance($diary, $entry);
sfContext::getInstance()->getConfiguration()->loadHelpers(array('Url', 'opUtil'));
$entry->setTitle($diary->getTitle());
$entry->setContent($diary->getBody());
$entry->setAuthorByMember($diary->getMember());
$entry->setLink(app_url_for('pc_frontend', '@diary_show?id='.$diary->getId(), true), 'self', 'alternate');
$entry->setLink(app_url_for('mobile_frontend', '@diary_show?id='.$diary->getId(), true), 'self', 'alternate');
return $entry;
}
}