<?php
	class KeywordsModel {
		public function addGetKeyword( $keyword ) {
			$query = sprintf( "select sp_i_get_add_keyword('%s') as keyword_id" , FNTH_db_addslashes( $keyword ) );
			return FNTH_db_get_field( $query , "keyword_id" );
		}

		public function deleteKeyword( $keyword_id ) {
			$query = sprintf( "delete from users_keywords where keyword_id=%d" , $keyword_id );
			FNTH_db_free_result( FNTH_db_query( $query ) );
			$query = sprintf( "delete from keywords where keyword_id=%d" , $keyword_id );
			FNTH_db_free_result( FNTH_db_query( $query ) );
		}

		public function purgeUnusedKeywords() {
			$query = "delete from keywords where keyword_id not in (select distinct keyword_id from users_keywords)";
			FNTH_db_free_result( FNTH_db_query( $query ) );
		}
	}
?>
