westdc-zf1/application/default/controllers/FilelistController.php

61 lines
2.4 KiB
PHP
Raw Normal View History

2010-03-10 06:41:50 +00:00
<?php
class FilelistController extends Zend_Controller_Action {
function indexAction() {
$uuid=$this->_request->getParam('uuid');
2010-03-19 10:18:58 +00:00
$filelist=new FilelistTable();
2010-03-10 06:41:50 +00:00
$adapter=$filelist->getAdapter();
2010-07-02 09:03:55 +00:00
$db=$adapter->query("select file_name,file_path,id,meta_uuid from westdc_fileinfo where meta_uuid='$uuid' and depth=1 order by isdir desc,file_name");
2010-03-10 06:41:50 +00:00
$files=$db->fetchAll();
2010-07-02 03:43:58 +00:00
$documents=array();
$i=0;
foreach($files as $file) {
$fileName=$file['file_name'];
if($fileName!=='/uuid.txt') {
$pathArray=explode("/",$fileName);
if(empty($pathArray[2])) {
$documents[$i] = $file;
$i++;
}
2010-06-22 04:07:24 +00:00
}
2010-07-02 03:43:58 +00:00
}
2010-03-10 06:41:50 +00:00
$this->_helper->layout()->disableLayout();
$this->_helper->viewRenderer->setNoRender();
2010-06-02 04:08:21 +00:00
echo Zend_Json::encode($documents);
2010-03-10 06:41:50 +00:00
}
2010-07-02 03:43:58 +00:00
function subAction() {
$uuid=$this->_request->getParam('uuid');
$getUrl=$this->_request->getParam('subpath');
$subPath=urldecode($getUrl);
2010-07-02 10:37:49 +00:00
$depth=substr_count($subPath,'/');
2010-07-02 03:43:58 +00:00
$filelist=new FilelistTable();
$adapter=$filelist->getAdapter();
2010-07-02 10:37:49 +00:00
$db=$adapter->query("select file_name,file_path,id,meta_uuid from westdc_fileinfo where meta_uuid='$uuid' and depth='$depth' and file_name ilike '$subpath%' order by isdir desc,file_name");
2010-07-02 03:43:58 +00:00
$files=$db->fetchAll();
$documents=array();
$i=0;
foreach($files as $subFile) {
if(substr($subFile['file_name'], 0,strlen($subPath))==$subPath) {// start with "/a/"
$subFilePath=str_replace($subPath, '', $subFile['file_name']);
if(!empty($subFilePath)) {
$pos = strpos($subFilePath, '/');
$pathArray=explode("/",$subFilePath);
if(empty($pathArray[1])) {
$documents[$i] = $subFile;
if ($pos === false) {
$documents[$i]['file_name']=$subPath.$pathArray[0];
} else {
$documents[$i]['file_name']=$subPath.$pathArray[0].'/';
}
$i++;
}
}
}
}
$this->_helper->layout()->disableLayout();
$this->_helper->viewRenderer->setNoRender();
echo Zend_Json::encode($documents);
}
}