ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilADTTest.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
10 {
11  protected int $id;
12  protected ilADT $properties;
13 
14  public const INTERESTS_NONE = 0;
15  public const INTERESTS_LANGUAGES = 1;
16  public const INTERESTS_IT = 2;
17 
18  // properties
19 
20  protected function initProperties(): ilADT
21  {
22  // this could be generated from XML or code comments or whatever
23 
25 
26  $properties_def = $factory->getDefinitionInstanceByType("Group");
27 
28  $name = $factory->getDefinitionInstanceByType("Text");
29  $name->setMaxLength(255);
30  $properties_def->addElement("name", $name);
31 
32  $status = $factory->getDefinitionInstanceByType("Boolean");
33  $properties_def->addElement("active", $status);
34 
35  // example options from ilLanguage
36  $this->lng->loadLanguageModule("meta");
37  $options = array();
38  foreach ($this->lng->getInstalledLanguages() as $lang) {
39  $options[$lang] = $this->lng->txt("meta_l_" . $lang);
40  }
41 
42  $lang = $factory->getDefinitionInstanceByType("Enum");
43  $lang->setNumeric(false);
44  $lang->setOptions($options);
45  $properties_def->addElement("lang", $lang);
46 
47  $age = $factory->getDefinitionInstanceByType("Integer");
48  $age->setMin(0);
49  $age->setMax(120);
50  $properties_def->addElement("age", $age);
51 
52  $weight = $factory->getDefinitionInstanceByType("Float");
53  $weight->setMin(0);
54  $weight->setMax(500);
55  $properties_def->addElement("weight", $weight);
56 
57  // null?
58  $home = $factory->getDefinitionInstanceByType("Location");
59  $properties_def->addElement("home", $home);
60 
61  $tags = $factory->getDefinitionInstanceByType("MultiText");
62  $tags->setMaxLength(255);
63  $tags->setMaxSize(5);
64  $properties_def->addElement("tags", $tags);
65 
66  $options = array(
67  self::INTERESTS_NONE => $this->lng->txt("test_interests_none"),
68  self::INTERESTS_LANGUAGES => $this->lng->txt("test_interests_languages"),
69  self::INTERESTS_IT => $this->lng->txt("test_interests_it")
70  );
71 
72  $intr = $factory->getDefinitionInstanceByType("MultiEnum");
73  $intr->setOptions($options);
74  $properties_def->addElement("interests", $intr);
75 
76  $date = $factory->getDefinitionInstanceByType("Date");
77  $properties_def->addElement("entry_date", $date);
78 
79  $dt = $factory->getDefinitionInstanceByType("DateTime");
80  $properties_def->addElement("last_login", $dt);
81 
82  // convert ADT definitions to proper ADTs
83  return $factory->getInstanceByDefinition($properties_def);
84  }
85 
86 
87  // CRUD/DB
88 
89  // simple sequence example
90 
91  protected function initDBBridge(ilADTDBBridge $a_adt_db): void
92  {
93  $a_adt_db->setTable("adt_test");
94  $a_adt_db->setPrimary(array("id" => array("integer", $this->id)));
95  }
96 
97  protected function parsePrimary(array $a_args): void
98  {
99  $this->id = (int) $a_args[0];
100  }
101 
102  protected function hasPrimary(): bool
103  {
104  return (bool) $this->id;
105  }
106 
107  protected function createPrimaryKeyb(): bool
108  {
109  $this->id = $this->db->nextId("adt_test");
110 
111  // INSERT is only done if createPrimaryKey() returns TRUE!
112  return true;
113  }
114 }
setPrimary(array $a_value)
Set primary fields (in MDB2 format)
const INTERESTS_IT
This is a ADT-based example object It has all supported ADTs and shows DB sequence-handling.
ADT base class.
Definition: class.ilADT.php:11
ilADT $properties
if($format !==null) $name
Definition: metadata.php:247
initDBBridge(ilADTDBBridge $a_adt_db)
ADT DB bridge base class.
setTable(string $a_table)
parsePrimary(array $a_args)
$lang
Definition: xapiexit.php:26
const INTERESTS_LANGUAGES
ADT based-object base class Currently "mixed" with ActiveRecord-pattern, could be splitted...
$factory
Definition: metadata.php:75
const INTERESTS_NONE