On 06/08/12 15:59, Yury Katkov wrote:
> Hi Jeroen!
>
> Each piece of programming documentation is as valuable as gold! Please do.
> I've spent about two days recently before I figured out these two
> lines that allow to want the value of the semantic property.
>
>   $params = array ("[[Pagename]]", "?ExampleProperty=", "mainlabel=-");
>   $result = SMWQueryProcessor::getResultFromFunctionParams( $params,
> SMW_OUTPUT_WIKI );

The above is a very complicated way to get the data you want 
(constructing a whole query with printouts to get a single data value). 
It's short, but it invokes all kinds of string-based parsing that may 
not be needed. Instead, you can do:

// Assuming that you have the names of page and property fixed:
// (all strings are DBKeys, that is, use '_' instead of ' ')
$propertyDi = new SMWDIProperty( 'ExampleProperty' );
$pageDi = new SMWDIWikiPage( 'Pagename', NS_MAIN, '' );
$valueDis = smwfGetStore()->getPropertyValues( $pageDi, $propertyDi );
// $valueDis now is an array of all property values, given as DI objects

// To create DV objects:
foreach ( $valueDis as $valueDi ) {
        $valueDv = SMWDataValueFactory::newDataItemValue( $valueDi, $propertyDi 
);
// do something ...
}

If page or property name comes from user input, then you can do 
something like:

$propertyDv = SMWDataValueFactory::newTypeIdValue( '__pro', $propertyName );
$pageDv = SMWDataValueFactory::newTypeIdValue( '_wpg', $pageName );

and then call getDataItem() to get the DIs. The strings '__pro' and 
'_wpg' are the type ids that control how SMW will handle the string to 
create a suitable DV object. You can see all builtin type ids in 
SMWDatavalueFactory, if you want to know this for other datatypes as 
well. However, if you have "clean" internal values, you can always 
create DI objects directly, rather than parsing them from a string.

Please take advantage of the devel list for such questions :-)

Cheers,

Markus


>
> I'm pretty sure that making custom datatypes is pretty common task and
> not only I will find your docs useful.
> -----
> Yury Katkov
>
>
>
>
> On Mon, Aug 6, 2012 at 5:47 PM, Jeroen De Dauw <jeroended...@gmail.com> wrote:
>>
>> Hey,
>>
>>> The sorting is not ideal, but of course there's no "IP address" type,
>> which is what would be required here.
>>
>> It's pretty trivial to create a DataValue for this, which is all that's
>> needed to have such a build in type. If anyone is interested in doing the
>> little programming work, I can write up some docs :)
>>
>> Cheers
>>
>> --
>> Jeroen De Dauw
>> http://www.bn2vs.com
>> Don't panic. Don't be evil.
>> --
>> ------------------------------------------------------------------------------
>> Live Security Virtual Conference
>> Exclusive live event will cover all the ways today's security and
>> threat landscape has changed and how IT managers can respond. Discussions
>> will include endpoint security, mobile security and the latest in malware
>> threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
>> _______________________________________________
>> Semediawiki-user mailing list
>> semediawiki-u...@lists.sourceforge.net
>> https://lists.sourceforge.net/lists/listinfo/semediawiki-user
>
> ------------------------------------------------------------------------------
> Live Security Virtual Conference
> Exclusive live event will cover all the ways today's security and
> threat landscape has changed and how IT managers can respond. Discussions
> will include endpoint security, mobile security and the latest in malware
> threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
> _______________________________________________
> Semediawiki-user mailing list
> semediawiki-u...@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/semediawiki-user
>



------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Semediawiki-devel mailing list
Semediawiki-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/semediawiki-devel

Reply via email to