Skip to content

Commit

Permalink
Create a new method to get a committee's ID
Browse files Browse the repository at this point in the history
This is in support of openva/rs-video-processor#59.
  • Loading branch information
waldoj committed Jan 30, 2018
1 parent 62486aa commit cd255da
Showing 1 changed file with 55 additions and 0 deletions.
55 changes: 55 additions & 0 deletions htdocs/includes/class.Committee.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,59 @@ function members()

}

/**
* Return the ID of a committee, when provided with a chamber and a name.
*/
function get_id()
{

if ( !isset($this->chamber) || !isset($this->name) )
{
return FALSE;
}

/*
* First, get a list of all committees' names and IDs.
*/
$sql = 'SELECT id, name
FROM committees
WHERE parent_id IS NULL
AND chamber = "' . $this->chamber . '"';
$result = mysql_query($sql);
if (mysql_num_rows($result) == 0)
{
return FALSE;
}

$committees = array();
while ($committee = mysql_fetch_array($result))
{
$committees[$committee{'id'}] = $committee['name'];
}

$shortest = -1;
foreach ($committees as $id => $name)
{

$distance = levenshtein($this->name, $name);
if ($distance === 0)
{
$closest = $id;
$shortest = 0;
break;
}

elseif ($distance <= $shortest || $shortest < 0)
{
$closest = $id;
$shortest = $distance;
}

}

$this->id = $closest;
return $this->id;

} // end get_id()

}

0 comments on commit cd255da

Please sign in to comment.