Skip to content

Commit

Permalink
Openethnographer Sidebar
Browse files Browse the repository at this point in the history
  • Loading branch information
danohu committed Mar 2, 2015
1 parent 796fb02 commit 99a3270
Show file tree
Hide file tree
Showing 9 changed files with 256 additions and 112 deletions.
16 changes: 15 additions & 1 deletion drupal_annotation/annotation.module
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,21 @@ function annotation_menu() {
'file' => 'annotation.store.inc',
);

$items['annotation/api/tags'] = array(
'page callback' => 'annotation_api_tags',
'access arguments' => array('access content'),
'type' => MENU_CALLBACK,
'file' => 'annotation.store.inc',
);

$items['annotation/api/quotation_list'] = array(
'page callback' => 'annotation_api_quotation_list',
'access arguments' => array('access content'),
'type' => MENU_CALLBACK,
'file' => 'annotation.store.inc',
);


return $items;
}

Expand Down Expand Up @@ -1026,7 +1041,6 @@ function annotation_export_rqda($uid, $filename) {
* @return String containing HTML that renders the annotated text in its context.
*/
function annotation_extract($annotation, $len_before, $len_after){

// Get the HTML source text of the annotated field.
$entity = entity_load_single($annotation->entity_type, $annotation->entity_id);
$field_items = field_get_items($annotation->entity_type, $entity, $annotation->field_name, $annotation->field_language);
Expand Down
43 changes: 35 additions & 8 deletions drupal_annotation/annotation.store.inc
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,43 @@ function annotation_api_endpoint($id = NULL) {
}

/**
* Annotation API root
* API for tags, to populate the sidebar
*/
function annotation_api() {
drupal_json_output(
array(
'name' => 'Annotator Store API',
'version' => ANNOTATOR_VERSION,
)
);
function visible_tags($nid){
$vocabulary = taxonomy_vocabulary_machine_name_load('openethnographer');
$tree = taxonomy_get_tree($vocabulary->vid);
// XXX this needs to handle public/private tags
if(!user_access('view any annotations') ) {
$tree = array_filter($tree, function($k){
return $k->uid != $USER->uid;});
}
//$parents = array_filter($tree, function($k){
return $tree;
}


function annotation_api_quotation_list(){
$tid = $_GET['tid'];
$term = taxonomy_term_load($tid);
print("<h2>Content tagged $term->name</h2><br/>");# " + $term->name + "</h2>");
print(annotation_quotation_list($term));
}



function annotation_api_tags(){
//XXX filter tags to those present on a page
// -- complication is that we also need all their ancestors
if(!empty($_GET['nid'])){
$nid = $_GET['nid'];
}

$vocabulary = taxonomy_vocabulary_machine_name_load('openethnographer');
$tree = taxonomy_get_tree($vocabulary->vid);
watchdog('oeth', 'I am a teapot');
return drupal_json_output(visible_tags());
}


/**
* Annotation API index
Expand Down
23 changes: 12 additions & 11 deletions drupal_annotator/annotator.module
Original file line number Diff line number Diff line change
Expand Up @@ -243,38 +243,39 @@ class OpenethnographerTaxonomy extends TaxonomyDisplayTermDisplayHandler {
public function displayTerm($term, $options = NULL) {
$build = array();
$build['term'] = array(
'#markup' => $this->quotation_list($term),
'#markup' => annotation_quotation_list($term),
'#weight' => 0,
);
return $build;
}

function annotations_by_node($nid, $termdivs, $term){

public function formFieldset(&$form, &$values, $options = NULL) {}
public function formSubmit($form, &$values) {}
}


function annotation_annotations_by_node($nid, $termdivs, $term){
$nd = node_load($nid);
$short_title = 'fubar';
$divs = implode('', $termdivs);
$header = '<div class="annotator-term-nodetitle">Annotations on <a href="' . url('node/'. $nid) . '">' . $nd->title .'</a>: </div>';
$inner = '<div class="annotator-extractgroup">' . $divs . '</div>';
$wrapped = '<div class="annotator-term-group">' . $header . $inner . '</div>';
return $wrapped;
}

function quotation_list($term){
function annotation_quotation_list($term){
$annots_by_nid = array();
$ans = db_query("SELECT * from {annotation} where tid = :tid", array(':tid' => $term->tid));
if($ans){
while($row = $ans->fetchAssoc()){
$ent = current(entity_load('annotation', array($row['id'])));
$annots_by_nid[$ent->nid][] = annotation_extract($ent, 35, 25);
$annot = current(entity_load('annotation', array($row['id'])));
$annots_by_nid[$annot->entity_id][] = annotation_extract($annot, 35, 25);
}
}
$nodedivs = array();
foreach($annots_by_nid as $k=>$v){
$nodedivs[] = $this->annotations_by_node($k, $v, $term);
$nodedivs[] = annotation_annotations_by_node($k, $v, $term);
}
return implode(", ", $nodedivs);
}

public function formFieldset(&$form, &$values, $options = NULL) {}
public function formSubmit($form, &$values) {}
}
Loading

0 comments on commit 99a3270

Please sign in to comment.