make the admin tag menu behave correctly now and show only arrows on nodes that have children

This commit is contained in:
Christian Weiske 2010-10-01 21:34:11 +02:00
parent cb1d41054b
commit bd92516e6f

View file

@ -1,31 +1,27 @@
<?php <?php
/*************************************************************************** /**
Copyright (C) 2004 - 2006 Scuttle project * Returns a list of tags managed by the admins, in json format
http://sourceforge.net/projects/scuttle/ * suitable for jsTree consumption.
http://scuttle.org/ *
* @param string $tag Tag for which the children tags shall be returned
*
* SemanticScuttle - your social bookmark manager.
*
* PHP version 5.
*
* @category Bookmarking
* @package SemanticScuttle
* @subcategory Templates
* @author Benjamin Huynh-Kim-Bang <mensonge@users.sourceforge.net>
* @author Christian Weiske <cweiske@cweiske.de>
* @author Eric Dane <ericdane@users.sourceforge.net>
* @license GPL http://www.gnu.org/licenses/gpl.html
* @link http://sourceforge.net/projects/semanticscuttle
*/
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
***************************************************************************/
/* Return a json file with list of linked tags */
$httpContentType = 'application/json'; $httpContentType = 'application/json';
$httpContentType='text/plain';
require_once '../www-header.php'; require_once '../www-header.php';
$tag = isset($_GET['tag']) ? trim($_GET['tag']) : '';
function assembleTagData($tag, SemanticScuttle_Service_Tag2Tag $t2t) function assembleTagData($tag, SemanticScuttle_Service_Tag2Tag $t2t)
{ {
if ($tag == '') { if ($tag == '') {
@ -36,27 +32,34 @@ function assembleTagData($tag, SemanticScuttle_Service_Tag2Tag $t2t)
$tagData = array(); $tagData = array();
foreach ($linkedTags as $tag) { foreach ($linkedTags as $tag) {
$tagData[] = createTagArray($tag); //FIXME: the hasChildren code is nasty, because it causes too many
// queries onto the database
$hasChildren = 0 < count($t2t->getAdminLinkedTags($tag, '>'));
$tagData[] = createTagArray($tag, $hasChildren);
} }
return $tagData; return $tagData;
} }
function createTagArray($tag) function createTagArray($tag, $hasChildren = true)
{ {
return array( $ar = array(
'data' => $tag, 'data' => $tag,
'attr' => array('rel' => $tag), 'attr' => array('rel' => $tag),
//'children' => array('foo', 'bar'),
'state' => 'closed'
); );
if ($hasChildren) {
//jstree needs that to show the arrows
$ar['state'] = 'closed';
}
return $ar;
} }
$tag = isset($_GET['tag']) ? trim($_GET['tag']) : '';
$tagData = assembleTagData( $tagData = assembleTagData(
$tag, $tag,
SemanticScuttle_Service_Factory::get('Tag2Tag') SemanticScuttle_Service_Factory::get('Tag2Tag')
); );
//$json = substr($json, 0, -1); // remove final comma avoiding IE6 Dojo bug
echo json_encode($tagData); echo json_encode($tagData);
?> ?>