/** * Switches two folders position. * @param $objectFolderId int - the ObjectFolder that is going to switch positions with one that is next to it * @param $incremental int - a relative position to the first ObjectFolder. The folder found in that position * switches position with the first folder. It'll be tippically -1 (folderUp) or 1 (folderDown) * @access private */ function switchObjectFolders($objectFolderId, $incremental) { // Get folder $objectFolderMapper = new ObjectFolderMapper(); $objectFolder = $objectFolderMapper->get($objectFolderId); /* @var $objectFolder ObjectFolder */ /* @var $folder Folder */ // Get container folder $folder = $objectFolder->getFolder(); // Get its children $objectFolderArray =& $folder->getObjectFolders(); // Lookup the folder $position = -1000; for ($i = 0; $i < count($objectFolderArray); $i++) { $arrayObjectFolder = $objectFolderArray[$i]; if ($objectFolder->getId() == $arrayObjectFolder->getId()) { $position = $i; break; } } assert($position != -1000); $position = $position + $incremental; $otherObjectFolder = $objectFolderArray[$position]; // Switch positions $objectFolder->switchPositionWith($otherObjectFolder); // Coordinate transaction $icfDatabase = new IcfDatabase(); $conn =& $icfDatabase->dbOpen(); $conn->StartTrans(); $objectFolderMapper = new ObjectFolderMapper(); $objectFolderMapper->setConnection($conn); // Save objects $objectFolderMapper->update($objectFolder); $objectFolderMapper->update($otherObjectFolder); // Close transaction $conn->completeTrans(); $icfDatabase->dbClose($conn); }
/** * Updates an object * @param $object Object to update, must have its ID set */ function update(&$object) { // Fill object Fulltext index $fullTextIndex = $this->generateFullTextIndex($object); $object->setFullTextIndex($fullTextIndex); // Coordinate transaction $icfDatabase = new IcfDatabase(); $conn = $icfDatabase->dbOpen(); $conn->StartTrans(); // Update object $objectMapper = new ObjectMapper(); $objectMapper->setConnection($conn); $objectMapper->update($object); // Recreate attributes $objectAttributeMapper = new ObjectAttributeMapper(); $objectAttributeMapper->setConnection($conn); $objectAttributeMapper->deleteByObjectId($object->getId()); $objectAttributeArray =& $object->getAttributes(); foreach ($objectAttributeArray as $objectAttribute) { $objectAttribute->setObjectID($object->getId()); $objectAttributeMapper->save($objectAttribute); } // Recreate folders $objectFolderMapper = new ObjectFolderMapper(); $objectFolderMapper->setConnection($conn); $objectFolderMapper->deleteByObjectId($object->getId()); $objectFolderArray =& $object->getObjectFolders(); foreach ($objectFolderArray as $objectFolder) { $objectFolder->setObjectID($object->getId()); $objectFolderMapper->save($objectFolder); } // Recreate relationships $objectRelationMapper = new ObjectRelationMapper(); $objectRelationMapper->setConnection($conn); $objectRelationMapper->deleteByParentId($object->getId()); $objectRelationArray =& $object->getObjectRelations(); foreach ($objectRelationArray as $objectRelation) { /* @var $objectRelation ObjectRelation */ $objectRelation->setParentID($object->getId()); $objectRelationMapper->save($objectRelation); } // Close transaction $conn->completeTrans(); $icfDatabase->dbClose($conn); }