Skip to content

Commit

Permalink
Remove automatic assignment of visibility = 1 at session creation (us…
Browse files Browse the repository at this point in the history
…e default value) + fix functions comments - loosely refs CT#7778
  • Loading branch information
ywarnier committed Jul 21, 2015
1 parent 7a64a95 commit b7b47b1
Showing 1 changed file with 51 additions and 55 deletions.
106 changes: 51 additions & 55 deletions main/inc/lib/sessionmanager.lib.php
Expand Up @@ -48,19 +48,21 @@ public static function fetch($id)
* Create a session
* @author Carlos Vargas <carlos.vargas@beeznest.com>, from existing code
* @param string $name
* @param string $startDate (YYYY-MM-DD hh:mm:ss)
* @param string $endDate (YYYY-MM-DD hh:mm:ss)
* @param integer If 1, means there are no date limits
* @param mixed If integer, this is the session coach id, if string, the coach ID will be looked for from the user table
* @param integer ID of the session category in which this session is registered
* @param integer Visibility after end date (0 = read-only, 1 = invisible, 2 = accessible)
* @param string Start limit = true if the start date has to be considered
* @param string End limit = true if the end date has to be considered
* @param string $fix_name
* @param string $startDate (YYYY-MM-DD hh:mm:ss)
* @param string $endDate (YYYY-MM-DD hh:mm:ss)
* @param string $displayStartDate (YYYY-MM-DD hh:mm:ss)
* @param string $displayEndDate (YYYY-MM-DD hh:mm:ss)
* @param string $coachStartDate (YYYY-MM-DD hh:mm:ss)
* @param string $coachEndDate (YYYY-MM-DD hh:mm:ss)
* @param mixed $coachId If integer, this is the session coach id, if string, the coach ID will be looked for from the user table
* @param integer $sessionCategoryId ID of the session category in which this session is registered
* @param integer $visibility Visibility after end date (0 = read-only, 1 = invisible, 2 = accessible)
* @param bool $fixSessionNameIfExists
* @param string $duration
* @param string $description Optional. The session description
* @param int $showDescription Optional. Whether show the session description
* @param array $extrafields
* @param int $showDescription Optional. Whether show the session description
* @param array $extraFields
* @param int $sessionAdminId Optional. If this sessions was created by a session admin, assign it to him
* @todo use an array to replace all this parameters or use the model.lib.php ...
* @return mixed Session ID on success, error message otherwise
* */
Expand All @@ -73,9 +75,9 @@ public static function create_session(
$coachStartDate,
$coachEndDate,
$coachId,
$id_session_category,
$id_visibility,
$fix_name = false,
$sessionCategoryId,
$visibility = 1,
$fixSessionNameIfExists = false,
$duration = null,
$description = null,
$showDescription = 0,
Expand Down Expand Up @@ -103,13 +105,10 @@ public static function create_session(
}

$name = Database::escape_string(trim($name));
$id_session_category = intval($id_session_category);
$id_visibility = intval($id_visibility);
$tbl_user = Database::get_main_table(TABLE_MAIN_USER);
$sessionCategoryId = intval($sessionCategoryId);
$visibility = intval($visibility);
$tbl_session = Database::get_main_table(TABLE_MAIN_SESSION);

$id_visibility = 1; // by default session visibility is read only

$startDate = Database::escape_string($startDate);
$endDate = Database::escape_string($endDate);

Expand All @@ -130,7 +129,7 @@ public static function create_session(
return $msg;
} else {
$ready_to_create = false;
if ($fix_name) {
if ($fixSessionNameIfExists) {
$name = self::generateNextSessionName($name);
if ($name) {
$ready_to_create = true;
Expand All @@ -153,7 +152,7 @@ public static function create_session(
'name' => $name,
'id_coach' => $coachId,
'session_admin_id' => $sessionAdminId,
'visibility' => $id_visibility,
'visibility' => $visibility,
'description' => $description,
'show_description' => intval($showDescription)
);
Expand Down Expand Up @@ -181,8 +180,8 @@ public static function create_session(
$values['coach_access_end_date'] = $coachEndDate;
}

if (!empty($id_session_category)) {
$values['session_category_id'] = $id_session_category;
if (!empty($sessionCategoryId)) {
$values['session_category_id'] = $sessionCategoryId;
}

$session_id = Database::insert($tbl_session, $values);
Expand Down Expand Up @@ -1294,27 +1293,24 @@ public static function generateNextSessionName($session_name)
/**
* Edit a session
* @author Carlos Vargas from existing code
* @param integer id
* @param string name
* @param integer year_start
* @param integer month_start
* @param integer day_start
* @param integer year_end
* @param integer month_end
* @param integer day_end
* @param integer nb_days_acess_before
* @param integer nb_days_acess_after
* @param integer nolimit
* @param integer id_coach
* @param integer id_session_category
* @param int $id_visibility
* @param bool
* @param bool
* @param string $description
* @param int $showDescription
* @return $id;
* The parameter id is a primary key
* */
* @param integer $id Session primary key
* @param string $name
* @param string $startDate
* @param string $endDate
* @param string $displayStartDate
* @param string $displayEndDate
* @param string $coachStartDate
* @param string $coachEndDate
* @param integer $coachId
* @param integer $sessionCategoryId
* @param int $visibility
* @param string $description
* @param bool $showDescription
* @param int $duration
* @param array $extraFields
* @param int $sessionAdminId
* @return mixed
*/
public static function edit_session(
$id,
$name,
Expand All @@ -1324,25 +1320,25 @@ public static function edit_session(
$displayEndDate,
$coachStartDate,
$coachEndDate,
$id_coach,
$id_session_category,
$id_visibility,
$coachId,
$sessionCategoryId,
$visibility,
$description = null,
$showDescription = 0,
$duration = null,
$extraFields = array(),
$sessionAdminId = 0
) {
$name = trim(stripslashes($name));
$id_coach = intval($id_coach);
$id_session_category = intval($id_session_category);
$id_visibility = intval($id_visibility);
$coachId = intval($coachId);
$sessionCategoryId = intval($sessionCategoryId);
$visibility = intval($visibility);
$tbl_session = Database::get_main_table(TABLE_MAIN_SESSION);

if (empty($name)) {
$msg = get_lang('SessionNameIsRequired');
return $msg;
} elseif (empty($id_coach)) {
} elseif (empty($coachId)) {
$msg = get_lang('CoachIsRequired');
return $msg;
} elseif (!empty($startDate) && !api_is_valid_date($startDate, 'Y-m-d H:i')) {
Expand Down Expand Up @@ -1371,10 +1367,10 @@ public static function edit_session(
$values = [
'name' => $name,
'duration' => $duration,
'id_coach' => $id_coach,
'id_coach' => $coachId,
'description'=> $description,
'show_description' => intval($showDescription),
'visibility' => $id_visibility
'visibility' => $visibility
];

if (!empty($sessionAdminId)) {
Expand Down Expand Up @@ -1404,8 +1400,8 @@ public static function edit_session(
$values['coach_access_end_date'] = $coachEndDate;
}

if (!empty($id_session_category)) {
$values['session_category_id'] = $id_session_category;
if (!empty($sessionCategoryId)) {
$values['session_category_id'] = $sessionCategoryId;
}

Database::update($tbl_session, $values, array(
Expand Down

0 comments on commit b7b47b1

Please sign in to comment.