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
<?php
class NewsArticle extends DataObject
{
    static $db = array (
        'Date' => 'Date',
        'Author' => 'Text',
        'NewsContent' => 'HTMLText'
        );

    static $has_one = array (
        'NewsHolder' => 'NewsHolder', 
        'NewsCategory' => 'NewsCategory'
        );

    public function getCMSFields_forPopup()
    {
        $fields = new FieldSet();
        $fields->push( new CalendarDateField('Date') );
        $fields->push( new TextField('Author') );
        $fields->push( new SimpleTinyMCEField('NewsContent','News Content') );
        $oData = (DataObject::get('NewsCategory'));
        if ($oData) $CategoriesSource = $oData->toDropDownMap('ID','NewsCategory');   	
        $dropdown = new DropdownField('NewsCategoryID','NewsCategory',$CategoriesSource);
        $dropdown->setEmptyString('-- Select category --');
        $fields->push ( $dropdown );
        return $fields;
    }
}
?>

<?php
    class NewsCategory extends DataObject
    {
    	static $db = array (
    		'NewsCategory' => 'Varchar(100)'
    	);
    	
    	static $has_one = array (
    		'NewsHolder' => 'NewsHolder'
    	);
    	
    	static $has_many = array (
    	    'NewsArticles' => 'NewsArticle'
    	);
    	
    	public function getCMSFields_forPopup() {
              return new FieldSet(
      			new TextField('NewsCategory', 'Category')
      		);
        }

    }
?>

<?php
/**
 * Defines the News Holder type
 */
class NewsHolder extends Page {
   static $db = array(
   );
   static $has_one = array(
   );
   static $icon = "sitefiles/images/treeicons/news";

   static $has_many = array (
   		'NewsArticles' => 'NewsArticle', 
   		'NewsCategories' => 'NewsCategory'
   	);

   	public function getCMSFields()
   	{
   		$f = parent::getCMSFields();
   		$f->addFieldToTab("Root.Content.NewsArticles", new DataObjectManager(
   			$this,
   			'NewsArticles',
   			'NewsArticle',
   			array('Date' => 'Date','Author'=>'Author','NewsContent' => 'NewsContent', 'NewsCategoryID' => 'NewsCategoryID'),
   			'getCMSFields_forPopup'
   		));
   		$f->addFieldToTab("Root.Content.NewsCategories", new DataObjectManager(
   			$this,
   			'NewsCategories',
   			'NewsCategory',
   			array('NewsCategory'=>'Category'),
   			'getCMSFields_forPopup'
   		));
   		return $f;
   	}


}

class NewsHolder_Controller extends Page_Controller {

}

?>