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 'label' => _m("Initialize"),
64 'progress' => _m('No import running'),
65 'complete' => _m('Initiated Yammer server connection...'),
67 'requesting-auth' => array(
68 'label' => _m('Connect to Yammer'),
69 'progress' => _m('Awaiting authorization...'),
70 'complete' => _m('Connected.'),
72 'import-users' => array(
73 'label' => _m('Import user accounts'),
74 'progress' => sprintf(_m("Importing %d user...", "Importing %d users...", $userCount), $userCount),
75 'complete' => sprintf(_m("Imported %d user.", "Imported %d users.", $userCount), $userCount),
77 'import-groups' => array(
78 'label' => _m('Import user groups'),
79 'progress' => sprintf(_m("Importing %d group...", "Importing %d groups...", $groupCount), $groupCount),
80 'complete' => sprintf(_m("Imported %d group.", "Imported %d groups.", $groupCount), $groupCount),
82 'fetch-messages' => array(
83 'label' => _m('Prepare public notices for import'),
84 'progress' => sprintf(_m("Preparing %d notice...", "Preparing %d notices...", $fetchedCount), $fetchedCount),
85 'complete' => sprintf(_m("Prepared %d notice.", "Prepared %d notices.", $fetchedCount), $fetchedCount),
87 'save-messages' => array(
88 'label' => _m('Import public notices'),
89 'progress' => sprintf(_m("Importing %d notice...", "Importing %d notices...", $savedCount), $savedCount),
90 'complete' => sprintf(_m("Imported %d notice.", "Imported %d notices.", $savedCount), $savedCount),
93 'label' => _m('Done'),
94 'progress' => sprintf(_m("Import is complete!")),
95 'complete' => sprintf(_m("Import is complete!")),
98 $steps = array_keys($labels);
99 $currentStep = array_search($runner->state(), $steps);
101 $classes = array('yammer-import');
103 $classes[] = 'yammer-error';
105 $classes[] = 'yammer-running';
107 $this->out->elementStart('fieldset', array('class' => implode(' ', $classes)));
108 $this->out->element('legend', array(), _m('Import status'));
109 foreach ($steps as $step => $state) {
110 if ($state == 'init') {
111 // Don't show 'init', it's boring.
114 if ($step < $currentStep) {
116 $this->progressBar($state,
118 $labels[$state]['label'],
119 $labels[$state]['complete']);
120 } else if ($step == $currentStep) {
121 // This step is in progress
122 $this->progressBar($state,
124 $labels[$state]['label'],
125 $labels[$state]['progress'],
128 // This step has not yet been done.
129 $this->progressBar($state,
131 $labels[$state]['label'],
135 $this->out->elementEnd('fieldset');
138 private function progressBar($state, $class, $label, $status, $error=null)
140 // @fixme prettify ;)
141 $this->out->elementStart('div', array('class' => "import-step import-step-$state $class"));
142 $this->out->element('div', array('class' => 'import-label'), $label);
143 $this->out->element('div', array('class' => 'import-status'), $status);
144 if ($class == 'progress') {
145 if ($state == 'done') {
146 $this->out->submit('abort-import', _m('Reset import state'));
149 $this->errorBox($error);
151 $this->out->submit('pause-import', _m('Pause import'));
155 $this->out->elementEnd('div');
158 private function errorBox($msg)
160 $errline = sprintf(_m('Encountered error "%s"'), $msg);
161 $this->out->elementStart('fieldset', array('class' => 'import-error'));
162 $this->out->element('legend', array(), _m('Paused'));
163 $this->out->element('p', array(), $errline);
164 $this->out->submit('continue-import', _m('Continue'));
165 $this->out->submit('abort-import', _m('Abort import'));
166 $this->out->elementEnd('fieldset');