actions.class.php 3.49 KB
Newer Older
Игорь's avatar
init    
Игорь 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
<?php

require_once dirname(__FILE__) . '/../lib/userGeneratorConfiguration.class.php';
require_once dirname(__FILE__) . '/../lib/userGeneratorHelper.class.php';

/**
 * user actions.
 *
 * @package    sf
 * @subpackage user
 * @author     Atma
 * @version    SVN: $Id: actions.class.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $
 */
class userActions extends autoUserActions
{
    protected function buildQuery()
    {
        $query = parent::buildQuery()
            ->andWhere("r.username <> 'root'");
        return $query;
    }

    public function executeNew(sfWebRequest $request)
    {
        $this->form = $this->configuration->getForm();
        if((int)$this->getTab() === 2){
            $this->form->setDefault('is_super_admin', true);
        }

        $this->setPartialFilter();

        $this->user = $this->form->getObject();
    }

    public function executeEdit(sfWebRequest $request)
    {
        $this->user = $this->getRoute()->getObject();
        $this->forward404Unless($this->user->getUsername() !== 'root');
        $this->forward404Unless($this->getUser()->getUsername() === 'root' || !$this->user->getIsSuperAdmin());
        $user = $this->getUser();
        $this->form = $this->configuration->getForm($this->user);
        $this->setPartialFilter();
    }

    public function executeUpdate(sfWebRequest $request)
    {
        $this->user = $this->getRoute()->getObject();
        $this->forward404Unless($this->user->getUsername() !== 'root');
        $this->forward404Unless($this->getUser()->getUsername() === 'root' || !$this->user->getIsSuperAdmin());
        $this->form = $this->configuration->getForm($this->user);

        $this->setPartialFilter();

        $user = $this->getUser();
        $this->processForm($request, $this->form);

        $this->setTemplate('edit');
    }

    public function executeDelete(sfWebRequest $request)
    {
        $this->dispatcher->notify(new sfEvent($this, 'admin.delete_object', array('object' => $this->getRoute()->getObject())));

        $user = $this->getUser();

        $object = $this->getRoute()->getObject();

        $this->forward404Unless($object->getUsername() !== 'root');
        $this->forward404Unless($this->getUser()->getUsername() === 'root' || !$object->getIsSuperAdmin());

        if ($object->delete())
        {
            if(!$request->isXmlHttpRequest())
            {
                $this->getUser()->setFlash('notice', 'The item was deleted successfully.');
            }
        }
        if(!$request->isXmlHttpRequest())
        {
            $redirect_url = (isset($this->_partial) ? $_SERVER['DOCUMENT_URI'] . '?_spath=' : '') . $this->generateUrl('user');
            $this->redirect($redirect_url);
        }
        else
        {
            return sfView::NONE;
        }
    }

    protected function executeBatchDelete(sfWebRequest $request)
    {
        $ids = $request->getParameter('ids');

        $records = Doctrine_Query::create()
            ->from('User')
            ->whereIn('id', $ids)
            ->execute();

        foreach ($records as $record)
        {
            if($record->getUsername() !== 'root' && ($this->getUser()->getUsername() === 'root' || !$record->getIsSuperAdmin())){
                $record->delete();
            }
        }

        $this->getUser()->setFlash('notice', 'The selected items have been deleted successfully.');
        $redirect_url = (isset($this->_partial) ? $_SERVER['DOCUMENT_URI'] . '?_spath=' : '') . $this->generateUrl('user');

        $this->redirect($redirect_url);
    }
}