Minor - format code.

1.9.x
Julio Montoya 11 years ago
parent 22c5de9970
commit 475ed30c5a
  1. 3
      main/gradebook/gradebook_edit_cat.php
  2. 6
      main/gradebook/lib/be/category.class.php
  3. 225
      main/gradebook/lib/fe/catform.class.php

@ -82,6 +82,7 @@ function check_skills() {
$catedit = Category::load($edit_cat);
$form = new CatForm(CatForm::TYPE_EDIT, $catedit[0], 'edit_cat_form');
if ($form->validate()) {
@ -115,11 +116,13 @@ if ($form->validate()) {
if ($values['hid_parent_id'] == 0 ) {
$cat->set_certificate_min_score($values['certif_min_score']);
}
if (empty ($values['visible'])) {
$visible = 0;
} else {
$visible = 1;
}
$cat->set_visible($visible);
$cat->save();
header('Location: '.Security::remove_XSS($_SESSION['gradebook_dest']).'?editcat=&selectcat=' . $cat->get_parent_id());

@ -558,7 +558,11 @@ class Category implements GradebookItem
}
$gradebook= new Gradebook();
$gradebook->update_skills_to_gradebook($this->id, $this->get_skills(false));
$gradebook->update_skills_to_gradebook(
$this->id,
$this->get_skills(false),
false
);
}
/**

@ -1,22 +1,17 @@
<?php
/* For licensing terms, see /license.txt */
/**
* Script
* @package chamilo.gradebook
*/
/**
* Init
*/
require_once dirname(__FILE__).'/../../../inc/global.inc.php';
require_once dirname(__FILE__).'/../be.inc.php';
/**
* Extends formvalidator with add&edit forms
* Class CatForm
*
* @author Stijn Konings
* @package chamilo.gradebook
*/
class CatForm extends FormValidator {
class CatForm extends FormValidator
{
const TYPE_ADD = 1;
const TYPE_EDIT = 2;
@ -32,7 +27,13 @@ class CatForm extends FormValidator {
* @param string form name
* @param method method
*/
function CatForm($form_type, $category_object,$form_name,$method = 'post',$action=null) {
public function CatForm(
$form_type,
$category_object,
$form_name,
$method = 'post',
$action = null
) {
parent :: __construct($form_name, $method, $action);
$this->form_type = $form_type;
if (isset ($category_object)) {
@ -54,12 +55,19 @@ class CatForm extends FormValidator {
* This function will build a move form that will allow the user to move a category to
* a another
*/
protected function build_move_form() {
protected function build_move_form()
{
$renderer =& $this->defaultRenderer();
$renderer->setElementTemplate('<span>{element}</span> ');
$this->addElement('static',null,null,'"'.$this->category_object->get_name().'" ');
$this->addElement(
'static',
null,
null,
'"' . $this->category_object->get_name() . '" '
);
$this->addElement('static', null, null, get_lang('MoveTo') . ' : ');
$select = $this->addElement('select', 'move_cat', null, null);
$line = null;
foreach ($this->category_object->get_target_categories() as $cat) {
for ($i = 0; $i < $cat[2]; $i++) {
$line .= '--';
@ -73,16 +81,20 @@ class CatForm extends FormValidator {
}
$this->addElement('submit', null, get_lang('Ok'));
}
/**
* This function builds an 'add category form, if parent id is 0, it will only
* show courses
*/
protected function build_add_form() {
protected function build_add_form()
{
//check if we are a root category
//if so, you can only choose between courses
if ($this->category_object->get_parent_id() == '0') {
//$select = $this->addElement('select','select_course',array(get_lang('PickACourse'),'test'), null);
$coursecat = Category :: get_not_created_course_categories(api_get_user_id());
$coursecat = Category :: get_not_created_course_categories(
api_get_user_id()
);
if (count($coursecat) == 0) {
//$select->addoption(get_lang('CourseIndependent'),'COURSEINDEPENDENT','disabled');
} else {
@ -96,17 +108,26 @@ class CatForm extends FormValidator {
} else {
//$select->addoption($row[1],$row[0]);
}
$this->setDefaults(array(
'select_course' => $this->category_object->get_course_code(),
$this->setDefaults(
array(
'select_course' => $this->category_object->get_course_code(
),
'hid_user_id' => $this->category_object->get_user_id(),
'hid_parent_id' => $this->category_object->get_parent_id()
));
)
);
} else {
$this->setDefaults(array(
$this->setDefaults(
array(
'hid_user_id' => $this->category_object->get_user_id(),
'hid_parent_id' => $this->category_object->get_parent_id()
));
$this->addElement('hidden','course_code', $this->category_object->get_course_code());
)
);
$this->addElement(
'hidden',
'course_code',
$this->category_object->get_course_code()
);
}
$this->build_basic_form();
}
@ -114,12 +135,22 @@ class CatForm extends FormValidator {
/**
* Builds an form to edit a category
*/
protected function build_editing_form() {
protected function build_editing_form()
{
$skills = $this->category_object->get_skills_for_select();
$course_code = api_get_course_id();
$session_id = api_get_session_id();
//Freeze or not
$test_cats = Category :: load(null, null, $course_code, null, null, $session_id, false); //already init
$test_cats = Category::load(
null,
null,
$course_code,
null,
null,
$session_id,
false
); //already init
$links = null;
if (isset($test_cats[0])) {
$links = $test_cats[0]->get_links();
@ -153,17 +184,31 @@ class CatForm extends FormValidator {
)
);
$this->addElement('hidden', 'hid_id', $this->category_object->get_id());
$this->addElement('hidden','course_code', $this->category_object->get_course_code());
$this->addElement(
'hidden',
'course_code',
$this->category_object->get_course_code()
);
$this->build_basic_form();
}
private function build_basic_form() {
/**
*
*/
private function build_basic_form()
{
$this->addElement('hidden', 'zero', 0);
$this->add_textfield('name', get_lang('CategoryName'), true, array('class'=>'span3','maxlength'=>'50'));
$this->add_textfield(
'name',
get_lang('CategoryName'),
true,
array('class' => 'span3', 'maxlength' => '50')
);
$this->addRule('name', get_lang('ThisFieldIsRequired'), 'required');
if (isset($this->category_object) && $this->category_object->get_parent_id() == 0) {
if (isset($this->category_object) &&
$this->category_object->get_parent_id() == 0
) {
//we can't change the root category
$this->freeze('name');
}
@ -181,33 +226,95 @@ class CatForm extends FormValidator {
if (api_is_platform_admin() || api_is_drh()) {
if (api_get_setting('allow_skills_tool') == 'true') {
//the magic should be here
// The magic should be here
$skills = $this->category_object->get_skills();
$this->addElement('select', 'skills', array(get_lang('Skills'), get_lang('SkillsAchievedWhenAchievingThisGradebook')), null, array('id'=>'skills', 'multiple'=>'multiple'));
$skillToSelect = array();
foreach ($skills as $skill) {
$skillToSelect[$skill['id']] = $skill['name'];
}
$this->addElement(
'select',
'skills',
array(
get_lang('Skills'),
get_lang('SkillsAchievedWhenAchievingThisGradebook')
),
$skillToSelect,
array('id' => 'skills', 'multiple' => 'multiple')
);
$content = '';
if (!empty($skills)) {
foreach ($skills as $skill) {
$content .= Display::tag('li', $skill['name'].'<a id="deleteskill_'.$skill['id'].'" class="closebutton" href="#"></a>', array('id'=>'skill_'.$skill['id'], 'class'=>'bit-box'));
$content .= Display::tag(
'li',
$skill['name'] . '<a id="deleteskill_' . $skill['id'] . '" class="closebutton" href="#"></a>',
array(
'id' => 'skill_' . $skill['id'],
'class' => 'bit-box'
)
);
}
}
$this->addElement('label', null, Display::tag('ul', $content, array('class'=>'holder holder_simple')));
$this->addElement(
'label',
null,
Display::tag(
'ul',
$content,
array('class' => 'holder holder_simple')
)
);
}
}
if (isset($this->category_object) && $this->category_object->get_parent_id() == 0) {
$this->add_textfield('certif_min_score', get_lang('CertificateMinScore'),false,array('class'=>'span1','maxlength'=>'5'));
$this->addRule('certif_min_score', get_lang('ThisFieldIsRequired'), 'required');
$this->addRule('certif_min_score',get_lang('OnlyNumbers'),'numeric');
$this->addRule(array('certif_min_score', 'zero'), get_lang('NegativeValue'), 'compare', '>=');
if (isset($this->category_object) && $this->category_object->get_parent_id(
) == 0
) {
$this->add_textfield(
'certif_min_score',
get_lang('CertificateMinScore'),
false,
array('class' => 'span1', 'maxlength' => '5')
);
$this->addRule(
'certif_min_score',
get_lang('ThisFieldIsRequired'),
'required'
);
$this->addRule(
'certif_min_score',
get_lang('OnlyNumbers'),
'numeric'
);
$this->addRule(
array('certif_min_score', 'zero'),
get_lang('NegativeValue'),
'compare',
'>='
);
} else {
$this->addElement('checkbox', 'visible', null, get_lang('Visible'));
}
$this->addElement('hidden', 'hid_user_id');
$this->addElement('hidden', 'hid_parent_id');
$this->addElement('textarea', 'description', get_lang('Description'), array('class'=>'span3','cols' => '34'));
$this->addElement(
'textarea',
'description',
get_lang('Description'),
array('class' => 'span3', 'cols' => '34')
);
if (isset($this->category_object) && $this->category_object->get_parent_id() == 0 && (api_is_platform_admin() || api_get_setting('teachers_can_change_grade_model_settings') == 'true')) {
if (isset($this->category_object) &&
$this->category_object->get_parent_id() == 0 &&
(api_is_platform_admin() || api_get_setting(
'teachers_can_change_grade_model_settings'
) == 'true')
) {
//Getting grade models
$obj = new GradeModel();
@ -226,7 +333,15 @@ class CatForm extends FormValidator {
//Freeze or not
$course_code = api_get_course_id();
$session_id = api_get_session_id();
$test_cats = Category :: load(null, null, $course_code, null, null, $session_id, false); //already init
$test_cats = Category :: load(
null,
null,
$course_code,
null,
null,
$session_id,
false
); //already init
$links = null;
if (!empty($test_cats[0])) {
$links = $test_cats[0]->get_links();
@ -240,16 +355,31 @@ class CatForm extends FormValidator {
}
if ($this->form_type == self :: TYPE_ADD) {
$this->addElement('style_submit_button', null, get_lang('AddCategory'), 'class="save"');
$this->addElement(
'style_submit_button',
null,
get_lang('AddCategory'),
'class="save"'
);
} else {
$this->addElement('hidden', 'editcat', intval($_GET['editcat']));
$this->addElement('style_submit_button', null, get_lang('EditCategory'), 'class="save"');
$this->addElement(
'style_submit_button',
null,
get_lang('EditCategory'),
'class="save"'
);
}
//if (!empty($grading_contents)) {
$this->addRule('weight', get_lang('OnlyNumbers'), 'numeric');
//$this->addRule('weight',get_lang('NoDecimals'),'nopunctuation');
$this->addRule(array ('weight', 'zero'), get_lang('NegativeValue'), 'compare', '>=');
$this->addRule(
array('weight', 'zero'),
get_lang('NegativeValue'),
'compare',
'>='
);
//}
$setting = api_get_setting('tool_visible_by_default_at_creation');
@ -264,7 +394,8 @@ class CatForm extends FormValidator {
* This function builds an 'select course' form in the add category process,
* if parent id is 0, it will only show courses
*/
protected function build_select_course_form() {
protected function build_select_course_form()
{
$select = $this->addElement('select','select_course',array(get_lang('PickACourse'),'test'), null);
$coursecat = Category :: get_all_courses(api_get_user_id());
//only return courses that are not yet created by the teacher
@ -281,11 +412,13 @@ class CatForm extends FormValidator {
$this->addElement('submit', null, get_lang('Ok'));
}
function display() {
function display()
{
parent :: display();
}
function setDefaults($defaults = array(), $filter = null) {
function setDefaults($defaults = array(), $filter = null)
{
parent::setDefaults($defaults, $filter);
}
}
Loading…
Cancel
Save