$event_schedule_id, 'isInModeration' => setDefaultIfPostKeyIsNotPresent('moderationSwitchBtn', $moderationVariables), 'flexibleModeActivated' => setDefaultIfPostKeyIsNotPresent('moderationSwitchFlexibleBtn', $moderationVariables), 'flexibleModeApplied' => 0, 'flexibleModeIsAgreed' => setDefaultIfPostKeyIsNotPresent('flexAgreed', $moderationVariables), 'flexibleModeHours' => $moderationVariables['flex_no_of_hours'], 'flexibleModeNumberToLiftModeration' => $moderationVariables['flex_places_to_lift_moderation'], 'author' => $_SESSION["logged_in"]["user_id"] ]; //save to moderation table saveModerationSettings( $event_schedule_id, $settings, INSERT_SETTINGS ); } /** * Check if posts key are exist and method is a post action * * @param null $post = any post form names * @param null $key = post keys * @return boolean * access private function */ function isAvailablePostKey($post, $key) : bool { //Ensure that post values are present $post = $post ?? $_POST; //Check if request method is post and check if posts keys are exist return ($_SERVER['REQUEST_METHOD'] == 'POST' && array_key_exists($key, $post)); } /** * Set default for post keys that are note present * * @param null $key = post variable key * @param null $post = form post array * @return void * access private function */ function setDefaultIfPostKeyIsNotPresent($key = null, $post = null) : int { //Ensure that post values are present $post = $post ?? $_POST; //Ensure that post will return defaults if keys are not present if (isAvailablePostKey($post, $key) && ($post[$key] == "on")) { return 1; } else { // force agree to moderation return 1; } } /** * Save function moderations settings * * @param integer $eventScheduleId = event schedule id * @param array $settings = form moderation array * @param integer $action = insert or update command * @return void * access public member function */ function saveModerationSettings($eventScheduleId, $settings = [], $action) { /** * Ensure that event schedule id is properly set */ if (notSet($eventScheduleId)) { return false; } querySaveModeration($eventScheduleId, $settings, $action); } /** * Query DB to save moderation settings in table event_schedule_moderation_settings * * @param integer $eventScheduleId = event schedule id * @param array $settings = form moderation array * @param integer $action = insert or update command * @return void * access protected member */ function querySaveModeration($eventScheduleId, $settings = [], $action) { // Get a reference to the controller object $CI = get_instance(); switch ($action) { /** * insert new settings including event schedule id, 1 = INSERT */ case INSERT_SETTINGS: $CI->db->insert(tableEventScheduleId, $settings); break; /** * Update settings using event schedule id, 2 = UPDATE */ case UPDATE_SETTINGS: $CI->db->where(eventScheduleId, $eventScheduleId); $CI->db->update(tableEventScheduleId, $settings); break; } } /** * Get list of event type and location type using its event_id and location_id * * @param string $field = table field * @param string $id = table primary key * @param array $ids = array of table id * @param string $table = table name * @return array * access public function */ function getEventAndLocationStringDetails(string $field, string $id, array $ids, string $table) : array { /** * We need to return empty array if null to prevent record matching errors */ if (empty(array_filter($ids))) { return []; } // Get a reference to the controller object $CI = get_instance(); $CI->db->select($field); $CI->db->where_in($id, $ids); $result = $CI->db->get($table); if ($result->num_rows() > 0) { return $result->result_array(); } } /** * Get per event moderation settings in ' event_schedule_moderation_setting' table * * @param integer $eventScheduleId = event schedule id * @return array * access public function */ function getIndividualPerEventScheduleModeration(int $eventScheduleId) : array { /** * We need to return empty array if null to prevent record matching errors */ if (notSet($eventScheduleId)) { return []; } // Get a reference to the controller object $CI = get_instance(); $CI->db->select("isInModeration, flexibleModeActivated , flexibleModeIsAgreed ,flexibleModeHours, flexibleModeNumberToLiftModeration"); $CI->db->where('event_schedule_id', $eventScheduleId); $result = $CI->db->get("event_schedule_moderation_setting"); /** * Return empty records if event schedule id doesnt exist */ if ($result->num_rows() == 0) { return array( 'flexibleModeIsAgreed' => false, 'flex_is_applied' => false, 'isActive' => false, 'flex_no_of_hours' => 0, 'flex_places_to_lift_moderation' =>0 ); } /** * Return list of values */ return array( 'flexibleModeIsAgreed' => $result->row()->flexibleModeIsAgreed, 'flex_is_applied' => $result->row()->flexibleModeActivated, 'isActive' => $result->row()->isInModeration, 'flex_no_of_hours' => $result->row()->flexibleModeHours, 'flex_places_to_lift_moderation' => $result->row()->flexibleModeNumberToLiftModeration ); }