PageRenderTime 23ms CodeModel.GetById 20ms app.highlight 1ms RepoModel.GetById 1ms app.codeStats 0ms

/apps/learn/domain/Learn.php

http://zoop.googlecode.com/
PHP | 32 lines | 30 code | 2 blank | 0 comment | 2 complexity | 7c450259df87972b7bd2e6cc6230b725 MD5 | raw file
 1<?php
 2class Learn
 3{
 4	static public function regenerateAllWordLetters()
 5	{
 6		SqlDeleteRows('delete from word_letter', array());
 7		$words = SqlFetchRows("select * from word", array());
 8		SqlEchoOn();
 9		foreach($words as $thisWord)
10		{
11			Learn::generateWordLetters($thisWord);
12		}
13	}
14	
15	static public function generateWordLetters($thisWord)
16	{
17		$letters = array();
18		for($i = 0; $i < $thisWord['len']; $i++)
19		{
20			if(isset($letters[$thisWord['word'][$i]]))
21				$letters[$thisWord['word'][$i]]++;
22			else
23				$letters[$thisWord['word'][$i]] = 1;
24		}
25		
26		foreach($letters as $letter => $count)
27		{
28			$sql = "insert into word_letter (word_id, letter, count) values (:wordId, :letter, :count)";
29			SqlInsertRow($sql, array('wordId' => $thisWord['id'], 'letter' => $letter, 'count' => $count));
30		}
31	}
32}