]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/YammerImport/lib/yammerprogressform.php
Merge branch 'yammer-master'
[quix0rs-gnu-social.git] / plugins / YammerImport / lib / yammerprogressform.php
1 <?php
2
3 class YammerProgressForm extends Form
4 {
5     /**
6      * ID of the form
7      *
8      * @return string ID of the form
9      */
10     function id()
11     {
12         return 'yammer-progress';
13     }
14
15     /**
16      * class of the form
17      *
18      * @return string class of the form
19      */
20     function formClass()
21     {
22         return 'form_settings';
23     }
24
25     /**
26      * Action of the form
27      *
28      * @return string URL of the action
29      */
30     function action()
31     {
32         return common_local_url('yammeradminpanel');
33     }
34
35     /**
36      * Data elements of the form
37      *
38      * @return void
39      */
40     function formData()
41     {
42         $runner = YammerRunner::init();
43
44         $userCount = $runner->countUsers();
45         $groupCount = $runner->countGroups();
46         $fetchedCount = $runner->countFetchedNotices();
47         $savedCount = $runner->countSavedNotices();
48
49         $labels = array(
50             'init' => array(
51                 'label' => _m("Initialize"),
52                 'progress' => _m('No import running'),
53                 'complete' => _m('Initiated Yammer server connection...'),
54             ),
55             'requesting-auth' => array(
56                 'label' => _m('Connect to Yammer'),
57                 'progress' => _m('Awaiting authorization...'),
58                 'complete' => _m('Connected.'),
59             ),
60             'import-users' => array(
61                 'label' => _m('Import user accounts'),
62                 'progress' => sprintf(_m("Importing %d user...", "Importing %d users...", $userCount), $userCount),
63                 'complete' => sprintf(_m("Imported %d user.", "Imported %d users.", $userCount), $userCount),
64             ),
65             'import-groups' => array(
66                 'label' => _m('Import user groups'),
67                 'progress' => sprintf(_m("Importing %d group...", "Importing %d groups...", $groupCount), $groupCount),
68                 'complete' => sprintf(_m("Imported %d group.", "Imported %d groups.", $groupCount), $groupCount),
69             ),
70             'fetch-messages' => array(
71                 'label' => _m('Prepare public notices for import'),
72                 'progress' => sprintf(_m("Preparing %d notice...", "Preparing %d notices...", $fetchedCount), $fetchedCount),
73                 'complete' => sprintf(_m("Prepared %d notice.", "Prepared %d notices.", $fetchedCount), $fetchedCount),
74             ),
75             'save-messages' => array(
76                 'label' => _m('Import public notices'),
77                 'progress' => sprintf(_m("Importing %d notice...", "Importing %d notices...", $savedCount), $savedCount),
78                 'complete' => sprintf(_m("Imported %d notice.", "Imported %d notices.", $savedCount), $savedCount),
79             ),
80             'done' => array(
81                 'label' => _m('Done'),
82                 'progress' => sprintf(_m("Import is complete!")),
83                 'complete' => sprintf(_m("Import is complete!")),
84             )
85         );
86         $steps = array_keys($labels);
87         $currentStep = array_search($runner->state(), $steps);
88
89         $this->out->elementStart('fieldset', array('class' => 'yammer-import'));
90         $this->out->element('legend', array(), _m('Import status'));
91         foreach ($steps as $step => $state) {
92             if ($state == 'init') {
93                 // Don't show 'init', it's boring.
94                 continue;
95             }
96             if ($step < $currentStep) {
97                 // This step is done
98                 $this->progressBar($state,
99                                    'complete',
100                                    $labels[$state]['label'],
101                                    $labels[$state]['complete']);
102             } else if ($step == $currentStep) {
103                 // This step is in progress
104                 $this->progressBar($state,
105                                    'progress',
106                                    $labels[$state]['label'],
107                                    $labels[$state]['progress']);
108             } else {
109                 // This step has not yet been done.
110                 $this->progressBar($state,
111                                    'waiting',
112                                    $labels[$state]['label'],
113                                    _m("Waiting..."));
114             }
115         }
116         $this->out->elementEnd('fieldset');
117     }
118
119     private function progressBar($state, $class, $label, $status)
120     {
121         // @fixme prettify ;)
122         $this->out->elementStart('div', array('class' => "import-step import-step-$state $class"));
123         $this->out->element('div', array('class' => 'import-label'), $label);
124         $this->out->element('div', array('class' => 'import-status'), $status);
125         $this->out->elementEnd('div');
126     }
127
128 }