File modules/cms/ui/action/tree/TreePathAction.class.php
Last commit: Thu Feb 16 22:57:35 2023 +0100 Jan Dankert New: More functions (adding, deleting) for tags.
1 <?php 2 namespace cms\ui\action\tree; 3 use cms\action\RequestParams; 4 use cms\model\BaseObject; 5 use cms\model\Element; 6 use cms\model\Folder; 7 use cms\model\Language; 8 use cms\model\Model; 9 use cms\model\ModelFactory; 10 use cms\model\Page; 11 use cms\model\Project; 12 use cms\model\Tag; 13 use cms\model\Template; 14 use cms\ui\action\TreeAction; 15 use cms\action\Method; 16 17 /** 18 * Calculating a path to an object, normally used for a breadcrumb navigation. 19 */ 20 class TreePathAction extends TreeAction implements Method { 21 22 public function view() { 23 $type = $this->request->getAlphanum('type'); 24 $id = $this->request->getAlphanum('id' ); 25 26 // Calculating the path to the actual object 27 $result = $this->calculatePath($type, $id); 28 $this->setTemplateVar('path', $result); 29 30 // The parent object 31 $this->setTemplateVar('parent', end($result ) ); 32 33 // The actual object 34 $name = $this->calculateName($type, $id); 35 $this->setTemplateVar('actual', $this->pathItem($type, $id, $name)); 36 } 37 38 39 public function post() { 40 } 41 42 43 /** 44 * The path to an object. 45 */ 46 protected function calculatePath($type, $id) { 47 48 switch( $type ) { 49 50 case 'index': 51 return array( 52 ); 53 54 case 'projectlist': 55 return array( 56 $this->pathItem('index',0) 57 ); 58 59 case 'taglist': 60 $project = new Project( $id ); 61 return array( 62 $this->pathItem('index' ,0), 63 $this->pathItem('projectlist',0), 64 $this->pathItem('project' , $project->projectid), 65 ); 66 67 case 'tag': 68 $tag = new Tag( $id ); 69 $tag->load(); 70 $project = new Project( $tag->projectid ); 71 return array( 72 $this->pathItem('index' ,0), 73 $this->pathItem('projectlist',0), 74 $this->pathItem('project' , $project->projectid), 75 $this->pathItem('taglist' , $project->projectid), 76 ); 77 78 case 'configuration': 79 return array( 80 $this->pathItem('index',0) 81 ); 82 83 case 'project': 84 return array( 85 $this->pathItem('index' ,0 ), 86 $this->pathItem('projectlist',0) 87 ); 88 case 'folder': 89 case 'link' : 90 case 'url' : 91 case 'alias' : 92 case 'page' : 93 case 'file' : 94 case 'image' : 95 case 'text' : 96 case 'script': 97 $o = new BaseObject( $id ); 98 $o->load(); 99 100 $result= array( 101 $this->pathItem('index' ,0 ), 102 $this->pathItem('projectlist' ), 103 $this->pathItem('project' , $o->projectid), 104 ); 105 106 $parents = array_keys( $o->parentObjectFileNames(true) ); 107 foreach( $parents as $pid ) 108 { 109 $f = new Folder($pid); 110 $f->load(); 111 $result[] = $this->pathItem('folder' ,$pid,$f->filename ); 112 } 113 return $result; 114 115 case 'pageelement' : 116 117 $ids = explode('_',$id); 118 if ( count($ids) > 1 ) 119 { 120 list( $pageid, $elementid ) = $ids; 121 } 122 123 $p = new Page($pageid); 124 $p->load(); 125 126 $result= array( 127 $this->pathItem('index' ,0 ), 128 $this->pathItem('projectlist' ), 129 $this->pathItem('project' , $p->projectid), 130 ); 131 132 $parents = array_keys( $p->parentObjectFileNames(true ) ); 133 foreach( $parents as $pid ) { 134 $f = new Folder($pid); 135 $f->load(); 136 $result[] = $this->pathItem('folder' ,$pid,$f->filename ); 137 } 138 $result[] = $this->pathItem('page' ,$pageid,$p->filename ); 139 return $result; 140 141 case 'userlist': 142 return array( 143 $this->pathItem('index' ,0 ), 144 $this->pathItem('usergroup' ,0) 145 ); 146 case 'usergroup': 147 return array( 148 $this->pathItem('index' ,0) 149 ); 150 case 'user': 151 return array( 152 $this->pathItem('index' ,0 ), 153 $this->pathItem('usergroup' ,0), 154 $this->pathItem('userlist' ,0) 155 ); 156 case 'grouplist': 157 return array( 158 $this->pathItem('index' ,0 ), 159 $this->pathItem('usergroup' ,0) 160 ); 161 case 'group': 162 return array( 163 $this->pathItem('index' ,0 ), 164 $this->pathItem('usergroup' ,0), 165 $this->pathItem('grouplist' ,0), 166 ); 167 168 case 'templatelist': 169 case 'languagelist': 170 case 'modellist': 171 return array( 172 $this->pathItem('index' ,0 ), 173 $this->pathItem('projectlist' ,0 ), 174 $this->pathItem('project' ,$id) 175 ); 176 177 case 'template': 178 $t = new Template( $id ); 179 $t->load(); 180 181 return array( 182 $this->pathItem('index' ,0 ), 183 $this->pathItem('projectlist' ,0 ), 184 $this->pathItem('project' ,$t->projectid), 185 $this->pathItem('templatelist',$t->projectid) 186 ); 187 188 case 'element': 189 $e = new Element( $id ); 190 $e->load(); 191 $t = new Template( $e->templateid ); 192 $t->load(); 193 194 return array( 195 $this->pathItem('index' ,0 ), 196 $this->pathItem('projectlist' ,0 ), 197 $this->pathItem('project' ,$t->projectid ), 198 $this->pathItem('templatelist',$t->projectid ), 199 $this->pathItem('template' ,$t->templateid,$t->name) 200 ); 201 202 case 'language': 203 $l = new Language( $id ); 204 $l->load(); 205 206 return array( 207 $this->pathItem('index' ,0 ), 208 $this->pathItem('projectlist' ,0 ), 209 $this->pathItem('project' ,$l->projectid), 210 $this->pathItem('languagelist',$l->projectid) 211 ); 212 213 case 'model': 214 $m = new Model( $id ); 215 $m->load(); 216 217 return array( 218 $this->pathItem('index' ,0 ), 219 $this->pathItem('projectlist' ,0 ), 220 $this->pathItem('project' ,$m->projectid), 221 $this->pathItem('modellist' ,$m->projectid) 222 ); 223 224 default: 225 throw new \InvalidArgumentException('Unknown type: '.$type); 226 } 227 } 228 229 230 protected function pathItem($action, $id = 0, $name = '' ) { 231 return array('type'=>$this->typeToInternal($action),'action'=>$action ,'id'=>$id,'name'=>$name ); 232 } 233 234 235 private function typeToInternal($type) 236 { 237 switch( $type) { 238 239 case 'projectlist': 240 return 'projects'; 241 242 case 'userlist': 243 return 'users'; 244 245 case 'grouplist': 246 return 'groups'; 247 248 case 'templatelist': 249 return 'templates'; 250 251 case 'languagelist': 252 return 'languages'; 253 254 case 'modellist': 255 return 'models'; 256 257 default: 258 return $type; 259 } 260 261 } 262 263 /** 264 * @param $type 265 * @param $id 266 * @return string 267 */ 268 protected function calculateName($type, $id) 269 { 270 $o = ModelFactory::create($type, $id); 271 272 if ($o) { 273 $o->load(); 274 $name = $o->getName(); 275 } 276 else{ 277 //$name = \cms\base\Language::lang($type); 278 $name = ''; 279 } 280 return $name; 281 } 282 283 }
Downloadmodules/cms/ui/action/tree/TreePathAction.class.php
History Thu, 16 Feb 2023 22:57:35 +0100 Jan Dankert New: More functions (adding, deleting) for tags. Thu, 16 Feb 2023 01:04:38 +0100 Jan Dankert New: Tags for base objects. Sun, 29 Jan 2023 00:20:21 +0100 Jan Dankert New node type "Script". Sat, 19 Mar 2022 00:43:14 +0100 dankert Fix: Added 'alias' to the list of known object types. Wed, 10 Mar 2021 23:51:22 +0100 Jan Dankert Refactoring: Cleaned the Request params. Mon, 8 Mar 2021 01:24:06 +0100 Jan Dankert New: Action menu on many lists; tables have now a fixed layout Thu, 4 Mar 2021 03:39:25 +0100 Jan Dankert New: Separate edit action for images and texts. Fri, 26 Feb 2021 01:06:01 +0100 Jan Dankert Refactoring accessing the request parameter values. Tue, 23 Feb 2021 23:27:50 +0100 Jan Dankert Fix: 'index' is the highest action in the path and in the breadcrumb. Wed, 10 Feb 2021 00:00:21 +0100 Jan Dankert Using only fullscreen views; Navigate to parent instead of complete breadcrumb. Wed, 18 Nov 2020 20:23:57 +0100 Jan Dankert Cleaning up the UI actions. Tue, 17 Nov 2020 23:51:00 +0100 Jan Dankert Refactoring: Every Actionmethod has now its own class.