com.lokorin.lokorin.lib
[ class tree: com.lokorin.lokorin.lib ] [ index: com.lokorin.lokorin.lib ] [ all elements ]

Source for file lib_languages.php

Documentation is available at lib_languages.php

  1. <?php
  2. /*
  3. * Lokorin.com
  4. * Copyright 2004-2006
  5. * Licensed under the GNU LGPL. See COPYING for full terms.
  6. */
  7. /**
  8. * A library that contains everything related to the programming language
  9. * information system in the site.
  10. * @author Andreas Launila
  11. * @version $Revision: 1.10 $
  12. * @package com.lokorin.lokorin.lib
  13. * @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
  14. */
  15.  
  16. /**
  17. * For access to common constants and functions.
  18. */
  19. require_once('common.php');
  20.  
  21. /**
  22. * Gets all available programming languages.
  23. * @return array An array of ProgrammingLanguage instances, each instance
  24. * represents one of the retrieved programming languages.
  25. * @access public
  26. */
  27. function getAllLanguages() {
  28. global $db;
  29. $rows = $db->querySelect(TABLE_PROGRAM_LANGS, array('id'));
  30. $langs = array();
  31. foreach($rows as $row) {
  32. $langs[] = new ProgrammingLanguage($row['id']);
  33. }
  34. return $langs;
  35. }
  36.  
  37. /**
  38. * Gets the names of all available languages.
  39. * @return array An array with the names of all languages with the
  40. * corresponding unique identifier as key.
  41. * @access public
  42. */
  43. function getAllLanguageNames() {
  44. global $db;
  45. $rows = $db->querySelect(TABLE_PROGRAM_LANGS, array('id', 'name'));
  46. $names = array();
  47. foreach($rows as $row) {
  48. $names[$row['id']] = $row['name'];
  49. }
  50. return $names;
  51. }
  52.  
  53. /**
  54. * Describes a programming language information block. Each instance has some
  55. * basic information about the respecting programming language.
  56. * @author Andreas Launila
  57. * @package com.lokorin.lokorin.lib
  58. */
  59. class ProgrammingLanguage extends TableEntry {
  60. /**
  61. * The name of the programming language.
  62. * @var string
  63. */
  64. private $name;
  65. /**
  66. * A brief description about the programming language.
  67. * @var string
  68. */
  69. private $description;
  70. /**
  71. * Constructor for ProgrammingLanguage.
  72. * @param integer $id The unique identifier for the programming language.
  73. */
  74. public function __construct($id) {
  75. $fields = array(
  76. 'name',
  77. 'description'
  78. );
  79. parent::__construct(TABLE_PROGRAM_LANGS, $id, $fields);
  80. }
  81.  
  82. /**
  83. * @see com.lokorin.lokorin.TableEntry.readRow($row)
  84. */
  85. protected function readRow($row) {
  86. $this->name = $row['name'];
  87. $this->description = $row['description'];
  88. }
  89. /**
  90. * Gets the name of the programming language.
  91. * @return string A language name.
  92. * @access public
  93. */
  94. function getName() {
  95. return $this->name;
  96. }
  97. /**
  98. * Gets the description of the programming language.
  99. * @return string A description.
  100. * @access public
  101. */
  102. function getDescription() {
  103. return $this->description;
  104. }
  105. /**
  106. * Gets a link to the language. More information about the language is
  107. * displayed when the link is clicked.
  108. * @return string XHTML compliant code representing a link.
  109. * @access public
  110. */
  111. function getLink() {
  112. return '<a href="'.PAGE_ROOT.'languages/'.strtolower($this->name).'">'.
  113. $this->name.'</a>';
  114. }
  115. }
  116. ?>

Documentation generated on Sun, 16 Apr 2006 21:03:35 +0200 by phpDocumentor 1.3.0RC4