]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/ExtendedProfile/extendedprofilewidget.php
Edit page placeholder, link on main profile to details
[quix0rs-gnu-social.git] / plugins / ExtendedProfile / extendedprofilewidget.php
1 <?php
2 /*
3  * StatusNet - the distributed open-source microblogging tool
4  * Copyright (C) 2011, StatusNet, Inc.
5  *
6  * This program is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU Affero General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU Affero General Public License for more details.
15  *
16  * You should have received a copy of the GNU Affero General Public License
17  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
18  */
19
20 if (!defined('STATUSNET')) {
21     exit(1);
22 }
23
24 class ExtendedProfileWidget extends Widget
25 {
26     const EDITABLE=true;
27
28     protected $profile;
29     protected $ext;
30
31     public function __construct(XMLOutputter $out=null, Profile $profile=null, $editable=false)
32     {
33         parent::__construct($out);
34
35         $this->profile = $profile;
36         $this->ext = new ExtendedProfile($this->profile);
37
38         $this->editable = $editable;
39     }
40
41     public function show()
42     {
43         $sections = $this->ext->getSections();
44         foreach ($sections as $name => $section) {
45             $this->showExtendedProfileSection($name, $section);
46         }
47     }
48
49     protected function showExtendedProfileSection($name, $section)
50     {
51         $this->out->element('h3', null, $section['label']);
52         $this->out->elementStart('table', array('class' => 'extended-profile'));
53         foreach ($section['fields'] as $fieldName => $field) {
54             $this->showExtendedProfileField($fieldName, $field);
55         }
56         $this->out->elementEnd('table');
57     }
58
59     protected function showExtendedProfileField($name, $field)
60     {
61         $this->out->elementStart('tr');
62
63         $this->out->element('th', null, $field['label']);
64
65         $this->out->elementStart('td');
66         if ($this->editable) {
67             $this->showEditableField($name, $field);
68         } else {
69             $this->showFieldValue($name, $field);
70         }
71         $this->out->elementEnd('td');
72
73         $this->out->elementEnd('tr');
74     }
75
76     protected function showFieldValue($name, $field)
77     {
78         $this->out->text($name);
79     }
80
81     protected function showEditableField($name, $field)
82     {
83         $out = $this->out;
84         //$out = new HTMLOutputter();
85         // @fixme
86         $type = strval(@$field['type']);
87         $id = "extprofile-" . $name;
88         $value = 'placeholder';
89
90         switch ($type) {
91             case '':
92             case 'text':
93                 $out->input($id, null, $value);
94                 break;
95             case 'textarea':
96                 $out->textarea($id, null, $value);
97                 break;
98             default:
99                 $out->input($id, null, "TYPE: $type");
100         }
101     }
102 }