public function uploadAction() { $this->_helper->viewRenderer->setNoRender(true); $this->view->layout()->disableLayout(true); $adapter = new Zend_ProgressBar_Adapter_JsPush(array('updateMethodName' => 'Zend_ProgressBar_Update', 'finishMethodName' => 'Zend_ProgressBar_Finish')); $progressBar = new Zend_ProgressBar($adapter, 0, 100); for ($i = 1; $i <= 100; $i++) { if ($i < 20) { $text = 'Just beginning'; } else { if ($i < 50) { $text = 'A bit done'; } else { if ($i < 80) { $text = 'Getting closer'; } else { $text = 'Nearly done'; } } } $progressBar->update($i, $text); usleep(100000); } $progressBar->finish(); }
public function uploadAction() { $adapter = new Zend_ProgressBar_Adapter_JsPush(array('updateMethodName' => 'Zend_ProgressBar_Update', 'finishMethodName' => 'Zend_ProgressBar_Finish')); $progressBar = new Zend_ProgressBar($adapter, 0, 100); for ($i = 1; $i <= 100; $i++) { if ($i < 20) { $text = 'Just beginning'; } else { if ($i < 50) { $text = 'A bit done'; } else { if ($i < 80) { $text = 'Getting closer'; } else { $text = 'Nearly done'; } } } $progressBar->update($i, $text); usleep(100000); } $progressBar->finish(); }
/** * Returns the actual progress of file up-/downloads * * @param string $id The upload to get the progress for * @return array|null */ public static function getProgress($id = null) { if (!function_exists('apc_fetch') and !function_exists('uploadprogress_get_info')) { // require_once 'Zend/File/Transfer/Exception.php'; throw new Zend_File_Transfer_Exception('Neither APC nor uploadprogress extension installed'); } $session = 'Zend_File_Transfer_Adapter_Http_ProgressBar'; $status = array('total' => 0, 'current' => 0, 'rate' => 0, 'message' => '', 'done' => false); if (is_array($id)) { if (isset($id['progress'])) { $adapter = $id['progress']; } if (isset($id['session'])) { $session = $id['session']; } if (isset($id['id'])) { $id = $id['id']; } else { unset($id); } } if (!empty($id) && ($id instanceof Zend_ProgressBar_Adapter || $id instanceof Zend_ProgressBar)) { $adapter = $id; unset($id); } if (empty($id)) { if (!isset($_GET['progress_key'])) { $status['message'] = 'No upload in progress'; $status['done'] = true; } else { $id = $_GET['progress_key']; } } if (!empty($id)) { if (self::isApcAvailable()) { $call = call_user_func(self::$_callbackApc, ini_get('apc.rfc1867_prefix') . $id); if (is_array($call)) { $status = $call + $status; } } else { if (self::isUploadProgressAvailable()) { $call = call_user_func(self::$_callbackUploadProgress, $id); if (is_array($call)) { $status = $call + $status; $status['total'] = $status['bytes_total']; $status['current'] = $status['bytes_uploaded']; $status['rate'] = $status['speed_average']; if ($status['total'] == $status['current']) { $status['done'] = true; } } } } if (!is_array($call)) { $status['done'] = true; $status['message'] = 'Failure while retrieving the upload progress'; } else { if (!empty($status['cancel_upload'])) { $status['done'] = true; $status['message'] = 'The upload has been canceled'; } else { $status['message'] = self::_toByteString($status['current']) . " - " . self::_toByteString($status['total']); } } $status['id'] = $id; } if (isset($adapter) && isset($status['id'])) { if ($adapter instanceof Zend_ProgressBar_Adapter) { // require_once 'Zend/ProgressBar.php'; $adapter = new Zend_ProgressBar($adapter, 0, $status['total'], $session); } if (!$adapter instanceof Zend_ProgressBar) { // require_once 'Zend/File/Transfer/Exception.php'; throw new Zend_File_Transfer_Exception('Unknown Adapter given'); } if ($status['done']) { $adapter->finish(); } else { $adapter->update($status['current'], $status['message']); } $status['progress'] = $adapter; } return $status; }
$cpbAdapter = new Zend_ProgressBar_Adapter_Console(array('elements' => array(Zend_ProgressBar_Adapter_Console::ELEMENT_PERCENT, Zend_ProgressBar_Adapter_Console::ELEMENT_BAR, Zend_ProgressBar_Adapter_Console::ELEMENT_ETA, Zend_ProgressBar_Adapter_Console::ELEMENT_TEXT))); $logger->info('Creating redirects from previous version...'); $batches = ceil($totalRows / $batchSize); $categoriesProgressBar = new Zend_ProgressBar($cpbAdapter, 0, $batches); $child = 'php -f ' . dirname(__FILE__) . '/umt113_redirect.php --'; $processesCheck = "ps x | grep \"{$child}\" | grep -v grep"; $i = 0; for (; $batches; $batches--) { $output = ''; if ($threadCount == 1) { exec($child . " {$i} {$batchSize} >> " . dirname(__FILE__) . "/url_migration.log 2>&1", $output, $status); } else { waitForChildren($processesCheck, $threadCount); exec($child . " {$i} {$batchSize} >> " . dirname(__FILE__) . "/url_migration.log 2>&1 &", $output, $status); } $categoriesProgressBar->update(++$i, ''); } if ($threadCount != 1) { waitForChildren($processesCheck, 1); } $categoriesProgressBar->finish(); $cnxConfig = Mage::getConfig()->getResourceConnectionConfig(Mage_Core_Model_Resource::DEFAULT_WRITE_RESOURCE); $connection = $migration->getResource()->createConnection('fresh_connection', (string) $cnxConfig->type, $cnxConfig); $connection->dropTable($tableProducts->getName()); $connection->dropTable($tableCategories->getName()); exit(0); function waitForChildren($command, $count) { $out = array(); exec($command, $out); $processCount = count($out);
$progressBar = new Zend_ProgressBar($adapter, 0, 100); for ($i = 1; $i <= 100; $i++) { if ($i < 20) { $text = 'Just beginning'; } else { if ($i < 50) { $text = 'A bit done'; } else { if ($i < 80) { $text = 'Getting closer'; } else { $text = 'Nearly done'; } } } $progressBar->update($i, $text); usleep(100000); } $progressBar->finish(); die; } ?> <html> <head> <title>Zend_ProgressBar Javascript Push Demo and Test</title> <style type="text/css"> iframe { position: absolute; left: -100px; top: -100px;
* This sample file demonstrates a simple use case of a jspull-driven progressbar */ if (isset($_GET['uploadId'])) { set_include_path(realpath(dirname(__FILE__) . '/../../../library') . PATH_SEPARATOR . get_include_path()); // require_once 'Zend/ProgressBar.php'; // require_once 'Zend/ProgressBar/Adapter/JsPull.php'; // require_once 'Zend/Session/Namespace.php'; $data = uploadprogress_get_info($_GET['uploadId']); $bytesTotal = $data === null ? 0 : $data['bytes_total']; $bytesUploaded = $data === null ? 0 : $data['bytes_uploaded']; $adapter = new Zend_ProgressBar_Adapter_JsPull(); $progressBar = new Zend_ProgressBar($adapter, 0, $bytesTotal, 'uploadProgress'); if ($bytesTotal === $bytesUploaded) { $progressBar->finish(); } else { $progressBar->update($bytesUploaded); } } ?> <html> <head> <title>Zend_ProgressBar Upload Demo</title> <style type="text/css"> iframe { position: absolute; left: -100px; top: -100px; width: 10px; height: 10px; overflow: hidden;
/** * Action - pdf * сreate a PDF document using the mPDF library * * Access to the action is possible in the following paths: * - /admin/tools/pdf * * @return void */ public function pdfAction() { $isCommonFont = false; $pdfParams = array(); //--------------------- // Получим параметры $params = $this->getRequest()->getParams(); $report = $params['name']; // Определим параметры для конвертации HTML в PDF switch ($report) { case 'phpinfo': // Установим параметры для отчета $html = Default_Plugin_SysBox::getPHPInfo(); $pdfParams['pdfReport'] = $report; $pdfParams['html'] = $html; $pdfParams['isCommonFont'] = true; $pdfParams['pathStylesheet'] = 'css/report/phpinfo.css'; $pdfParams['headerLeftMargin'] = 'Params of PHP'; $pdfParams['headerCentreMargin'] = Default_Plugin_SysBox::getFullURL_Res('/images/system/settings32x32.png'); $pdfParams['footerRightMargin'] = Default_Plugin_SysBox::getFullUrl_For_FilePDF($report); break; case 'zend-progress': $adapter = new Zend_ProgressBar_Adapter_JsPush(array('updateMethodName' => 'BSA.Dialogs.Zend_ProgressBar_Update', 'finishMethodName' => 'BSA.Dialogs.Zend_ProgressBar_Finish')); $progressBar = new Zend_ProgressBar($adapter, 0, 100); for ($i = 1; $i <= 100; $i++) { if ($i < 20) { $text = 'Just beginning'; } else { if ($i < 50) { $text = 'A bit done'; } else { if ($i < 80) { $text = 'Getting closer'; } else { $text = 'Nearly done'; } } } $progressBar->update($i, $text); usleep(100000); } $progressBar->finish(); die; break; default: break; } // Создать PDF файл из HTML $urlFilePDF = Default_Plugin_SysBox::mpdfGenerator_Html2PDF($pdfParams); // Установим свой и предыдущий Breadcrumbs $Zend_Auth = Zend_Registry::get("Zend_Auth"); $lastBreadcrumbs = $Zend_Auth->lastBreadcrumbs; $this->_breadcrumbs->addStep($lastBreadcrumbs['title'], $this->getUrl($lastBreadcrumbs['action'], $lastBreadcrumbs['controller'], $lastBreadcrumbs['module'])); $this->_breadcrumbs->addStep($this->Translate('Отчет в PDF формате')); $this->view->urlFilePDF = $urlFilePDF; }