From 1a75499bf5a0d42f6f866ae59f4a8ae17a15f175 Mon Sep 17 00:00:00 2001 From: Silvio Date: Thu, 16 Sep 2010 16:29:10 -0300 Subject: sfIsisImporterStats now relying in a doctine model --- lib/sfIsisImporterStats.class.php | 52 ++++++++++++++++++++++----------------- 1 file changed, 29 insertions(+), 23 deletions(-) (limited to 'lib') diff --git a/lib/sfIsisImporterStats.class.php b/lib/sfIsisImporterStats.class.php index db5c316..21f2757 100644 --- a/lib/sfIsisImporterStats.class.php +++ b/lib/sfIsisImporterStats.class.php @@ -22,27 +22,42 @@ class sfIsisImporterStats return self::$instance; } - /** - * Constructor. - */ - private function __construct() - { - $this->stats = array(); - } - /** * Simple accumulator. * * @param string $section Section name */ - public function increase($section) + public function increase($data) { - if (!isset($this->stats[$section])) + $stats = Doctrine_Core::getTable('ImportStat')->findByPayload($data); + + if ($stats) { - $this->stats[$section] = 0; + $stats->count++; } + else + { + $stats = new ImportStat(); + $stats->payload = $data; + $stats->count = 1; + $stats->type = 'param'; + $stats->save(); + } + } - $this->stats[$section]++; + /** + * Compute similars. + * + * @param string $name Name + * @param string $function Function that determines similarity index + */ + public function similarity($name, $function = 'soundex') + { + $stats = new ImportStat(); + $stats->param = call_user_func($function, $name); + $stats->payload = $name; + $stats->type = $function; + $stats->save(); } /** @@ -52,7 +67,7 @@ class sfIsisImporterStats */ public function soundex($name) { - $this->stats['sounded'][soundex($name)] = $name; + $this->similarity($name); } /** @@ -62,7 +77,7 @@ class sfIsisImporterStats */ public function metaphone($name) { - $this->stats['sounded'][metaphone($name)] = $name; + $this->similarity($name, 'metaphone'); } /** @@ -75,13 +90,4 @@ class sfIsisImporterStats $this->soundex($name); $this->metaphone($name); } - - /** - * Display statistics. - * - * @todo Write and test - */ - public function display() - { - } } -- cgit v1.2.3