My favorites
▼
|
Sign in
uninformed
Web application for the resolutionfinder.org project
Project Home
Downloads
Wiki
Issues
Source
Checkout
Browse
Changes
Source path:
svn
/
trunk
/
lib
/
model
/
doctrine
/
Document.class.php
‹r652
r793
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
<?php
/**
* Document
*
* This class has been auto-generated by the Doctrine ORM Framework
*
* @package uninformed
* @subpackage model
* @author Your name here
* @version SVN: $Id: Builder.php 6820 2009-11-30 17:27:49Z jwage $
*/
class Document extends BaseDocument
{
protected $titleChange = false;
protected $adoptionDateChange = false;
protected static $autoCompletable = array(
'code' => true,
);
public function setUp()
{
parent::setUp();
$this->hasAccessor('root_document_id', 'getRootDocumentId');
}
public function getRootDocumentId() {
$root_document_id = $this->_get('root_document_id');
return empty($root_document_id) ? $this->_get('id') : $root_document_id;
}
public function preSave($event) {
$invoker = $event->getInvoker();
$slug = $invoker->_get('title');
$slug = substr(Doctrine_Inflector::urlize($slug), 0, 30);
$invoker->_set('slug', $slug);
// update clause slugs if the name changed
$modified = $invoker->getModified();
if (array_key_exists('title', $modified)) {
$this->titleChange = true;
}
if (array_key_exists('adoption_date', $modified)) {
$this->adoptionDateChange = true;
}
$root_document_id = $invoker->_get('root_document_id');
$parent_document_id = $invoker->_get('parent_document_id');
if (!empty($parent_document_id) && empty($root_document_id)) {
$root_document_id = $invoker->DocumentParent->root_document_id;
$invoker->set('root_document_id', $root_document_id);
}
}
public function postSave($event) {
if ($this->titleChange) {
$this->titleChange = false;
$invoker = $event->getInvoker();
$clauses = $invoker->getClauses();
foreach ($clauses as $clause) {
$slug = (string)$clause;
$slug = substr(Doctrine_Inflector::urlize($slug), 0, 30);
$clause->_set('slug', $slug);
$clause->save();
}
}
if ($this->adoptionDateChange) {
$this->adoptionDateChange = false;
$invoker = $event->getInvoker();
$clauses = $invoker->getClauses();
foreach ($clauses as $clause) {
$clause->forceIsLatestClauseUpdate();
}
}
}
public function getDocumentsByRoot() {
$root_document_id = $this->root_document_id;
$query = Doctrine_Query::create()
->from('Document d')
->where('d.id = ? OR d.root_document_id = ?', array($root_document_id, $root_document_id))
->orderBy('d.adoption_date');
return $query->execute();
}
public function getClauseList() {
$query = Doctrine_Query::create()
->from('Clause c')
->innerJoin('c.ClauseBody cb')
->where('c.document_id = ?', $this->_get('id'))
->orderBy("c.clause_number, c.clause_number_information, c.clause_number_subparagraph");
return $query->execute();
}
public function getStructuredOrganisation() {
$s = array('main' => '', 'current' => '', 'sub' => '', );
$organisationId = $this->getOrganisationId();
if (empty($organisationId)) {
$s['main'] = 'Other';
return $s;
}
$q = Doctrine_Query::create()
->select('so.name, so.parent_id, mo.name, mo.parent_id')
->from('Organisation so')
->innerJoin('so.OrganisationParent mo')
->where('so.id = ?', array($organisationId));
$suborgan = $q->fetchArray();
if (!empty($suborgan)) {
$suborgan = reset($suborgan);
if ($suborgan['OrganisationParent']['parent_id']) {
$q = Doctrine_Query::create()
->select('o.name')
->from('Organisation o')
->where('o.id = ?', array($suborgan['OrganisationParent']['parent_id']));
$s['main'] = $q->execute(array(), Doctrine_Core::HYDRATE_SINGLE_SCALAR);;
$s['current'] = $suborgan['OrganisationParent']['name'];
$s['sub'] = $suborgan['name'];
} else {
$s['main'] = $suborgan['OrganisationParent']['name'];
$s['current'] = $suborgan['name'];
}
}
return $s;
}
public function getAdoptionYear() {
return date('Y', strtotime($this->_get('adoption_date')));
}
public function getLegalValue() {
return $this->_get('DocumentType')->_get('legal_value');
}
public function getSlug() {
return $this->_get('id').'-'.$this->_get('slug');
}
public function __toString() {
if (strlen($this->_get('code')) > 3) {
return (string)$this->_get('code');
}
if (strlen($this->_get('title')) < 20) {
return (string)$this->_get('title');
}
return (string)substr($this->_get('title'), 0, 20).'..';
}
public static function filterUrls(sfEvent $event, $urls)
{
$urls = array('aboutus', 'news', 'help');
foreach ($urls as $key => $route) {
$urls[$key] = new isicsSitemapURL('@'.$route, date(DateTime::ATOM , filemtime(__DIR__.'/../../../apps/frontend/modules/default/templates/'.$route.'Success.php')));
}
$q = Doctrine_Query::create()
->select('id, slug, title, updated_at')
->from('Document');
$documents = $q->fetcharray();
foreach ($documents as $document) {
$urls[] = new isicsSitemapURL('@document?id='.$document['id'].'-'.$document['slug'], date(DateTime::ATOM , strtotime($document['updated_at'])));
}
return $urls;
}
}
Show details
Hide details
Change log
r653
by lukas.smith on Sep 26, 2010
Diff
added default urls to sitemap
Go to:
...odel/doctrine/Document.class.php
Project members,
sign in
to write a code review
Older revisions
r652
by lukas.smith on Sep 26, 2010
Diff
added default urls to sitemap
r651
by lukas.smith on Sep 26, 2010
Diff
added default urls to sitemap
r598
by lukas.smith on Jul 11, 2010
Diff
fixed date format
All revisions of this file
File info
Size: 5898 bytes, 174 lines
View raw file
Powered by
Google Project Hosting