public function getProperties() { global $lng; $props = array(); if (!ilObjRoomSharing::_lookupOnline($this->obj_id)) { $props[] = array("alert" => true, "property" => $lng->txt("status"), "value" => $lng->txt("offline")); } return $props; }
/** * Clones all data of a given room sharing pool to a new one. * * @param ilObjRoomSharing $a_pool * @param ilObjRoomSharing $a_new_pool * * @return bool true if cloning was successful */ public static function clonePool(ilObjRoomSharing $a_pool, ilObjRoomSharing $a_new_pool) { // Pool main properties $rooms_agreement_file_id = $a_pool->getRoomsAgreementFileId(); $cloned_rooms_agreement_file_id = "0"; if (ilRoomSharingNumericUtils::isPositiveNumber($rooms_agreement_file_id)) { $rooms_agreement_file = new ilObjMediaObject($rooms_agreement_file_id); $cloned_agreement_file = $rooms_agreement_file->duplicate(); $cloned_rooms_agreement_file_id = $cloned_agreement_file->getId(); } $a_new_pool->setOnline($a_pool->isOnline()); $a_new_pool->setMaxBookTime($a_pool->getMaxBookTime()); $a_new_pool->setRoomsAgreementFileId($cloned_rooms_agreement_file_id); $a_new_pool->update(); // Other database related information $db = new ilRoomSharingDatabase($a_pool->getPoolId()); $clone_db = new ilRoomSharingDatabase($a_new_pool->getPoolId()); // Booking attributes $all_booking_attributes = $db->getAllBookingAttributes(); foreach ($all_booking_attributes as $booking_attribute) { $clone_db->insertBookingAttribute($booking_attribute['name']); } // Room attributes $all_room_attributes = $db->getAllRoomAttributes(); $room_attrs_id_mapping = array(); foreach ($all_room_attributes as $room_attribute) { $id_of_cloned_attribute = $clone_db->insertRoomAttribute($room_attribute['name']); $room_attrs_id_mapping[$room_attribute['id']] = $id_of_cloned_attribute; } // Floorplans $all_floorplan_ids = $db->getAllFloorplanIds(); // Key is original id and value the new one $floorplans_ids_mapping = array(); foreach ($all_floorplan_ids as $floorplan_id) { if (ilRoomSharingNumericUtils::isPositiveNumber($floorplan_id)) { $floorplan = new ilObjMediaObject($floorplan_id); $cloned_floorplan = $floorplan->duplicate(); $clone_db->insertFloorplan($cloned_floorplan->getId()); $floorplans_ids_mapping[$floorplan_id] = $cloned_floorplan->getId(); } } // Rooms $all_rooms = $db->getAllRooms(); foreach ($all_rooms as $room) { // Critical: should be the floorplan_id the building_id or the file_id? // building_id is actually used.. $mapped_floorplan_id = $floorplans_ids_mapping[$room['file_id']]; $flooplan_id_to_set = "0"; if (ilRoomSharingNumericUtils::isPositiveNumber($mapped_floorplan_id)) { $flooplan_id_to_set = $mapped_floorplan_id; } $cloned_room_id = $clone_db->insertRoom($room['name'], $room['type'], $room['min_alloc'], $room['max_alloc'], $flooplan_id_to_set, $room['building_id']); // Room attribute assignments $room_attributes = $db->getAttributesForRoom($room['id']); foreach ($room_attributes as $room_attribute) { $mapped_attr_id = $room_attrs_id_mapping[$room_attribute['id']]; if (ilRoomSharingNumericUtils::isPositiveNumber($mapped_attr_id)) { $clone_db->insertAttributeForRoom($cloned_room_id, $mapped_attr_id, $room_attribute['count']); } } } // Privileges $classes = $db->getClasses(); // Key is original id and value the new one $mapped_classes_ids = array(); foreach ($classes as $class) { $cloned_class_id = $clone_db->insertClass($class['name'], $class['description'], $class['role_id'], $class['priority'], $class['id']); $mapped_classes_ids[$class['id']] = $cloned_class_id; } foreach ($mapped_classes_ids as $class_id => $cloned_class_id) { $users_ids_for_class = $db->getUsersForClass($class_id); foreach ($users_ids_for_class as $user_id) { $clone_db->assignUserToClass($cloned_class_id, $user_id); } } }
/** * Checks wether a user may invoke a command or not * (this method is called by ilAccessHandler::checkAccess) * * Please do not check any preconditions handled by * ilConditionHandler here. Also don't do usual RBAC checks. * * @param string $a_cmd * @param string $a_permission * @param int $a_ref_id * @param int $a_obj_id * @param int $a_user_id (if not provided, current user is taken) * * @return boolean true if the pool can be shown */ public function _checkAccess($a_cmd, $a_permission, $a_ref_id, $a_obj_id, $a_user_id = "") { /* @var $ilAccess ilAccessHandler */ /* @var $ilUser ilObjUser */ /* @var $lng ilLanguage */ global $ilUser, $ilAccess, $lng; if ($a_user_id === "") { $a_user_id = $ilUser->getId(); } $rVal = false; // Check whether the user has write permissions (owner has always write permissions). if ($ilAccess->checkAccessOfUser($a_user_id, 'write', '', $a_ref_id, "xrs", $a_obj_id)) { $rVal = true; } else { $rVal = ilObjRoomSharing::_lookupOnline($a_obj_id); if (!$rVal) { $lng->loadLanguageModule("rep_robj_xrs"); $message = $lng->txt('rep_robj_xrs_pool') . ' "' . ilObject2::_lookupTitle($a_obj_id) . '" ' . $lng->txt('rep_robj_xrs_is_offline'); ilUtil::sendInfo($message, true); } } return $rVal; }