From 664ff5014b890c83964d8062341a7041143bdd4e Mon Sep 17 00:00:00 2001 From: Julio Montoya Date: Sat, 8 Jan 2011 09:06:12 +0100 Subject: [PATCH 1/7] Adding model.lib.php in order to avoid repeating code --- main/inc/lib/career.lib.php | 101 ++------------------------- main/inc/lib/model.lib.php | 122 +++++++++++++++++++++++++++++++++ main/inc/lib/promotion.lib.php | 95 ++----------------------- 3 files changed, 133 insertions(+), 185 deletions(-) create mode 100755 main/inc/lib/model.lib.php diff --git a/main/inc/lib/career.lib.php b/main/inc/lib/career.lib.php index 71b89f2e48..3550c147b9 100755 --- a/main/inc/lib/career.lib.php +++ b/main/inc/lib/career.lib.php @@ -7,107 +7,16 @@ * @package chamilo.library */ -class Career { +require_once 'model.lib.php'; + +class Career extends Model { var $table; - var $columns = array('name','description'); + var $columns = array('id', 'name','description'); public function __construct() { $this->table = Database::get_main_table(TABLE_CAREER); - } - - /** - * a little bit of javascript to display a prettier warning when deleting a note - * - * @return unknown - * - */ - function javascript_notebook() - { - return ""; - } - - /** - * Saves an element into the DB - * - * @param array $values - * @return bool - * - */ - function save($values) { - /*if (!is_array($values) or empty($values['note_title'])) { - return false; - }*/ - unset($values['submit']); - $id = Database::insert($this->table, $values); - if (is_numeric($id)){ - return $id; - } - } - - /** - * Gets an element - */ - function get($id) { - if (empty($id)) { return array(); } - $result = Database::select('*',$this->table, array('where'=>array('id = ?'=>intval($id))),'first'); - return $result; - } - - function get_all() { - return $careers = Database::select('*',$this->table); - } - - /** - * Get the count of elements - */ - function get_count() { - $row = Database::select('count(*) as count', $this->table, array(),'first'); - return $row['count']; - } - - - /** - * Updates the obj in the database - * - * @param array $values - * - */ - function update($values) { - /*if (!is_array($values) or empty($values['note_title'])) { - return false; - }*/ - unset($values['submit']); - $table = Database :: get_main_table(TABLE_CAREER); - $id = $values['id']; - unset($values['id']); - $result = Database::update($this->table, $values, array('id = ?'=>$id)); - if ($result != 1){ - return false; - } - return true; - } - - /** - * Delets an item - */ - function delete($id) { - if (empty($id) or $id != strval(intval($id))) { return false; } - // Database table definition - $result = Database :: delete($this->table, array('id = ?' => $id)); - if ($result != 1){ - return false; - } - return true; - } + } /** * Displays the title + grid diff --git a/main/inc/lib/model.lib.php b/main/inc/lib/model.lib.php new file mode 100755 index 0000000000..8ec6e22304 --- /dev/null +++ b/main/inc/lib/model.lib.php @@ -0,0 +1,122 @@ +table, array('id = ?' => $id)); + if ($result != 1){ + return false; + } + return true; + } + + private function clean_parameters($params){ + $clean_params = array(); + if (!empty($params)) { + foreach($params as $key=>$value) { + if (in_array($key, $this->columns)) { + $clean_params[$key] = $value; + } + } + } + return $clean_params; + } + + /** + * Displays the title + grid + */ + function display() { + } + + + + /** + * Gets an element + */ + function get($id) { + if (empty($id)) { return array(); } + $result = Database::select('*',$this->table, array('where'=>array('id = ?'=>intval($id))),'first'); + return $result; + } + + function get_all() { + return $careers = Database::select('*',$this->table); + } + + /** + * Get the count of elements + */ + function get_count() { + $row = Database::select('count(*) as count', $this->table, array(),'first'); + return $row['count']; + } + + /** + * a little bit of javascript to display a prettier warning when deleting a note + * + * @return unknown + * + */ + function javascript() + { + + } + + /** + * Saves an element into the DB + * + * @param array $values + * @return bool + * + */ + function save($values) { + $values = $this->clean_parameters($values); + if (!empty($values)) { + $id = Database::insert($this->table, $values); + if (is_numeric($id)){ + return $id; + } + } + return false; + } + + /** + * Updates the obj in the database + * + * @param array $values + * + */ + function update($values) { + $values = $this->clean_parameters($values); + if (!empty($values)) { + $id = $values['id']; + unset($values['id']); + $result = Database::update($this->table, $values, array('id = ?'=>$id)); + if ($result){ + return true; + } + } + return false; + } + + +} \ No newline at end of file diff --git a/main/inc/lib/promotion.lib.php b/main/inc/lib/promotion.lib.php index e9f3c8192f..5d536565a8 100755 --- a/main/inc/lib/promotion.lib.php +++ b/main/inc/lib/promotion.lib.php @@ -7,104 +7,21 @@ * @package chamilo.library */ -class Promotion { +require_once 'model.lib.php'; + +class Promotion extends Model { var $table; - var $columns = array('name','description'); + var $columns = array('id','name','description','career_id'); public function __construct() { $this->table = Database::get_main_table(TABLE_PROMOTION); } - /** - * a little bit of javascript to display a prettier warning when deleting a note - * - * */ - function javascript_notebook() - { - return ""; - } - - - /** - * Saves an element into the DB - * - * @param array $values - * @return bool - * - */ - function save($values) { - /*if (!is_array($values) or empty($values['note_title'])) { - return false; - }*/ - unset($values['submit']); - $id = Database::insert($this->table, $values); - if (is_numeric($id)){ - return $id; - } - } - /** - * Gets an element - */ - function get($id) { - if (empty($id)) { return array(); } - $result = Database::select('*',$this->table, array('where'=>array('id = ?'=>intval($id))),'first'); - return $result; - } - - /** - * Get the count of elements - */ - function get_count() { - $row = Database::select('count(*) as count', $this->table, array(),'first'); - return $row['count']; - } - function get_all_promotions_by_career_id($career_id) { return Database::select('*', $this->table, array('where'=>array('career_id = ?'=>$career_id))); - } - - /** - * Updates the obj in the database - * - * @param array $values - * - */ - function update($values) { - /*if (!is_array($values) or empty($values['note_title'])) { - return false; - }*/ - unset($values['submit']); - $id = $values['id']; - unset($values['id']); - $result = Database::update($this->table, $values, array('id = ?'=>$id)); - if ($result != 1){ - return false; - } - return true; - } - - /** - * Delets an item - */ - function delete($id) { - if (empty($id) or $id != strval(intval($id))) { return false; } - // Database table definition - $result = Database :: delete($this->table, array('id = ?' => $id)); - if ($result != 1){ - return false; - } - return true; - } - + } + /** * Displays the title + grid */ From e8df58f11e5f7ecbf2ba364b943e9a6e298de06f Mon Sep 17 00:00:00 2001 From: ywarnier Date: Sun, 9 Jan 2011 19:46:55 -0500 Subject: [PATCH 2/7] Added feature to hide course tools on the whole platform - implements BT#1942. This might have consequences on the plugins development. --- documentation/changelog.html | 5 ++-- main/inc/lib/course_home.lib.php | 21 +++++++++++++++- main/install/db_main.sql | 26 ++++++++++++++++++- main/install/migrate-db-1.8.7-1.8.8-pre.sql | 28 +++++++++++++++++++-- 4 files changed, 74 insertions(+), 6 deletions(-) diff --git a/documentation/changelog.html b/documentation/changelog.html index 3df754301e..23d36d0e04 100755 --- a/documentation/changelog.html +++ b/documentation/changelog.html @@ -25,8 +25,8 @@
  • New application of a drop-down menu to select where to save new documents created (Feature #1758)
  • Added possibility to chose target in links even when not on homepage (Feature #1879)
  • Now showing teachers results in exercises results list (was confusing for most teachers)
  • -
  • Update Google Maps plugin to 1.98 (Feature #1925)
  • -
  • Add a personal portfolio to Social Network. All users can easy copy some files from several courses in his/her personal portfolio (Feature #1853)
  • +
  • Updated Google Maps plugin to 1.98 (Feature #1925)
  • +
  • Added a personal portfolio to Social Network. All users can easy copy some files from several courses in his/her personal portfolio (Feature #1853)
  • Students can edit, move and delete documents and drawings; create, move and delete subfolders, create user templates and make personal backups into a course inside his user shared folder (Features #2076, #2484)
  • Learning Path: New LP exercises reports added for teachers and admins (Feature BT#1634)
  • Support for displaying vector graphics files (SVG) and multimedia OGG files, facilitating the inclusion of videos and audios in HTML 5 (Feature #2244)
  • @@ -48,6 +48,7 @@
  • Students also can export documents to pdf
  • Easy enabled for spellcheck button on web editor (Feature #2207)
  • Increased control by platform administrator on the visibility of the folders in the documents tool (Feature #2164,#2484)
  • +
  • Added admin feature to hide tools from all courses - BT#1942
  • Debugging