Typo
[AOOS.git] / modules / News / News.php
blob1314d8e6c9c6d0dd1977382b065dcbea71162219
1 <?php
3 /**
4 * News-module
5 * @author Sebastian Skejø
6 */
8 class News extends AOOSModule
10 private $_view = null;
12 public function __construct($core) {
13 parent::__construct($core);
14 $view = new NewsView($this);
15 $this->_view = $view;
18 static public function dependencies() {
19 return array("Paginator", "Form", "Reciever");
22 static public function files() {
23 return array("NewsView" => "NewsView.php");
26 public function dataModelDefinition() {
27 $m = new AOOSModel($this->core());
28 $m->setSource("mysql");
29 $m->setTable("News");
30 $m->setColumnIndex(array("author", "title", "date", "content", "id"));
31 $m->setProperties("id", AOOSMODEL_TYPE_INTEGER, AOOSMODEL_FLAG_FROM_DATABASE|AOOSMODEL_FLAG_PRIMARY_KEY|AOOSMODEL_FLAG_GUI_PRIVATE);
32 $m->setProperties("author", AOOSMODEL_TYPE_STRING,
33 AOOSMODEL_FLAG_FROM_DATABASE,
34 AOOSMODEL_PROP_ESCAPE|
35 AOOSMODEL_PROP_NOHTML|
36 AOOSMODEL_PROP_STRIP);
37 $m->setProperties("title", AOOSMODEL_TYPE_STRING,
38 AOOSMODEL_FLAG_FROM_DATABASE,
39 AOOSMODEL_PROP_ESCAPE|
40 AOOSMODEL_PROP_NOHTML|
41 AOOSMODEL_PROP_STRIP);
42 $m->setProperties("date", AOOSMODEL_TYPE_INTEGER,
43 AOOSMODEL_FLAG_FROM_DATABASE|AOOSMODEL_FLAG_GUI_PRIVATE,
44 AOOSMODEL_PROP_TIME);
45 $m->setProperties("content", AOOSMODEL_TYPE_TEXT,
46 AOOSMODEL_FLAG_FROM_DATABASE,
47 AOOSMODEL_PROP_ESCAPE|
48 AOOSMODEL_PROP_NOHTML);
49 return $m;
52 public function show() {
53 $this->dataModel()->populate(null, array("id", "DESC")); // Get all fields ordered descending by id
54 $p = $this->core()->getModule("Paginator");
55 switch($p->getOption(0)) {
56 case("add"):
57 return $this->_view->add();
58 break;
59 case("show"):
60 return $this->_view->show();
61 break;
62 default:
63 return $this->_view->noargs();
64 break;
68 public function addNews($news) {
69 $this->dataModel()->appendRow($news);
70 $this->dataModel()->save();
71 $this->emit("newsAdded", $news->title);
72 WidgetInterface::addMessage($news->title."' added!'");
73 return true;
76 /**
77 * @param $newsid The news id
79 public function deleteNews($newsid) {
80 $this->dataModel()->remove($newsid);
81 $this->dataModel()->save();
82 $this->emit("newsDeleted", $newsid);
83 return true;
87 class NewsView extends AOOSModule {
88 static public function dependencies() {
89 return array("Form", "Reciever", "Paginator");
92 public function add() {
93 $f = $this->core()->getModule("Form")->getWidget("Form");
94 $r = $this->core()->getModule("Reciever");
95 $p = $this->core()->getModule("Paginator");
97 if ($row = $r->getRow("POST")) {
98 $this->parent()->addNews($row);
101 $ignorecols = array("id");
102 $f->setAction($p->currentURL());
103 $f->setMethod("POST");
104 $f->setModel($this->parent()->dataModel());
105 return $f;
108 public function show() {
109 $p = $this->core()->getModule("Paginator");
110 $f = $this->core()->getModule("Form");
111 $l = $f->getWidget("List");
112 $modpath = $this->core()->getSetting("module_dir");
113 $l->setStyle(file_get_contents($modpath.'News/news_show.tmpl'));
114 return $l->strRow($this->parent()->dataModel()->find(array("id" => $p->getOption(1))));
117 public function noargs() {
118 $p = $this->core()->getModule("Paginator");
119 $f = $this->core()->getModule("Form");
120 $l = $f->getWidget("List");
121 $modpath = $this->core()->getSetting("module_dir");
122 $l->setStyle(file_get_contents($modpath.'News/news_default.tmpl'));
123 $l->setModel($this->parent()->dataModel());
124 return $l;
127 // vim: number