aboutsummaryrefslogtreecommitdiff
path: root/lib/sfIsisImporterStats.class.php
blob: bea264d94851c53bf3191c13ca4ceca457fcb339 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
<?php

/**
 * Statistics gathering for importing procedures.
 */
class sfIsisImporterStats
{
  /**
   * @var $instance Singleton instance
   */
  private static $instance = null;

  /**
   * Get the singleton instance.
   */
  public static function getInstance()
  {
    if(self::$instance == null) {
      self::$instance = new self;
    }

    return self::$instance;
  }

  /**
   * Simple accumulator.
   *
   * @param string $section Section name
   */
  public function increase($data)
  {
    $stats = Doctrine_Core::getTable('ImportStat')->findByPayload($data);

    if ($stats)
    {
      $stats->count++;
    }
    else
    {
      $stats          = new ImportStat();
      $stats->payload = $data;
      $stats->count   = 1;
      $stats->type    = 'param';
      $stats->save();
      $stats->free(true);
    }
  }

  /**
   * 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();
    $stats->free(true);
  }

  /**
   * Compute soundex.
   *
   * @param string $name Name
   */
  public function soundex($name)
  {
    $this->similarity($name);
  }

  /**
   * Compute metaphone.
   *
   * @param string $name Name
   */
  public function metaphone($name)
  {
    $this->similarity($name, 'metaphone');
  }

  /**
   * Compute similar words indexes.
   *
   * @param string $name Name
   */
  public function similar($name)
  {
    $this->soundex($name);
    $this->metaphone($name);
  }
}