Created
December 21, 2010 13:31
-
-
Save PowerKiKi/749931 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function getDb() | |
{ | |
require($_SERVER['DOCUMENT_ROOT'] . '/typo3conf/localconf.php'); | |
$db = new DBMysql($typo_db_host, $typo_db_username, $typo_db_password); | |
$db->connect($typo_db); | |
return $db; | |
} | |
/** | |
* Returns content (including all their tags) which are tagged by defined $tags. | |
* eg: get content of type 'project' or type 'manifestations' which are of themes 'déchets' or 'energie' | |
* $tags = array( | |
* array(20, 23), // types | |
* array(5, 6), // themes | |
* ); | |
* @param array $tags groups of tags to be matched. Within a group tags are 'OR'. Groups amongst them are 'AND'. | |
*/ | |
function getData(array $tags) | |
{ | |
$db = getDb(); | |
// Gather UID of content which are tagged by $tags | |
$contentsUID = null; | |
foreach ($tags as $orTags) | |
{ | |
foreach ($orTags as $i => $t) | |
{ | |
$orTags[$i] = (int)$t; | |
} | |
// Look for 'OR' tags | |
$query = "SELECT `uid_foreign` FROM `tx_tagpack_tags_relations_mm` WHERE `tablenames` = 'tt_news' AND `uid_local` IN (" . join(', ', $orTags) . ");"; | |
$result = $db->query($query); | |
$uid = $db->getRowArrays($result); | |
// Apply the 'AND' with other tag groups | |
if ($contentsUID == null) | |
{ | |
$contentsUID = $uid; | |
} | |
else | |
{ | |
$contentsUID = array_intersect($contentsUID, $uid); | |
} | |
} | |
if (!count($contentsUID)) | |
return array(); | |
// Get content | |
$query = "SELECT * FROM `tt_news` WHERE `uid` IN (" . join(', ', $contentsUID) . ");"; | |
$result = $db->query($query); | |
$contents = $db->getAssocArrays($result); | |
// Get all tags for content | |
$query = "SELECT `uid_foreign`, `tx_tagpack_tags`.* FROM `tx_tagpack_tags` LEFT JOIN `tx_tagpack_tags_relations_mm` ON `uid_local` = `uid` AND `tablenames` = 'tt_news' WHERE `uid_foreign` IN (" . join(', ', $contentsUID) . ");"; | |
$result = $db->query($query); | |
$tags = $db->getAssocArrays($result); | |
// Dispatch tags among content with same structure as tesseract so we are compatible will previously written code | |
foreach ($contents as $ic => $content) | |
{ | |
foreach ($tags as $it => $tag) | |
{ | |
if ($tag['uid_foreign'] == $content['uid']) | |
{ | |
$contents[$ic]['__substructure']['tags']['records'][] = $tag; | |
unset($tags[$it]); | |
} | |
} | |
} | |
return $contents; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment