/** * Maps a FolderClass object contained in a recordset to an object representation * * @param $rs Recordset filled with the object data * @return objeto Mapped FolderClass object */ function &mapOne($rs) { if ($rs == null) { return null; } $object = new FolderClass(); $object->setId($rs->fields["ID"]); $object->setClassID($rs->fields["classID"]); $object->setFolderID($rs->fields["folderID"]); $object->setIsDefault($rs->fields["isDefault"]); $object->setPosition($rs->fields["position"]); return $object; }
/** * Only to be called from getFolderArray, provides the recursive feature * @param $childrenArray array of children folders * @param $class The class being displayed * @param $allowedFolderArray Array being constructed with folders to display in a tree * @return allowedFolderArray for method chaining */ function getFolderArrayRecursive($childrenArray, $class, $allowedFolderArray, $object = null) { // Get the session $session = new Session(); // For each root folder, inspect it foreach ($childrenArray as $folder) { /* @var $folder Folder */ // Has this folder allowed children? if ($folder->hasAllowedLeaf($class, Action::ADD_OBJECTS_ACTION())) { // echo "Evaluando folder: " . $folder->getTitle() . "<br/>"; /* @var $folderClass FolderClass */ // Can the user add objects to this folder ? $folderClass = $folder->getFolderClass($class); if (is_null($folderClass)) { $folderClass = new FolderClass($class->getId(), $folder->getId()); $folderClass->setIsDefault(false); } // Must be displayed... $id = $folder->getId(); $parentId = 0; $closed = "leaf.gif"; $open = "leaf.gif"; $mode = ""; $checked = false; // If we are not rendering an update, we must check items that are marked as default if (is_null($object)) { $checked = $folderClass->getIsDefault(); } // Has him a parent ? if (is_null($folder->getParentId()) == false) { $parentId = $folder->getParentId(); } // If we are rendering an update, we must check items that are marked as it in the Persistence layer if ($object != null) { $checked = $object->isObjectInFolder($folder->getId()); } // Determine images if (count($folder->getChildren()) > 0) { $closed = "folderClosed.gif"; $open = "folderOpen.gif"; } // Create and add the new allowed item $arrayItem = array("id" => $id, "title" => $folder->getTitle(), "parentId" => $parentId, "closed" => $closed, "open" => $open, "mode" => $mode, "checked" => $checked); array_push($allowedFolderArray, $arrayItem); } // Display its children $allowedFolderArray = $this->getFolderArrayRecursive($folder->getChildren(), $class, $allowedFolderArray, $object); } return $allowedFolderArray; }
/** * Updates a new folder */ function updateFolder() { $controllerData =& $this->collectControlerData(); $folderId = $controllerData["folderIdHidden"]; $title = $controllerData["titleText"]; $parentId = $controllerData["parentIdHidden"]; $position = $controllerData["positionText"]; $shortDescription = $controllerData["shortDescriptionText"]; $longDescription = $controllerData["longDescriptionTextarea"]; $classesIdArray = $controllerData["classesIdSelect"]; if ($title == null || $title == "") { $this->addErrorMessage("title"); } if ($shortDescription == null || $shortDescription == "") { $this->addErrorMessage("shortdescription"); } if ($longDescription == null || $longDescription == "") { $this->addErrorMessage("longdescription"); } if (count($classesIdArray) <= 0) { $this->addErrorMessage("classes"); } if (count($this->controllerMessageArray) > 0) { $this->displayUpdateFolderView("addFolder.tpl.php"); return; } $folder = new Folder(); $folder->setId($folderId); $folder->setTitle($title); $folder->setParentId($parentId); $folder->setPosition($position); $folder->setShortDescription($shortDescription); $folder->setLongDescription($longDescription); $folderClassesArray = array(); foreach ($classesIdArray as $classId) { $folderClass = new FolderClass(); $folderClass->setClassID($classId); $folderClass->setPosition(1); $folderClass->setIsDefault(0); array_push($folderClassesArray, $folderClass); } $folder->setFolderClasses($folderClassesArray); $folderService = new FolderService(); $folderService->update($folder); $this->redirectToReferer(); }