ProductObject

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
<?php
/**
 * Base class for Product DataObjects.
 *
 * Sets up standard $db fields, default data relation, and CMSFields method.
 * Child classes will usually only need to modify $belongs_many_many to allow
 * separate relations between product categories.
 * If extra $db fields are needed then getCMSFields() will need to be
 * extended as well.
 *
 * @todo add product photo relation
 * @todo research adding icons with the checkboxes in the popup
 * @todo look into changing $db['description'] to wysiwyg field in popup
 */
class ProductObject extends DataObject {
    static $db = array (
    'name' => 'Text',
    'code' => 'Text',
    'description' => 'Text',
    'voc' => 'Boolean',
    'bodyshop' => 'Boolean',
    'phosphate' => 'Boolean',
    'npe' => 'Boolean',
    );

    static $has_one = array (
    'MyProductSheet' => 'File',
    'MyMSDS' => 'File'
    );

    static $many_many = array(
      'AvailableSizes' => 'ProductSize',
    );

    function getCMSFields() {
        return new FieldSet(
        new TextField('code', 'Product Code'),
        new TextField('name', 'Product Name'),
        new TextAreaField('description', 'Description'),
        // HTML tags are coming through escaped. Need to solve before using.
        #new SimpleTinyMCEField('description', 'Description'),
        new CheckboxField(
        $name = "voc",
        $title = "VOC Compliant"),
        new CheckboxField(
        $name = "bodyshop",
        $title = "Bodyshop Safe"),
        new CheckboxField(
        $name = "phosphate",
        $title = "Phosphate Free"),
        new CheckboxField(
        $name = "npe",
        $title = "NPE Free"),
        new FileIFrameField('MyProductSheet', 'Upload Product Data Sheet'),
        new FileIFrameField('MyMSDS', 'Upload MSDS'),
        new ManyManyDataObjectManager(
            $this,
            'AvalableSizes',
            'ProductSize',
            array(
            'size' => 'Size',
            )
        )
        );
    }

}
?>

ProductObjectAdditive

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
<?php
/**
 * Child of ProductObject
 *
 * $belongs_many_many extended with new key=>value to separate relation from
 * sibling classes. If $db is extended then getCMSFields() needs to
 * be extended as well. The matching ProductList child may need getCMSFields()
 * extended to accomidate the change as well.
 *
 * @author Joshua Lewis
 */
class ProductObjectAdditive extends ProductObject
{
    static $db = array();

    static $belongs_many_many = array(
    'AdditiveLists' => 'ProductListAdditive',
    );
}
?>

ProductList

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
<?php
/**
 * Base class for productholder pages.
 *
 * Most children will extend it only to keep separate relations between product
 * categories but may also extend $db and getCMSFields().
 *
 * @todo look into having custom titles for in the CMS page type dropdown.
 */
class ProductList extends Page {
    static $db = array();

    /**
     * Sets the the value for DataObjectManager/ComplexTableField to use as
     * $sourceClass parameter.
     *
     * Must be set in each child class to get unique relationships and needs to
     * match the source class of relationship set in static $many_many array.
     * This setup keeps getCMSFields from having to be set in each child when
     * the only change would be $sourceClass.
     *
     * In testing $many_many would only accept direct string for value and
     * cause an error when this variable was called in it's place.
     *
     * @var String
     */
    protected $dataObjectSourceClass = 'ProductObject';

    /**
     * Generic site tree icon for all product list pages. Overwritten in
     * children for better usability.
     *
     * -file.gif is appended to path given so name files accordingly
     *
     * @var sting filepath to 16x16 gif icon for site tree.
     */
    static $icon = "themes/stinger/img/treeicons/product_list";

    /**
     * Used to tell if a user can create pages of this type.
     *
     * Since this page type is intended to contain common elements for child
     * pages and shoulden't be used to create pages for the site and should always
     * return false. Child page types will have to overload it and return true
     * or else they won't be available
     *
     * @return TRUE/FALSE
     */
    function canCreate()
    {
        return FALSE;
    }

    /**
     * Extends standard FieldSets with DataObjectManager to manage Products
     * relation.
     * $dataObjectSourceClass lets children easily change to fit their relation
     * when no extra fields are needed without having to duplicate the method.
     *
     * @return FieldSet
     */
    function getCMSFields() {
        $fields = parent::getCMSFields();
        $productfields = new ManyManyDataObjectManager(
            $this,
            'Products',
            // Set at top of class and in sub-classes, see comments above.
            $this->dataObjectSourceClass,
            array(
            'code' => 'Code',
            'name' => 'Name',
            'description' => 'Description',
            ),
            'getCMSFields'
        );
        $productfields->setColumnWidths(array(
            'code' => 10,
            'name' => 30,
            'description' => 60
        ));
        $productfields->setAddTitle('A Product');
        $fields->removeFieldfromTab('Root.Content.Main', 'Content');
        $fields->addFieldToTab('Root.Content.Main', $productfields);
        return $fields;
    }
}

ProductListAdditive

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
<?php
/**
 * Overwrites ProductList relation with new one targeting appropriate child
 * class of ProductObject to keep separate relations between product Categories.
 * Can be used to extend $db and CMSFields with new fields as needed.
 * $many_many key needs to match key used in ProductList or an error is produced
 * I don't know why that happens.
 *
 * @author Joshua Lewis
 */
class ProductListAdditive extends ProductList
{
    static $db = array();
    protected $dataObjectSourceClass = 'ProductObjectAdditive';
    static $many_many = array(
    'Products' => 'ProductObjectAdditive'
    );

    /**
     * Overwrites icon set in parent class for better usability.
     *
     * This icon should be a variation of the ProductList's icon so that pages
     * of this type can be differentiated from siblings but still recognized as
     * being from in the same family.
     *
     * @var sting filepath to 16x16 gif icon for site tree.
     */
    static $icon = "themes/stinger/img/treeicons/additive_list";

    /**
     * Used to tell if a user can create pages of this type.
     *
     * Overloads inherited version from Product list. If not done pages of this
     * type could never be created in the CMS.
     *
     * @return TRUE/FALSE
     */
    function canCreate()
    {
        return TRUE;
    }
}

ProductSize

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
<?php
/**
 * Package sizes for products.
 *
 * When used in a many_many relation with ProductObjects this class allows
 * different sets of available products sizes to be set for each product.
 *
 * @author Joshua
 */
class ProductSize extends DataObject
{
    public static $db = array(
    'size' => 'Text',
    );

    public static $belongs_many_many = array(
    'AvailableSizes' => 'ProductObject',
    );

    function getCMSFields() {
        return new FieldSet(
        new TextField('size', 'Package Size')
        );
    }
}
?>