/** * Constructs the IcfTemplating object */ function IcfTemplating($page = "") { // Load configuration $icfConfig = new IcfConfig(); $this->tpl =& new Savant2(); // add a template path $this->tpl->addPath("template", $icfConfig->cfg_site_beTemplatePath); $this->tpl->assign("templatePath", $icfConfig->cfg_site_beTemplateUrl); $this->tpl->assign("basePath", $icfConfig->cfg_site_feBaseUrl); // multilingual support require_once $this->getStringsFile($icfConfig); // Session support $session = new Session(); $this->tpl->assign("user", $session->getSessionUser()); // basic toolbar support $toolbarItem = new icfToolbarItem(); $toolbarItem->setName("exit"); $toolbarItem->setTitle($text["exit"]); $toolbarItem->setUrl("login.php"); $toolbarItem->setImage("/images/exit.png"); $toolbarItem->setImage2("/images/exit_f2.png"); $toolbar = new IcfToolbar(); $toolbar->addToolbarItem($toolbarItem); // Menu support $menu = new IcfMenu(); // Only work it if the session is valid $session = new Session(); if ($session->isValid() == true) { $user = $session->getSessionUser(); // Classes whose objects the user can create $baseClassMapper = new BaseClassMapper(); $classes = $baseClassMapper->findByPermission(Action::ADD_OBJECTS_ACTION(), $user); $menu->setContents($classes); // The folders $folderMapper = new FolderMapper(); $rootFolder = $folderMapper->getRoot(); $folderArray = array(0 => $rootFolder); $menu->setFolders($folderArray); } // Set the generated content in the context of this request (available for client pages to change it) $this->setText($text); $this->setToolbar($toolbar); $this->setMenu($menu); }
/** * Constructs HomeController, executing the method given as parameter * * @param $method Name of the method to execute * @param &tpl Template method implementation */ function HomeController($method = null, $icfTemplating) { $this->tpl = $icfTemplating->getTpl(); $this->text = $icfTemplating->getText(); // Title of the page $this->tpl->assign('pageTitle', $this->text['home']); // Pending contents $objectMapper = new ObjectMapper(); $objects = $objectMapper->findPending(); $objectsCount = count($objects); $this->controllerData["pending"] = $objectsCount; // Allowed classes to add $session = new Session(); $baseClassMapper = new BaseClassMapper(); $classArray = $baseClassMapper->findByPermission(Action::ADD_OBJECTS_ACTION(), $session->getSessionUser()); $this->tpl->assign("classArray", $classArray); switch ($method) { default: $this->show_view(); } }
/** * Synchronizes an object with the database * @param $object object to be synchronized. It should already be persistent (had its id assigned) */ function update($object) { // Set updated and updatedBy $isoDateFormat = new IsoDateFormat(); $session = new Session(); $date = Date::getTodayDate(); $user = $session->getSessionUser(); $object->setUpdated($isoDateFormat->toDatetimeString($date)); $object->setUpdatedBy($user->getId()); $persistence = $this->newPersistenceObject(); $persistence->setProperty("ID", $object->getId()); $persistence->setProperty("classID", $object->getClassID()); $persistence->setProperty("created", $object->getCreated()); $persistence->setProperty("createdBy", $object->getCreatedBy()); $persistence->setProperty("endPublishing", $object->getEndPublishing()); $persistence->setProperty("fullTextIndex", $object->getFullTextIndex()); $persistence->setProperty("hits", $object->getHits()); $persistence->setProperty("isPublished", $object->getIsPublished()); $persistence->setProperty("startPublishing", $object->getStartPublishing()); $persistence->setProperty("updated", $object->getUpdated()); $persistence->setProperty("updatedBy", $object->getUpdatedBy()); $persistence->update(); }
/** * Checks if a certain user can do certain action * @param $user User - user that intends to do action, if null, session user is employed * @param $action Action - action to be done * @return boolean - true if the user should be allowed, false if not */ function canDoAction($user = null, $action) { if ($user == null) { $session = new Session(); $user = $session->getSessionUser(); } // Has this folder the permission itself ? if ($this->getPermission($user, $action) != null) { return true; } // It doesn't... has any of his parents an inheritable permission ? $folder = $this->getFolder(); $parent = $folder->getParent(); while ($parent != null) { $folderClass = $parent->getFolderClass($this->getClass()); // If its father folder does not have a relationship to the wanted class, go to the grandfather... if ($folderClass == null) { $parent = $parent->getParent(); continue; } $permission = $folderClass->getPermission($user, $action); if ($permission != null) { // The permission exists... if it is inheritable, then this object should inherit it if ($permission->getIncludeChildren()) { return true; } } // Continue the search in the parent of this parent $parent = $parent->getParent(); } return false; }
/** * Checks if a certain user can do certain action for one of the classes linked to this folder * @param $user User - user that intends to do action. If null, session user is used * @param $action Action - action to be done * @return boolean - true if the user should be allowed, false if not */ function canDoAction($user = null, $action) { if ($user == null) { $session = new Session(); $user = $session->getSessionUser(); } foreach ($this->getFolderClasses() as $folderClass) { if ($folderClass->canDoAction($user, $action)) { return true; } } return false; }
/** * Determines if the given user can do certain action. This is determined * examining the folders that this object is in and thus extracting the permissions. * @param $user User instance, tipically from the session, If $user is null, the user from session is used. * @param $action Action instance, obtained from one of its static accesors * @return true if the user is allowed, false if it is not */ function canDoAction($user = null, $action) { if ($user == null) { $session = new Session(); $user = $session->getSessionUser(); } $objectFoldersArray = $this->getObjectFolders(); foreach ($objectFoldersArray as $objectFolder) { /* @var $objectFolder ObjectFolder */ $folder = $objectFolder->getFolder(); $folderClass = $folder->getFolderClass($this->getClass()); // If it has no record for this class, continue (shouldn't happen unless the user erases a folderClass previously owned) if ($folderClass == null) { continue; } if ($folderClass->canDoAction($user, $action)) { return true; } } return false; }