Skip to content

Commit

Permalink
Merge pull request #3 from Daniel-KM/method_list
Browse files Browse the repository at this point in the history
Added a method to list the codes and values of terms of a taxonomy.
  • Loading branch information
jajm authored Dec 1, 2016
2 parents f925548 + ce5a538 commit 11a9c4c
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
25 changes: 25 additions & 0 deletions models/Table/TaxonomyTerm.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,29 @@ public function findByCode($taxonomy_id, $code)
->where('code = ?', $code);
return $this->fetchObject($select);
}

/**
* List the codes and values of a taxonomy.
*
* @uses Omeka_Db_Table::findPairsForSelectForm()
* @param Taxonomy|integer $taxonomy
* @return array Associative array where codes are keys.
*/
public function listByTaxonomy($taxonomy)
{
$taxonomyId = is_object($taxonomy) ? $taxonomy->id : (integer) $taxonomy;
return $this->findPairsForSelectForm(array('taxonomy_id' => $taxonomyId));
}

/**
* Retrieve the array of columns that are used by findPairsForSelectForm().
*
* @see Omeka_Db_Table::findPairsForSelectForm()
* @return array
*/
protected function _getColumnPairs()
{
$alias = $this->getTableAlias();
return array($alias . '.code', $alias . '.value');
}
}
9 changes: 7 additions & 2 deletions views/admin/taxonomy-term/list.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
<?php echo head(array('title' => __('%s taxonomy terms', $taxonomy->name))); ?>
<?php echo flash(); ?>
<?php
$total = count($terms);
$title = __('%s taxonomy terms (%s)', $taxonomy->name, $total ?: __('none'));
echo head(array(
'title' => $title,
));
echo flash(); ?>

<a href="<?php echo url('taxonomy'); ?>/taxonomy-term/add/taxonomy_id/<?php echo $taxonomy->id; ?>"><?php echo __('Add a new term'); ?></a>

Expand Down

0 comments on commit 11a9c4c

Please sign in to comment.