7 * @license http://www.gnu.org/licenses/agpl.html AGPL Version 3
8 * @author Philipp Schüle <p.schuele@metaways.de>
9 * @copyright Copyright (c) 2010-2014 Metaways Infosystems GmbH (http://www.metaways.de)
14 * backend class for Zend_Json_Server
16 * This class handles all Json requests for the Filemanager application
18 * @package Filemanager
19 * @subpackage Frontend
21 class Filemanager_Frontend_Json extends Tinebase_Frontend_Json_Abstract
28 protected $_applicationName = 'Filemanager';
31 * search file/directory nodes
33 * @param array $filter
34 * @param array $paging
37 public function searchNodes($filter, $paging)
39 $result = $this->_search($filter, $paging, Filemanager_Controller_Node::getInstance(), 'Filemanager_Model_NodeFilter');
40 $this->_removeAppIdFromPathFilter($result);
46 * remove app id (base path) from filter
48 * @param array $_result
50 * @todo is this really needed? perhaps we can set the correct path in Tinebase_Model_Tree_Node_PathFilter::toArray
52 protected function _removeAppIdFromPathFilter(&$_result)
54 $app = Tinebase_Application::getInstance()->getApplicationByName($this->_applicationName);
56 foreach ($_result['filter'] as $idx => &$filter) {
57 if ($filter['field'] === 'path') {
58 if (is_array($filter['value'])) {
59 $filter['value']['path'] = Tinebase_Model_Tree_Node_Path::removeAppIdFromPath($filter['value']['path'], $app);
61 $filter['value'] = Tinebase_Model_Tree_Node_Path::removeAppIdFromPath($filter['value'], $app);
70 * @param array $filename
71 * @param string $type directory or file
72 * @param string $tempFileId
73 * @param boolean $forceOverwrite
76 public function createNode($filename, $type, $tempFileId = array(), $forceOverwrite = false)
78 $nodes = Filemanager_Controller_Node::getInstance()->createNodes((array)$filename, $type, (array)$tempFileId, $forceOverwrite);
79 $result = (count($nodes) === 0) ? array() : $this->_recordToJson($nodes->getFirstRecord());
87 * @param string|array $filenames
88 * @param string $type directory or file
89 * @param string|array $tempFileIds
90 * @param boolean $forceOverwrite
93 public function createNodes($filenames, $type, $tempFileIds = array(), $forceOverwrite = false)
95 $nodes = Filemanager_Controller_Node::getInstance()->createNodes((array)$filenames, $type, (array)$tempFileIds, $forceOverwrite);
97 return $this->_multipleRecordsToJson($nodes);
103 * @param string|array $sourceFilenames string->single file, array->multiple
104 * @param string|array $destinationFilenames string->singlefile OR directory, array->multiple files
105 * @param boolean $forceOverwrite
108 public function copyNodes($sourceFilenames, $destinationFilenames, $forceOverwrite)
110 $nodes = Filemanager_Controller_Node::getInstance()->copyNodes((array)$sourceFilenames, $destinationFilenames, $forceOverwrite);
112 return $this->_multipleRecordsToJson($nodes);
118 * @param string|array $sourceFilenames string->single file, array->multiple
119 * @param string|array $destinationFilenames string->singlefile OR directory, array->multiple files
120 * @param boolean $forceOverwrite
123 public function moveNodes($sourceFilenames, $destinationFilenames, $forceOverwrite)
125 $nodes = Filemanager_Controller_Node::getInstance()->moveNodes((array)$sourceFilenames, $destinationFilenames, $forceOverwrite);
127 return $this->_multipleRecordsToJson($nodes);
133 * @param string|array $filenames string->single file, array->multiple
136 public function deleteNodes($filenames)
138 Filemanager_Controller_Node::getInstance()->deleteNodes((array)$filenames);
141 'status' => 'success'
146 * returns the node record
150 public function getNode($id)
152 return $this->_get($id, Filemanager_Controller_Node::getInstance());
157 * save node here in json fe just updates meta info (name, description, relations, customfields, tags, notes),
158 * if record already exists (after it had been uploaded)
159 * @param array with record data
162 public function saveNode($recordData)
164 if((isset($recordData['created_by']) || array_key_exists('created_by', $recordData))) {
165 return $this->_save($recordData, Filemanager_Controller_Node::getInstance(), 'Node');
166 } else { // on upload complete
172 * Search for records matching given arguments
174 * @param array $filter
175 * @param array $paging
178 public function searchDownloadLinks($filter, $paging)
180 return $this->_search($filter, $paging, Filemanager_Controller_DownloadLink::getInstance(), 'Filemanager_Model_DownloadLinkFilter');
184 * Return a single record
187 * @return array record data
189 public function getDownloadLink($id)
191 return $this->_get($id, Filemanager_Controller_DownloadLink::getInstance());
195 * creates/updates a record
197 * @param array $recordData
198 * @return array created/updated record
200 public function saveDownloadLink($recordData)
202 return $this->_save($recordData, Filemanager_Controller_DownloadLink::getInstance(), 'DownloadLink');
206 * deletes existing records
211 public function deleteDownloadLinks($ids)
213 return $this->_delete($ids, Filemanager_Controller_DownloadLink::getInstance());