Completed
Pull Request — master (#203)
by
unknown
40:36
created

ForumCategory   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 0
dl 0
loc 42
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A getCMSFieldsForPopup() 0 14 2
1
<?php
2
3
namespace SilverStripe\Forum\Models;
4
5
use SilverStripe\Forms\TextField;
6
use SilverStripe\Forms\DropdownField;
7
use SilverStripe\Forms\FieldList;
8
use SilverStripe\Forum\Pages\ForumHolder;
9
use SilverStripe\ORM\DataObject;
10
use SilverStripe\ORM\FieldType\DBVarchar;
11
12
/**
13
 * A Forum Category is applied to each forum page in a has one relation.
14
 *
15
 * These will be editable via the {@link GridField} on the Forum object.
16
 *
17
 * @TODO    replace StackableOrder with the SortableGridField module implementation.
18
 *
19
 * @package forum
20
 * @property DBVarchar Title
21
 * @property DBVarchar StackableOrder
22
 * @method ForumHolder ForumHolder
23
 */
24
class ForumCategory extends DataObject
25
{
26
    /** @var array */
27
    private static $db = array(
28
        'Title'          => 'Varchar(100)',
29
        'StackableOrder' => 'Varchar(2)'
30
    );
31
32
    /** @var array */
33
    private static $has_one = array(
34
        'ForumHolder' => 'ForumHolder'
35
    );
36
37
    /** @var array */
38
    private static $has_many = array(
39
        'Forums' => 'Forum'
40
    );
41
42
    /** @var string */
43
    private static $default_sort = 'StackableOrder DESC';
44
45
    /**
46
     * Get the fields for the category edit/ add
47
     * in the complex table field popup window.
48
     *
49
     * @return FieldList
50
     */
51
    public function getCMSFieldsForPopup()
52
    {
53
54
        // stackable order is a bit of a workaround for sorting in complex table
55
        $values = array();
56
        for ($i = 1; $i < 100; $i++) {
57
            $values[$i] = $i;
58
        }
59
60
        return FieldList::create(
61
            TextField::create('Title'),
62
            DropdownField::create('StackableOrder', 'Select the Ordering (99 top of the page, 1 bottom)', $values)
63
        );
64
    }
65
}
66