ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
class.ilADTTest.php
Go to the documentation of this file.
1 <?php
2 
3 include_once "Services/ADT/classes/_Example/class.ilADTBasedObject.php";
4 
11 {
12  protected $id; // [int]
13  protected $properties; // [ilADTGroup]
14 
15  const INTERESTS_NONE = 0;
17  const INTERESTS_IT = 2;
18 
19 
20  // properties
21 
22  protected function initProperties()
23  {
24  global $lng;
25 
26  // this could be generated from XML or code comments or whatever
27 
28  include_once "Services/ADT/classes/class.ilADTFactory.php";
30 
31  $properties_def = $factory->getDefinitionInstanceByType("Group");
32 
33  $name = $factory->getDefinitionInstanceByType("Text");
34  $name->setMaxLength(255);
35  $properties_def->addElement("name", $name);
36 
37  $status = $factory->getDefinitionInstanceByType("Boolean");
38  $properties_def->addElement("active", $status);
39 
40  // example options from ilLanguage
41  $lng->loadLanguageModule("meta");
42  $options = array();
43  foreach ($lng->getInstalledLanguages() as $lang) {
44  $options[$lang] = $lng->txt("meta_l_" . $lang);
45  }
46 
47  $lang = $factory->getDefinitionInstanceByType("Enum");
48  $lang->setNumeric(false);
49  $lang->setOptions($options);
50  $properties_def->addElement("lang", $lang);
51 
52 
53  $age = $factory->getDefinitionInstanceByType("Integer");
54  $age->setMin(0);
55  $age->setMax(120);
56  $properties_def->addElement("age", $age);
57 
58  $weight = $factory->getDefinitionInstanceByType("Float");
59  $weight->setMin(0);
60  $weight->setMax(500);
61  $properties_def->addElement("weight", $weight);
62 
63  // null?
64  $home = $factory->getDefinitionInstanceByType("Location");
65  $properties_def->addElement("home", $home);
66 
67  $tags = $factory->getDefinitionInstanceByType("MultiText");
68  $tags->setMaxLength(255);
69  $tags->setMaxSize(5);
70  $properties_def->addElement("tags", $tags);
71 
72  $options = array(
73  self::INTERESTS_NONE => $lng->txt("test_interests_none"),
74  self::INTERESTS_LANGUAGES => $lng->txt("test_interests_languages"),
75  self::INTERESTS_IT => $lng->txt("test_interests_it")
76  );
77 
78  $intr = $factory->getDefinitionInstanceByType("MultiEnum");
79  $intr->setOptions($options);
80  $properties_def->addElement("interests", $intr);
81 
82  $date = $factory->getDefinitionInstanceByType("Date");
83  $properties_def->addElement("entry_date", $date);
84 
85  $dt = $factory->getDefinitionInstanceByType("DateTime");
86  $properties_def->addElement("last_login", $dt);
87 
88  // convert ADT definitions to proper ADTs
89  return $factory->getInstanceByDefinition($properties_def);
90  }
91 
92 
93  // CRUD/DB
94 
95  // simple sequence example
96 
97  protected function initDBBridge(ilADTGroupDBBridge $a_adt_db)
98  {
99  $a_adt_db->setTable("adt_test");
100  $a_adt_db->setPrimary(array("id"=>array("integer", $this->id)));
101  }
102 
103  protected function parsePrimary(array $a_args)
104  {
105  $this->id = (int) $a_args[0];
106  }
107 
108  protected function hasPrimary()
109  {
110  return (bool) $this->id;
111  }
112 
113  protected function createPrimaryKey()
114  {
115  global $ilDB;
116 
117  $this->id = $ilDB->nextId("adt_test");
118 
119  // INSERT is only done if createPrimaryKey() returns TRUE!
120  return true;
121  }
122 }
const INTERESTS_IT
This is a ADT-based example object.
$factory
Definition: metadata.php:47
static getInstance()
Get singleton.
if($format !==null) $name
Definition: metadata.php:146
$tags
Definition: croninfo.php:19
initDBBridge(ilADTGroupDBBridge $a_adt_db)
Create styles array
The data for the language used.
parsePrimary(array $a_args)
const INTERESTS_LANGUAGES
global $lng
Definition: privfeed.php:17
global $ilDB
ADT based-object base class.
if(!isset($_REQUEST['ReturnTo'])) if(!isset($_REQUEST['AuthId'])) $options
Definition: as_login.php:20
const INTERESTS_NONE