3 class YammerProgressForm extends Form
8 * @return string ID of the form
12 return 'yammer-progress-form';
18 * @return string class of the form
22 $classes = array('form_settings');
23 $runner = YammerRunner::init();
24 if ($runner->lastError()) {
25 $classes[] = 'import-error';
26 } else if ($runner->state() == 'done') {
27 $classes[] = 'import-done';
29 $classes[] = 'import-progress';
31 return implode(' ', $classes);
37 * @return string URL of the action
41 return common_local_url('yammeradminpanel');
45 * Data elements of the form
51 $this->out->hidden('subaction', 'progress');
53 $runner = YammerRunner::init();
55 $error = $runner->lastError();
56 $userCount = $runner->countUsers();
57 $groupCount = $runner->countGroups();
58 $fetchedCount = $runner->countFetchedNotices();
59 $savedCount = $runner->countSavedNotices();
63 // TRANS: Field label for a Yammer import initialise step.
64 'label' => _m('Initialize'),
65 // TRANS: "In progress" description.
66 'progress' => _m('No import running'),
67 // TRANS: "Complete" description for initialize state.
68 'complete' => _m('Initiated Yammer server connection...'),
70 'requesting-auth' => array(
71 // TRANS: Field label for a Yammer import connect step.
72 'label' => _m('Connect to Yammer'),
73 // TRANS: "In progress" description.
74 'progress' => _m('Awaiting authorization...'),
75 // TRANS: "Complete" description for connect state.
76 'complete' => _m('Connected.'),
78 'import-users' => array(
79 // TRANS: Field label for a Yammer user import users step.
80 'label' => _m('Import user accounts'),
81 // TRANS: "In progress" description.
82 // TRANS: %d is the number of users to be imported.
83 'progress' => sprintf(_m('Importing %d user...',
84 'Importing %d users...',
87 // TRANS: "Complete" description for step.
88 // TRANS: %d is the number of users imported.
89 'complete' => sprintf(_m('Imported %d user.',
94 'import-groups' => array(
95 // TRANS: Field label for a Yammer group import step.
96 'label' => _m('Import user groups'),
97 // TRANS: "In progress" description.
98 // TRANS: %d is the number of groups to be imported.
99 'progress' => sprintf(_m('Importing %d group...',
100 'Importing %d groups...',
103 // TRANS: "Complete" description for step.
104 // TRANS: %d is the number of groups imported.
105 'complete' => sprintf(_m('Imported %d group.',
106 'Imported %d groups.',
110 'fetch-messages' => array(
111 // TRANS: Field label for a Yammer import prepare notices step.
112 'label' => _m('Prepare public notices for import'),
113 // TRANS: "In progress" description.
114 // TRANS: %d is the number of notices to be prepared for import.
115 'progress' => sprintf(_m('Preparing %d notice...',
116 'Preparing %d notices...',
119 // TRANS: "Complete" description for step.
120 // TRANS: %d is the number of notices prepared for import.
121 'complete' => sprintf(_m('Prepared %d notice.',
122 'Prepared %d notices.',
126 'save-messages' => array(
127 // TRANS: Field label for a Yammer import notices step.
128 'label' => _m('Import public notices'),
129 // TRANS: "In progress" description.
130 // TRANS: %d is the number of notices to be imported.
131 'progress' => sprintf(_m('Importing %d notice...',
132 'Importing %d notices...',
135 // TRANS: "Complete" description for step.
136 // TRANS: %d is the number of notices imported.
137 'complete' => sprintf(_m('Imported %d notice.',
138 'Imported %d notices.',
143 // TRANS: Field label for a Yammer import done step.
144 'label' => _m('Done'),
145 // TRANS: "In progress" description for done step.
146 'progress' => sprintf(_m('Import is complete!')),
147 // TRANS: "Complete" description for done step.
148 'complete' => sprintf(_m('Import is complete!')),
151 $steps = array_keys($labels);
152 $currentStep = array_search($runner->state(), $steps);
154 $classes = array('yammer-import');
156 $classes[] = 'yammer-error';
158 $classes[] = 'yammer-running';
160 $this->out->elementStart('fieldset', array('class' => implode(' ', $classes)));
161 // TRANS: Fieldset legend.
162 $this->out->element('legend', array(), _m('Import status'));
163 foreach ($steps as $step => $state) {
164 if ($state == 'init') {
165 // Don't show 'init', it's boring.
168 if ($step < $currentStep) {
170 $this->progressBar($state,
172 $labels[$state]['label'],
173 $labels[$state]['complete']);
174 } else if ($step == $currentStep) {
175 // This step is in progress
176 $this->progressBar($state,
178 $labels[$state]['label'],
179 $labels[$state]['progress'],
182 // This step has not yet been done.
183 $this->progressBar($state,
185 $labels[$state]['label'],
186 // TRANS: Progress bar status.
190 $this->out->elementEnd('fieldset');
193 private function progressBar($state, $class, $label, $status, $error=null)
195 // @fixme prettify ;)
196 $this->out->elementStart('div', array('class' => "import-step import-step-$state $class"));
197 $this->out->element('div', array('class' => 'import-label'), $label);
198 $this->out->element('div', array('class' => 'import-status'), $status);
199 if ($class == 'progress') {
200 if ($state == 'done') {
201 // TRANS: Button text for resetting the import state.
202 $this->out->submit('abort-import', _m('Reset import state'));
205 $this->errorBox($error);
207 // TRANS: Button text for pausing an import.
208 $this->out->submit('pause-import', _m('Pause import'));
212 $this->out->elementEnd('div');
215 private function errorBox($msg)
217 // TRANS: Error message. %s are the error details.
218 $errline = sprintf(_m('Encountered error "%s".'), $msg);
219 $this->out->elementStart('fieldset', array('class' => 'import-error'));
220 // TRANS: Fieldset legend for a paused import.
221 $this->out->element('legend', array(), _m('Paused'));
222 $this->out->element('p', array(), $errline);
223 // TRANS: Button text for continuing a paused import.
224 $this->out->submit('continue-import', _m('Continue'));
225 // TRANS: Button text for aborting a paused import.
226 $this->out->submit('abort-import', _m('Abort import'));
227 $this->out->elementEnd('fieldset');