source: trunk/jpdd/class.dkg.row.php @ 71

Last change on this file since 71 was 71, checked in by dkg, 6 years ago

JPDD: allow editing of people as well.

File size: 3.5 KB
Line 
1<?php  /* -*- indent-tabs-mode: nil; tab-width: 4; c-basic-offset: 2; -*-
2
3       */
4
5if (!class_exists('DKG_Row')) {
6
7  class DKG_Row {
8        function DKG_Row($args) {
9          global $dkg_site;
10          if (is_array($args)) {
11                if (array_key_exists('id', $args)) {
12                  $args['data'] = $dkg_site->getSingletonFromSQL('SELECT * FROM '.$this->getSingletonTable().' WHERE id = '.(int)$args['id']);
13                } 
14                if (array_key_exists('data', $args)) {
15                  reset($args['data']);
16                  while (list($k,$v) = each($args['data'])) {
17                        $title = '_'.$k;
18                        $this->$title = $v;
19                  }
20                }
21          }
22        }
23
24    // set up basic form:
25        function getCreationForm() {
26      global $dkg_site;
27      $sn = $this->getShortName();
28      return '<form action='.$dkg_site->Path('edit', $sn).' method="post">
29<fieldset><legend>New '.$sn.'</legend>
30'.$dkg_site->getFormTokenHiddenInput().'
31'.$this->getCreationFormInnards().'
32<div style="clear:both;"><input type="submit" value="Make new '.$sn.'"/></div>
33</form>
34';
35        }
36
37    // set up basic form:
38        function getEditForm() {
39      global $dkg_site;
40      $sn = $this->getShortName();
41      return '<form action='.$this->getEditPath().' method="post">
42<fieldset><legend>Edit '.$sn.' '.$this->getLinkedTitle().'</legend>
43'.$dkg_site->getFormTokenHiddenInput().'
44'.$this->getEditFormInnards().'
45<div style="clear:both;"><input type="submit" value="Save changes"/></div>
46</form>
47';
48        }
49
50
51    // override to allow creation and editing...
52    // NULL means anyone can create or edit
53    // an array means anyone with any of the privileges in the array
54    // can do this thing.
55        function getCreatePrivilege() {
56          return array();
57        }
58        function getEditPrivilege() {
59          return array();
60        }
61
62
63        function getSingletonTable() {
64          global $dkg_site;
65          return $dkg_site->getSingletonTable(get_class($this));
66        }
67        function getShortName() {
68          global $dkg_site;
69          return $dkg_site->getShortName(get_class($this));
70        }
71
72        function getID() {
73          global $dkg_site;
74          if (!is_null($this->_id)) {
75                return (int)($this->_id);
76          } else {
77                $dkg_site->error('getID called on an item without an ID!');
78          }
79        }
80
81        function getTitle($allowempty = false) {
82          global $dkg_site;
83          if (!is_null($this->_title)) {
84                return htmlentities($this->_title);
85          } else {
86        if ($allowempty)
87          return '';
88        else
89          $dkg_site->error('getTitle called on an item without an title!');
90          }
91        }
92
93    function getViewPath() {
94          global $dkg_site;
95      return $dkg_site->Path($this->getShortName(), $this->getID());
96    }
97    function getEditPath() {
98          global $dkg_site;
99      return $dkg_site->Path('edit', $this->getShortName(), $this->getID());
100    }
101
102        function getLinkedTitle() {
103          return '<a href="'.$this->getViewPath().'">'.$this->getTitle().'</a>';
104        }
105
106        function getDescription($allowempty = false) {
107          global $dkg_site;
108          if (!is_null($this->_description)) {
109                return $dkg_site->filterBlock($this->_description);
110          } else {     
111        if ($allowempty)
112          return '';
113        else
114          $dkg_site->error('getDescription called on an item without a description!');
115          }
116        }
117
118        function getCreationFormInnards() {
119      return '';
120    }
121        function getDetailInnards() {
122      return '';
123    }
124
125        function getDetailView() {
126          global $dkg_site;
127
128          $ret = '<h2>'.$this->getTitle().'</h2>';
129      if (is_null($this->getEditPrivilege()) || ($dkg_site->isAuthenticated() && $dkg_site->_authenticated_user->canEdit($this))) {
130        $ret .= "\n".'<div><a href="'.$this->getEditPath().'">edit</a></div>'."\n";
131      }
132      $ret .= $this->getDetailInnards();
133          return $ret;
134        }
135  }
136
137}
Note: See TracBrowser for help on using the repository browser.