source: trunk/jpdd/class.jpdd.workshop.php @ 72

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

JPDD: added organizations (with descriptions), editable by admins.

File size: 3.9 KB
Line 
1<?php  /* -*- indent-tabs-mode: nil; tab-width: 4; c-basic-offset: 2; -*-
2
3       */
4
5require_once('class.dkg.row.php');
6
7if (!class_exists('JPDD_Workshop')) {
8
9  class JPDD_Workshop extends DKG_Row {
10
11        var $_short_title_length = 35;
12
13        function getCreatePrivilege() {
14          return array('Update Workshops');
15        }
16       
17        function getEditPrivilege() {
18          return array('Update Workshops');
19        }
20
21        function getAttendees($flavor) {
22          global $jpdd;
23          $jpdd->prepClass('person');
24          return $jpdd->getSeriesFromSQL('SELECT person.* FROM person JOIN attendance ON (person.id = attendance.person_id) WHERE workshop_id = '.$this->getID().' AND flavor = '.$jpdd->escStr($flavor), 'JPDD_Person');
25        }
26
27        function getFormInnards() {
28          global $jpdd;
29          return '<div>
30<label>Title<br/><input type="text" size="72" name="title" value="'.$this->getTitle(true).'"/></label><br/>
31<label>Short Title<br/><input type="text" maxlength="'.(int)$this->_short_title_length.'" name="short_title" value="'.htmlentities($this->_short_title).'"/></label><br/>
32<label>Description<br/><textarea name="description" rows="20" cols="80">'.$this->getDescription(true).'</textarea></label>
33<div class="attendance" style="text-align: right;">
34<label>Min. Attendees: <input type="text" size="2" maxlength="2" name="min_attendees" value="'.($jpdd->isEmpty($this->_min_attendees) ? '' : (int)$this->_min_attendees).'"/></label><br/>
35<label>Max. Attendees: <input type="text" size="2" maxlength="2" name="max_attendees" value="'.($jpdd->isEmpty($this->_max_attendees) ? '' : (int)$this->_max_attendees).'"/></label>
36</div>
37</div>';
38        }
39
40        function applyPostForm() {
41          $this->_title = $_POST['title'];
42          $this->_short_title = $_POST['short_title'];
43          $this->_description = $_POST['description'];
44          $this->_min_attendees = $_POST['min_attendees'];
45          $this->_max_attendees = $_POST['max_attendees'];
46        }
47
48        function handleEdit() {
49          global $jpdd;
50          $this->applyPostForm();
51          $res = $jpdd->executeSQL('UPDATE '.$this->getSingletonTable().' SET '.
52                                                           'title = '.$jpdd->escStr($this->_title).', '.
53                                                           'short_title = '.$jpdd->stringOrDefault($this->_short_title).', '.
54                                                           'description = '.$jpdd->escStr($this->_description).', '.
55                                                           'min_attendees = '.$jpdd->intOrDefault($this->_min_attendees).', '.
56                                                           'max_attendees = '.$jpdd->intOrDefault($this->_max_attendees).' WHERE '.
57                                                           'id = '.$this->getID(), false);
58          if (false === $res) {
59                return false;
60          } else {
61                $this->JPDD_Workshop(array('id' => $this->getID()));
62                return true;
63          }
64        }
65
66        function handleCreation() {
67          // just insert a new row, grab the created ID, and re-initialize
68          // ourselves, returning true if successful.
69          global $jpdd;
70          $this->applyPostForm();
71          $res = $jpdd->executeSQL('INSERT INTO '.$this->getSingletonTable().' (title, short_title, description, min_attendees, max_attendees) VALUES ('.
72                                                           $jpdd->escStr($this->_title).', '.
73                                                           $jpdd->stringOrDefault($this->_short_title).', '.
74                                                           $jpdd->escStr($this->_description).', '.
75                                                           $jpdd->intOrDefault($this->_min_attendees).', '.
76                                                           $jpdd->intOrDefault($this->_max_attendees).')', false);
77          if (false === $res) {
78                return false;
79          } else {
80                $this->JPDD_Workshop(array('data' => $jpdd->getSingletonFromSQL('SELECT * from workshop WHERE id = currval(\'workshop_id_seq\')')));
81                return true;
82          }
83        }
84
85        function getDetailInnards() {
86          global $jpdd;
87
88          $presenters = $this->getAttendees('presenter');
89          if (count($presenters)) {
90                $ret .= '<div>Presented by: '.join(', ', array_map(create_function('$xx', 'return $xx->getLinkedTitle();'), $presenters)).'</div>';
91          }
92
93          $ret .= '<div class="workshop-blurb">'.$this->getDescription().'</div>';
94
95          $ret .= '<div class="attendance">Min. Attendees: '.(int)($this->_min_attendees).'<br/>'.
96                'Max. Attendees: '.(int)($this->_max_attendees).'<br/>'.
97                'Current Attendees: '.count($this->getAttendees('attendee')).
98                '</div>';
99          return $ret;
100        }
101  }
102}
Note: See TracBrowser for help on using the repository browser.