root/trunk/apps/main/modules/utils/actions/actions.class.php

Revision 2, 5.5 kB (checked in by nperriault, 2 years ago)

First commit of the extracted code from production, I hope no passwd has been forgotten :-)

Line 
1 <?php
2 /**
3  * utils actions.
4  *
5  * @package    symfonians
6  * @subpackage utils
7  */
8 class utilsActions extends myActions
9 {
10
11   public function executeContact()
12   {
13     if ($this->getRequest()->getMethod() == sfRequest::POST)
14     {
15       $this->getRequest()->setAttribute('message', $this->getRequestParameter('body'));
16       $mailSent = $this->sendSwiftSmtpPlainMail('mail', 'contact',
17                                                 sfConfig::get('app_contact_default_recipient'),
18                                                 $this->getRequestParameter('subject'),
19                                                 array('reply-to' => array('address' => $this->getRequestParameter('email'),
20                                                                           'name'    => $this->getRequestParameter('name'))));
21       if (!$mailSent)
22       {
23         $this->getRequest()->setError('errors', $this->__('Unable to send your message. Please try again later.'));
24         return sfView::SUCCESS;
25       }
26
27       $this->setFlash('notice', $this->__('Your message has been sent'));
28       $this->forward('utils', 'contactSent');
29     }
30   }
31
32   public function executeContactSent()
33   {
34   }
35
36   public function executeDeleteConnection()
37   {
38     $from  = $this->getRequestParameter('from');
39     $to    = $this->getRequestParameter('to');
40     $id    = $this->getRequestParameter('id');
41     $owner = false;
42     $redirect_route = false;
43     switch ($from)
44     {
45       case 'application':
46         if ($to == 'company')
47         {
48           $connection = ApplicationCompanyPeer::retrieveByPK($id);
49           $this->forward404Unless($connection, sprintf('Connection not found from "%s" to "%s" with id #%d', $from, $to, $id));
50           $owner = $connection->getSubmitterId() == $this->getUser()->getId();
51         }
52         else
53         {
54           $connection = ApplicationDeveloperPeer::retrieveByPK($id);
55           $this->forward404Unless($connection, sprintf('Connection not found from "%s" to "%s" with id #%d', $from, $to, $id));
56           $owner = $connection->getDeveloperId() == $this->getUser()->getId();
57         }
58         $redirect_route = '@application_page?slug='.$connection->getApplication()->getSlug();
59       break;
60       case 'company':
61         if ($to == 'application')
62         {
63           $connection = ApplicationCompanyPeer::retrieveByPK($id);
64           $this->forward404Unless($connection, sprintf('Connection not found from "%s" to "%s" with id #%d', $from, $to, $id));
65           $owner = $connection->getSubmitterId() == $this->getUser()->getId();
66         }
67         else
68         {
69           $connection = CompanyPersonPeer::retrieveByPK($id);
70           $this->forward404Unless($connection, sprintf('Connection not found from "%s" to "%s" with id #%d', $from, $to, $id));
71           $owner = $connection->getUserId() == $this->getUser()->getId();
72         }
73         $redirect_route = '@company_page?slug='.$connection->getCompany()->getSlug();
74       break;
75       case 'person':
76         if ($to == 'application')
77         {
78           $connection = ApplicationDeveloperPeer::retrieveByPK($id);
79           $owner = $connection->getDeveloperId() == $this->getUser()->getId();
80         }
81         else
82         {
83           $connection = CompanyPersonPeer::retrieveByPK($id);
84           $this->forward404Unless($connection, sprintf('Connection not found from "%s" to "%s" with id #%d', $from, $to, $id));
85           $owner = $connection->getUserId() == $this->getUser()->getId();
86         }
87         $redirect_route = '@person_page?username='.$connection->getsfGuardUser()->getUsername();
88       break;
89     }
90     if (!$owner && !$this->getUser()->hasCredential('admin'))
91     {
92       $this->setFlash('warning', $this->__('You do not own this connection'));
93       $this->redirect($redirect_route);
94     }
95     parent::purgeObjectRelatedCache($connection);
96     $connection->delete();
97     $this->forward404Unless($redirect_route);
98     $this->setFlash('notice', $this->__('The connection has been deleted'));
99     $this->redirect($redirect_route);
100   }
101
102   public function executeError404()
103   {
104   }
105
106   public function executeI18nRelocate()
107   {
108     $request = $this->getRequest();
109     $culture = $request->getParameter('culture');
110     $enabled_cultures = sfConfig::get('app_cultures_enabled', array());
111     $this->forward404Unless(in_array($culture, $enabled_cultures),
112                             sprintf('Culture %s is not enabled', $culture));
113     $redirect = $this->generateI18nRedirectFromReferer($culture);
114     $this->logMessage(sprintf('Locale changed to %s, redirecting to %s',
115                               $culture, $redirect), 'debug');
116     $this->getUser()->setCulture($culture);
117     $this->redirect($redirect);
118   }
119
120   public function handleErrorContact()
121   {
122     return sfView::SUCCESS;
123   }
124
125   /**
126    * Generates and returns an i18n url from the current request referer
127    *
128    * @param  string  $new_culture
129    * @return string
130    */
131   protected function generateI18nRedirectFromReferer($new_culture)
132   {
133     $referer = $this->getRequest()->getReferer();
134     $default_culture = sfConfig::get('sf_default_culture', 'en');
135     $current_culture = $this->getUser()->getCulture() or $default_culture;
136
137     // New i18n domain computation
138     if ($new_culture == $default_culture)
139     {
140       $domain = SYMFONIANS_MAIN_DOMAIN;
141     }
142     else
143     {
144       $domain = sprintf('%s.%s', $new_culture, SYMFONIANS_MAIN_DOMAIN);
145     }
146
147     // Referer generation
148     if (!$referer)
149     {
150       $redirect = sprintf('http://%s', $domain);
151     }
152     else
153     {
154       $redirect = str_replace($this->getRequest()->getHost(), $domain, $referer);
155     }
156     return $redirect;
157   }
158
159 }
160
Note: See TracBrowser for help on using the browser.