1 | <?php |
---|
2 | |
---|
3 | /** |
---|
4 | * This class has been auto-generated by the Doctrine ORM Framework |
---|
5 | */ |
---|
6 | class Commentaire extends BaseCommentaire |
---|
7 | { |
---|
8 | public function getTitre() { |
---|
9 | return $this->getPresentation(); |
---|
10 | } |
---|
11 | |
---|
12 | public function __toString() { |
---|
13 | $str = substr($this->commentaire, 0, 250); |
---|
14 | if (strlen($str) == 250) { |
---|
15 | $str .= '...'; |
---|
16 | } |
---|
17 | return $str; |
---|
18 | } |
---|
19 | |
---|
20 | protected static $mois = array('01'=>'janvier', '02'=>'février', '03'=>'mars', '04'=>'avril', '05'=>'mai', '06'=>'juin', '07'=>'juillet', '08'=>'août', '09'=>'septembre', '10'=>'octobre', '11'=>'novembre', '12'=>'décembre'); |
---|
21 | |
---|
22 | /** |
---|
23 | * Overrides getPresentation from corresponding column |
---|
24 | * if $format is set to specific strings, returns a modified version : |
---|
25 | * 'none' => empty string |
---|
26 | * 'noauteur' => presentation without the author information |
---|
27 | * 'nodossier' => presentation without the section information |
---|
28 | * 'noloi' => presentation without the name of the law |
---|
29 | * 'noarticle' => presentation without the name of the law nor the article's |
---|
30 | * if $virgule is set to 1, adds a ', ' at the end of the string |
---|
31 | */ |
---|
32 | public function getPresentation($format = '', $virgule = 0) { |
---|
33 | if ($format == 'none') return ''; |
---|
34 | else $present = $this->_get('presentation'); |
---|
35 | if ($format == 'noauteur') { |
---|
36 | $present = preg_replace('/\sd(\'|e\s)[A-ZÉÈÊ][\wçàéëêèïîôöûüÉ\s\-]+\sle\s(\d)/', ' du \2', $present); |
---|
37 | $present = preg_replace('/Suite aux/', 'Suite à ses', $present); |
---|
38 | } else if ($format == 'nodossier') { |
---|
39 | $present = preg_replace('/^.* - (Suite aux|Au sujet)/', '\1', $present); |
---|
40 | } else if ($format == 'noloi' || $format == 'noarticle') { |
---|
41 | $present = preg_replace('/^.* - /', '', $present); |
---|
42 | } |
---|
43 | if ($format == 'noarticle') { |
---|
44 | $present = preg_replace('/(A propos de l\')article\s.*\s(alinéa\s\d+)/', '\1\2', $present); |
---|
45 | $present = preg_replace('/A propos de l\'article\s.*$/', '', $present); |
---|
46 | } |
---|
47 | if ($virgule == 1 && $present != '') return $present.', '; |
---|
48 | else return $present; |
---|
49 | } |
---|
50 | |
---|
51 | public function addObject($object_type, $object_id) { |
---|
52 | if (!$this->id) { |
---|
53 | throw new Exception('no commentaire id'); |
---|
54 | } |
---|
55 | $object = Doctrine::getTable($object_type)->find($object_id); |
---|
56 | if ($object) { |
---|
57 | Doctrine::getTable('CommentaireObject')->findUniqueOrCreate($object_type, $object_id, $this->id); |
---|
58 | $object->updateNbCommentaires(); |
---|
59 | if ($object_type == 'Section' && $object->id != $object->section_id) |
---|
60 | $this->addObject($object_type, $object->section_id); |
---|
61 | else if ($object_type == 'TitreLoi') { |
---|
62 | if ($object->id != $object->titre_loi_id) |
---|
63 | $this->addObject($object_type, $object->titre_loi_id); |
---|
64 | if ($object->parlementaire_id) |
---|
65 | $this->addObject('Parlementaire', $object->parlementaire_id); |
---|
66 | } else if ($object_type == 'ArticleLoi' && $object->titre_loi_id) |
---|
67 | $this->addObject('TitreLoi', $object->titre_loi_id); |
---|
68 | } |
---|
69 | } |
---|
70 | |
---|
71 | public function updateNbCommentaires($inc = 0) { |
---|
72 | $o = Doctrine::getTable($this->object_type)->find($this->object_id); |
---|
73 | $o->updateNbCommentaires($inc); |
---|
74 | foreach ($this->getObjects() as $object) { |
---|
75 | $o = Doctrine::getTable($object->object_type)->find($object->object_id); |
---|
76 | if (isset($o)) |
---|
77 | $o->updateNbCommentaires($inc); |
---|
78 | } |
---|
79 | } |
---|
80 | |
---|
81 | public function setIsPublic($b) { |
---|
82 | $this->_set('is_public', $b); |
---|
83 | if ($this->id) { |
---|
84 | $this->updateNbCommentaires(($b) ? 1 : -1); |
---|
85 | } |
---|
86 | } |
---|
87 | public function getLien() { |
---|
88 | return preg_replace('/@amendement\?id=/', '@amendement_id?id=', $this->_get('lien')); |
---|
89 | } |
---|
90 | } |
---|