Index: trunk/extensions/SemanticMediaWiki/includes/SMW_DataValueFactory.php |
— | — | @@ -40,15 +40,16 @@ |
41 | 41 | * can be set later on. |
42 | 42 | */ |
43 | 43 | static public function newAttributeValue($attstring, $value=false) { |
44 | | - if(!array_key_exists($attstring,SMWDataValueFactory::$m_typelabels)) { |
45 | | - $atitle = Title::newFromText($attstring, SMW_NS_ATTRIBUTE); |
46 | | - if ($atitle !== NULL) { |
47 | | - return SMWDataValueFactory::newAttributeObjectValue($atitle,$value); |
48 | | - } else { |
49 | | - return new SMWOldDataValue(new SMWErrorTypeHandler(wfMsgForContent('smw_notype'))); |
50 | | - } |
| 44 | + if(array_key_exists($attstring,SMWDataValueFactory::$m_typelabels)) { // use cache |
| 45 | + return SMWDataValueFactory::newTypedValue(SMWDataValueFactory::$m_typelabels[$attstring], $value, $attstring); |
| 46 | + } // else: find type for attribute: |
| 47 | + |
| 48 | + $atitle = Title::newFromText($attstring, SMW_NS_ATTRIBUTE); |
| 49 | + if ($atitle !== NULL) { |
| 50 | + return SMWDataValueFactory::newAttributeObjectValue($atitle,$value); |
| 51 | + } else { |
| 52 | + return new SMWErrorValue(wfMsgForContent('smw_notype'), $value); |
51 | 53 | } |
52 | | - return SMWDataValueFactory::newTypedValue(SMWDataValueFactory::$m_typelabels[$attstring], $value); |
53 | 54 | } |
54 | 55 | |
55 | 56 | /** |
— | — | @@ -57,22 +58,23 @@ |
58 | 59 | * can be set later on. |
59 | 60 | */ |
60 | 61 | static public function newAttributeObjectValue(Title $att, $value=false) { |
| 62 | + SMWDataValueFactory::$m_typelabels['Testnary'] = SMWDataValueFactory::newSpecialValue(SMW_SP_HAS_TYPE, 'String;Integer;Wikipage;Date'); /// DEBUG |
61 | 63 | $attstring = $att->getText(); |
62 | | - SMWDataValueFactory::$m_typelabels['Testnary'] = SMWDataValueFactory::newSpecialValue(SMW_SP_HAS_TYPE, 'String;Integer;Wikipage;Date'); /// DEBUG |
63 | | - if(!array_key_exists($attstring,SMWDataValueFactory::$m_typelabels)) { |
64 | | - $typearray = smwfGetStore()->getSpecialValues($att,SMW_SP_HAS_TYPE); |
65 | | - if (count($typearray)==1) { |
66 | | - SMWDataValueFactory::$m_typelabels[$attstring] = $typearray[0]; |
67 | | - $result = SMWDataValueFactory::newTypedValue(SMWDataValueFactory::$m_typelabels[$attstring], $value); |
68 | | - SMWDataValueFactory::$m_typeids[$attstring] = $result->getTypeID(); // also cache typeid |
69 | | - return $result; |
70 | | - } elseif (count($typearray)==0) { |
71 | | - return new SMWErrorValue(wfMsgForContent('smw_notype'), $value); |
72 | | - } else { |
73 | | - return new SMWErrorValue(wfMsgForContent('smw_manytypes'), $value); |
74 | | - } |
| 64 | + if(array_key_exists($attstring,SMWDataValueFactory::$m_typelabels)) { // use cache |
| 65 | + return SMWDataValueFactory::newTypedValue(SMWDataValueFactory::$m_typelabels[$attstring], $value, $attstring); |
| 66 | + } // else: find type for attribute: |
| 67 | + |
| 68 | + $typearray = smwfGetStore()->getSpecialValues($att,SMW_SP_HAS_TYPE); |
| 69 | + if (count($typearray)==1) { |
| 70 | + SMWDataValueFactory::$m_typelabels[$attstring] = $typearray[0]; |
| 71 | + $result = SMWDataValueFactory::newTypedValue(SMWDataValueFactory::$m_typelabels[$attstring], $value, $attstring); |
| 72 | + SMWDataValueFactory::$m_typeids[$attstring] = $result->getTypeID(); // also cache typeid |
| 73 | + return $result; |
| 74 | + } elseif (count($typearray)==0) { |
| 75 | + return new SMWErrorValue(wfMsgForContent('smw_notype'), $value); |
| 76 | + } else { |
| 77 | + return new SMWErrorValue(wfMsgForContent('smw_manytypes'), $value); |
75 | 78 | } |
76 | | - return SMWDataValueFactory::newTypedValue(SMWDataValueFactory::$m_typelabels[$attstring], $value); |
77 | 79 | } |
78 | 80 | |
79 | 81 | /** |
— | — | @@ -116,8 +118,11 @@ |
117 | 119 | * Create a value from a type value (basically containing strings). |
118 | 120 | * If no $value is given, an empty container is created, the value of which |
119 | 121 | * can be set later on. |
| 122 | + * @param $typevalue datavalue representing the type of the object |
| 123 | + * @param $value user value string, or false if unknown |
| 124 | + * @param $attstring text name of according attribute, or false (may be relevant for getting further parameters) |
120 | 125 | */ |
121 | | - static public function newTypedValue(SMWDataValue $typevalue, $value=false) { |
| 126 | + static public function newTypedValue(SMWDataValue $typevalue, $value=false, $attstring=false) { |
122 | 127 | if (array_key_exists($typevalue->getWikiValue(), SMWDataValueFactory::$m_valueclasses)) { |
123 | 128 | $vc = SMWDataValueFactory::$m_valueclasses[$typevalue->getWikiValue()]; |
124 | 129 | // check if class file was already included for this class |
— | — | @@ -149,6 +154,9 @@ |
150 | 155 | } |
151 | 156 | } |
152 | 157 | |
| 158 | + if ($attstring != false) { |
| 159 | + $result->setAttribute($attstring); |
| 160 | + } |
153 | 161 | if ($value !== false) { |
154 | 162 | $result->setUserValue($value); |
155 | 163 | } |