예제 #1
0
 /**
  * Factory pattern
  * @param string $name Name of table
  * @return \Lazer\Classes\Database
  * @throws LazerException If there's problems with load file
  */
 public static function table($name)
 {
     Helpers\Validate::table($name)->exists();
     $self = new Database();
     $self->name = $name;
     $self->setFields();
     $self->setPending();
     return $self;
 }
예제 #2
0
 /**
  * Add an article
  */
 public function addArticleAction($content, $languageId)
 {
     $row = Lazer::table('article');
     $row->language_id = $languageId;
     $row->content = $content;
     $row->save();
 }
예제 #3
0
 public static function db_init()
 {
     //db init
     Lazer::create('language', array('id' => 'integer', 'name' => 'string'));
     Lazer::create('article', array('id' => 'integer', 'content' => 'string', 'language_id' => 'integer'));
     Lazer::create('word', array('id' => 'integer', 'content' => 'string', 'language_id' => 'integer'));
     Lazer::create('article_word', array('article_id' => 'integer', 'word_id' => 'integer'));
     Lazer::create('translate', array('id' => 'integer', 'word_id' => 'integer', 'dest_language_id' => 'integer', 'content' => 'string'));
     return true;
 }
예제 #4
0
 /**
  * Process query with joined data
  * @param object $row One row of data
  * @return Database
  */
 protected function join($row)
 {
     $keys['local'] = $this->keys['local'];
     $keys['foreign'] = $this->keys['foreign'];
     if ($this->relationType == 'hasAndBelongsToMany') {
         $join = Database::table($this->getJunction())->groupBy($this->tables['local'] . '_id')->where($this->tables['local'] . '_id', '=', $row->{$keys['local']})->findAll()->asArray(null, $this->tables['foreign'] . '_id');
         if (empty($join)) {
             return array();
         }
         return Database::table($this->tables['foreign'])->where($keys['foreign'], 'IN', $join[$row->{$keys['local']}]);
     }
     return Database::table($this->tables['foreign'])->where($keys['foreign'], '=', $row->{$keys['local']});
 }
예제 #5
0
 function installDB()
 {
     //install users
     try {
         \Lazer\Classes\Helpers\Validate::table('users')->exists();
     } catch (\Lazer\Classes\LazerException $e) {
         //Database doesn't exist
         Lazer::create('users', array('userid' => 'string', 'name' => 'string', 'email' => 'string', 'pass' => 'string', 'role' => 'string'));
         $users = json_decode(file_get_contents('../users.json'));
         if ($users != null && count($users) > 0) {
             $user = Lazer::table('users');
             foreach ($users as $jsonUser) {
                 $user->userid = $this->getGUID();
                 $user->name = $jsonUser->name;
                 $user->email = $jsonUser->email;
                 $user->pass = $this->randomPassword();
                 $user->role = isset($jsonUser->role) ? $jsonUser->role : 'user';
                 $user->save();
             }
         }
     }
     //install categories
     try {
         \Lazer\Classes\Helpers\Validate::table('categories')->exists();
     } catch (\Lazer\Classes\LazerException $e) {
         //Database doesn't exist
         Lazer::create('categories', array('categoryid' => 'string', 'label' => 'string'));
         $category = Lazer::table('categories');
         $category->categoryid = "travels";
         $category->label = 'Travels';
         $category->save();
         $category->categoryid = "most_creative";
         $category->label = 'Most creative';
         $category->save();
         $category->categoryid = "funniest";
         $category->label = 'Funiest';
         $category->save();
         $category->categoryid = "40";
         $category->label = '40';
         $category->save();
     }
     //install photos
     try {
         \Lazer\Classes\Helpers\Validate::table('photos')->exists();
     } catch (\Lazer\Classes\LazerException $e) {
         //Database doesn't exist
         Lazer::create('photos', array('photoid' => 'string', 'userid' => 'string', 'filepath' => 'string', 'status' => 'string'));
     }
     //install rates
     try {
         \Lazer\Classes\Helpers\Validate::table('rates')->exists();
     } catch (\Lazer\Classes\LazerException $e) {
         //Database doesn't exist
         Lazer::create('rates', array('photoid' => 'string', 'userid' => 'string', 'categoryid' => 'string', 'rate' => 'string'));
     }
 }
 public function delete()
 {
     try {
         $subject = Lazer::table($this->_table)->find($this->id)->delete();
         return true;
     } catch (LazerException $e) {
         return false;
     }
     return false;
 }