Skip to content

Commit

Permalink
Add field to check whether generate certificates - refs #7525
Browse files Browse the repository at this point in the history
  • Loading branch information
AngelFQC committed Feb 13, 2015
1 parent fddc3f4 commit c044bdc
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 2 deletions.
1 change: 1 addition & 0 deletions main/gradebook/gradebook_add_cat.php
Expand Up @@ -131,6 +131,7 @@ function check_skills() {
$cat->set_user_id($values['hid_user_id']);
$cat->set_parent_id($values['hid_parent_id']);
$cat->set_weight($values['weight']);
$cat->setGenerateCertificates($values['generate_certificates']);

if (empty ($values['visible'])) {
$visible = 0;
Expand Down
1 change: 1 addition & 0 deletions main/gradebook/gradebook_edit_cat.php
Expand Up @@ -109,6 +109,7 @@ function check_skills() {
$cat->set_user_id($values['hid_user_id']);
$cat->set_parent_id($values['hid_parent_id']);
$cat->set_weight($values['weight']);
$cat->setGenerateCertificates($values['generate_certificates']);

if ($values['hid_parent_id'] == 0 ) {
$cat->set_certificate_min_score($values['certif_min_score']);
Expand Down
28 changes: 27 additions & 1 deletion main/gradebook/lib/be/category.class.php
Expand Up @@ -24,6 +24,7 @@ class Category implements GradebookItem
private $session_id;
private $skills = array();
private $grade_model_id;
private $generateCertificates;

public function __construct()
{
Expand Down Expand Up @@ -186,6 +187,16 @@ public function get_skills_for_select()
return $skill_select;
}

public function setGenerateCertificates($generateCertificates)
{
$this->generateCertificates = $generateCertificates;
}

public function getGenerateCetificates()
{
return $this->generateCertificates;
}

/**
* @param int $id
* @param int $session_id
Expand Down Expand Up @@ -350,6 +361,7 @@ private static function create_root_category()
$cat->set_parent_id(null);
$cat->set_weight(0);
$cat->set_visible(1);
$cat->setGenerateCertificates(false);

return $cat;
}
Expand All @@ -375,6 +387,7 @@ private static function create_category_objects_from_sql_result($result)
$cat->set_certificate_min_score($data['certif_min_score']);
$cat->set_grade_model_id($data['grade_model_id']);
$cat->set_locked($data['locked']);
$cat->setGenerateCertificates($data['generate_certificates']);
$allcat[] = $cat;
}

Expand Down Expand Up @@ -413,6 +426,10 @@ public function add()
$sql .= ', certif_min_score ';
}

if (isset($this->generateCertificates)) {
$sql .= ', generate_certificates ';
}

/*
$setting = api_get_setting('tool_visible_by_default_at_creation');
$visible = 1;
Expand Down Expand Up @@ -446,6 +463,9 @@ public function add()
if (isset($this->certificate_min_score) && !empty($this->certificate_min_score)) {
$sql .= ', '.intval($this->get_certificate_min_score());
}
if (isset($this->generateCertificates)) {
$sql .= ', ' . intval($this->generateCertificates);
}
$sql .= ')';
Database::query($sql);
$id = Database::insert_id();
Expand Down Expand Up @@ -528,6 +548,7 @@ public function save()
}
$sql .= ', weight = "'.Database::escape_string($this->get_weight())
.'", visible = '.intval($this->is_visible())
. ', generate_certificates = ' . intval($this->generateCertificates)
.' WHERE id = '.intval($this->id);

Database::query($sql);
Expand Down Expand Up @@ -643,7 +664,7 @@ public function shows_all_information_an_category($selectcat = '')
return null;
} else {
$tbl_category = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_CATEGORY);
$sql='SELECT name,description,user_id,course_code,parent_id,weight,visible,certif_min_score,session_id FROM '.$tbl_category.' c WHERE c.id='.intval($selectcat);
$sql='SELECT name,description,user_id,course_code,parent_id,weight,visible,certif_min_score,session_id, generate_certificates FROM '.$tbl_category.' c WHERE c.id='.intval($selectcat);
$result = Database::query($sql);
$row = Database::fetch_array($result, 'ASSOC');

Expand Down Expand Up @@ -1592,6 +1613,11 @@ public static function register_user_certificate($category_id, $user_id)
);
/** @var Category $category */
$category = $cats_course[0];

if (!$category->getGenerateCetificates()) {
return false;
}

$alleval_course = $category->get_evaluations($user_id, true);
$alllink_course = $category->get_links($user_id, true);
$evals_links = array_merge($alleval_course, $alllink_course);
Expand Down
15 changes: 15 additions & 0 deletions main/gradebook/lib/fe/catform.class.php
Expand Up @@ -179,6 +179,7 @@ protected function build_editing_form()
'weight' => $this->category_object->get_weight(),
'visible' => $this->category_object->is_visible(),
'certif_min_score' => $this->category_object->get_certificate_min_score(),
'generate_certificates' => $this->category_object->getGenerateCetificates()
)
);
$this->addElement('hidden', 'hid_id', $this->category_object->get_id());
Expand Down Expand Up @@ -350,6 +351,20 @@ private function build_basic_form()
$this->freeze('grade_model_id');
}
}

$generateCertificatesParams = array();

if ($this->category_object->getGenerateCetificates()) {
$generateCertificatesParams['checked'] = 'checked';
}

$this->addElement(
'checkbox',
'generate_certificates',
null,
get_lang('GenerateCertificates'),
$generateCertificatesParams
);
}

if ($this->form_type == self :: TYPE_ADD) {
Expand Down
3 changes: 2 additions & 1 deletion main/install/db_main.sql
Expand Up @@ -1370,7 +1370,8 @@ CREATE TABLE IF NOT EXISTS gradebook_category (
document_id int unsigned DEFAULT NULL,
locked int NOT NULL DEFAULT 0,
default_lowest_eval_exclude TINYINT default null,
PRIMARY KEY (id)
generate_certificates TINYINT NOT NULL DEFAULT 0,
PRIMARY KEY (id)
);
DROP TABLE IF EXISTS gradebook_evaluation;
CREATE TABLE IF NOT EXISTS gradebook_evaluation (
Expand Down
2 changes: 2 additions & 0 deletions main/install/migrate-db-1.9.0-1.10.0-pre.sql
Expand Up @@ -34,6 +34,8 @@ CREATE TABLE session_field_options (id INT NOT NULL PRIMARY KEY AUTO_INCREMENT,

ALTER TABLE skill ADD COLUMN criteria text DEFAULT '';

ALTER TABLE gradebook_category ADD COLUMN generate_certificates TINYINT NOT NULL DEFAULT 0;

-- Do not move this query
UPDATE settings_current SET selected_value = '1.10.0.7' WHERE variable = 'chamilo_database_version';

Expand Down

0 comments on commit c044bdc

Please sign in to comment.