/** * Method to add a new booking into the database * * @param type $a_booking_values Array with the values of the booking * @param type $a_booking_attr_values Array with the values of the booking-attributes * @param type $a_booking_participants Array with the values of the participants * @param type $a_recurrence_entries Array with recurrence information * @param boolean $sendmessage Send message * * @throws ilRoomSharingBookException * @return array Booking-IDs which are canceled */ public function addBooking($a_booking_values, $a_booking_attr_values, $a_booking_participants, $a_recurrence_entries, $sendmessage = true) { if ($this->permission->checkPrivilege(PRIVC::ADD_OWN_BOOKINGS)) { $this->date_from = $a_booking_values['from']['date'] . " " . $a_booking_values['from']['time']; $this->date_to = $a_booking_values['to']['date'] . " " . $a_booking_values['to']['time']; $this->room_id = $a_booking_values['room']; $this->participants = $a_booking_participants; $this->recurrence = $a_recurrence_entries; $datetimes = $this->generateDatetimesForBooking(); $this->validateBookingInput($datetimes['from'], $datetimes['to']); $a_booking_values['from'] = $datetimes['from']; $a_booking_values['to'] = $datetimes['to']; $booking_ids_of_bookings_to_be_canceled = $this->ilRoomsharingDatabase->getBookingIdsForRoomInDateimeRanges($this->room_id, $a_booking_values['from'], $a_booking_values['to']); if (ilRoomSharingNumericUtils::isPositiveNumber(count($booking_ids_of_bookings_to_be_canceled))) { $bookings = new ilRoomSharingBookings($this->pool_id); try { $bookings->removeMultipleBookings($booking_ids_of_bookings_to_be_canceled, true); } catch (ilRoomSharingBookingsException $ex) { throw new ilRoomSharingBookException($ex->getMessage()); } } $success = $this->ilRoomsharingDatabase->insertBookingRecurrence($a_booking_attr_values, $a_booking_values, $a_booking_participants); if ($success) { if ($sendmessage) { $this->sendBookingNotification(); } return count($booking_ids_of_bookings_to_be_canceled); } else { throw new ilRoomSharingBookException($this->lng->txt('rep_robj_xrs_booking_add_error')); } } else { throw new ilRoomSharingBookException($this->lng->txt('rep_robj_xrs_no_permission_for_action')); } return 0; }
/** * Reads a booking * * @param array $a_bookingData * @param integer $a_participation_id * * @return array Booking-Information */ private function readBookingData($a_bookingData) { $one_booking = array(); $one_booking['recurrence'] = ilRoomSharingNumericUtils::isPositiveNumber($a_bookingData['seq_id']); $one_booking['date'] = ilRoomSharingBookingUtils::readBookingDate($a_bookingData); $one_booking['sortdate'] = $a_bookingData['date_from']; // Get the name of the booked room $one_booking['room'] = $this->ilRoomsharingDatabase->getRoomName($a_bookingData['room_id']); $one_booking['room_id'] = $a_bookingData['room_id']; $one_booking['subject'] = $a_bookingData['subject']; $one_booking['person_responsible'] = $this->readBookingResponsiblePerson($a_bookingData['user_id']); $one_booking['person_responsible_id'] = $a_bookingData['user_id']; // The booking id $one_booking['booking_id'] = $a_bookingData['id']; return $one_booking; }
/** * @covers ilRoomSharingNumericUtils::allNumbersPositive */ public function testNotAllNumbersPositive() { $ZERO1 = 0; $ZERO2 = 0.0; $NEG1 = -1; $NEG2 = -0.0342; $numbers1 = array(1, '1', "1", PHP_INT_MAX, $ZERO1, '0x4', 0.01, 1.5, PHP_INT_MAX + 0.234); $this->assertFalse(UTILS::allNumbersPositive($numbers1)); $this->assertFalse(UTILS::allNumbersPositive($numbers1, false)); $numbers2 = array(1, '1', "1", PHP_INT_MAX, '0x4', 0.01, $ZERO2, 1.5, PHP_INT_MAX + 0.234); $this->assertFalse(UTILS::allNumbersPositive($numbers2)); $this->assertFalse(UTILS::allNumbersPositive($numbers2, false)); $numbers3 = array(1, '1', $NEG1, "1", PHP_INT_MAX, '0x4', 0.01, 1.5, PHP_INT_MAX + 0.234); $this->assertFalse(UTILS::allNumbersPositive($numbers3)); $this->assertFalse(UTILS::allNumbersPositive($numbers3, false)); $this->assertFalse(UTILS::allNumbersPositive($numbers3, true)); $numbers4 = array(1, '1', "1", PHP_INT_MAX, '0x4', 0.01, 1.5, $NEG2, PHP_INT_MAX + 0.234); $this->assertFalse(UTILS::allNumbersPositive($numbers4)); $this->assertFalse(UTILS::allNumbersPositive($numbers4, false)); $this->assertFalse(UTILS::allNumbersPositive($numbers4, true)); }
/** * Generates monthly days at a fixed date with a fixed number of repeatings. * What is a fixed date? 1-31 (day of month) * * @param string $a_startday Startday * @param integer $a_monthday Number for day of month * @param string $a_count Number of repeatings * @param integer $a_every_x_months every X months (e.g. every 2-months) * @param string $a_time_from Time from (hh:mm:ss) * @param string $a_time_to Time to (hh:mm:ss) * @param integer $a_day_difference Day difference between from-day and to-day * * @return array Generated Date(times) */ public static function generateMonthlyDaysAtFixedDateWithCount($a_startday, $a_monthday, $a_count, $a_every_x_months, $a_time_from = NULL, $a_time_to = NULL, $a_day_difference = NULL) { if (ilRoomSharingNumericUtils::isPositiveNumber($a_day_difference, true)) { $day_difference_to_end_day = $a_day_difference; } else { $day_difference_to_end_day = 0; } if ($a_time_from != NULL) { $time = " " . $a_time_from; $time_format = " H:i:s"; } else { $time = ""; $time_format = ""; } $startday = $a_startday . $time; $day_of_startday = date("d", strtotime($startday)); //Is the startday in the future? Then skip the month of the startday! if ($day_of_startday > $a_monthday) { $startday = date('Y-m-d' . $time_format, strtotime($startday . " + " . $a_every_x_months . " month")); } $days['from'] = array(); $days['to'] = array(); for ($i = 0; $i < $a_count; $i++) { $startmonth = date('m', strtotime($startday)); $startyear = date('Y', strtotime($startday)); $starttime = date($time_format, strtotime($startday)); if (checkdate($startmonth, $a_monthday, $startyear)) { $days['from'][] = $startyear . "-" . $startmonth . "-" . $a_monthday . $starttime; } else { //If the day is not valid (e.g. 31 February), what to do? //--> Calendar does nothing! So here nothing, too! } //Set the startday to the next X month (depending on user choice) $startday = date('Y-m-d' . $time_format, strtotime($startday . " + " . $a_every_x_months . " month")); } $days['from'] = self::removeDatesBeforeNow($days['from'], $time_format); foreach ($days['from'] as $start_day) { $to_date = date('Y-m-d', strtotime($start_day . ' + ' . $day_difference_to_end_day . ' day')); if ($a_time_to != NULL) { $days['to'][] = $to_date . " " . $a_time_to; } else { $days['to'][] = $to_date; } } return $days; }
/** * 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); } } }
/** * Determines whether or not the given input field is an attribute field which contains a * valid amount. * * @param $a_input_item the input item that should be checked * * @return boolean true if the set attribute is valid; false otherwise */ private function isSetAttributeValid($a_input_item) { $valid = false; if (!empty($a_input_item)) { $post_var = $a_input_item->getPostVar(); if (!empty($post_var) && ilRoomSharingStringUtils::startsWith($post_var, self::ATTRIBUTE_ID_PREFIX)) { $valid = ilRoomSharingNumericUtils::isPositiveNumber($a_input_item->getValue(), true); } } return $valid; }
/** * Deletes given attribute and associations/assignments to it (rooms - attributes). * * @throws ilRoomSharingAttributesException * * @param integer $a_attribute_id * * @return integer number of deleted assignments */ public function deleteAttribute($a_attribute_id) { $this->checkUserPrivileges(); $deletedAssignments = 0; if (ilRoomSharingNumericUtils::isPositiveNumber($a_attribute_id, true)) { $deletedAssignments += $this->ilRoomsharingDatabase->deleteAttributeBookingAssign($a_attribute_id); $this->ilRoomsharingDatabase->deleteBookingAttribute($a_attribute_id); } else { throw new ilRoomSharingAttributesException('rep_robj_xrs_fake_attribute_id_provided'); } return $deletedAssignments; }
/** * Method to update the booking participants in the database. * * @global type $ilUser * * @param integer $a_booking_id * @param array $a_booking_participants * Array with the values of the booking-participants * @param array $a_old_booking_participants * Array with the old values of the booking-participants */ public function updateBookingParticipants($a_booking_id, $a_booking_participants, $a_old_booking_participants) { global $ilUser; $booked_participants = array(); foreach ($a_booking_participants as $booking_participant_value) { // Only insert the attribute value, if a value was submitted by the user if ($booking_participant_value != $ilUser->getLogin()) { //(avoids duplicate participations for one user in one booking) if (in_array($booking_participant_value, $booked_participants)) { continue; } $booked_participants[] = $booking_participant_value; //Check if the user is still in the booking if (in_array($booking_participant_value, $a_old_booking_participants)) { continue; } //Get the id of the participant (user) by the given username $booking_participant_id = $this->ilRoomSharingDatabase->getUserIdByUsername($booking_participant_value); //Check if the id has a correct format if (ilRoomSharingNumericUtils::isPositiveNumber($booking_participant_id)) { $this->insertBookingParticipant($a_booking_id, $booking_participant_id); } } } //Check if the user are no longer in the booking and //delete the participations from the booking. foreach ($a_old_booking_participants as $booking_participant_value) { if (in_array($booking_participant_value, $a_old_booking_participants) && !in_array($booking_participant_value, $booked_participants)) { //Get the id of the participant (user) by the given username $booking_participant_id = $this->ilRoomSharingDatabase->getUserIdByUsername($booking_participant_value); if (ilRoomSharingNumericUtils::isPositiveNumber($booking_participant_id)) { $this->deleteParticipation($booking_participant_id, $a_booking_id); } } } }
/** * Returns the titles of all the existing floorplans. * * @return array with titles */ private function getAllFloorplanTitles() { $all_fplan_ids = $this->ilRoomsharingDatabase->getAllFloorplanIds(); $fplan_titles = array(); foreach ($all_fplan_ids as $fplan_id) { if (ilRoomSharingNumericUtils::isPositiveNumber($fplan_id)) { $mobj = $this->getMediaObjectInstance($fplan_id); $fplan_titles[] = $mobj->getTitle(); } } return $fplan_titles; }
/** * Adds a new class to the database * * @param string $a_name Name of the class * @param string $a_description Description of the class * @param integer $a_role_id Role-ID of a possible assigned role * @param integer $a_priority Priority of the class * @param integer $a_copy_class_id Possible class-ID of which the privileges should be copied * * @return integer New ID of the inserted class */ public function insertClass($a_name, $a_description, $a_role_id, $a_priority, $a_copy_class_id) { $this->ilDB->insert(dbc::CLASSES_TABLE, array('id' => array('integer', $this->ilDB->nextId(dbc::CLASSES_TABLE)), 'name' => array('text', $a_name), 'description' => array('text', $a_description), 'priority' => array('integer', $a_priority), 'role_id' => array('integer', $a_role_id), 'pool_id' => array('integer', $this->pool_id))); $insertedID = $this->ilDB->getLastInsertId(); if (ilRoomSharingNumericUtils::isPositiveNumber($insertedID)) { //Should privileges of another class should be copied? if (ilRoomSharingNumericUtils::isPositiveNumber($a_copy_class_id)) { $privilege_array = array('class_id' => array('integer', $insertedID)); //Get privileges of the class, which should be copied $copied_privileges = $this->getPrivilegesOfClass($a_copy_class_id); foreach ($copied_privileges as $privilege_key => $privilege_value) { $privilege_array[$privilege_key] = array('integer', $privilege_value); } $this->ilDB->insert(dbc::CLASS_PRIVILEGES_TABLE, $privilege_array); } else { $this->ilDB->insert(dbc::CLASS_PRIVILEGES_TABLE, array('class_id' => array('integer', $insertedID))); } } return $insertedID; }
/** * Checks the min and max allocation fields of the room for validity. * Throws an exception if illegal values are present. * * @throws ilRoomSharingRoomException */ private function checkMinMaxAlloc() { $min_alloc_given = !empty($this->min_alloc); $min_alloc_valid = ilRoomSharingNumericUtils::isPositiveNumber($this->min_alloc, true); $max_alloc_valid = ilRoomSharingNumericUtils::isPositiveNumber($this->max_alloc, true); if ($min_alloc_given && !$min_alloc_valid || !$max_alloc_valid) { throw new ilRoomSharingRoomException('rep_robj_xrs_illegal_room_min_max_alloc'); } if ($min_alloc_given && $min_alloc_valid && (int) $this->min_alloc > (int) $this->max_alloc) { throw new ilRoomSharingRoomException('rep_robj_xrs_illegal_room_min_max_alloc'); } }
private function cleanUpAfterSuccessfulSave($sequence = false, $a_count_canceled_bookings = 0) { global $ilTabs; $ilTabs->clearTargets(); $this->parent_obj->setTabs(); $this->ctrl->setCmd("render"); $this->parent_obj->performCommand(""); if ($sequence) { ilUtil::sendSuccess($this->lng->txt('rep_robj_xrs_seq_booking_added'), true); } else { ilUtil::sendSuccess($this->lng->txt('rep_robj_xrs_booking_added'), true); } if (ilRoomSharingNumericUtils::isPositiveNumber($a_count_canceled_bookings)) { ilUtil::sendInfo($a_count_canceled_bookings . " " . $this->lng->txt('rep_robj_xrs_booking_lower_priority_canceled'), true); } }
/** * Edits a already created class values * * @param array $a_classData Array with class data submitted by the frontend * * @throws ilRoomSharingPrivilegesException */ public function editClass($a_classData) { if (!ilRoomSharingNumericUtils::isPositiveNumber($a_classData['id'])) { throw new ilRoomSharingPrivilegesException("rep_robj_xrs_class_id_incorrect"); } $this->ilRoomsharingDatabase->updateClass($a_classData['id'], $a_classData['name'], $a_classData['description'], $a_classData['role_id'], $a_classData['priority']); }
/** * Reads a booking * * @param array $a_bookingData * * @return array Booking-Information */ private function readBookingData($a_bookingData) { $one_booking = array(); $one_booking['recurrence'] = ilRoomSharingNumericUtils::isPositiveNumber($a_bookingData['seq_id']); $one_booking['date'] = ilRoomSharingBookingUtils::readBookingDate($a_bookingData); $one_booking['sortdate'] = $a_bookingData['date_from']; $one_booking['room'] = $this->ilRoomsharingDatabase->getRoomName($a_bookingData['room_id']); $one_booking['room_id'] = $a_bookingData['room_id']; $participants = $this->readBookingParticipants($a_bookingData); $one_booking['participants'] = $participants['names']; $one_booking['participants_ids'] = $participants['ids']; $one_booking['subject'] = $a_bookingData['subject']; $one_booking['comment'] = $a_bookingData['bookingcomment']; $attributes = $this->readBookingAttributes($a_bookingData); foreach ($attributes as $attribute_name => $attribute_value) { $one_booking[$attribute_name] = $attribute_value; } $one_booking['id'] = $a_bookingData['id']; return $one_booking; }