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

skala
ywarnier 15 years ago
parent 27d23c70df
commit 275038f596
  1. 2
      main/admin/careers.php
  2. 16
      main/inc/lib/career.lib.php

@ -148,7 +148,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 = $career->copy($_GET['id']);
$res = $career->copy($_GET['id'], true); //copy career and promotions inside
if ($res) {
Display::display_confirmation_message(get_lang('Copied'));
}

@ -106,7 +106,7 @@ class Career extends Model {
* @param integer Career ID
* @return integer New career ID on success, false on failure
*/
public function copy($id) {
public function copy($id, $copy_promotions = false) {
$career = $this->get($id);
$new = array();
foreach ($career as $key => $val) {
@ -128,12 +128,14 @@ class Career extends Model {
}
}
$cid = $this->save($new);
//Now also copy each session of the promotion as a new session and register it inside the promotion
$promotion = new Promotion();
$promo_list = $promotion->get_all_promotions_by_career_id($id);
if (!empty($promo_list)) {
foreach($promo_list as $item) {
$pid = $promotion->copy($item['id'], $cid);
if ($copy_promotions) {
//Now also copy each session of the promotion as a new session and register it inside the promotion
$promotion = new Promotion();
$promo_list = $promotion->get_all_promotions_by_career_id($id);
if (!empty($promo_list)) {
foreach($promo_list as $item) {
$pid = $promotion->copy($item['id'], $cid);
}
}
}
return $cid;

Loading…
Cancel
Save