[ Index ]

PHP Cross Reference of Yamoon 0.9.0

title

Body

[close]

/Yamoon/ -> Language.php (source)

   1  <?php
   2  
   3  require_once  ('Config.php');
   4  
   5  /**
   6    * Language.php - manages language creation, update and delete.
   7    */
   8  
   9  class Language {
  10      var $name;
  11      var $cmd;
  12      var $config;
  13  
  14      /**
  15        * Language Constructor.
  16        * $language = new Language($config, $id);
  17        * 
  18        * param $config Configuration class
  19        * param $id When provided, grab all info for that language
  20        */
  21  	function Language ($config, $id="") {
  22          $this->config = $config;
  23          if ($id > 0) {
  24              $this->id = $id;
  25              $rows = $this->config->select("select id, name, cmd from languages where id = ?", $id);
  26              if (isset($rows[0]) && $rows[0]->id > 0) {
  27                  $this->name = $rows[0]->name;
  28                  $this->cmd = $rows[0]->cmd;
  29              } else {
  30                  error_log("Language not found");
  31                  return false;
  32              }
  33          }
  34          return true;
  35      }
  36  
  37      /**
  38        * Create a new language if there's no language with that name yet.
  39        * Construct object first.
  40        * $language->create("my lang", "/bin/mylang");
  41        *
  42        * param $name The language name
  43        * param $cmd Its binary, if not provided try to check it
  44        * return $id Newly created language's ID
  45        */
  46  	function create ($name, $cmd="") {
  47          if ($this->config->select("select id from languages where name = ?", $name))
  48              return false;
  49          else {
  50              $values = array($name, $cmd);
  51              $this->config->query("insert into languages values (NULL, ?, ?)", $values);
  52              $rows = $this->config->select("select last_insert_id() as id");
  53              $this->id = $rows[0]->id;
  54              $this->name = $name;
  55              $this->cmd = $cmd;
  56              return $this->id;
  57          }
  58      }
  59  
  60      /**
  61        * Update the current language on the database using the current parameters.
  62        * $language->name = "my language's new name";
  63        * $language->update()
  64        */
  65  	function update () {
  66          $values = array( $this->name, $this->cmd, $this->id );
  67          return $this->config->query("update languages set name = ?, cmd = ? where id = ?", $values);
  68      }
  69  
  70      /**
  71        * Delete the current language IF and only IF there's no service using it.
  72        * $language->delete();
  73        */
  74  	function delete () {
  75          $values = array( $this->id );
  76          if ($this->config->select("select id from services where language = ?", $values))
  77              return null;
  78          return $this->config->query("delete from languages where id = ?", $values);
  79      }
  80  
  81      /**
  82        * Dumper.
  83        * $language->dump();
  84        */
  85  	function dump () {
  86          print "\t\t\t* Language: $this->name\n";
  87          if ($this->cmd)
  88              print "\t\t\t  Language Cmd: $this->cmd\n";
  89      }
  90  }
  91  ?>


Generated: Sat Feb 19 17:29:53 2005 Cross-referenced by PHPXref 0.6