-
Notifications
You must be signed in to change notification settings - Fork 1
/
semanticweblog.types.inc
226 lines (195 loc) · 8.12 KB
/
semanticweblog.types.inc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
<?php
// $Id$
/**
* @file:
* This file contains all non-hook and non-theme Functions with the purpose of managing Associaton Types
*
* @author Benjamin Birkenhake <benjamin@birkenhake.org>
* @package semanticweblog
* @copyright creative commons by-sa
*
*/
function semanticweblog_load_all_types() {
$result = db_query("SELECT * FROM {semanticweblog_types}");
while ($item = db_fetch_array($result)) {
if ($item != "") {
$items[$item['atid']] = $item;
}
}
if ($items == "") {
drupal_set_message(l(t('No association types set, add at least one.'), "admin/content/associationtype"), 'warning', FALSE);
$items[0] = array('atid' => '0', 'name' => t('No Association Types defined'));
}
return $items;
}
function semanticweblog_get_all_types() {
global $semanticweblog_association_types;
if (is_array($semanticweblog_association_types) and count($semanticweblog_association_types)>0){
return $semanticweblog_association_types;
}else{
$semanticweblog_association_types = semanticweblog_load_all_types();
return $semanticweblog_association_types;
}
}
function semanticweblog_name2atid($name) {
$name = trim($name);
$types = semanticweblog_get_all_types();
foreach($types as $type){
//dprint_r("[".$type["name"]."][".$name."]");
if($type["name"]==$name){
return $type["atid"];
}
}
}
// The functions and forms for creating an Association Type
function semanticweblog_manage_association_types() {
// Add an Assoctyoe
$form["semanticweblog_manage_association_types"]["new_type_name"] = array('#type' => 'textfield',
'#title' => t('Association Type Name'),
'#default_value' => '',
'#size' => 30,
'#maxlength' => 512,
'#description' => t('Enter a name for the Association type'),
);
$form["semanticweblog_manage_association_types"]["new_type_role1"] = array('#type' => 'textfield',
'#title' => t('Association First Role'),
'#default_value' => '',
'#size' => 30,
'#maxlength' => 512,
'#description' => t('Enter a name for the firste Role of the Association type'),
);
$form["semanticweblog_manage_association_types"]["new_type_role2"] = array('#type' => 'textfield',
'#title' => t('Association Second Role'),
'#default_value' => '',
'#size' => 30,
'#maxlength' => 512,
'#description' => t('Enter a name for the second Role of the Association type'),
);
$form["semanticweblog_manage_association_types"]["new_type_sentence"] = array('#type' => 'textfield',
'#title' => t('Sentence'),
'#default_value' => '',
'#size' => 30,
'#maxlength' => 512,
'#description' => t('Enter a sentence of the type "term1 verb term2"'),
);
$form["semanticweblog_manage_association_types"]["submit"] = array('#type' => 'submit',
'#value' => t('Create new Association Type'),
);
return $form;
}
function semanticweblog_manage_association_types_validate($form, &$form_state) {
if ($form_state['values']['new_type_name'] == '') {
form_set_error('new_type_name', t('Your Association Type needs a Name.'));
}
if ($form_state['values']['new_type_role1'] == '') {
form_set_error('new_type_role1', t('Your Association Type needs a first Role.'));
}
if ($form_state['values']['new_type_role2'] == '') {
form_set_error('new_type_role2', t('Your Association Type needs a second Role.'));
}
if ($form_state['values']['new_type_sentence'] == '') {
form_set_error('new_type_role2', t('Your Association Type needs a Sentence.'));
}
}
function semanticweblog_manage_association_types_submit($form, &$form_state) {
$name = $form_state['values']['new_type_name'];
$role1 = $form_state['values']['new_type_role1'];
$role2 = $form_state['values']['new_type_role2'];
$sentence = $form_state['values']['new_type_sentence'];
semanticweblog_insert_associationtype($name, $role1, $role2, $sentence);
drupal_set_message(t('Your association type has been saved.'));
}
function semanticweblog_insert_associationtype($name, $role1, $role2, $sentence) {
db_query("INSERT INTO {semanticweblog_types} (name, role1, role2, sentence) VALUES ('%s', '%s', '%s', '%s')", $name, $role1, $role2, $sentence);
}
// The functions and forms for editing an Association type
function semanticweblog_edit_association_type() {
// Edit an Assoctyoe
$atid = arg(3);
$ats = semanticweblog_get_all_types();
$myat = $ats[$atid];
$form["semanticweblog_manage_association_types"]["new_type_name"] = array('#type' => 'textfield',
'#title' => t('Association Type Name'),
'#default_value' => $myat["name"],
'#size' => 30,
'#maxlength' => 512,
'#description' => t('Enter a name for the Association type'),
);
$form["semanticweblog_manage_association_types"]["new_type_role1"] = array('#type' => 'textfield',
'#title' => t('Association First Role'),
'#default_value' => $myat["role1"],
'#size' => 30,
'#maxlength' => 512,
'#description' => t('Enter a name for the firste Role of the Association type'),
);
$form["semanticweblog_manage_association_types"]["new_type_role2"] = array('#type' => 'textfield',
'#title' => t('Association Second Role'),
'#default_value' => $myat["role2"],
'#size' => 30,
'#maxlength' => 512,
'#description' => t('Enter a name for the second Role of the Association type'),
);
$form["semanticweblog_manage_association_types"]["new_type_sentence"] = array('#type' => 'textfield',
'#title' => t('Association Second Role'),
'#default_value' => $myat["sentence"],
'#size' => 30,
'#maxlength' => 512,
'#description' => t('Enter a name for the second Role of the Association type'),
);
$form["semanticweblog_manage_association_types"]["atid"] = array('#type' => 'hidden',
'#value' => $myat["atid"],
);
$form["semanticweblog_manage_association_types"]["submit"] = array('#type' => 'submit',
'#value' => t('Edit this Association Type'),
);
return $form;
}
function semanticweblog_edit_association_type_validate($form, &$form_state) {
if ($form_state['values']['new_type_name'] == '') {
form_set_error('new_type_name', t('Your Association Type needs a Name.'));
}
if ($form_state['values']['new_type_role1'] == '') {
form_set_error('new_type_role1', t('Your Association Type needs a first Role.'));
}
if ($form_state['values']['new_type_role2'] == '') {
form_set_error('new_type_role2', t('Your Association Type needs a second Role.'));
}
if ($form_state['values']['new_type_sentence'] == '') {
form_set_error('new_type_role2', t('Your Association Type needs a sentence.'));
}
}
function semanticweblog_update_associationtype($name, $role1, $role2, $sentence, $atid) {
db_query("UPDATE {semanticweblog_types} SET name='%s', role1='%s', role2='%s', sentence='%s' WHERE atid=%d", $name, $role1, $role2, $sentence, $atid);
}
function semanticweblog_edit_association_type_submit($form, &$form_state) {
$atid = $form_state['values']['atid'];
$name = $form_state['values']['new_type_name'];
$role1 = $form_state['values']['new_type_role1'];
$role2 = $form_state['values']['new_type_role2'];
$sentence = $form_state['values']['new_type_sentence'];
semanticweblog_update_associationtype($name, $role1, $role2, $sentence, $atid);
drupal_set_message(t('Your association type has been edited.'));
drupal_goto("admin/content/associationtype");
}
// The functions and files for deleting an Association Type
function semanticweblog_delete_association_type() {
$atid = arg(3);
$ats = semanticweblog_get_all_types();
$myat = $ats[$atid];
$form["semanticweblog_manage_association_types"]["atid"] = array('#type' => 'hidden',
'#value' => $myat["atid"],
);
$form["semanticweblog_manage_association_types"]["submit"] = array('#type' => 'submit',
'#value' => t('Delete this Association Type'),
);
return $form;
}
function semanticweblog_delete_associationtype($atid) {
db_query("DELETE FROM {semanticweblog_types} WHERE atid=%d", $atid);
}
function semanticweblog_delete_association_type_submit($form, &$form_state) {
$atid = $form_state['values']['atid'];
semanticweblog_delete_associationtype($atid);
drupal_set_message(t('Your association type has been deleted.'));
drupal_goto("admin/content/associationtype");
}