src/SudoBible.php
protected function getIdFor($strType, $strNameAbbr)
	{
		// Validate input
		if (!in_array($strType, ['book', 'translation', 'topic']))
			throw new Exception('Invalid entity type "' . $strType . '"');

		// Query the db to get the ID
		$strTableName = 'sudo_bible_' . $strType . 's';
		$q = 'SELECT `id` FROM `' . $strTableName . '` WHERE `name` LIKE ?';
		$aParams = [$strNameAbbr];
		if ('topic' !== $strType) {
			$q .= ' OR `abbr` LIKE ?';
			$aParams[] = $strNameAbbr;
		}
		$aResult = $this->runPreparedQuery($q, $aParams);
		$iId = $aResult[0]->id;

		// Validate result
		if (!is_numeric($iId))
			throw new Exception('Invalid ' . $strType . ' "' .  $strNameAbbr . '" given.');

		return $iId;
	}
protected function getIdFor($strType, $strNameAbbr)
	{
		// Validate input
		if (!in_array($strType, ['book', 'translation', 'topic']))
			throw new Exception('Invalid entity type "' . $strType . '"');

		// Query the db to get the ID
		$strTableName = 'sudo_bible_' . $strType . 's';
		$q = 'SELECT `id` FROM `' . $strTableName . '` WHERE `name` LIKE ?';
		$aParams = [$strNameAbbr];
		if ('topic' !== $strType) {
			$q .= ' OR `abbr` LIKE ?';
			$aParams[] = $strNameAbbr;
		}
		$aResult = $this->runPreparedQuery($q, $aParams);
		$iId = $aResult[0]->id;

		// Validate result
		if (!is_numeric($iId))
			throw new Exception('Invalid ' . $strType . ' "' .  $strNameAbbr . '" given.');

		return $iId;
	}
protected function getIdFor ( $ strType , $ strNameAbbr ) { // Validate input if ( ! in_array ( $ strType , [ 'book' , 'translation' , 'topic' ] ) ) throw new Exception ( 'Invalid entity type "' . $ strType . '"' ) ; // Query the db to get the ID $ strTableName = 'sudo_bible_' . $ strType . 's' ; $ q = 'SELECT `id` FROM `' . $ strTableName . '` WHERE `name` LIKE ?' ; $ aParams = [ $ strNameAbbr ] ; if ( 'topic' !== $ strType ) { $ q .= ' OR `abbr` LIKE ?' ; $ aParams [ ] = $ strNameAbbr ; } $ aResult = $ this -> runPreparedQuery ( $ q , $ aParams ) ; $ iId = $ aResult [ 0 ] -> id ; // Validate result if ( ! is_numeric ( $ iId ) ) throw new Exception ( 'Invalid ' . $ strType . ' "' . $ strNameAbbr . '" given.' ) ; return $ iId ; }
Get an ID, given the name.

For now, we're using this instead of a JOIN in the main query
so we can throw a useful error.

@param string $strType translation, book, or topic
@param string $strNameAbbr Name of the translation or book.
@throws Exception
@return int
Get an ID given the name .