DocumentController.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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_Cloud
  17. * @subpackage examples
  18. * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. */
  21. /**
  22. * @category Zend
  23. * @package Zend_Cloud
  24. * @subpackage examples
  25. * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  26. * @license http://framework.zend.com/license/new-bsd New BSD License
  27. */
  28. class DocumentController extends Zend_Controller_Action
  29. {
  30. public $dependencies = array('config');
  31. /**
  32. * @var Zend_Cloud_DocumentService_Adapter
  33. */
  34. protected $_doc = null;
  35. public function preDispatch()
  36. {
  37. $this->_doc = Zend_Cloud_DocumentService_Factory::getAdapter(
  38. $this->config->document
  39. );
  40. }
  41. public function indexAction()
  42. {
  43. $this->view->collections = $this->_doc->listCollections();
  44. }
  45. public function showAction()
  46. {
  47. $request = $this->getRequest();
  48. if (!$name = $this->view->collection = $this->_getParam('collection', false)) {
  49. return;
  50. }
  51. $q = $this->_doc->select("*");
  52. $this->view->data = $this->_doc->query($name, $q, array(
  53. Zend_Cloud_DocumentService_Adapter_SimpleDB::RETURN_DOCUMENTS => true
  54. ));
  55. }
  56. public function createAction()
  57. {
  58. $request = $this->getRequest();
  59. if (!$request->isPost()) {
  60. return;
  61. }
  62. if (!$name = $this->_getParam('name', false)) {
  63. return;
  64. }
  65. $this->_doc->createCollection($name);
  66. return $this->_helper->redirector('index');
  67. }
  68. public function addDocumentAction()
  69. {
  70. $this->view->fieldcount = 5;
  71. $this->view->collections = $this->_doc->listCollections();
  72. $request = $this->getRequest();
  73. if (!$request->isPost()) {
  74. return;
  75. }
  76. if (!$name = $this->view->name = $this->_getParam('name', false)) {
  77. return;
  78. }
  79. if (!$id = $this->_getParam('id', false)) {
  80. return;
  81. }
  82. $fields = array();
  83. foreach ($this->_getParam('field', array()) as $field) {
  84. if (!$field["name"]) {
  85. continue;
  86. }
  87. $fields[$field["name"]] = $field["value"];
  88. }
  89. if (empty($fields)) {
  90. return;
  91. }
  92. $document = new Zend_Cloud_DocumentService_Document($id, $fields);
  93. $this->_doc->insertDocument($name, $document);
  94. return $this->_helper->redirector('show', null, null, array("collection" => $name));
  95. }
  96. public function deleteDocumentAction()
  97. {
  98. $request = $this->getRequest();
  99. if (!$request->isPost()) {
  100. return;
  101. }
  102. if (!$name = $this->view->name = $this->_getParam('name', false)) {
  103. return;
  104. }
  105. if (!$id = $this->_getParam('id', false)) {
  106. return;
  107. }
  108. $this->_doc->deleteDocument($name, $id);
  109. return $this->_helper->redirector('show', null, null, array("collection" => $name));
  110. }
  111. }