Helper.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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 demonstration username
  35. *
  36. * IMPORTANT: These login credentials may be used for demonstration purposes only.
  37. * Getting your own username and password takes less than 1 minute.
  38. * Goto http://is.gd/5dK5A to sign up.
  39. */
  40. const USERNAME = 'zfdemos';
  41. /**
  42. * LiveDocx demonstration password
  43. *
  44. * IMPORTANT: These login credentials may be used for demonstration purposes only.
  45. * Getting your own username and password takes less than 1 minute.
  46. * Goto http://is.gd/5dK5A to sign up.
  47. */
  48. const PASSWORD = 'fkj3487o4zf35';
  49. /**
  50. * Line length in characters (used to wrap long lines)
  51. */
  52. const LINE_LENGTH = 80;
  53. /**
  54. * Default Locale
  55. */
  56. const LOCALE = 'en_US';
  57. /**
  58. * Decorator to format return value of list methods
  59. *
  60. * @param array $result
  61. * @return string
  62. */
  63. public static function listDecorator($result)
  64. {
  65. $ret = '';
  66. $date = new Zend_Date();
  67. if (count($result) > 0) {
  68. foreach ($result as $record) {
  69. $date->set($record['createTime']);
  70. $createTimeFormatted = $date->get(Zend_Date::RFC_1123);
  71. $date->set($record['modifyTime']);
  72. $modifyTimeFormatted = $date->get(Zend_Date::RFC_1123);
  73. $ret .= sprintf(' Filename : %s%s', $record['filename'], PHP_EOL);
  74. $ret .= sprintf(' File Size : %d b%s', $record['fileSize'], PHP_EOL);
  75. $ret .= sprintf(' Creation Time : %d (%s)%s', $record['createTime'], $createTimeFormatted, PHP_EOL);
  76. $ret .= sprintf('Last Modified Time : %d (%s)%s', $record['modifyTime'], $modifyTimeFormatted, PHP_EOL);
  77. $ret .= PHP_EOL;
  78. }
  79. }
  80. unset($date);
  81. return $ret;
  82. }
  83. /**
  84. * Decorator to format array
  85. *
  86. * @param array $result
  87. * @return string
  88. */
  89. public static function arrayDecorator($result)
  90. {
  91. $ret = '';
  92. $count = count($result);
  93. if ($count > 0) {
  94. for ($i = 0; $i < $count; $i ++) {
  95. $ret .= $result[$i];
  96. if ($count === ($i + 1)) {
  97. $ret .= '.';
  98. } elseif ($count === ($i + 2)) {
  99. $ret .= ' & ';
  100. } else {
  101. $ret .= ', ';
  102. }
  103. }
  104. } else {
  105. $ret .= 'none';
  106. }
  107. return $ret;
  108. }
  109. /**
  110. * Wrap the length of long lines
  111. *
  112. * @param string $str
  113. * @return string
  114. */
  115. public static function wrapLine($str)
  116. {
  117. return wordwrap($str, self::LINE_LENGTH);
  118. }
  119. }