Added code option to choose whether sessions are copied along with the promotion (BT#1916)

skala
ywarnier 15 years ago
parent 275038f596
commit b172f6f11a
  1. 2
      main/admin/promotions.php
  2. 1
      main/inc/lib/career.lib.php
  3. 21
      main/inc/lib/promotion.lib.php

@ -162,7 +162,7 @@ if (isset($_GET['action']) && $_GET['action'] == 'add') {
if (api_get_session_id() != 0 && !api_is_allowed_to_session_edit(false, true)) { if (api_get_session_id() != 0 && !api_is_allowed_to_session_edit(false, true)) {
api_not_allowed(); api_not_allowed();
} }
$res = $promotion->copy($_GET['id']); $res = $promotion->copy($_GET['id'], null, true);
if ($res) { if ($res) {
Display::display_confirmation_message(get_lang('Copied')); Display::display_confirmation_message(get_lang('Copied'));
} }

@ -104,6 +104,7 @@ class Career extends Model {
/** /**
* Copies the career to a new one * Copies the career to a new one
* @param integer Career ID * @param integer Career ID
* @param boolean Whether or not to copy the promotions inside
* @return integer New career ID on success, false on failure * @return integer New career ID on success, false on failure
*/ */
public function copy($id, $copy_promotions = false) { public function copy($id, $copy_promotions = false) {

@ -114,9 +114,10 @@ class Promotion extends Model {
* Copies the promotion to a new one * Copies the promotion to a new one
* @param integer Promotion ID * @param integer Promotion ID
* @param integer Career ID, in case we want to change it * @param integer Career ID, in case we want to change it
* @param boolean Whether or not to copy the sessions inside
* @return integer New promotion ID on success, false on failure * @return integer New promotion ID on success, false on failure
*/ */
public function copy($id, $career_id = null) { public function copy($id, $career_id = null, $copy_sessions = false) {
$promotion = $this->get($id); $promotion = $this->get($id);
$new = array(); $new = array();
foreach ($promotion as $key => $val) { foreach ($promotion as $key => $val) {
@ -143,14 +144,16 @@ class Promotion extends Model {
} }
} }
$pid = $this->save($new); $pid = $this->save($new);
//Now also copy each session of the promotion as a new session and register it inside the promotion if ($copy_sessions) {
require_once api_get_path(LIBRARY_PATH).'sessionmanager.lib.php'; //Now also copy each session of the promotion as a new session and register it inside the promotion
$session_list = SessionManager::get_all_sessions_by_promotion($id); require_once api_get_path(LIBRARY_PATH).'sessionmanager.lib.php';
if (!empty($session_list)) { $session_list = SessionManager::get_all_sessions_by_promotion($id);
foreach($session_list as $item) { if (!empty($session_list)) {
$sid = SessionManager::copy_session($item['id'], true, true); foreach($session_list as $item) {
if ($sid != 0) { $sid = SessionManager::copy_session($item['id'], true, true);
SessionManager::suscribe_sessions_to_promotion($pid,array($sid)); if ($sid != 0) {
SessionManager::suscribe_sessions_to_promotion($pid,array($sid));
}
} }
} }
} }

Loading…
Cancel
Save