PageRenderTime 49ms CodeModel.GetById 22ms RepoModel.GetById 1ms app.codeStats 0ms

/katherine_rc/CounterBalance.php

https://bitbucket.org/maxpanzer/cred_katherine
PHP | 79 lines | 50 code | 14 blank | 15 comment | 3 complexity | ddd866045a81b27f99c18e3c29e4867a MD5 | raw file
  1. <?php
  2. class CounterBalance{
  3. private static $instance;
  4. /*
  5. * counter balance value (choosen randomly)
  6. */
  7. private $counterBalance;
  8. /*
  9. * counter balance groups.
  10. */
  11. private $allCounterBalanceGroups = array("A1"=>array("A-B", "E-A", "B-D", "B-E", "A-D", "D-E"),
  12. "A2"=>array("B-A", "A-E", "D-B", "E-B", "D-A", "E-D"),
  13. "A3"=>array("D-E", "A-D", "B-E", "B-D", "E-A", "A-B"),
  14. "A4"=>array("E-D", "D-A", "E-B", "D-B", "A-E", "B-A"),
  15. "B1"=>array("",""),
  16. "B2"=>array("",""),
  17. "B3"=>array("",""),
  18. "B4"=>array("",""),
  19. "C1"=>array("A-B", "E-A", "B-D", "B-E", "A-D", "D-E"),
  20. "C2"=>array("B-A", "A-E", "D-B", "E-B", "D-A", "E-D"),
  21. "C3"=>array("D-E", "A-D", "B-E", "B-D", "E-A", "A-B"),
  22. "C4"=>array("E-D", "D-A", "E-B", "D-B", "A-E", "B-A")
  23. );
  24. /*
  25. * specify the groups for which the thoughts should be listed.
  26. * starts at 0.
  27. * "A"=>(0,5) means that the goups at 0th and 5th locations at
  28. * $allCounterBalanceGroups[A*] will have thoughts listed.
  29. * for e.g. "A"=>(0,5) means $allCounterBalanceGroups[A1][0] and
  30. * $allCounterBalanceGroups[A1][5] will have thoughts listed.
  31. */
  32. private $counterBalanceGroupsWithThoughts = array("A"=>array(4,5),
  33. "B"=>array(1,4),
  34. "C"=>array(1,2),
  35. );
  36. private function __construct(){
  37. $this->counterBalance = mt_rand(1, 4);
  38. }
  39. // Getter method for creating/returning the single instance of this class
  40. public final static function getInstance() {
  41. if(!self::$instance) {
  42. self::$instance = new CounterBalance();
  43. }
  44. return self::$instance;
  45. }
  46. public function getCounterBalanceValue() {
  47. return $this->counterBalance;
  48. }
  49. public function generateRandomCounterBalanceGroup($version) {
  50. $temp = $version.$this->counterBalance;
  51. return $this->allCounterBalanceGroups[$temp];
  52. }
  53. public function getCounterBalanceGroupsWithThoughts($version){
  54. return $this->counterBalanceGroupsWithThoughts[$version];
  55. }
  56. public static function isThoughtsNeededForRound($groupsWithThoughts, $roundNumber){
  57. foreach($groupsWithThoughts as $value) {
  58. if($value == $roundNumber) {
  59. return 1;
  60. }
  61. }
  62. return 0;
  63. }
  64. }
  65. ?>