Index: trunk/extensions/SemanticMediaWiki/includes/SMW_QP_JSONlink.php |
— | — | @@ -41,47 +41,30 @@ |
42 | 42 | if ( $outputmode == SMW_OUTPUT_FILE ) { // create detached JSON file |
43 | 43 | $itemstack = array(); // contains Items for the items section |
44 | 44 | $propertystack = array(); // contains Properties for the property section |
45 | | - $firstPropertyIsPageDef = false; // we onlt drop first property if its of type wpg |
46 | | - $count = 0; |
| 45 | + |
47 | 46 | // generate property section |
48 | 47 | foreach ( $res->getPrintRequests() as $pr ) { |
49 | | - if ( array_key_exists( $pr->getTypeID(), $this->types ) ) { |
50 | | - $propertystack[] = '"' . str_replace( " ", "_", strtolower( $pr->getLabel() ) ) . '" : { "valueType": "' . $this->types[$pr->getTypeID()] . '" }'; |
51 | | - } else { |
52 | | - $propertystack[] = '"' . str_replace( " ", "_", strtolower( $pr->getLabel() ) ) . '" : { "valueType": "text" }'; |
| 48 | + if ( $pr->getMode() != SMWPrintRequest::PRINT_THIS ) { |
| 49 | + if ( array_key_exists( $pr->getTypeID(), $this->types ) ) { |
| 50 | + $propertystack[] = '"' . str_replace( " ", "_", strtolower( $pr->getLabel() ) ) . '" : { "valueType": "' . $this->types[$pr->getTypeID()] . '" }'; |
| 51 | + } else { |
| 52 | + $propertystack[] = '"' . str_replace( " ", "_", strtolower( $pr->getLabel() ) ) . '" : { "valueType": "text" }'; |
| 53 | + } |
53 | 54 | } |
54 | | - // if we're at the first item and it doesn't have a label its the page |
55 | | - if ( $count == 0 && $pr->getLabel() == "" ) { |
56 | | - $firstPropertyIsPageDef = true; |
57 | | - } |
58 | | - $count++; |
59 | 55 | } |
60 | | - // drop bogus empty first item that got stuffed in here (I don't know why its here) |
61 | | - if ( $firstPropertyIsPageDef ) { |
62 | | - array_shift( $propertystack ); // drop first property |
63 | | - } |
64 | | - |
65 | 56 | $properties = "\"properties\": {\n\t\t" . implode( ",\n\t\t", $propertystack ) . "\n\t}"; |
66 | 57 | |
67 | 58 | // generate items section |
68 | | - $row = $res->getNext(); |
69 | | - while ( $row !== false ) { |
| 59 | + while ( ( $row = $res->getNext() ) !== false ) { |
| 60 | + $rowsubject = false; // the wiki page value that this row is about |
70 | 61 | $valuestack = array(); // contains Property-Value pairs to characterize an Item |
71 | | - $count = 0; // counter |
72 | | - $prefixedtext = ''; // save label for uri specification |
73 | 62 | foreach ( $row as $field ) { |
74 | | - $req = $field->getPrintRequest(); |
75 | | - // when we're processing the first item and its a page we process it a little differently |
76 | | - // this is the original code |
77 | | - if ( $count == 0 && $firstPropertyIsPageDef ) { |
78 | | - $values = ''; |
79 | | - foreach ( $field->getContent() as $value ) { |
80 | | - $values = $value->getShortText( $outputmode, null ); // assign last value to label |
81 | | - $prefixedtext = $value->getPrefixedText(); |
82 | | - } |
83 | | - $valuestack[] = '"label": "' . $values . '"'; |
84 | | - $label = $values; |
85 | | - } else { |
| 63 | + $pr = $field->getPrintRequest(); |
| 64 | + if ( $rowsubject === false ) { |
| 65 | + $rowsubject = $field->getResultSubject(); |
| 66 | + $valuestack[] = '"label": "' . $rowsubject->getShortText( $outputmode, null ) . '"'; |
| 67 | + } |
| 68 | + if ( $pr->getMode() != SMWPrintRequest::PRINT_THIS ) { |
86 | 69 | $values = array(); |
87 | 70 | $finalvalues = ''; |
88 | 71 | while ( ( $value = $field->getNextObject() ) !== false ) { |
— | — | @@ -106,30 +89,19 @@ |
107 | 90 | $finalvalues = $values[0]; |
108 | 91 | } |
109 | 92 | } |
110 | | - if ( $finalvalues != '' ) $valuestack[] = '"' . str_replace( " ", "_", strtolower( $req->getLabel() ) ) . '": ' . $finalvalues . ''; |
| 93 | + if ( $finalvalues != '' ) $valuestack[] = '"' . str_replace( " ", "_", strtolower( $pr->getLabel() ) ) . '": ' . $finalvalues . ''; |
111 | 94 | } |
112 | | - $count++; |
113 | 95 | } |
114 | | - // if we had a page definition, stuff in the uri |
115 | | - if ( $firstPropertyIsPageDef ) { |
116 | | - $valuestack[] = '"uri" : "' . $wgServer . $wgScriptPath . '/index.php?title=' . $prefixedtext . '"'; |
| 96 | + if ( $rowsubject !== false ) { // stuff in the page URI and some category data |
| 97 | + $valuestack[] = '"uri" : "' . $wgServer . $wgScriptPath . '/index.php?title=' . $rowsubject->getPrefixedText() . '"'; |
| 98 | + $page_cats = smwfGetStore()->getPropertyValues( $rowsubject, SMWPropertyValue::makeProperty( '_INST' ) ); // TODO: set limit to 1 here |
| 99 | + if ( count( $page_cats ) > 0 ) { |
| 100 | + $valuestack[] = '"type" : "' . reset($page_cats)->getShortHTMLText() . '"'; |
| 101 | + } |
117 | 102 | } |
118 | 103 | |
119 | | - // try to determine type/category |
120 | | - $catlist = array(); |
121 | | - $dbr = wfGetDB( DB_SLAVE ); |
122 | | - $cl = $dbr->tableName( 'categorylinks' ); |
123 | | - $arttitle = Title::newFromText( $label ); |
124 | | - if ( $arttitle instanceof Title ) { |
125 | | - $catid = $arttitle->getArticleID(); |
126 | | - $catres = $dbr->select( $cl, 'cl_to', "cl_from = $catid", __METHOD__, array( 'ORDER BY' => 'cl_sortkey' ) ); |
127 | | - while ( $catrow = $dbr->fetchRow( $catres ) ) $catlist[] = $catrow[0]; |
128 | | - $dbr->freeResult( $catres ); |
129 | | - if ( sizeof( $catlist ) > 0 ) $valuestack[] = '"type" : "' . $catlist[0] . '"'; |
130 | | - } |
131 | 104 | // create property list of item |
132 | 105 | $itemstack[] = "\t{\n\t\t\t" . implode( ",\n\t\t\t", $valuestack ) . "\n\t\t}"; |
133 | | - $row = $res->getNext(); |
134 | 106 | } |
135 | 107 | |
136 | 108 | $items = "\"items\": [\n\t" . implode( ",\n\t", $itemstack ) . "\n\t]"; |