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; }
public function __construct($data = null) { // Initialize table try { LazerValidate::table($this->_table)->exists(); } catch (LazerException $e) { // Table doesn't exist Lazer::create($this->_table, $this->_schema); } if (is_object($data)) { // Convert stdObject to Array $data = get_object_vars($data); } if (is_array($data)) { // Initialize this object with provided data foreach ($data as $i => $value) { $this->{$i} = $value; } } }
/** * Add data to configs and create all necessary files */ protected function addRelation() { if ($this->relationType == 'hasAndBelongsToMany') { $junction = $this->getJunction(); try { Validate::table($junction)->exists(); } catch (LazerException $e) { Database::create($junction, array($this->tables['local'] . '_id' => 'integer', $this->tables['foreign'] . '_id' => 'integer')); $this->insertRelationData($junction, $this->tables['local'], 'hasMany', array('local' => $this->tables['local'] . '_id', 'foreign' => $this->keys['local'])); $this->insertRelationData($junction, $this->tables['foreign'], 'hasMany', array('local' => $this->tables['foreign'] . '_id', 'foreign' => $this->keys['foreign'])); } } $this->insertRelationData($this->tables['local'], $this->tables['foreign'], $this->relationType, $this->keys); }
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')); } }