Commit 7cb61ec9 authored by vermeul's avatar vermeul

added get_categories function to allow retrieving amiguous category names....

added get_categories function to allow retrieving amiguous category names. Eliminated many PHP warning messages
parent e7750252
......@@ -6,7 +6,7 @@
* @version 0.1
* @license GNU General Public Licence 2.0
*/
use MathRenderer;
use Math\Renderer;
class YATA {
public static $annotations = "";
......@@ -49,7 +49,6 @@ class YATA {
//
public static function annotation_query( $parser, $querystring) {
$title = $parser->getTitle();
$wikiPage = new WikiPage( $title );
$queries_found = preg_match_all(
......@@ -93,9 +92,9 @@ class YATA {
# get the category entry from DB
$cat = self::get_category($dbr, $category);
$in_categories[] = $cat->name;
if ($cat) {
$cats = self::get_categories($dbr, $category);
foreach($cats as $cat) {
$in_categories[] = $cat->name;
$cat_ids[] = $cat->id;
if ($depth) {
$child_categories = self::get_child_categories($dbr, $cat, 0, $depth-1);
......@@ -112,9 +111,29 @@ class YATA {
}
}
}
else {
array_push($errors, "no such category found: $category");
}
#$cat = self::get_category($dbr, $category);
#$in_categories[] = $cat->name;
#if ($cat) {
# $cat_ids[] = $cat->id;
# if ($depth) {
# $child_categories = self::get_child_categories($dbr, $cat, 0, $depth-1);
# foreach($child_categories as $child_category) {
# $cat_ids[] = $child_category->id;
# $in_categories[] = $child_category->name;
# }
# }
# elseif ($depth === "") {
# $child_categories = self::get_child_categories($dbr, $cat, 0, null);
# foreach($child_categories as $child_category) {
# $cat_ids[] = $child_category->id;
# $in_categories[] = $child_category->name;
# }
# }
#}
#else {
# array_push($errors, "no such category found: $category");
#}
}
$where[] =
......@@ -333,7 +352,11 @@ class YATA {
foreach($table_rows as $table_row) {
$rows_rendered .= "<tr>";
foreach($all_columns as $column) {
$rows_rendered .= "<td>" . $table_row[$column] . "</td>";
$rows_rendered .= "<td>";
if (isset($table_row[$column])) {
$rows_rendered .= $table_row[$column];
}
$rows_rendered .= "</td>";
}
$rows_rendered .= "</tr>";
}
......@@ -1049,6 +1072,36 @@ EOT;
return $categories;
}
public static function get_categories($dbr, $category) {
# return one ore many categories of a given name
$category = trim($category);
if (substr($category, 0,1) == '#') {
$cat = self::get_category($dbr, $category);
return array($cat);
}
if( strpos($category, '/')) {
$cat = self::get_category($dbr, $category);
return array($cat);
}
$selection = array(
'id' => 'c.id',
'name' => 'c.name',
'hashtag' => 'c.hashtag',
'description' => 'c.description',
'parent_name' => "''",
'parent_id' => 'c.parent_id'
);
$rows = $dbr->select(
array('c' =>'yata_category'),
$selection,
array(
'name' => $category,
)
);
return $rows;
}
public static function get_category($dbr, $category) {
$category = trim($category);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment