Documentation is available at staticfolderclass.php
1 <?php
2 /**
3 * @author Jan H. Andersen <jha@ipwsystems.dk>
4 * @author Martin R. Larsen <mrl@ipwsystems.dk>
5 * @copyright {@link http://www.ipwsystems.dk/ IPW Systems a.s}
6 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
7 * @package METAjour
8 * @subpackage core
9 * $Id: staticfolderclass.php,v 1.1 2005/02/07 09:56:20 jan Exp $
10 */
11 require_once('basicclass.php');
12
13 class staticfolder extends basic {
14
15 function staticfolder() {
16 $this->basic();
17 $this->addcolumn('name',0,UI_STRING);
18
19 $this->removeview('createvariant');
20 }
21
22 function getRoot() {
23 return $this->userhandler->getDirStaticbinfile();
24 }
25
26 function getRelativePath($objectid) {
27 # returns the path above AND INCLUDING the referred objectid
28 # the method will usually be called with a parentid as parameter
29 # note that the complete relative path is returned WITHOUT a trailing slash
30 $res = '';
31 if ($objectid > 0) {
32 $obj = owRead($objectid);
33 if ($obj) {
34 $res = $obj->getName();
35 if ($obj->getParentId() > 0) $res = $this->getRelativePath($obj->getParentId()).'/'.$obj->getName();
36 }
37 }
38 return $res;
39 }
40
41 function getFullPath() {
42 # returns the complete absolute path to (and including) the current
43 # object. Only used from outside of the class
44 $s = $this->getRelativePath($this->getParentId());
45 if (!empty($s)) {
46 return $this->getRoot().$s.'/'.$this->getName();
47 } else {
48 return $this->getRoot().$this->getName();
49 }
50 }
51
52 function prv_CreateObject($arr) {
53 if (!file_exists($this->getRoot().$this->getRelativePath($this->getParentId()).'/'.$arr['name'])) {
54 mkdir($this->getRoot().$this->getRelativePath($this->getParentId()).'/'.$arr['name']);
55 }
56 parent::prv_CreateObject($arr);
57 }
58
59 function prv_UpdateObject($objectid, $arr) {
60 $obj = owRead($objectid);
61 if ($obj) {
62 if ($arr['name'] != $obj->elements[0]['name']) {
63 if (rename($this->getRoot().$this->getRelativePath($this->getParentId()).'/'.$obj->elements[0]['name'],
64 $this->getRoot().$this->getRelativePath($this->getParentId()).'/'.$arr['name']))
65 parent::prv_UpdateObject($objectid, $arr);
66 }
67 }
68 }
69
70 function prv_ReadObject($objectid) {
71 $arr = end($this->elements);
72 if (!is_dir($this->getRoot().$this->getRelativePath($arr['parentid']).'/'.$arr['name'])) {
73 $db = &getDbConn();
74 if (!empty($objectid)) $db->Execute("delete from ".$this->objecttable." where objectid = $objectid");
75 $this->_removeelement = true;
76 return array();
77 }
78 parent::prv_ReadObject($objectid);
79 }
80
81 function prv_DeleteObject() {
82 parent::prv_DeleteObject();
83 }
84
85 function listObjects($parentid=0,$objectid=0) {
86 $s = $this->getRoot().$this->getRelativePath($parentid).'/*';
87 $s = str_replace('//','/',$s);
88 $matches = glob($s,GLOB_ONLYDIR);
89 if (is_array($matches)) {
90 $db = &getDbConn();
91 $dirs = $db->getCol("select name from ".$this->objecttable.", object where ".$this->objecttable.".objectid = object.objectid and object.deleted = 0 and object.parentid = $parentid");
92 if (!$dirs) $dirs = array();
93 foreach ($matches as $fname) {
94 if (!in_array(basename($fname),$dirs)) {
95 $obj = owNew($this->type);
96 $obj->createObject(array('name' => basename($fname)),$parentid);
97 $check = glob($this->getRoot().$this->getRelativePath($parentid).'/'.basename($fname),GLOB_ONLYDIR);
98 if (!empty($check))
99 $db->execute("update object set haschild = 1 where objectid = ".$obj->getObjectId());
100 }
101 }
102 }
103 return parent::listObjects($parentid,$objectid);
104 }
105
106 }
Documentation generated on Thu, 9 Jun 2005 06:53:35 +0200 by phpDocumentor 1.2.3