root/trunk/lib/helper/ObjectUrlHelper.php

Revision 75, 5.7 kB (checked in by nperriault, 3 months ago)

[1.1]:

  • Companies and people modules migrated, with according form classes and templates, and functional test suite
  • Enhanced SymfoniansTestBrowser?
Line 
1 <?php
2 sfLoader::loadHelpers('Url');
3
4 /**
5  * Link to a user profile
6  *
7  * @param  sfGuardUser $person
8  * @param  array       $options
9  * @return string
10  */
11 function link_to_person($person, $options = null)
12 {
13   if (is_null($person))
14   {
15     return __('&lt;Removed profile&gt;');
16   }
17
18   $options = _parse_attributes($options);
19
20   if (isset($options['label']))
21   {
22     $label = $options['label'];
23     unset($options['label']);
24   }
25   else
26   {
27     $label = $person->getDisplayName();
28   }
29
30   $append = '';
31   if (isset($options['include_flag']))
32   {
33     if (flag_image_tag($person->getCountry()) != '')
34     {
35       $append = '&nbsp;'.flag_image_tag($person->getCountry());
36     }
37     unset($options['include_flag']);
38   }
39
40   if (!isset($options['title']))
41   {
42     $options['title'] = __('Access %person%\'s profile',
43                            array('%person%' => $person->getDisplayName()));
44   }
45
46   return link_to($label,
47                  '@person_page?username='.$person->getUsername(),
48                  $options).$append;
49 }
50
51 /**
52  * Link to a company profile
53  *
54  * @param  Company  $company
55  * @param  array    $options
56  * @return string
57  */
58 function link_to_company($company, $options = null)
59 {
60   if (is_null($company))
61   {
62     return __('&lt;Removed company&gt;');
63   }
64
65   $options = _parse_attributes($options);
66
67   if (isset($options['label']))
68   {
69     $label = $options['label'];
70     unset($options['label']);
71   }
72   else
73   {
74     $label = $company->getName();
75   }
76
77   $append = '';
78   if (isset($options['include_flag']))
79   {
80     if (flag_image_tag($company->getCountry()) != '')
81     {
82       $append = '&nbsp;'.flag_image_tag($company->getCountry());
83     }
84     unset($options['include_flag']);
85   }
86
87   if (!isset($options['title']))
88   {
89     $options['title'] = __('Access %company% page',
90                            array('%company%' => $company->getName()));
91   }
92
93   return link_to($label,
94                  '@company_page?slug='.$company->getSlug(),
95                  $options).$append;
96 }
97
98 /**
99  * Link to a application profile
100  *
101  * @param  Application  $application
102  * @param  array    $options
103  * @return string
104  */
105 function link_to_application($application, $options = null)
106 {
107   if (is_null($application))
108   {
109     return __('&lt;Removed application&gt;');
110   }
111
112   $options = _parse_attributes($options);
113
114   if (isset($options['label']))
115   {
116     $label = $options['label'];
117     unset($options['label']);
118   }
119   else
120   {
121     $label = $application->getName();
122   }
123
124   $append = '';
125   if (isset($options['include_flag']))
126   {
127     if (flag_image_tag($application->getCountry()) != '')
128     {
129       $append = '&nbsp;'.flag_image_tag($application->getCountry());
130     }
131     unset($options['include_flag']);
132   }
133
134   if (!isset($options['title']))
135   {
136     $options['title'] = __('Access %app% application\'s details page',
137                            array('%app%' => $application->getName()));
138   }
139
140   return link_to($label,
141                  '@application_page?slug='.$application->getSlug(),
142                  $options).$append;
143 }
144
145 /**
146  * Link to a job profile
147  *
148  * @param  Job  $job
149  * @param  array    $options
150  * @return string
151  */
152 function link_to_job($job, $options = null)
153 {
154   if (is_null($job))
155   {
156     return __('&lt;Removed job offer&gt;');
157   }
158
159   $options = _parse_attributes($options);
160
161   if (isset($options['label']))
162   {
163     $label = $options['label'];
164     unset($options['label']);
165   }
166   else
167   {
168     $label = $job->getTitle();
169   }
170
171   $append = '';
172   if (isset($options['include_flag']))
173   {
174     if (flag_image_tag($job->getCountry()) != '')
175     {
176       $append = '&nbsp;'.flag_image_tag($job->getCountry());
177     }
178     unset($options['include_flag']);
179   }
180
181   if (!isset($options['title']))
182   {
183     $options['title'] = __('Access %jobtitle% offer page',
184                            array('%jobtitle%' => $job->getTitle()));
185   }
186
187   return link_to($label,
188                  '@job_page?slug='.$job->getSlug(),
189                  $options).$append;
190 }
191
192 ### Thumb links
193
194 /**
195  * Generates a thumb with a link on it pointing to an person page
196  *
197  * @param  string       $format
198  * @param  sfGuardUser  $person
199  * @param  mixed        $options
200  * @return string
201  */
202 function link_thumb_to_person($format, $person, $options = null)
203 {
204   $options = _parse_attributes($options);
205   $image_src = null;
206
207   if (isset($options['imgclass']))
208   {
209     $imgclass = $options['imgclass'];
210     unset($options['imgclass']);
211   }
212   else
213   {
214     $imgclass = 'avatar';
215   }
216
217   $force_reload = false;
218   if (isset($options['force_reload']))
219   {
220     $force_reload = $options['force_reload'];
221     unset($options['force_reload']);
222   }
223
224   if (isset($options['route']))
225   {
226     $route = $options['route'];
227     unset($options['route']);
228   }
229   else
230   {
231     $route = '@person_page?username='.$person->getUsername();
232   }
233
234   if (!$content = person_image_tag($person, $format, 'alt='.$person->getDisplayName().' class='.$imgclass))
235   {
236     $content = $person->getDisplayName();
237   }
238
239   return link_to($content, $route, $options);
240 }
241
242 /**
243  * Generates url for a blog post
244  *
245  * @return string
246  */
247 function blog_post_url($local_event, $absolute = false)
248 {
249   $route = _gen_local_event_route($local_event);
250   return url_for($route, $absolute);
251 }
252
253 /**
254  * Generates a link to a blog post
255  *
256  * @param  LocalEvent $local_event
257  * @param  mixed      $options
258  * @return string
259  */
260 function link_to_local_event($local_event, $options = null)
261 {
262   $local_event_route = _gen_local_event_route($local_event);
263   return link_to($local_event->getTitle(), $local_event_route, $options);
264 }
265
266 /**
267  * Generates a link to a local event
268  *
269  * @param  LocalEvent $local_event
270  * @return string
271  */
272 function _gen_local_event_route($local_event)
273 {
274   if (is_null($local_event))
275   {
276     return null;
277   }
278   if (!$local_event instanceof LocalEvent)
279   {
280     $local_event = $local_event->getRawValue();
281   }
282   return $local_event->getRoute();
283 }
284
Note: See TracBrowser for help on using the browser.