/** * Static function to find the tm_id for a string tag. If the tag doesn't * exist, it will be created. * * A doctrine exception will be thrown if the tag string is invalid * * @param string $tagstr * @return int */ public static function get_tm_id($tagstr) { if (!$tagstr || !is_string($tagstr) || !strlen($tagstr)) { throw new Exception('Invalid non-string tag'); } // check cache $lower = strtolower($tagstr); if (isset(self::$TM_ID_CACHE[$lower])) { return self::$TM_ID_CACHE[$lower]; } // lookup or create $tm = Doctrine::getTable('TagMaster')->findOneBy('tm_name', $tagstr); if (!$tm) { $tm = new TagMaster(); $tm->tm_name = $tagstr; $tm->tm_type = TagMaster::$TYPE_JOURNALISTIC; $tm->save(); // could throw exception } // cache and return self::$TM_ID_CACHE[$lower] = $tm->tm_id; return $tm->tm_id; }