Accessing the name of a property from a Query Printer

View: New views
3 Messages — Rating Filter:   Alert me  

Accessing the name of a property from a Query Printer

by Asheesh Laroia-3 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I'm improving the SMW CSV query printer we're working on at CC (source is
in the CC_SMW_Extensions repository at code.creativecommons.org's git; if
we didn't announce it before, ask - I'm happy to write more about it
later).

For our CSV printer, I figured - if a page has two values for a property,
they should show up in the same column of a spreadsheet joined by ","
rather than in separate columns.  So I began to change the CSV Query
Printer to keep track of which property name it was printing.

However, in abstract SMWDataValue $object->m_property is *protected*.  So
I can't read it.  So my query printer can't tell what property it is
printing, and therefore can't specially handle this case.

Why is it protected?  Can a get_property_name() method be added?  Am I
handling this wrong?

-- Asheesh.

--
When taxes are due, Americans tend to feel quite bled-white and blue.

-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://sourceforge.net/services/buy/index.php
_______________________________________________
Semediawiki-devel mailing list
Semediawiki-devel@...
https://lists.sourceforge.net/lists/listinfo/semediawiki-devel

[PATCH] Accessing the name of a property from a Query Printer

by Asheesh Laroia-3 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I'm attaching a very short patch that creates getPropertyName() in the
SMW_DataValue.php file.

This is useful for custom query printers that need to know the name of the
property they are reading (to, for example, detect properties with more
than one value, as the CSV query printer needs).

Permission is granted to re-use this under the same terms as the current
SMW codebase.  Please commit!

-- Asheesh.

--
Did I do an INCORRECT THING??
[getPropertyName.patch]

diff --git a/includes/SMW_DataValue.php b/includes/SMW_DataValue.php
index d16256f..96c88a1 100644
--- a/includes/SMW_DataValue.php
+++ b/includes/SMW_DataValue.php
@@ -140,6 +140,14 @@ abstract class SMWDataValue {
  $this->m_errors[] = $errorstring;
  }
 
+ /**
+ * Return the name of this property. Helpful for writing custom
+ * query printing functions.
+ */
+ public function getPropertyName() {
+ return $this->m_property;
+ }
+
 ///// Abstract processing methods /////
 
  /**


-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://sourceforge.net/services/buy/index.php
_______________________________________________
Semediawiki-devel mailing list
Semediawiki-devel@...
https://lists.sourceforge.net/lists/listinfo/semediawiki-devel

Re: [PATCH] Accessing the name of a property from a Query Printer

by Asheesh Laroia-3 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Mon, 23 Jun 2008, Asheesh Laroia wrote:

> I'm attaching a very short patch that creates getPropertyName() in the
> SMW_DataValue.php file.

Please still commit this - it turns out to be useful for another extension
of mine.

> This is useful for custom query printers that need to know the name of
> the property they are reading (to, for example, detect properties with
> more than one value, as the CSV query printer needs).

For what it's worth, I don't need the patch for CSV query printer in the
end - I fixed the bug based on a careful reading of QP_Table! (-:

-- Asheesh.

--
When you try to make an impression, the chances are that is the
impression you will make.

-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://sourceforge.net/services/buy/index.php
_______________________________________________
Semediawiki-devel mailing list
Semediawiki-devel@...
https://lists.sourceforge.net/lists/listinfo/semediawiki-devel