* @package Wombat */ WBClass::load('WBAjax' , 'WBLog'); /** * AJAX component: VFS Tre * * @version 0.3.0 * @package Wombat */ class WBAjax_VFS_Tree extends WBAjax { const VFS_SELECT_DIR_LAST = 'vfsdir_select_dir_last'; const VFS_USER = 'vfsfile_user'; /** * File Table Access * @var WBLog */ private $log; /** * File Table Access * @var WBDatasource_Tree */ private $dirtree; /** * second constructor * * This protect the actual constructor. */ protected function init() { // empty default implementation $this->log = WBLog::start('VFSTree'); if (!$this->sess->has(self::VFS_SELECT_DIR_LAST)) { $this->sess->set(self::VFS_SELECT_DIR_LAST, 0); } $user = $this->sess->get(self::VFS_USER); if (empty($user)) { $user = $this->user->getId(); } // Tree member $this->dirtree = WBClass::create('WBDatasource_Tree', array("treetable" => "vfsdir")); $clause = array(); $clause[] = array( 'field' => $this->dirtree->getIdentifier('user'), 'value' => $user ); $this->dirtree->setClause($clause); } /** * create move view * * @return view to move a file */ protected function select() { $type = $this->req->get('type'); $from = $this->req->get('src'); $vfsdid = $this->sess->get(self::VFS_SELECT_DIR_LAST); if (strcmp($type, 'file') == 0) { $from = $this->req->get('id'); } else { $from = $this->req->get('id'); } return $this->selectDisplay($type, $from, $vfsdid); } /** * create view to select target dir * * @return view to select target dir */ protected function selectDes() { $type = $this->req->get('type'); $from = $this->req->get('from'); $vfsdid = $this->req->get('id', $this->sess->get(self::VFS_SELECT_DIR_LAST)); $this->sess->set(self::VFS_SELECT_DIR_LAST, $vfsdid); return $this->selectDisplay($type, $from, $vfsdid); } /** * Actually Display * * @param string $type * @param string $from * @param string $vfsdid */ private function selectDisplay($type, $from, $vfsdid) { if (0 == $vfsdid) { $vfsdid = null; } $parents = $this->dirtree->getParent($vfsdid, 0); $list = $this->dirtree->getChildren($vfsdid); $cwd = $this->dirtree->get($vfsdid); $this->tmpl->addGlobalVar('from', $from); $this->tmpl->addGlobalVar('type', $type); $this->tmpl->addGlobalVar('cwd_parent_count', count($parents)); $this->tmpl->addGlobalVar('list_count', count($list)); $this->tmpl->addGlobalVars($cwd, 'cwd_'); $this->tmpl->readTemplatesFromInput('VFS/ajax/tree/tree.tmpl'); $this->tmpl->addRows('parent_list_entry', $parents); $this->tmpl->addRows('list_entry', $list); return $this->tmpl->getParsedTemplate('snippet'); } }