Автор: Grzegorz Kuźnik
Пример #1
0
 public function testDBStructure()
 {
     $tables = array("article", "word", "article_word", "language", "translate");
     foreach ($tables as $table) {
         LaserValidate::table($table)->exists();
     }
 }
 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;
         }
     }
 }
Пример #3
0
 /**
  * Delete fields from array
  * @param array $fields Indexed array
  */
 public function deleteFields(array $fields)
 {
     $fields = Helpers\Validate::arrToLower($fields);
     Helpers\Validate::table($this->name)->fields($fields);
     $config = $this->config();
     $config->schema = array_diff_key($this->schema(), array_flip($fields));
     $data = $this->getData();
     foreach ($data as $key => $object) {
         foreach ($fields as $name) {
             unset($data[$key]->{$name});
         }
     }
     Helpers\Data::table($this->name)->put($data);
     Helpers\Config::table($this->name)->put($config);
 }
Пример #4
0
 /**
  * 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);
 }
Пример #5
0
 /**
  * @covers Lazer\Classes\Helpers\Validate::relationType
  * @expectedException Lazer\Classes\LazerException
  */
 public function testRelationTypeNotExists()
 {
     $this->object->relationType('someRelation');
 }
Пример #6
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'));
     }
 }