Index: trunk/extensions/SemanticForms/includes/SF_TemplateField.inc |
— | — | @@ -10,22 +10,46 @@ |
11 | 11 | class SFTemplateField { |
12 | 12 | var $field_name; |
13 | 13 | var $label; |
14 | | - var $semantic_field; |
15 | 14 | var $semantic_property; |
16 | | - var $is_relation; |
17 | 15 | var $field_type; |
18 | 16 | var $possible_values; |
19 | 17 | var $is_list; |
20 | 18 | |
21 | | - static function newWithValues($name, $label) { |
| 19 | + static function create($name, $label) { |
22 | 20 | $f = new SFTemplateField(); |
23 | 21 | $f->field_name = trim(str_replace('\\', '', $name)); |
24 | 22 | $f->label = trim(str_replace('\\', '', $label)); |
25 | 23 | return $f; |
26 | 24 | } |
27 | 25 | |
| 26 | + /** |
| 27 | + * Create an SFTemplateField object based on the corresponding field |
| 28 | + * in the template definition (which we first have to find) |
| 29 | + */ |
| 30 | + static function createFromList($field_name, $all_fields, $strict_parsing) { |
| 31 | + // see if this field matches one of the fields defined for |
| 32 | + // the template it's part of - if it is, use all available |
| 33 | + // information about that field; if it's not, either create |
| 34 | + // an object for it or not, depending on whether the |
| 35 | + // template has a 'strict' setting in the form definition |
| 36 | + $the_field = null; |
| 37 | + foreach ($all_fields as $cur_field) { |
| 38 | + if ($field_name == $cur_field->field_name) { |
| 39 | + $the_field = $cur_field; |
| 40 | + break; |
| 41 | + } |
| 42 | + } |
| 43 | + if ($the_field == null) { |
| 44 | + if ($strict_parsing) { |
| 45 | + return null; |
| 46 | + } |
| 47 | + $the_field = new SFTemplateField(); |
| 48 | + } |
| 49 | + return $the_field; |
| 50 | + } |
| 51 | + |
28 | 52 | function setTypeAndPossibleValues() { |
29 | | - $proptitle = Title::newFromText($this->semantic_field, SMW_NS_PROPERTY); |
| 53 | + $proptitle = Title::makeTitleSafe(SMW_NS_PROPERTY, $this->semantic_property); |
30 | 54 | if ($proptitle === NULL) |
31 | 55 | return; |
32 | 56 | $store = smwfGetStore(); |
— | — | @@ -44,7 +68,7 @@ |
45 | 69 | |
46 | 70 | foreach ($allowed_values as $value) { |
47 | 71 | // HTML-unencode each value |
48 | | - $this->possible_values[] = html_entity_decode($value->getXSDValue()); |
| 72 | + $this->possible_values[] = html_entity_decode($value->getWikiValue()); |
49 | 73 | } |
50 | 74 | // HACK - if there were any possible values, set the field |
51 | 75 | // type to be 'enumeration', regardless of what the actual type is |
— | — | @@ -53,30 +77,45 @@ |
54 | 78 | } |
55 | 79 | } |
56 | 80 | |
57 | | - // setSemanticData() - called when template is parsed during the creation |
58 | | - // of a form |
59 | | - function setSemanticData($semantic_field, $is_relation, $is_list) { |
60 | | - $this->semantic_field = str_replace('\\', '', $semantic_field); |
61 | | - $this->is_relation = $is_relation; |
| 81 | + /** |
| 82 | + * Called when template is parsed during the creation of a form |
| 83 | + */ |
| 84 | + function setSemanticProperty($semantic_property) { |
| 85 | + $this->semantic_property = str_replace('\\', '', $semantic_property); |
62 | 86 | $this->possible_values = array(); |
63 | | - $this->is_list = $is_list; |
64 | 87 | // set field type and possible values, if any |
65 | 88 | $this->setTypeAndPossibleValues(); |
66 | 89 | } |
67 | 90 | |
| 91 | + /** |
| 92 | + * Returns whether the semantic property represented by this field |
| 93 | + * has the passed-in type constant (e.g., '_str', '_wpg') |
| 94 | + */ |
| 95 | + function propertyIsOfType($type_constant) { |
| 96 | + global $smwgContLang; |
| 97 | + $datatypeLabels = $smwgContLang->getDatatypeLabels(); |
| 98 | + $page_type = $datatypeLabels[$type_constant]; |
| 99 | + return ($this->field_type == $page_type); |
| 100 | + } |
| 101 | + |
68 | 102 | function createTemplateText($template_name, $template_fields, $category, $aggregating_property, $aggregating_label, $template_format) { |
69 | | - $text = "<noinclude>\n"; |
70 | | - $text .= wfMsgForContent('sf_template_docu', $template_name) . "\n"; |
71 | | - $text .= "<pre>\n"; |
72 | | - $text .= "{{" . $template_name; |
| 103 | + $template_header = wfMsgForContent('sf_template_docu', $template_name); |
| 104 | + $text =<<<END |
| 105 | +<noinclude> |
| 106 | +$template_header |
| 107 | +<pre> |
| 108 | + |
| 109 | +END; |
| 110 | + $text .= '{{' . $template_name; |
73 | 111 | if (count($template_fields) > 0) { $text .= "\n"; } |
74 | 112 | foreach ($template_fields as $field) { |
75 | 113 | $text .= "|" . $field->field_name . "=\n"; |
76 | 114 | } |
77 | | - $text .= "}}\n"; |
78 | | - $text .= "</pre>\n"; |
79 | | - $text .= wfMsgForContent('sf_template_docufooter') . "\n"; |
| 115 | + $template_footer = wfMsgForContent('sf_template_docufooter'); |
80 | 116 | $text .=<<<END |
| 117 | +}} |
| 118 | +</pre> |
| 119 | +$template_footer |
81 | 120 | </noinclude><includeonly> |
82 | 121 | |
83 | 122 | END; |