Added support for promotion cloning (BT#1916)

skala
ywarnier 14 years ago
parent 48bd2bfe13
commit cf2114ce81
  1. 13
      main/admin/promotions.php
  2. 42
      main/inc/lib/promotion.lib.php

@ -64,7 +64,7 @@ $extra_params['autowidth'] = 'true'; //use the width of the parent
$extra_params['height'] = 'auto'; //use the width of the parent
//With this function we can add actions to the jgrid
$action_links = 'function action_formatter (cellvalue, options, rowObject) {
return \'<a href="add_sessions_to_promotion.php?id=\'+options.rowId+\'"><img title="'.get_lang('AddSession').'" width="22px" src="../img/session_add.png"></a> <a href="?action=edit&id=\'+options.rowId+\'"><img width="20px" src="../img/edit.png" title="'.get_lang('Edit').'"></a> <a onclick="javascript:if(!confirm('."\'".addslashes(api_htmlentities(get_lang("ConfirmYourChoice"),ENT_QUOTES))."\'".')) return false;" href="?action=delete&id=\'+options.rowId+\'"><img title="'.get_lang('Delete').'" src="../img/delete.png"></a>\';
return \'<a href="add_sessions_to_promotion.php?id=\'+options.rowId+\'"><img title="'.get_lang('AddSession').'" width="22px" src="../img/session_add.png"></a> <a href="?action=edit&id=\'+options.rowId+\'"><img width="20px" src="../img/edit.png" title="'.get_lang('Edit').'"></a> <a onclick="javascript:if(!confirm('."\'".addslashes(api_htmlentities(get_lang("ConfirmYourChoice"),ENT_QUOTES))."\'".')) return false;" href="?action=delete&id=\'+options.rowId+\'"><img title="'.get_lang('Delete').'" src="../img/delete.png"></a> <a onclick="javascript:if(!confirm('."\'".addslashes(api_htmlentities(get_lang("ConfirmYourChoice"),ENT_QUOTES))."\'".')) return false;" href="?action=copy&id=\'+options.rowId+\'"><img title="'.get_lang('Copy').'" src="../img/copy.gif" alt="'.get_lang('Copy').'"></a>\';
}';
?>
@ -158,7 +158,16 @@ if (isset($_GET['action']) && $_GET['action'] == 'add') {
Display::display_confirmation_message(get_lang('Deleted'));
}
$promotion->display();
} elseif (isset($_GET['action']) && $_GET['action'] == 'copy') {
if (api_get_session_id() != 0 && !api_is_allowed_to_session_edit(false, true)) {
api_not_allowed();
}
$res = $promotion->copy($_GET['id']);
if ($res) {
Display::display_confirmation_message(get_lang('Copied'));
}
$promotion->display();
} else {
$promotion->display();
$promotion->display();
}
Display::display_footer();

@ -110,4 +110,44 @@ class Promotion extends Model {
return $form;
}
}
/**
* Copies the promotions to a new one
* @param integer Promotion ID
* @return integer New promotion ID on success, false on failure
*/
public function copy($id) {
$promotion = $this->get($id);
$new = array();
foreach ($promotion as $key => $val) {
switch ($key) {
case 'id':
case 'updated_at':
break;
case 'name':
$val .= ' '.get_lang('Copy');
$new[$key] = $val;
break;
case 'created_at':
$val = api_get_utc_datetime();
$new[$key] = $val;
break;
default:
$new[$key] = $val;
break;
}
}
$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));
}
}
}
return $pid;
}
}
Loading…
Cancel
Save