Fixing careers and promotions classes when there is no data, fixing also the created_at and updated_at behaviour in the model.lib.php

skala
Julio Montoya 14 years ago
parent 3b0a1c17b1
commit 79bdda7727
  1. 13
      main/admin/promotions.php
  2. 9
      main/inc/ajax/model.ajax.php
  3. 7
      main/inc/lib/career.lib.php
  4. 2
      main/inc/lib/display.lib.php
  5. 5
      main/inc/lib/model.lib.php
  6. 10
      main/inc/lib/promotion.lib.php

@ -76,7 +76,18 @@ if (isset($_GET['action']) && $_GET['action'] == 'add') {
if (api_get_session_id() != 0 && !api_is_allowed_to_session_edit(false, true)) {
api_not_allowed();
}
$url = api_get_self().'?action='.Security::remove_XSS($_GET['action']);
//First you need to create a Career
$career = new Career();
$careers = $career->get_all();
if (empty($careers)) {
$url = Display::url(get_lang('YouNeedToCreateACareerFirst'), 'careers.php?action=add');
Display::display_normal_message($url, false);
Display::display_footer();
exit;
}
$url = api_get_self().'?action='.Security::remove_XSS($_GET['action']);
$form = $promotion->return_form($url, 'add');
// The validation or display

@ -44,7 +44,7 @@ switch ($action) {
//3. Calculating first, end, etc
$total_pages = 0;
if ($count >0) {
if ($count > 0) {
if (!empty($limit)) {
$total_pages = ceil($count/$limit);
}
@ -52,7 +52,12 @@ if ($count >0) {
if ($page > $total_pages) {
$page = $total_pages;
}
$start = $limit * $page - $limit;
$start = $limit * $page - $limit;
if ($start < 0 ) {
$start = 0;
}
//4. Deleting an element if the user wants to
if ($_REQUEST['oper'] == 'del') {

@ -84,13 +84,16 @@ class Career extends Model {
$status_list = $this->get_status_list();
$form->addElement('select', 'status', get_lang('Status'), $status_list);
$form->addElement('text', 'created_at', get_lang('CreatedAt'));
$form->freeze('created_at');
if ($action == 'edit') {
$form->addElement('text', 'created_at', get_lang('CreatedAt'));
$form->freeze('created_at');
}
$form->addElement('style_submit_button', 'submit', get_lang('Modify'), 'class="save"');
// Setting the defaults
$defaults = $this->get($_GET['id']);
$defaults['created_at'] = api_convert_and_format_date($defaults['created_at']);
$defaults['updated_at'] = api_convert_and_format_date($defaults['updated_at']);
$form->setDefaults($defaults);

@ -874,7 +874,7 @@ class Display {
if (!empty($extra_params['rowNum'])) {
$obj->rowNum = $extra_params['rowNum'];
}
//height: 'auto',
$obj->viewrecords = 'true';

@ -112,9 +112,14 @@ class Model {
*/
public function update($params) {
$params = $this->clean_parameters($params);
//If the class have the updated at we update the date
if (in_array('updated_at', $this->columns)) {
$params['updated_at'] = api_get_utc_datetime();
}
//If the class have the created at we remove it
if (in_array('created_at', $this->columns)) {
unset($params['created_at']);
}
if (!empty($params)) {
$id = $params['id'];

@ -94,10 +94,10 @@ class Promotion extends Model {
$status_list = $this->get_status_list();
$form->addElement('select', 'status', get_lang('Status'), $status_list);
$form->addElement('text', 'created_at', get_lang('CreatedAt'));
$form->freeze('created_at');
if ($action == 'edit') {
$form->addElement('text', 'created_at', get_lang('CreatedAt'));
$form->freeze('created_at');
}
$form->addElement('style_submit_button', 'submit', get_lang('Modify'), 'class="save"');
// Setting the defaults
@ -105,8 +105,6 @@ class Promotion extends Model {
$defaults['created_at'] = api_convert_and_format_date($defaults['created_at']);
$defaults['updated_at'] = api_convert_and_format_date($defaults['updated_at']);
$form->setDefaults($defaults);
// Setting the rules
$form->addRule('name', '<div class="required">'.get_lang('ThisFieldIsRequired'), 'required');

Loading…
Cancel
Save