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)) {
api_not_allowed();
}
$res = $promotion->copy($_GET['id']);
$res = $promotion->copy($_GET['id'], null, true);
if ($res) {
Display::display_confirmation_message(get_lang('Copied'));
}

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

@ -114,9 +114,10 @@ class Promotion extends Model {
* Copies the promotion to a new one
* @param integer Promotion ID
* @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
*/
public function copy($id, $career_id = null) {
public function copy($id, $career_id = null, $copy_sessions = false) {
$promotion = $this->get($id);
$new = array();
foreach ($promotion as $key => $val) {
@ -143,14 +144,16 @@ class Promotion extends Model {
}
}
$pid = $this->save($new);
//Now also copy each session of the promotion as a new session and register it inside the promotion
require_once api_get_path(LIBRARY_PATH).'sessionmanager.lib.php';
$session_list = SessionManager::get_all_sessions_by_promotion($id);
if (!empty($session_list)) {
foreach($session_list as $item) {
$sid = SessionManager::copy_session($item['id'], true, true);
if ($sid != 0) {
SessionManager::suscribe_sessions_to_promotion($pid,array($sid));
if ($copy_sessions) {
//Now also copy each session of the promotion as a new session and register it inside the promotion
require_once api_get_path(LIBRARY_PATH).'sessionmanager.lib.php';
$session_list = SessionManager::get_all_sessions_by_promotion($id);
if (!empty($session_list)) {
foreach($session_list as $item) {
$sid = SessionManager::copy_session($item['id'], true, true);
if ($sid != 0) {
SessionManager::suscribe_sessions_to_promotion($pid,array($sid));
}
}
}
}

Loading…
Cancel
Save