Helper.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. <?php
  2. /**
  3. * Zend Framework
  4. *
  5. * LICENSE
  6. *
  7. * This source file is subject to the new BSD license that is bundled
  8. * with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://framework.zend.com/license/new-bsd
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@zend.com so we can send you a copy immediately.
  14. *
  15. * @category Zend
  16. * @package Zend_Service
  17. * @subpackage LiveDocx
  18. * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. * @version $Id$
  21. */
  22. /** Zend_Date **/
  23. require_once 'Zend/Date.php';
  24. /**
  25. * @category Demos
  26. * @package Demos_Zend_Service
  27. * @subpackage LiveDocx
  28. * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
  29. * @license http://framework.zend.com/license/new-bsd New BSD License
  30. */
  31. class Demos_Zend_Service_LiveDocx_Helper
  32. {
  33. /**
  34. * LiveDocx demo username
  35. */
  36. const USERNAME = 'zfdemos';
  37. /**
  38. * LiveDocx demo password
  39. */
  40. const PASSWORD = 'fkj3487o4zf35';
  41. /**
  42. * Line length in characters (used to wrap long lines)
  43. */
  44. const LINE_LENGTH = 80;
  45. /**
  46. * Default Locale
  47. */
  48. const LOCALE = 'en_US';
  49. /**
  50. * Decorator to format return value of list methods
  51. *
  52. * @param array $result
  53. * @return string
  54. */
  55. public static function listDecorator($result)
  56. {
  57. $ret = '';
  58. $dateFormat = Zend_Date::RFC_1123;
  59. $date = new Zend_Date();
  60. $date->setLocale(self::LOCALE);
  61. if (count($result) > 0) {
  62. foreach ($result as $record) {
  63. $date->set($record['createTime']);
  64. $createTimeFormatted = $date->get($dateFormat);
  65. $date->set($record['modifyTime']);
  66. $modifyTimeFormatted = $date->get($dateFormat);
  67. $ret .= sprintf(' Filename : %s%s', $record['filename'], PHP_EOL);
  68. $ret .= sprintf(' File Size : %d b%s', $record['fileSize'], PHP_EOL);
  69. $ret .= sprintf(' Creation Time : %d (%s)%s', $record['createTime'], $createTimeFormatted, PHP_EOL);
  70. $ret .= sprintf('Last Modified Time : %d (%s)%s', $record['modifyTime'], $modifyTimeFormatted, PHP_EOL);
  71. $ret .= PHP_EOL;
  72. }
  73. }
  74. unset($date);
  75. return $ret;
  76. }
  77. /**
  78. * Decorator to format array
  79. *
  80. * @param array $result
  81. * @return string
  82. */
  83. public static function arrayDecorator($result)
  84. {
  85. $ret = '';
  86. $count = count($result);
  87. if ($count > 0) {
  88. for ($i = 0; $i < $count; $i ++) {
  89. $ret .= $result[$i];
  90. if ($count === ($i + 1)) {
  91. $ret .= '.';
  92. } elseif ($count === ($i + 2)) {
  93. $ret .= ' & ';
  94. } else {
  95. $ret .= ', ';
  96. }
  97. }
  98. } else {
  99. $ret .= 'none';
  100. }
  101. return $ret;
  102. }
  103. /**
  104. * Wrap the length of long lines
  105. *
  106. * @param string $str
  107. * @return string
  108. */
  109. public static function wrapLine($str)
  110. {
  111. return wordwrap($str, self::LINE_LENGTH);
  112. }
  113. }