actions.class.php 2.14 KB
Newer Older
Яков's avatar
first  
Яков committed
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
<?php

/**
 * callback actions.
 *
 * @package    sf
 * @subpackage callback
 * @author     Atma
 * @version    SVN: $Id: actions.class.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $
 */
class callbackActions extends sfActions
{
    /**
     * Executes index action
     *
     * @param sfRequest $request A request object
     */
    public function executeNew(sfWebRequest $request)
    {
        $callback_form = new wwwCallbackForm();
        $params = $request->getParameter($callback_form->getName());
        $params['phone'] = preg_replace("/[^0-9]/", '', $params['phone']);
        if ($params['offer_id'] == '')
        {
            $params['offer_id'] = null;
        }
        $callback_form->bind($params);
        $is_valid = $callback_form->isValid();
        if($is_valid){
            $callback = $callback_form->save();

            $mail_body = "Обратный звонок" . "\n";
            $mail_body .= "Телефон: " . $callback->getPhone() . "\n";
            $mail_body .= "Имя: " . $callback->getName() . "\n";

            $emails_dirty = NotificationEmailsTable::getInstance()->createQuery('e')
                ->select('e.email')
                ->where("e.is_active = 1")
                ->andWhere("e.notic_type = 'call' OR e.notic_type = 'all'")
                ->fetchArray();

            if (count($emails_dirty) > 0)
            {
                $emails = array();

                foreach ($emails_dirty as $e)
                {
                    $emails[] = $e['email'];
                }

                sfContext::getInstance()->getConfiguration()->loadHelpers('Partial');

                get_component('pages', 'emailSender',
                    array(
                        'type' => 'simple',
                        'emailTo' => $emails,
                        'param' => array('mailBody' => $mail_body, 'subject' => 'Обратный звонок')
                    )
                );
            }

            $callback_form = new wwwCallbackForm();
        }
        echo $this->getPartial('callback/callback', array('callback_form' => $callback_form, 'is_valid' => $is_valid));
        return sfView::NONE;
    }
}