|
|
|
@ -11,20 +11,20 @@ |
|
|
|
|
*/ |
|
|
|
|
class Model { |
|
|
|
|
|
|
|
|
|
var $table; |
|
|
|
|
var $columns; |
|
|
|
|
var $required; |
|
|
|
|
var $is_course_model =false; |
|
|
|
|
public $table; |
|
|
|
|
public $columns; |
|
|
|
|
public $required; |
|
|
|
|
public $is_course_model =false; |
|
|
|
|
|
|
|
|
|
// var $pk; some day this will be implemented |
|
|
|
|
|
|
|
|
|
public function __construct() { |
|
|
|
|
public function __construct() |
|
|
|
|
{ |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Useful finder - experimental akelos like only use in notification.lib.php send function |
|
|
|
|
*/ |
|
|
|
|
public function find($type, $options = null) { |
|
|
|
|
public function find($type, $options = null) |
|
|
|
|
{ |
|
|
|
|
switch ($type) { |
|
|
|
|
case 'all': |
|
|
|
|
return self::get_all($options); |
|
|
|
@ -36,10 +36,13 @@ class Model { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Delets an item |
|
|
|
|
* Deletes an item |
|
|
|
|
*/ |
|
|
|
|
public function delete($id) { |
|
|
|
|
if (empty($id) or $id != strval(intval($id))) { return false; } |
|
|
|
|
public function delete($id) |
|
|
|
|
{ |
|
|
|
|
if (empty($id) or $id != strval(intval($id))) { |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
$params = array('id = ?' => $id); |
|
|
|
|
if ($this->is_course_model) { |
|
|
|
|
$course_id = api_get_course_int_id(); |
|
|
|
@ -53,7 +56,12 @@ class Model { |
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private function clean_parameters($params){ |
|
|
|
|
/** |
|
|
|
|
* @param array $params |
|
|
|
|
* @return array |
|
|
|
|
*/ |
|
|
|
|
private function clean_parameters($params) |
|
|
|
|
{ |
|
|
|
|
$clean_params = array(); |
|
|
|
|
if (!empty($params)) { |
|
|
|
|
foreach ($params as $key=>$value) { |
|
|
|
@ -74,8 +82,11 @@ class Model { |
|
|
|
|
/** |
|
|
|
|
* Gets an element |
|
|
|
|
*/ |
|
|
|
|
public function get($id) { |
|
|
|
|
if (empty($id)) { return array(); } |
|
|
|
|
public function get($id) |
|
|
|
|
{ |
|
|
|
|
if (empty($id)) { |
|
|
|
|
return array(); |
|
|
|
|
} |
|
|
|
|
$params = array('id = ?'=>intval($id)); |
|
|
|
|
if ($this->is_course_model) { |
|
|
|
|
$course_id = api_get_course_int_id(); |
|
|
|
@ -85,18 +96,29 @@ class Model { |
|
|
|
|
return $result; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public function get_all($options = null) { |
|
|
|
|
/** |
|
|
|
|
* @param array $options |
|
|
|
|
* @return array |
|
|
|
|
*/ |
|
|
|
|
public function get_all($options = null) |
|
|
|
|
{ |
|
|
|
|
return Database::select('*', $this->table, $options); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public function get_all_for_export($options = null) { |
|
|
|
|
/** |
|
|
|
|
* @param array $options |
|
|
|
|
* @return array |
|
|
|
|
*/ |
|
|
|
|
public function get_all_for_export($options = null) |
|
|
|
|
{ |
|
|
|
|
return Database::select('name, description', $this->table, $options); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Get the count of elements |
|
|
|
|
*/ |
|
|
|
|
public function get_count() { |
|
|
|
|
public function get_count() |
|
|
|
|
{ |
|
|
|
|
$row = Database::select('count(*) as count', $this->table, array('where' => array('parent_id = ?' => '0')),'first'); |
|
|
|
|
return $row['count']; |
|
|
|
|
} |
|
|
|
@ -104,7 +126,8 @@ class Model { |
|
|
|
|
/** |
|
|
|
|
* a little bit of javascript to display |
|
|
|
|
*/ |
|
|
|
|
public function javascript() { |
|
|
|
|
public function javascript() |
|
|
|
|
{ |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
@ -151,11 +174,12 @@ class Model { |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Updates the obj in the database. The $params['id'] must exist in order to update a record |
|
|
|
|
* |
|
|
|
|
* @param array $values |
|
|
|
|
* @return bool |
|
|
|
|
* |
|
|
|
|
*/ |
|
|
|
|
public function update($params) { |
|
|
|
|
public function update($params) |
|
|
|
|
{ |
|
|
|
|
$params = $this->clean_parameters($params); |
|
|
|
|
|
|
|
|
|
if ($this->is_course_model) { |
|
|
|
|