]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/YammerImport/actions/yammeradminpanel.php
Pretty it up a bit more
[quix0rs-gnu-social.git] / plugins / YammerImport / actions / yammeradminpanel.php
1 <?php
2 /**
3  * StatusNet, the distributed open-source microblogging tool
4  *
5  * Yammer import administration panel
6  *
7  * PHP version 5
8  *
9  * LICENCE: This program is free software: you can redistribute it and/or modify
10  * it under the terms of the GNU Affero General Public License as published by
11  * the Free Software Foundation, either version 3 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU Affero General Public License for more details.
18  *
19  * You should have received a copy of the GNU Affero General Public License
20  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
21  *
22  * @category  Settings
23  * @package   StatusNet
24  * @author    Zach Copley <zach@status.net>
25  * @copyright 2010 StatusNet, Inc.
26  * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
27  * @link      http://status.net/
28  */
29
30 if (!defined('STATUSNET')) {
31     exit(1);
32 }
33
34 class YammeradminpanelAction extends AdminPanelAction
35 {
36     /**
37      * Returns the page title
38      *
39      * @return string page title
40      */
41     function title()
42     {
43         return _m('Yammer Import');
44     }
45
46     /**
47      * Instructions for using this form.
48      *
49      * @return string instructions
50      */
51     function getInstructions()
52     {
53         return _m('Yammer import tool');
54     }
55
56     /**
57      * Show the Yammer admin panel form
58      *
59      * @return void
60      */
61     function showForm()
62     {
63         $form = new YammerAdminPanelForm($this);
64         $form->show();
65         return;
66     }
67
68     function showStylesheets()
69     {
70         parent::showStylesheets();
71         $this->cssLink('plugins/YammerImport/css/admin.css', null, 'screen, projection, tv');
72     }
73 }
74
75 class YammerAdminPanelForm extends AdminForm
76 {
77     /**
78      * ID of the form
79      *
80      * @return string ID of the form
81      */
82     function id()
83     {
84         return 'yammeradminpanel';
85     }
86
87     /**
88      * class of the form
89      *
90      * @return string class of the form
91      */
92     function formClass()
93     {
94         return 'form_settings';
95     }
96
97     /**
98      * Action of the form
99      *
100      * @return string URL of the action
101      */
102     function action()
103     {
104         return common_local_url('yammeradminpanel');
105     }
106
107     /**
108      * Data elements of the form
109      *
110      * @return void
111      */
112     function formData()
113     {
114         $runner = YammerRunner::init();
115
116         switch($runner->state())
117         {
118             case 'init':
119             case 'requesting-auth':
120                 $this->showAuthForm();
121             default:
122         }
123         $this->showImportState($runner);
124     }
125
126     private function showAuthForm()
127     {
128         $this->out->element('p', array(), 'show an auth form');
129     }
130
131     private function showImportState(YammerRunner $runner)
132     {
133         $userCount = $runner->countUsers();
134         $groupCount = $runner->countGroups();
135         $fetchedCount = $runner->countFetchedNotices();
136         $savedCount = $runner->countSavedNotices();
137
138         $labels = array(
139             'init' => array(
140                 'label' => _m("Initialize"),
141                 'progress' => _m('No import running'),
142                 'complete' => _m('Initiated Yammer server connection...'),
143             ),
144             'requesting-auth' => array(
145                 'label' => _m('Connect to Yammer'),
146                 'progress' => _m('Awaiting authorization...'),
147                 'complete' => _m('Connected.'),
148             ),
149             'import-users' => array(
150                 'label' => _m('Import user accounts'),
151                 'progress' => sprintf(_m("Importing %d user...", "Importing %d users...", $userCount), $userCount),
152                 'complete' => sprintf(_m("Imported %d user.", "Imported %d users.", $userCount), $userCount),
153             ),
154             'import-groups' => array(
155                 'label' => _m('Import user groups'),
156                 'progress' => sprintf(_m("Importing %d group...", "Importing %d groups...", $groupCount), $groupCount),
157                 'complete' => sprintf(_m("Imported %d group.", "Imported %d groups.", $groupCount), $groupCount),
158             ),
159             'fetch-messages' => array(
160                 'label' => _m('Prepare public notices for import'),
161                 'progress' => sprintf(_m("Preparing %d notice...", "Preparing %d notices...", $fetchedCount), $fetchedCount),
162                 'complete' => sprintf(_m("Prepared %d notice.", "Prepared %d notices.", $fetchedCount), $fetchedCount),
163             ),
164             'save-messages' => array(
165                 'label' => _m('Import public notices'),
166                 'progress' => sprintf(_m("Importing %d notice...", "Importing %d notices...", $savedCount), $savedCount),
167                 'complete' => sprintf(_m("Imported %d notice.", "Imported %d notices.", $savedCount), $savedCount),
168             ),
169             'done' => array(
170                 'label' => _m('Done'),
171                 'progress' => sprintf(_m("Import is complete!")),
172                 'complete' => sprintf(_m("Import is complete!")),
173             )
174         );
175         $steps = array_keys($labels);
176         $currentStep = array_search($runner->state(), $steps);
177
178         $this->out->elementStart('fieldset', array('class' => 'yammer-import'));
179         $this->out->element('legend', array(), _m('Import status'));
180         foreach ($steps as $step => $state) {
181             if ($step < $currentStep) {
182                 // This step is done
183                 $this->progressBar($state,
184                                    'complete',
185                                    $labels[$state]['label'],
186                                    $labels[$state]['complete']);
187             } else if ($step == $currentStep) {
188                 // This step is in progress
189                 $this->progressBar($state,
190                                    'progress',
191                                    $labels[$state]['label'],
192                                    $labels[$state]['progress']);
193             } else {
194                 // This step has not yet been done.
195                 $this->progressBar($state,
196                                    'waiting',
197                                    $labels[$state]['label'],
198                                    _m("Waiting..."));
199             }
200         }
201         $this->out->elementEnd('fieldset');
202     }
203
204     private function progressBar($state, $class, $label, $status)
205     {
206         // @fixme prettify ;)
207         $this->out->elementStart('div', array('class' => "import-step import-step-$state $class"));
208         $this->out->element('div', array('class' => 'import-label'), $label);
209         $this->out->element('div', array('class' => 'import-status'), $status);
210         $this->out->elementEnd('div');
211     }
212
213     /**
214      * Action elements
215      *
216      * @return void
217      */
218     function formActions()
219     {
220         // No submit buttons needed at bottom
221     }
222 }