My favorites | Sign in
Project Home Downloads Wiki Issues Source
Checkout   Browse   Changes    
 
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
<?php

/**
* entity
*
* This class has been auto-generated by the Doctrine ORM Framework
*
* @package worldmap
* @subpackage model
* @author Your name here
* @version SVN: $Id: Builder.php 6820 2009-11-30 17:27:49Z jwage $
*/
class entity extends Baseentity
{
protected $updateCache = false;

public function preSave($event) {
if (get_class($this) !== 'entity') {
$entity_id = $this->getEntityId();
if (empty($entity_id)) {
$this->updateCache = true;
} else {
$modified = $this->getModified();
if (isset($modified['name'])
|| isset($modified['lat'])
|| isset($modified['lng'])
) {
$this->updateCache = true;
$entity = Doctrine::getTable('entity')->find(array($entity_id));
}
}
if ($this->updateCache) {
if (empty($entity)) {
$entity_id = null;
$entity = new entity();
$entity->setType(get_class($this));
}
$entity->setName($this->getName());
$entity->setLat($this->getLat());
$entity->setLng($this->getLng());
$entity->save();
if (empty($entity_id)) {
$this->setEntityId($entity->getId());
}
}
}
}

public function postSave($event) {
$this->updateCache();
}

public function preDelete($event) {
if (get_class($this) !== 'entity') {
$entity = Doctrine::getTable('entity')->find(array($this->getEntityId()));
if (!empty($entity)) {
$entity->delete();
$this->updateCache = true;
}
}
}

public function postDelete($event) {
$this->updateCache();
}

protected function updateCache() {
if ($this->updateCache) {
$entities = Doctrine::getTable('entity')
->createQuery('e')
->select('e.id, e.name, e.lat, e.lng, e.type')
->execute(array(), Doctrine::HYDRATE_ARRAY);

$data = 'var pointData = '.json_encode($entities);
file_put_contents(sfConfig::get('sf_web_dir').'/js/cache/data.js', $data);

$this->updateCache = false;
}
}
}

Change log

r143 by lukas.smith on Dec 27, 2009   Diff
tweaked error handling when deleting
Go to: 
Project members, sign in to write a code review

Older revisions

r139 by lukas.smith on Dec 25, 2009   Diff
minor code structure tweak, moved
common code to updateCache()
r138 by lukas.smith on Dec 25, 2009   Diff
only regenerate when deleting an
entity specialization
r137 by lukas.smith on Dec 25, 2009   Diff
also update the js cache file on
delete
All revisions of this file

File info

Size: 2445 bytes, 80 lines
Powered by Google Project Hosting