Completed
Branch master (380ad8)
by Pierre-Henry
33:44
created

EditAlbumForm::display()   B

Complexity

Conditions 3
Paths 3

Size

Total Lines 28
Code Lines 20

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 3
eloc 20
c 2
b 0
f 0
nc 3
nop 0
dl 0
loc 28
rs 8.8571
1
<?php
2
/**
3
 * @author         Pierre-Henry Soria <[email protected]>
4
 * @copyright      (c) 2012-2018, Pierre-Henry Soria. All Rights Reserved.
5
 * @license        GNU General Public License; See PH7.LICENSE.txt and PH7.COPYRIGHT.txt in the root directory.
6
 * @package        PH7 / App / System / Module / Picture / Form
7
 */
8
9
namespace PH7;
10
11
use PH7\Framework\Config\Config;
12
use PH7\Framework\Mvc\Request\Http;
13
use PH7\Framework\Session\Session;
14
use PH7\Framework\Url\Header;
15
16
class EditAlbumForm
17
{
18
    public static function display()
0 ignored issues
show
Coding Style introduced by
display uses the super-global variable $_POST which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
19
    {
20
        if (isset($_POST['submit_edit_picture_album'])) {
21
            if (\PFBC\Form::isValid($_POST['submit_edit_picture_album'])) {
22
                new EditAlbumFormProcess();
23
            }
24
25
            Header::redirect();
26
        }
27
28
        $oAlbum = (new PictureModel)->album(
29
            (new Session)->get('member_id'),
30
            (new Http)->get('album_id'),
31
            '1',
32
            0,
33
            1
34
        );
35
        $sTitlePattern = Config::getInstance()->values['module.setting']['url_title.pattern'];
36
37
        $oForm = new \PFBC\Form('form_edit_picture_album');
38
        $oForm->configure(array('action' => ''));
39
        $oForm->addElement(new \PFBC\Element\Hidden('submit_edit_picture_album', 'form_edit_picture_album'));
40
        $oForm->addElement(new \PFBC\Element\Token('edit_album'));
41
        $oForm->addElement(new \PFBC\Element\Textbox(t('Album Cover Name:'), 'name', array('value' => $oAlbum->name, 'required' => 1, 'pattern' => $sTitlePattern, 'validation' => new \PFBC\Validation\RegExp($sTitlePattern))));
42
        $oForm->addElement(new \PFBC\Element\Textarea(t('Album Cover Description:'), 'description', array('value' => $oAlbum->description, 'validation' => new \PFBC\Validation\Str(2, 200))));
43
        $oForm->addElement(new \PFBC\Element\Button);
44
        $oForm->render();
45
    }
46
}
47