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 return 'form_settings';
28 * @return string URL of the action
32 return common_local_url('yammeradminpanel');
36 * Data elements of the form
42 $this->out->hidden('subaction', 'progress');
44 $runner = YammerRunner::init();
46 $error = $runner->lastError();
47 $userCount = $runner->countUsers();
48 $groupCount = $runner->countGroups();
49 $fetchedCount = $runner->countFetchedNotices();
50 $savedCount = $runner->countSavedNotices();
54 'label' => _m("Initialize"),
55 'progress' => _m('No import running'),
56 'complete' => _m('Initiated Yammer server connection...'),
58 'requesting-auth' => array(
59 'label' => _m('Connect to Yammer'),
60 'progress' => _m('Awaiting authorization...'),
61 'complete' => _m('Connected.'),
63 'import-users' => array(
64 'label' => _m('Import user accounts'),
65 'progress' => sprintf(_m("Importing %d user...", "Importing %d users...", $userCount), $userCount),
66 'complete' => sprintf(_m("Imported %d user.", "Imported %d users.", $userCount), $userCount),
68 'import-groups' => array(
69 'label' => _m('Import user groups'),
70 'progress' => sprintf(_m("Importing %d group...", "Importing %d groups...", $groupCount), $groupCount),
71 'complete' => sprintf(_m("Imported %d group.", "Imported %d groups.", $groupCount), $groupCount),
73 'fetch-messages' => array(
74 'label' => _m('Prepare public notices for import'),
75 'progress' => sprintf(_m("Preparing %d notice...", "Preparing %d notices...", $fetchedCount), $fetchedCount),
76 'complete' => sprintf(_m("Prepared %d notice.", "Prepared %d notices.", $fetchedCount), $fetchedCount),
78 'save-messages' => array(
79 'label' => _m('Import public notices'),
80 'progress' => sprintf(_m("Importing %d notice...", "Importing %d notices...", $savedCount), $savedCount),
81 'complete' => sprintf(_m("Imported %d notice.", "Imported %d notices.", $savedCount), $savedCount),
84 'label' => _m('Done'),
85 'progress' => sprintf(_m("Import is complete!")),
86 'complete' => sprintf(_m("Import is complete!")),
89 $steps = array_keys($labels);
90 $currentStep = array_search($runner->state(), $steps);
92 $classes = array('yammer-import');
94 $classes[] = 'yammer-error';
96 $classes[] = 'yammer-running';
98 $this->out->elementStart('fieldset', array('class' => implode(' ', $classes)));
99 $this->out->element('legend', array(), _m('Import status'));
100 foreach ($steps as $step => $state) {
101 if ($state == 'init') {
102 // Don't show 'init', it's boring.
105 if ($step < $currentStep) {
107 $this->progressBar($state,
109 $labels[$state]['label'],
110 $labels[$state]['complete']);
111 } else if ($step == $currentStep) {
112 // This step is in progress
113 $this->progressBar($state,
115 $labels[$state]['label'],
116 $labels[$state]['progress'],
119 // This step has not yet been done.
120 $this->progressBar($state,
122 $labels[$state]['label'],
126 $this->out->elementEnd('fieldset');
129 private function progressBar($state, $class, $label, $status, $error=null)
131 // @fixme prettify ;)
132 $this->out->elementStart('div', array('class' => "import-step import-step-$state $class"));
133 $this->out->element('div', array('class' => 'import-label'), $label);
134 $this->out->element('div', array('class' => 'import-status'), $status);
135 if ($class == 'progress') {
136 if ($state == 'done') {
137 $this->out->submit('abort-import', _m('Reset import state'));
140 $this->errorBox($error);
142 $this->out->submit('pause-import', _m('Pause import'));
146 $this->out->elementEnd('div');
149 private function errorBox($msg)
151 $errline = sprintf(_m('Encountered error "%s"'), $msg);
152 $this->out->elementStart('fieldset', array('class' => 'import-error'));
153 $this->out->element('legend', array(), _m('Paused'));
154 $this->out->element('p', array(), $errline);
155 $this->out->submit('continue-import', _m('Continue'));
156 $this->out->submit('abort-import', _m('Abort import'));
157 $this->out->elementEnd('fieldset');