Tree.class.php (18307B)
1 <?php 2 3 namespace util; 4 5 use cms\action\RequestParams; 6 use cms\base\Language as L; 7 use cms\model\PageContent; 8 use cms\model\Permission; 9 use cms\model\Alias; 10 use cms\model\Element; 11 use cms\model\Link; 12 use cms\model\BaseObject; 13 use cms\model\Page; 14 use cms\model\Template; 15 use cms\model\User; 16 use cms\model\Project; 17 use cms\model\Group; 18 use cms\model\Folder; 19 use cms\model\Value; 20 use language\Messages; 21 use util\exception\SecurityException; 22 23 24 /** 25 * Navigation tree. 26 * 27 * @author Jan Dankert 28 */ 29 class Tree 30 { 31 public $treeElements = array(); 32 33 private $userIsAdmin = false; 34 35 /** 36 * Konstruktor. 37 */ 38 public function __construct() 39 { 40 // Feststellen, ob der angemeldete Benutzer ein Administrator ist 41 $user = Request::getUser(); 42 $this->userIsAdmin = is_object($user) && $user->isAdmin; 43 } 44 45 public function root() 46 { 47 $this->overview(); 48 } 49 50 51 public function overview() 52 { 53 $treeElement = new TreeElement(); 54 $treeElement->id = 0; 55 $treeElement->text = L::lang('PROJECTS'); 56 $treeElement->description = L::lang('PROJECTS'); 57 $treeElement->action = 'projectlist'; 58 $treeElement->icon = 'projectlist'; 59 $treeElement->type = 'projects'; 60 61 $this->addTreeElement($treeElement); 62 63 if ($this->userIsAdmin) { 64 65 $treeElement = new TreeElement(); 66 $treeElement->text = L::lang('USER_AND_GROUPS'); 67 $treeElement->description = L::lang('USER_AND_GROUPS'); 68 $treeElement->icon = 'userlist'; 69 $treeElement->type = 'userandgroups'; 70 $treeElement->action = 'usergroup'; 71 72 $this->addTreeElement($treeElement); 73 } 74 75 76 if ($this->userIsAdmin) { 77 $treeElement = new TreeElement(); 78 $treeElement->text = L::lang('PREFERENCES'); 79 $treeElement->description = L::lang('PREFERENCES'); 80 $treeElement->icon = 'configuration'; 81 //$treeElement->type = 'configuration'; 82 $treeElement->action = 'configuration'; 83 84 $this->addTreeElement($treeElement); 85 } 86 87 } 88 89 90 public function userandgroups() 91 { 92 if (!$this->userIsAdmin) 93 throw new SecurityException(); 94 95 $treeElement = new TreeElement(); 96 $treeElement->text = L::lang('USER'); 97 $treeElement->description = L::lang('USER'); 98 $treeElement->action = 'userlist'; 99 $treeElement->icon = 'userlist'; 100 $treeElement->type = 'users'; 101 102 $this->addTreeElement($treeElement); 103 104 $treeElement = new TreeElement(); 105 $treeElement->text = L::lang('GROUPS'); 106 $treeElement->description = L::lang('GROUPS'); 107 $treeElement->action = 'grouplist'; 108 $treeElement->icon = 'grouplist'; 109 $treeElement->type = 'groups'; 110 111 $this->addTreeElement($treeElement); 112 } 113 114 115 public function projects() 116 { 117 // Schleife ueber alle Projekte 118 foreach (Project::getAllProjects() as $id => $name) { 119 120 $project = new Project($id); 121 $rootFolder = new Folder($project->getRootObjectId()); 122 $rootFolder->load(); 123 124 // Berechtigt für das Projekt? 125 if ($rootFolder->hasRight(Permission::ACL_READ)) { 126 $treeElement = new TreeElement(); 127 128 $treeElement->internalId = $id; 129 $treeElement->id = $id; 130 $treeElement->text = $name; 131 $treeElement->icon = 'project'; 132 $treeElement->action = 'project'; 133 $treeElement->type = 'project'; 134 $treeElement->description = ''; 135 136 $this->addTreeElement($treeElement); 137 } 138 } 139 } 140 141 142 public function project($projectid) 143 { 144 $project = new Project($projectid); 145 146 // Hoechster Ordner der Projektstruktur 147 $folder = new Folder($project->getRootObjectId()); 148 $folder->load(); 149 150 $defaultLanguageId = $project->getDefaultLanguageId(); 151 $defaultModelId = $project->getDefaultModelId(); 152 153 // Ermitteln, ob der Benutzer Projektadministrator ist 154 // Projektadministratoren haben das Recht, im Root-Ordner die Eigenschaften zu aendern. 155 $userIsProjectAdmin = $folder->hasRight(Permission::ACL_PROP); 156 157 if ($folder->hasRight(Permission::ACL_READ)) { 158 $treeElement = new TreeElement(); 159 $treeElement->id = $folder->objectid; 160 // $treeElement->text = $folder->name; 161 $treeElement->text = L::lang('FOLDER_ROOT'); 162 $treeElement->description = L::lang('FOLDER_ROOT_DESC'); 163 $treeElement->extraId[RequestParams::PARAM_LANGUAGE_ID] = $defaultLanguageId; 164 $treeElement->extraId[RequestParams::PARAM_MODEL_ID] = $defaultModelId; 165 $treeElement->icon = 'folder'; 166 $treeElement->action = 'folder'; 167 // $treeElement->url = Html::url( 'folder','',$folder->objectid,array(RequestParams::PARAM_TARGET=>'content') ); 168 $treeElement->type = 'folder'; 169 $treeElement->internalId = $folder->objectid; 170 $this->addTreeElement($treeElement); 171 } 172 173 174 // Templates 175 if ($userIsProjectAdmin) { 176 $treeElement = new TreeElement(); 177 $treeElement->id = $projectid; 178 $treeElement->extraId[RequestParams::PARAM_PROJECT_ID] = $projectid; 179 $treeElement->extraId[RequestParams::PARAM_MODEL_ID] = $defaultModelId; 180 $treeElement->extraId[RequestParams::PARAM_LANGUAGE_ID] = $defaultLanguageId; 181 $treeElement->internalId = $projectid; 182 $treeElement->text = L::lang('TEMPLATES'); 183 // $treeElement->url = Html::url('template','listing',0,array(RequestParams::PARAM_TARGETSUBACTION=>'listing',RequestParams::PARAM_TARGET=>'content')); 184 $treeElement->description = L::lang('TEMPLATES_DESC'); 185 $treeElement->icon = 'templatelist'; 186 $treeElement->action = 'templatelist'; 187 $treeElement->type = 'templates'; 188 $this->addTreeElement($treeElement); 189 } 190 191 192 // Sprachen 193 if ($userIsProjectAdmin) { 194 $treeElement = new TreeElement(); 195 $treeElement->description = ''; 196 $treeElement->id = $projectid; 197 $treeElement->extraId[RequestParams::PARAM_PROJECT_ID] = $projectid; 198 $treeElement->internalId = $projectid; 199 $treeElement->action = 'languagelist'; 200 $treeElement->text = L::lang('LANGUAGES'); 201 // $treeElement->url = Html::url('language','listing',0,array(RequestParams::PARAM_TARGETSUBACTION=>'listing',RequestParams::PARAM_TARGET=>'content')); 202 $treeElement->icon = 'languagelist'; 203 $treeElement->description = L::lang('LANGUAGES_DESC'); 204 205 // Nur fuer Projekt-Administratoren aufklappbar 206 if ($userIsProjectAdmin) 207 $treeElement->type = 'languages'; 208 209 $this->addTreeElement($treeElement); 210 } 211 212 if ($userIsProjectAdmin) { 213 214 // Projektmodelle 215 $treeElement = new TreeElement(); 216 $treeElement->description = ''; 217 218 // Nur fuer Projekt-Administratoren aufklappbar 219 if ($userIsProjectAdmin) 220 $treeElement->type = 'models'; 221 222 $treeElement->id = $projectid; 223 $treeElement->internalId = $projectid; 224 $treeElement->extraId[RequestParams::PARAM_PROJECT_ID] = $projectid; 225 $treeElement->description = L::lang('MODELS_DESC'); 226 $treeElement->text = L::lang('MODELS'); 227 // $treeElement->url = Html::url('model','listing',0,array(RequestParams::PARAM_TARGETSUBACTION=>'listing',RequestParams::PARAM_TARGET=>'content')); 228 $treeElement->action = 'modellist'; 229 $treeElement->icon = 'modellist'; 230 $this->addTreeElement($treeElement); 231 } 232 233 } 234 235 236 public function users() 237 { 238 if (!$this->userIsAdmin) 239 throw new SecurityException(); 240 241 242 foreach (User::getAllUsers() as $user) { 243 $treeElement = new TreeElement(); 244 $treeElement->id = $user->userid; 245 $treeElement->internalId = $user->userid; 246 $treeElement->text = $user->name; 247 $treeElement->action = 'user'; 248 //$treeElement->type = 'user'; 249 $treeElement->icon = 'user'; 250 251 $desc = $user->fullname; 252 253 if ($user->isAdmin) 254 $desc .= ' (' . L::lang('USER_ADMIN') . ') '; 255 if ($user->desc == "") 256 $desc .= ' - ' . L::lang('NO_DESCRIPTION_AVAILABLE'); 257 else 258 $desc .= ' - ' . $user->desc; 259 260 $treeElement->description = $desc; 261 262 $this->addTreeElement($treeElement); 263 } 264 } 265 266 267 public function groups() 268 { 269 if (!$this->userIsAdmin) 270 throw new SecurityException(); 271 272 273 foreach (Group::getRootGroups() as $id => $name) { 274 $treeElement = new TreeElement(); 275 276 $g = new Group($id); 277 $g->load(); 278 279 $treeElement->id = $id; 280 $treeElement->internalId = $id; 281 $treeElement->text = $g->name; 282 $treeElement->icon = 'group'; 283 $treeElement->description = L::lang('GROUP') . ' ' . $g->name . ': ' . implode(', ', $g->getUsers()); 284 $treeElement->type = 'userofgroup'; 285 $treeElement->action = 'group'; 286 287 $this->addTreeElement($treeElement); 288 } 289 } 290 291 292 public function userofgroup($id) 293 { 294 if (!$this->userIsAdmin) 295 throw new SecurityException(); 296 297 298 $g = new Group($id); 299 300 301 foreach ($g->getChildrenIds() as $id) { 302 $treeElement = new TreeElement(); 303 304 $subGroup = new Group($id); 305 $subGroup->load(); 306 $treeElement->id = $id; 307 $treeElement->internalId = $id; 308 $treeElement->text = $subGroup->name; 309 $treeElement->icon = 'group'; 310 $treeElement->description = L::lang('GROUP') . ' ' . $subGroup->name . ': ' . implode(', ', $subGroup->getUsers()); 311 $treeElement->type = 'userofgroup'; 312 $treeElement->action = 'group'; 313 314 $this->addTreeElement($treeElement); 315 } 316 317 318 319 foreach ($g->getUsers() as $id => $name) { 320 $treeElement = new TreeElement(); 321 322 $u = new User($id); 323 $u->load(); 324 $treeElement->id = $u->userid; 325 $treeElement->internalId = $u->userid; 326 $treeElement->text = $u->name; 327 $treeElement->icon = 'user'; 328 $treeElement->action = 'user'; 329 $treeElement->description = $u->fullname; 330 331 $this->addTreeElement($treeElement); 332 } 333 334 335 } 336 337 338 public function page($id) 339 { 340 $page = new Page($id); 341 342 $page->load(); 343 344 $template = new Template($page->templateid); 345 346 foreach ($template->getElementIds() as $elementid) { 347 $element = new Element($elementid); 348 $element->load(); 349 350 if ($element->isWritable()) { 351 $treeElement = new TreeElement(); 352 $treeElement->id = $id . '_' . $elementid; 353 $treeElement->internalId = $id . '_' . $elementid; 354 $treeElement->text = $element->label; 355 $treeElement->action = 'pageelement'; 356 357 if ( in_array($element->typeid,[Element::ELEMENT_TYPE_LINK,Element::ELEMENT_TYPE_INSERT])) 358 $treeElement->type = 'pageelement'; 359 360 $treeElement->icon = 'el_' . $element->getTypeName(); 361 $treeElement->extraId = array('elementid' => $elementid); 362 363 364 $treeElement->description = L::lang('EL_' . $element->getTypeName()); 365 if ($element->desc != '') 366 $treeElement->description .= ' - ' . Text::maxLength($element->desc, 25); 367 else 368 $treeElement->description .= ' - ' . L::lang('NO_DESCRIPTION_AVAILABLE'); 369 370 $this->addTreeElement($treeElement); 371 } 372 } 373 } 374 375 376 /** 377 * Gets the linked object (if there is one). 378 * 379 * @param $id 380 * @return void 381 * @throws exception\ObjectNotFoundException 382 */ 383 public function pageelement($id) 384 { 385 $ids = explode('_', $id); 386 if (count($ids) > 1) { 387 list($pageid, $elementid) = $ids; 388 389 $page = new Page($pageid); 390 391 $page->load(); 392 393 $element = new Element($elementid); 394 $element->load(); 395 396 $pageContent = new PageContent(); 397 $pageContent->pageId = $page->pageid; 398 $pageContent->elementId = $elementid; 399 $project = $page->getProject(); 400 $pageContent->languageid = $project->getDefaultLanguageId(); 401 $pageContent->load(); 402 403 $value = new Value(); 404 $value->contentid = $pageContent->contentId; 405 $value->load(); 406 407 if (BaseObject::available($value->linkToObjectId)) { 408 $o = new BaseObject($value->linkToObjectId); 409 $o->load(); 410 if ( $o->hasRight( Permission::ACL_READ ) ) { 411 412 $treeElement = new TreeElement(); 413 $treeElement->type = $o->getType(); 414 $treeElement->action = $o->getType(); 415 $treeElement->icon = $o->getType(); 416 $treeElement->id = $o->objectid; 417 $treeElement->internalId = $o->objectid; 418 $treeElement->extraId = array(); 419 $treeElement->text = $o->getName(); 420 $treeElement->description = L::lang('' . $o->getType()) . ' ' . $o->objectid; 421 422 $this->addTreeElement($treeElement); 423 } 424 } 425 } 426 } 427 428 429 public function value($id) 430 { 431 if ($id != 0) { 432 $value = new Value(); 433 $value->loadWithId($id); 434 435 $objectid = intval($value->linkToObjectId); 436 if ($objectid != 0) { 437 $object = new BaseObject($objectid); 438 $object->load(); 439 440 $treeElement = new TreeElement(); 441 $treeElement->id = $id; 442 $treeElement->internalId = $id; 443 $treeElement->text = $object->getDefaultName()->name; 444 if (in_array($object->getType(), array('page', 'folder'))) { 445 $treeElement->type = $object->getType(); 446 $treeElement->internalId = $object->objectid; 447 } 448 $treeElement->action = $object->getType(); 449 $treeElement->icon = $object->getType(); 450 $treeElement->extraId = array(RequestParams::PARAM_LANGUAGE_ID => $object->getProject()->getDefaultLanguageId()); 451 452 $defaultName = $object->getDefaultName(); 453 454 if ($defaultName->description ) 455 $treeElement->description .= ' - ' . $defaultName->description; 456 else 457 $treeElement->description .= ' - ' . L::lang('NO_DESCRIPTION_AVAILABLE'); 458 459 $this->addTreeElement($treeElement); 460 } 461 } 462 } 463 464 465 public function link($id) 466 { 467 $link = new Link($id); 468 $link->load(); 469 470 $o = new BaseObject($link->linkedObjectId); 471 $o->load(); 472 473 if ( $o->hasRight( Permission::ACL_READ ) ) { 474 // Object is readable 475 476 $treeElement = new TreeElement(); 477 $treeElement->id = $o->objectid; 478 $treeElement->internalId = $o->objectid; 479 $treeElement->text = $o->getName(); 480 $treeElement->description = L::lang('' . $o->getType()) . ' ' . $id; 481 482 $defaultName = $o->getDefaultName(); 483 484 if ($defaultName->description ) 485 $treeElement->description .= ': ' . $defaultName->description; 486 else 487 $treeElement->description .= ' - ' . L::lang('NO_DESCRIPTION_AVAILABLE'); 488 489 $treeElement->action = $o->getType(); 490 $treeElement->icon = $o->getType(); 491 $treeElement->extraId = array(RequestParams::PARAM_LANGUAGE_ID => $_REQUEST[RequestParams::PARAM_LANGUAGE_ID], RequestParams::PARAM_MODEL_ID => $_REQUEST[RequestParams::PARAM_MODEL_ID]); 492 493 // Besonderheiten fuer bestimmte Objekttypen 494 495 if ($o->isPage) { 496 // Nur wenn die Seite beschreibbar ist, werden die 497 // Elemente im Baum angezeigt 498 if ($o->hasRight(Permission::ACL_WRITE)) 499 $treeElement->type = 'pageelements'; 500 } 501 $this->addTreeElement($treeElement); 502 } 503 504 } 505 506 507 public function alias($id) 508 { 509 $alias = new Alias($id); 510 $alias->load(); 511 512 $o = new BaseObject($alias->linkedObjectId); 513 $o->load(); 514 515 $treeElement = new TreeElement(); 516 $treeElement->id = $o->objectid; 517 $treeElement->internalId = $o->objectid; 518 $treeElement->text = $o->getName(); 519 $treeElement->description = L::lang('' . $o->getType()) . ' ' . $id; 520 521 $treeElement->action = $o->getType(); 522 $treeElement->icon = $o->getType(); 523 524 // Besonderheiten fuer bestimmte Objekttypen 525 if ($o->isPage) { 526 // Nur wenn die Seite beschreibbar ist, werden die 527 // Elemente im Baum angezeigt 528 if ($o->hasRight(Permission::ACL_WRITE)) 529 $treeElement->type = 'page'; 530 } 531 532 $this->addTreeElement($treeElement); 533 } 534 535 536 public function url($id) 537 { 538 // URLs have no sub-nodes. 539 // do nothing. 540 } 541 542 543 /** 544 * Laedt Elemente zu einem Ordner 545 */ 546 public function folder($id) 547 { 548 $f = new Folder($id); 549 $f->load(); 550 551 /** @var BaseObject $o */ 552 foreach ($f->getObjects() as $o) { 553 // Wenn keine Leseberechtigung 554 if (!$o->hasRight(Permission::ACL_READ)) 555 continue; 556 557 $treeElement = new TreeElement(); 558 $treeElement->id = $o->objectid; 559 $treeElement->internalId = $o->objectid; 560 $treeElement->text = $o->getDefaultName()->name; 561 $treeElement->description = L::lang('' . $o->getType()) . ' ' . $o->objectid; 562 563 $defaultName = $o->getDefaultName(); 564 565 if ( $defaultName->description ) 566 $treeElement->description .= ': ' . $defaultName->description; 567 else 568 $treeElement->description .= ' - ' . L::lang('NO_DESCRIPTION_AVAILABLE'); 569 570 $treeElement->action = $o->getType(); 571 $treeElement->icon = $o->getType(); 572 573 if ( in_array($o->getType(),['folder','link','page','alias'])) // openable? 574 $treeElement->type = $o->getType(); 575 576 $this->addTreeElement($treeElement); 577 } 578 } 579 580 581 public function templates($projectid) 582 { 583 $project = new Project($projectid); 584 585 foreach ($project->getTemplates() as $id => $name) { 586 $treeElement = new TreeElement(); 587 588 $t = new Template($id); 589 $t->load(); 590 $treeElement->text = $t->name; 591 $treeElement->id = $id; 592 $treeElement->icon = 'template'; 593 $treeElement->action = 'template'; 594 $treeElement->internalId = $id; 595 $treeElement->extraId = array(); 596 $treeElement->type = 'template'; 597 $treeElement->description = $t->name . ' (' . L::lang(Messages::TEMPLATE) . ' ' . $id . ')'; 598 $this->addTreeElement($treeElement); 599 } 600 } 601 602 603 public function template($id) 604 { 605 606 $t = new Template($id); 607 $t->load(); 608 609 // Anzeigen der Template-Elemente 610 // 611 foreach ($t->getElementIds() as $elementid) { 612 $e = new Element($elementid); 613 $e->load(); 614 615 // "Code"-Element nur fuer Administratoren 616 if ($e->type == 'code' && !$this->userIsAdmin) 617 continue; 618 619 $treeElement = new TreeElement(); 620 $treeElement->id = $elementid; 621 $treeElement->internalId = $elementid; 622 $treeElement->extraId = array(); 623 $treeElement->text = $e->label; 624 $treeElement->icon = 'el_' . $e->type; 625 $treeElement->action = 'element'; 626 627 if ($e->desc == '') 628 $desc = L::lang('NO_DESCRIPTION_AVAILABLE'); 629 else 630 $desc = $e->desc; 631 $treeElement->description = $e->name . ' (' . L::lang('EL_' . $e->type) . '): ' . Text::maxLength($desc, 40); 632 $this->addTreeElement($treeElement); 633 } 634 } 635 636 637 /** 638 * Sprachen 639 */ 640 public function languages($projectid) 641 { 642 // Sprachvarianten 643 // 644 $project = new Project($projectid); 645 646 foreach ($project->getLanguages() as $languageid => $name) { 647 $treeElement = new TreeElement(); 648 $treeElement->id = $languageid; 649 $treeElement->internalId = $languageid; 650 $treeElement->text = $name; 651 $treeElement->icon = 'language'; 652 $treeElement->action = 'language'; 653 $treeElement->description = ''; 654 $this->addTreeElement($treeElement); 655 } 656 } 657 658 659 // Projektvarianten 660 // 661 public function models($projectid) 662 { 663 664 $project = new Project($projectid); 665 666 foreach ($project->getModels() as $id => $name) { 667 $treeElement = new TreeElement(); 668 $treeElement->id = $id; 669 $treeElement->internalId = $id; 670 $treeElement->text = $name; 671 $treeElement->action = 'model'; 672 $treeElement->icon = 'model'; 673 $treeElement->description = ''; 674 $this->addTreeElement($treeElement); 675 } 676 } 677 678 679 /** 680 * Hinzufuegen eines Baum-Elementes 681 * @param TreeElement Hinzuzufuegendes Baumelement 682 */ 683 private function addTreeElement($treeElement) 684 { 685 $this->treeElements[] = $treeElement; 686 } 687 } 688 689 ?>