Index: trunk/extensions/SemanticMediaWiki/includes/storage/SMW_SQLStore.php |
— | — | @@ -1518,10 +1518,10 @@ |
1519 | 1519 | * be computed). |
1520 | 1520 | * |
1521 | 1521 | * Some notes on sorting: sorting is applied only to fields that appear in the query |
1522 | | - * by verifying conditions and the sorting conditions thus operate on the values that |
1523 | | - * satisfy the given conditions. This may have side effects in cases where one porperty |
| 1522 | + * by verifying conditions, and the sorting conditions thus operate on the values that |
| 1523 | + * satisfy the given conditions. This may have side effects in cases where one property |
1524 | 1524 | * that shall be sorted has multiple values. If no condition other than existence applies |
1525 | | - * to such a property, the value that is relevant for sorting is not really dertermined and |
| 1525 | + * to such a property, the value that is relevant for sorting is not really determined and |
1526 | 1526 | * the behaviour of SQL is not clear (I think). If the condition preselects larger or smaller |
1527 | 1527 | * values, however, then these would probably be used for sorting. Overall this should not |
1528 | 1528 | * be a problem, since it only occurs in cases where the sort order is not fully specified anyway. |
— | — | @@ -1534,11 +1534,10 @@ |
1535 | 1535 | * @param $db The database object |
1536 | 1536 | * @param $curtables Array with names of aliases of tables refering to the 'current' element (the one to which the description basically applies). |
1537 | 1537 | * @param $nary_pos If the subcondition is directly appended to an nary relation, this parameter holds the numerical index of the position in the nary in order to be able to join condition tables to that position. |
1538 | | - * @param $sort True if the subcondition should be used for sorting. This is only meaningful for queries that are below some property statement. |
1539 | 1538 | * |
1540 | 1539 | * @TODO: Maybe there need to be optimisations in certain cases (atomic implementation for common nestings of descriptions?) |
1541 | 1540 | */ |
1542 | | - protected function createSQLQuery(SMWDescription $description, &$from, &$where, &$db, &$curtables, $nary_pos = '', $sort = false) { |
| 1541 | + protected function createSQLQuery(SMWDescription $description, &$from, &$where, &$db, &$curtables, $nary_pos = '') { |
1543 | 1542 | $subwhere = ''; |
1544 | 1543 | if ($description instanceof SMWThingDescription) { |
1545 | 1544 | // nothing to check |
— | — | @@ -1661,11 +1660,15 @@ |
1662 | 1661 | } |
1663 | 1662 | } elseif ($description instanceof SMWSomeProperty) { |
1664 | 1663 | $id = SMWDataValueFactory::getPropertyObjectTypeID($description->getProperty()); |
| 1664 | + $sort = false; |
1665 | 1665 | switch ($id) { |
1666 | 1666 | case '_wpg': |
1667 | 1667 | $tablename = 'RELS'; |
1668 | 1668 | $pcolumn = 'relation_title'; |
1669 | 1669 | $sub = true; |
| 1670 | + if ($this->m_sortkey == $description->getProperty()->getDBKey()) { |
| 1671 | + $sort = 'object_title'; |
| 1672 | + } |
1670 | 1673 | break; |
1671 | 1674 | case '_txt': |
1672 | 1675 | $tablename = 'TEXT'; |
— | — | @@ -1681,6 +1684,13 @@ |
1682 | 1685 | $tablename = 'ATTS'; |
1683 | 1686 | $pcolumn = 'attribute_title'; |
1684 | 1687 | $sub = true; |
| 1688 | + if ($this->m_sortkey == $description->getProperty()->getDBKey()) { |
| 1689 | + if (SMWDataValueFactory::newTypeIDValue($id)->isNumeric()) { |
| 1690 | + $sort = 'value_num'; |
| 1691 | + } else { |
| 1692 | + $sort = 'value_xsd'; |
| 1693 | + } |
| 1694 | + } |
1685 | 1695 | } |
1686 | 1696 | if ($table = $this->addJoin($tablename, $from, $db, $curtables, $nary_pos)) { |
1687 | 1697 | global $smwgQSubpropertyDepth; |
— | — | @@ -1695,7 +1705,10 @@ |
1696 | 1706 | if ($sub) { |
1697 | 1707 | $nexttables = array(); |
1698 | 1708 | $nexttables['p' . $tablename] = $table; // keep only current table for reference |
1699 | | - $this->createSQLQuery($description->getDescription(), $from, $subwhere, $db, $nexttables, $nary_pos, ($this->m_sortkey == $description->getProperty()->getDBKey()) ); |
| 1709 | + $this->createSQLQuery($description->getDescription(), $from, $subwhere, $db, $nexttables, $nary_pos); |
| 1710 | + if ($sort) { |
| 1711 | + $this->m_sortfield = "$table.$sort"; |
| 1712 | + } |
1700 | 1713 | if ( $subwhere != '') { |
1701 | 1714 | $where .= ' AND (' . $subwhere . ')'; |
1702 | 1715 | } |
— | — | @@ -1703,11 +1716,6 @@ |
1704 | 1717 | } |
1705 | 1718 | } |
1706 | 1719 | |
1707 | | - if ($sort && (!$description instanceof SMWValueDescription) ) { |
1708 | | - if (array_key_exists('pRELS', $curtables)) { |
1709 | | - $this->m_sortfield = $curtables['pRELS'] . '.object_title'; |
1710 | | - } |
1711 | | - } |
1712 | 1720 | } |
1713 | 1721 | |
1714 | 1722 | /** |