| 
									
										
										
										
											2010-09-24 17:22:44 -07:00
										 |  |  | <?php | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class YammerProgressForm extends Form | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * ID of the form | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @return string ID of the form | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     function id() | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2010-09-28 15:45:00 -07:00
										 |  |  |         return 'yammer-progress-form'; | 
					
						
							| 
									
										
										
										
											2010-09-24 17:22:44 -07:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * class of the form | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @return string class of the form | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     function formClass() | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2010-09-28 15:54:44 -07:00
										 |  |  |         $classes = array('form_settings'); | 
					
						
							|  |  |  |         $runner = YammerRunner::init(); | 
					
						
							|  |  |  |         if ($runner->lastError()) { | 
					
						
							|  |  |  |             $classes[] = 'import-error'; | 
					
						
							|  |  |  |         } else if ($runner->state() == 'done') { | 
					
						
							|  |  |  |             $classes[] = 'import-done'; | 
					
						
							|  |  |  |         } else { | 
					
						
							|  |  |  |             $classes[] = 'import-progress'; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         return implode(' ', $classes); | 
					
						
							| 
									
										
										
										
											2010-09-24 17:22:44 -07:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * Action of the form | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @return string URL of the action | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     function action() | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         return common_local_url('yammeradminpanel'); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * Data elements of the form | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @return void | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     function formData() | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2010-09-28 15:45:00 -07:00
										 |  |  |         $this->out->hidden('subaction', 'progress'); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-09-24 17:22:44 -07:00
										 |  |  |         $runner = YammerRunner::init(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-09-28 15:45:00 -07:00
										 |  |  |         $error = $runner->lastError(); | 
					
						
							| 
									
										
										
										
											2010-09-24 17:22:44 -07:00
										 |  |  |         $userCount = $runner->countUsers(); | 
					
						
							|  |  |  |         $groupCount = $runner->countGroups(); | 
					
						
							|  |  |  |         $fetchedCount = $runner->countFetchedNotices(); | 
					
						
							|  |  |  |         $savedCount = $runner->countSavedNotices(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $labels = array( | 
					
						
							|  |  |  |             'init' => array( | 
					
						
							| 
									
										
										
										
											2011-06-19 15:02:31 +02:00
										 |  |  |                 // TRANS: Field label for a Yammer import initialise step.
 | 
					
						
							|  |  |  |                 'label' => _m('Initialize'), | 
					
						
							|  |  |  |                 // TRANS: "In progress" description.
 | 
					
						
							| 
									
										
										
										
											2010-09-24 17:22:44 -07:00
										 |  |  |                 'progress' => _m('No import running'), | 
					
						
							| 
									
										
										
										
											2011-06-19 15:02:31 +02:00
										 |  |  |                 // TRANS: "Complete" description for initialize state.
 | 
					
						
							| 
									
										
										
										
											2010-09-24 17:22:44 -07:00
										 |  |  |                 'complete' => _m('Initiated Yammer server connection...'), | 
					
						
							|  |  |  |             ), | 
					
						
							|  |  |  |             'requesting-auth' => array( | 
					
						
							| 
									
										
										
										
											2011-06-19 15:02:31 +02:00
										 |  |  |                 // TRANS: Field label for a Yammer import connect step.
 | 
					
						
							| 
									
										
										
										
											2010-09-24 17:22:44 -07:00
										 |  |  |                 'label' => _m('Connect to Yammer'), | 
					
						
							| 
									
										
										
										
											2011-06-19 15:02:31 +02:00
										 |  |  |                 // TRANS: "In progress" description.
 | 
					
						
							| 
									
										
										
										
											2010-09-24 17:22:44 -07:00
										 |  |  |                 'progress' => _m('Awaiting authorization...'), | 
					
						
							| 
									
										
										
										
											2011-06-19 15:02:31 +02:00
										 |  |  |                 // TRANS: "Complete" description for connect state.
 | 
					
						
							| 
									
										
										
										
											2010-09-24 17:22:44 -07:00
										 |  |  |                 'complete' => _m('Connected.'), | 
					
						
							|  |  |  |             ), | 
					
						
							|  |  |  |             'import-users' => array( | 
					
						
							| 
									
										
										
										
											2011-06-19 15:02:31 +02:00
										 |  |  |                 // TRANS: Field label for a Yammer user import users step.
 | 
					
						
							| 
									
										
										
										
											2010-09-24 17:22:44 -07:00
										 |  |  |                 'label' => _m('Import user accounts'), | 
					
						
							| 
									
										
										
										
											2011-06-19 15:02:31 +02:00
										 |  |  |                 // TRANS: "In progress" description.
 | 
					
						
							|  |  |  |                 // TRANS: %d is the number of users to be imported.
 | 
					
						
							|  |  |  |                 'progress' => sprintf(_m('Importing %d user...', | 
					
						
							|  |  |  |                                          'Importing %d users...', | 
					
						
							|  |  |  |                                          $userCount), | 
					
						
							|  |  |  |                                       $userCount), | 
					
						
							|  |  |  |                 // TRANS: "Complete" description for step.
 | 
					
						
							|  |  |  |                 // TRANS: %d is the number of users imported.
 | 
					
						
							|  |  |  |                 'complete' => sprintf(_m('Imported %d user.', | 
					
						
							|  |  |  |                                          'Imported %d users.', | 
					
						
							|  |  |  |                                          $userCount), | 
					
						
							|  |  |  |                                       $userCount), | 
					
						
							| 
									
										
										
										
											2010-09-24 17:22:44 -07:00
										 |  |  |             ), | 
					
						
							|  |  |  |             'import-groups' => array( | 
					
						
							| 
									
										
										
										
											2011-06-19 15:02:31 +02:00
										 |  |  |                 // TRANS: Field label for a Yammer group import step.
 | 
					
						
							| 
									
										
										
										
											2010-09-24 17:22:44 -07:00
										 |  |  |                 'label' => _m('Import user groups'), | 
					
						
							| 
									
										
										
										
											2011-06-19 15:02:31 +02:00
										 |  |  |                 // TRANS: "In progress" description.
 | 
					
						
							|  |  |  |                 // TRANS: %d is the number of groups to be imported.
 | 
					
						
							|  |  |  |                 'progress' => sprintf(_m('Importing %d group...', | 
					
						
							|  |  |  |                                          'Importing %d groups...', | 
					
						
							|  |  |  |                                          $groupCount), | 
					
						
							|  |  |  |                                       $groupCount), | 
					
						
							|  |  |  |                 // TRANS: "Complete" description for step.
 | 
					
						
							|  |  |  |                 // TRANS: %d is the number of groups imported.
 | 
					
						
							|  |  |  |                 'complete' => sprintf(_m('Imported %d group.', | 
					
						
							|  |  |  |                                          'Imported %d groups.', | 
					
						
							|  |  |  |                                          $groupCount), | 
					
						
							|  |  |  |                                       $groupCount), | 
					
						
							| 
									
										
										
										
											2010-09-24 17:22:44 -07:00
										 |  |  |             ), | 
					
						
							|  |  |  |             'fetch-messages' => array( | 
					
						
							| 
									
										
										
										
											2011-06-19 15:02:31 +02:00
										 |  |  |                 // TRANS: Field label for a Yammer import prepare notices step.
 | 
					
						
							| 
									
										
										
										
											2010-09-24 17:22:44 -07:00
										 |  |  |                 'label' => _m('Prepare public notices for import'), | 
					
						
							| 
									
										
										
										
											2011-06-19 15:02:31 +02:00
										 |  |  |                 // TRANS: "In progress" description.
 | 
					
						
							|  |  |  |                 // TRANS: %d is the number of notices to be prepared for import.
 | 
					
						
							|  |  |  |                 'progress' => sprintf(_m('Preparing %d notice...', | 
					
						
							|  |  |  |                                          'Preparing %d notices...', | 
					
						
							|  |  |  |                                          $fetchedCount), | 
					
						
							|  |  |  |                                       $fetchedCount), | 
					
						
							|  |  |  |                 // TRANS: "Complete" description for step.
 | 
					
						
							|  |  |  |                 // TRANS: %d is the number of notices prepared for import.
 | 
					
						
							|  |  |  |                 'complete' => sprintf(_m('Prepared %d notice.', | 
					
						
							|  |  |  |                                          'Prepared %d notices.', | 
					
						
							|  |  |  |                                          $fetchedCount), | 
					
						
							|  |  |  |                                       $fetchedCount), | 
					
						
							| 
									
										
										
										
											2010-09-24 17:22:44 -07:00
										 |  |  |             ), | 
					
						
							|  |  |  |             'save-messages' => array( | 
					
						
							| 
									
										
										
										
											2011-06-19 15:02:31 +02:00
										 |  |  |                 // TRANS: Field label for a Yammer import notices step.
 | 
					
						
							| 
									
										
										
										
											2010-09-24 17:22:44 -07:00
										 |  |  |                 'label' => _m('Import public notices'), | 
					
						
							| 
									
										
										
										
											2011-06-19 15:02:31 +02:00
										 |  |  |                 // TRANS: "In progress" description.
 | 
					
						
							|  |  |  |                 // TRANS: %d is the number of notices to be imported.
 | 
					
						
							|  |  |  |                 'progress' => sprintf(_m('Importing %d notice...', | 
					
						
							|  |  |  |                                          'Importing %d notices...', | 
					
						
							|  |  |  |                                          $savedCount), | 
					
						
							|  |  |  |                                       $savedCount), | 
					
						
							|  |  |  |                 // TRANS: "Complete" description for step.
 | 
					
						
							|  |  |  |                 // TRANS: %d is the number of notices imported.
 | 
					
						
							|  |  |  |                 'complete' => sprintf(_m('Imported %d notice.', | 
					
						
							|  |  |  |                                          'Imported %d notices.', | 
					
						
							|  |  |  |                                          $savedCount), | 
					
						
							|  |  |  |                                       $savedCount), | 
					
						
							| 
									
										
										
										
											2010-09-24 17:22:44 -07:00
										 |  |  |             ), | 
					
						
							|  |  |  |             'done' => array( | 
					
						
							| 
									
										
										
										
											2011-06-19 15:02:31 +02:00
										 |  |  |                 // TRANS: Field label for a Yammer import done step.
 | 
					
						
							| 
									
										
										
										
											2010-09-24 17:22:44 -07:00
										 |  |  |                 'label' => _m('Done'), | 
					
						
							| 
									
										
										
										
											2011-06-19 15:02:31 +02:00
										 |  |  |                 // TRANS: "In progress" description for done step.
 | 
					
						
							|  |  |  |                 'progress' => sprintf(_m('Import is complete!')), | 
					
						
							|  |  |  |                 // TRANS: "Complete" description for done step.
 | 
					
						
							|  |  |  |                 'complete' => sprintf(_m('Import is complete!')), | 
					
						
							| 
									
										
										
										
											2010-09-24 17:22:44 -07:00
										 |  |  |             ) | 
					
						
							|  |  |  |         ); | 
					
						
							|  |  |  |         $steps = array_keys($labels); | 
					
						
							|  |  |  |         $currentStep = array_search($runner->state(), $steps); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-09-28 15:45:00 -07:00
										 |  |  |         $classes = array('yammer-import'); | 
					
						
							|  |  |  |         if ($error) { | 
					
						
							|  |  |  |             $classes[] = 'yammer-error'; | 
					
						
							|  |  |  |         } else { | 
					
						
							|  |  |  |             $classes[] = 'yammer-running'; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         $this->out->elementStart('fieldset', array('class' => implode(' ', $classes))); | 
					
						
							| 
									
										
										
										
											2011-06-19 15:02:31 +02:00
										 |  |  |         // TRANS: Fieldset legend.
 | 
					
						
							| 
									
										
										
										
											2010-09-24 17:22:44 -07:00
										 |  |  |         $this->out->element('legend', array(), _m('Import status')); | 
					
						
							|  |  |  |         foreach ($steps as $step => $state) { | 
					
						
							|  |  |  |             if ($state == 'init') { | 
					
						
							|  |  |  |                 // Don't show 'init', it's boring.
 | 
					
						
							|  |  |  |                 continue; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |             if ($step < $currentStep) { | 
					
						
							|  |  |  |                 // This step is done
 | 
					
						
							|  |  |  |                 $this->progressBar($state, | 
					
						
							|  |  |  |                                    'complete', | 
					
						
							|  |  |  |                                    $labels[$state]['label'], | 
					
						
							|  |  |  |                                    $labels[$state]['complete']); | 
					
						
							|  |  |  |             } else if ($step == $currentStep) { | 
					
						
							|  |  |  |                 // This step is in progress
 | 
					
						
							|  |  |  |                 $this->progressBar($state, | 
					
						
							|  |  |  |                                    'progress', | 
					
						
							|  |  |  |                                    $labels[$state]['label'], | 
					
						
							| 
									
										
										
										
											2010-09-28 15:45:00 -07:00
										 |  |  |                                    $labels[$state]['progress'], | 
					
						
							|  |  |  |                                    $error); | 
					
						
							| 
									
										
										
										
											2010-09-24 17:22:44 -07:00
										 |  |  |             } else { | 
					
						
							|  |  |  |                 // This step has not yet been done.
 | 
					
						
							|  |  |  |                 $this->progressBar($state, | 
					
						
							|  |  |  |                                    'waiting', | 
					
						
							|  |  |  |                                    $labels[$state]['label'], | 
					
						
							| 
									
										
										
										
											2011-06-19 15:02:31 +02:00
										 |  |  |                                    // TRANS: Progress bar status.
 | 
					
						
							|  |  |  |                                    _m('Waiting...')); | 
					
						
							| 
									
										
										
										
											2010-09-24 17:22:44 -07:00
										 |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         $this->out->elementEnd('fieldset'); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-09-28 15:45:00 -07:00
										 |  |  |     private function progressBar($state, $class, $label, $status, $error=null) | 
					
						
							| 
									
										
										
										
											2010-09-24 17:22:44 -07:00
										 |  |  |     { | 
					
						
							|  |  |  |         // @fixme prettify ;)
 | 
					
						
							|  |  |  |         $this->out->elementStart('div', array('class' => "import-step import-step-$state $class")); | 
					
						
							|  |  |  |         $this->out->element('div', array('class' => 'import-label'), $label); | 
					
						
							|  |  |  |         $this->out->element('div', array('class' => 'import-status'), $status); | 
					
						
							| 
									
										
										
										
											2010-09-28 15:45:00 -07:00
										 |  |  |         if ($class == 'progress') { | 
					
						
							|  |  |  |             if ($state == 'done') { | 
					
						
							| 
									
										
										
										
											2011-06-19 15:02:31 +02:00
										 |  |  |                 // TRANS: Button text for resetting the import state.
 | 
					
						
							| 
									
										
										
										
											2010-09-28 15:45:00 -07:00
										 |  |  |                 $this->out->submit('abort-import', _m('Reset import state')); | 
					
						
							|  |  |  |             } else { | 
					
						
							|  |  |  |                 if ($error) { | 
					
						
							|  |  |  |                     $this->errorBox($error); | 
					
						
							|  |  |  |                 } else { | 
					
						
							| 
									
										
										
										
											2011-06-19 15:02:31 +02:00
										 |  |  |                     // TRANS: Button text for pausing an import.
 | 
					
						
							| 
									
										
										
										
											2010-09-28 15:45:00 -07:00
										 |  |  |                     $this->out->submit('pause-import', _m('Pause import')); | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2010-09-24 17:22:44 -07:00
										 |  |  |         $this->out->elementEnd('div'); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-09-28 15:45:00 -07:00
										 |  |  |     private function errorBox($msg) | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2011-06-19 15:02:31 +02:00
										 |  |  |         // TRANS: Error message. %s are the error details.
 | 
					
						
							|  |  |  |         $errline = sprintf(_m('Encountered error "%s".'), $msg); | 
					
						
							| 
									
										
										
										
											2010-09-28 15:45:00 -07:00
										 |  |  |         $this->out->elementStart('fieldset', array('class' => 'import-error')); | 
					
						
							| 
									
										
										
										
											2011-06-19 15:02:31 +02:00
										 |  |  |         // TRANS: Fieldset legend for a paused import.
 | 
					
						
							| 
									
										
										
										
											2010-09-28 15:45:00 -07:00
										 |  |  |         $this->out->element('legend', array(), _m('Paused')); | 
					
						
							|  |  |  |         $this->out->element('p', array(), $errline); | 
					
						
							| 
									
										
										
										
											2011-06-19 15:02:31 +02:00
										 |  |  |         // TRANS: Button text for continuing a paused import.
 | 
					
						
							| 
									
										
										
										
											2010-09-28 15:45:00 -07:00
										 |  |  |         $this->out->submit('continue-import', _m('Continue')); | 
					
						
							| 
									
										
										
										
											2011-06-19 15:02:31 +02:00
										 |  |  |         // TRANS: Button text for aborting a paused import.
 | 
					
						
							| 
									
										
										
										
											2010-09-28 15:45:00 -07:00
										 |  |  |         $this->out->submit('abort-import', _m('Abort import')); | 
					
						
							|  |  |  |         $this->out->elementEnd('fieldset'); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2010-09-24 17:22:44 -07:00
										 |  |  | } |