#5023 Implements Doctrine for database access

skala
Laurent Opprecht 13 years ago
parent ab21c1b338
commit 82abdd7c8f
  1. 3
      main/inc/lib/course_entity.class.php
  2. 2
      main/inc/lib/entity.class.php
  3. 122
      main/inc/lib/student_publication.class.php

@ -11,7 +11,10 @@ class CourseEntity extends Entity
public function __construct()
{
$current_course = self::current_course();
if ($current_course) {
$this->defaults('c_id', self::current_course()->get_id());
}
$this->defaults('session_id', api_get_session_id());
}

@ -19,8 +19,10 @@ class Entity
if ($result === false) {
$repo = \Entity\Course::repository();
$course_id = api_get_course_int_id();
if ($course_id) {
$result = $repo->find($course_id);
}
}
return $result;
}

@ -30,8 +30,7 @@ class StudentPublication
public static function void()
{
static $result = null;
if($result)
{
if ($result) {
return $result;
}
@ -39,7 +38,13 @@ class StudentPublication
return $result;
}
/**
* @return Model\StudentPublicationRepository
*/
public static function repository()
{
return StudentPublicationRepository::instance();
}
/**
*
@ -48,36 +53,7 @@ class StudentPublication
*/
public static function query($where)
{
$table_item_property = Database::get_course_table(TABLE_ITEM_PROPERTY);
$table = Database::get_course_table(TABLE_STUDENT_PUBLICATION);
$tool = 'work';
$sql = "SELECT pub.*,
prop.id AS property_id,
prop.tool,
prop.insert_user_id,
prop.insert_date,
prop.lastedit_date,
prop.ref,
prop.lastedit_type,
prop.lastedit_user_id,
prop.to_group_id,
prop.to_user_id,
prop.visibility,
prop.start_visible,
prop.end_visible,
prop.id_session
FROM
$table AS pub,
$table_item_property AS prop
WHERE
(pub.id = prop.ref AND
pub.c_id = prop.c_id AND
prop.tool = '$tool')";
$sql .= $where ? "AND ($where)" : '';
$result = new ResultSet($sql);
return $result->return_type(__CLASS__);
return self::repository()->query($where);
}
/**
@ -88,8 +64,7 @@ class StudentPublication
*/
public static function get_by_id($c_id, $id)
{
$c_id = is_object($c_id) ? $c_id->get_id() : (int) $c_id;
return self::query("pub.c_id = $c_id AND pub.id = $id")->first();
return self::repository()->get_by_id($c_id, $id);
}
protected $c_id = 0;
@ -157,8 +132,6 @@ class StudentPublication
}
}
public function get_c_id()
{
return $this->c_id;
@ -437,3 +410,78 @@ class StudentPublication
}
}
class StudentPublicationRepository
{
/**
*
* @staticvar null $result
* @return StudentPublicationRepository
*/
public static function instance()
{
static $result = null;
if (empty($result)) {
$result = new self();
}
return $resutl;
}
/**
*
* @param string $where
* @return \ResultSet
*/
public function query($where)
{
$table_item_property = Database::get_course_table(TABLE_ITEM_PROPERTY);
$table = Database::get_course_table(TABLE_STUDENT_PUBLICATION);
$tool = 'work';
$sql = "SELECT pub.*,
prop.id AS property_id,
prop.tool,
prop.insert_user_id,
prop.insert_date,
prop.lastedit_date,
prop.ref,
prop.lastedit_type,
prop.lastedit_user_id,
prop.to_group_id,
prop.to_user_id,
prop.visibility,
prop.start_visible,
prop.end_visible,
prop.id_session
FROM
$table AS pub,
$table_item_property AS prop
WHERE
(pub.id = prop.ref AND
pub.c_id = prop.c_id AND
prop.tool = '$tool')";
$sql .= $where ? "AND ($where)" : '';
$result = new ResultSet($sql);
return $result->return_type(__CLASS__);
}
/**
*
* @param int|Course $c_id
* @param int $id
* @return \Model\StudentPublication
*/
public function get_by_id($c_id, $id)
{
$c_id = is_object($c_id) ? $c_id->get_id() : (int) $c_id;
return $this->query("pub.c_id = $c_id AND pub.id = $id")->first();
}
public function update($pub)
{
}
}
Loading…
Cancel
Save