ILIAS  trunk Revision v11.0_alpha-1749-g1a06bdef097
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
ILIAS\components\ToDoExample\TodoRepository Class Reference
+ Collaboration diagram for ILIAS\components\ToDoExample\TodoRepository:

Public Member Functions

 __construct (ilDBInterface $db)
 
 getItemsOfUser (int $user_id)
 Get the items of a user. More...
 
 createItem (TodoItem $item)
 Create an item in the database The returned item has an automatically created id. More...
 
 updateItem (TodoItem $item)
 Update an item in the database. More...
 
 deleteItem (ToDoItem $item)
 

Protected Attributes

ilDBInterface $db
 

Detailed Description

Definition at line 25 of file TodoRepository.php.

Constructor & Destructor Documentation

◆ __construct()

ILIAS\components\ToDoExample\TodoRepository::__construct ( ilDBInterface  $db)

Definition at line 29 of file TodoRepository.php.

References ILIAS\components\ToDoExample\TodoRepository\$db.

30  {
31  $this->db = $db;
32  }

Member Function Documentation

◆ createItem()

ILIAS\components\ToDoExample\TodoRepository::createItem ( TodoItem  $item)

Create an item in the database The returned item has an automatically created id.

Definition at line 62 of file TodoRepository.php.

References ILIAS\components\ToDoExample\TodoItem\getDeadline(), ILIAS\components\ToDoExample\TodoItem\getDescription(), ILIAS\components\ToDoExample\TodoItem\getTitle(), ILIAS\components\ToDoExample\TodoItem\getUserId(), and ILIAS\components\ToDoExample\TodoItem\widthTodoId().

62  : TodoItem
63  {
64  $todo_id = $this->db->nextId('todo_items');
65 
66  $this->db->insert('todo_items', [
67  'todo_id' => ['integer', $todo_id],
68  'user_id' => ['integer', $item->getUserId()],
69  'title' => ['text', $item->getTitle()],
70  'description' => ['clob', $item->getDescription()],
71  'deadline' => ['date', $item->getDeadline()]
72  ]);
73 
74  return $item->widthTodoId($todo_id);
75  }
+ Here is the call graph for this function:

◆ deleteItem()

ILIAS\components\ToDoExample\TodoRepository::deleteItem ( ToDoItem  $item)

Definition at line 94 of file TodoRepository.php.

94  : void
95  {
96  $query = "DELETE FROM todo_items WHERE todo_id = %s";
97 
98  $this->db->manipulateF($query, ['integer'], [$item->getTodoId()]);
99  }

◆ getItemsOfUser()

ILIAS\components\ToDoExample\TodoRepository::getItemsOfUser ( int  $user_id)

Get the items of a user.

Returns
ToDoItem[]

Definition at line 38 of file TodoRepository.php.

References null.

38  : array
39  {
40  $items = [];
41 
42  $query = "SELECT * FROM todo_items WHERE user_id = %s";
43 
44  $result = $this->db->queryF($query, ['integer'], [$user_id]);
45 
46  while ($row = $this->db->fetchAssoc($result)) {
47  $items[] = new TodoItem(
48  $row['item_id'],
49  $row['user_id'],
50  $row['title'],
51  $row['description'] ?? null,
52  $row['deadline'] ?? null
53  );
54  }
55  return $items;
56  }
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null

◆ updateItem()

ILIAS\components\ToDoExample\TodoRepository::updateItem ( TodoItem  $item)

Update an item in the database.

Definition at line 80 of file TodoRepository.php.

References ILIAS\components\ToDoExample\TodoItem\getDeadline(), ILIAS\components\ToDoExample\TodoItem\getDescription(), ILIAS\components\ToDoExample\TodoItem\getTitle(), ILIAS\components\ToDoExample\TodoItem\getTodoId(), and ILIAS\components\ToDoExample\TodoItem\getUserId().

80  : void
81  {
82  $this->db->update('todo_items', [
83  'user_id' => ['integer', $item->getUserId()],
84  'title' => ['text', $item->getTitle()],
85  'description' => ['clob', $item->getDescription()],
86  'deadline' => ['date', $item->getDeadline()]
87  ], [
88  'todo_id' => ['integer', $item->getTodoId()]
89  ]);
90 
91  }
+ Here is the call graph for this function:

Field Documentation

◆ $db

ilDBInterface ILIAS\components\ToDoExample\TodoRepository::$db
protected

The documentation for this class was generated from the following file: