Esempio n. 1
0
 public function testHasOneSimple()
 {
     // Find user with id `1`
     $user1 = Model\User::find(1);
     // Consist
     $this->assertInstanceOf('Gas\\ORM', $user1);
     $this->assertInstanceOf('Gas\\Data', $user1->record);
     // Check result
     $this->assertEquals($user1->id, '1');
     $this->assertEquals($user1->name, 'John Doe');
     $this->assertEquals($user1->email, '*****@*****.**');
     $this->assertEquals($user1->username, 'johndoe');
     // Grab related wife
     $user1_wife = $user1->wife();
     // Consist
     $this->assertInstanceOf('Gas\\ORM', $user1_wife);
     $this->assertInstanceOf('Gas\\Data', $user1_wife->record);
     // Check results, this should be `Patricia Doe` with `2` as her id
     $this->assertEquals($user1_wife->id, '2');
     $this->assertEquals($user1_wife->name, 'Patricia Doe');
     // Since the third parameter for user <-> wife relationship
     // contain `select:id,name` for pre-process relation
     // Other fields should be null
     $this->assertNull($user1_wife->hair_color);
 }
Esempio n. 2
0
 public function testSaveUpdate()
 {
     // Create new resource
     $data = array('id' => 1, 'name' => 'Mr. Foo', 'username' => 'foo', 'email' => '*****@*****.**');
     Model\User::make($data)->save();
     // Get the new created resource
     $foo = Model\User::find(1);
     // At this moment, resource should contain all Mr. Foo values
     $this->assertEquals($foo->name, 'Mr. Foo');
     $this->assertEquals($foo->email, '*****@*****.**');
     $this->assertEquals($foo->username, 'foo');
     // Change all Foo's attribute into Bar
     $foo->name = 'Mr. Bar';
     $foo->email = '*****@*****.**';
     $foo->username = '******';
     // Update
     $foo->save();
     // Retrive back the user using old id
     $bar = Model\User::find(1);
     // Consist
     $this->assertInstanceOf('Gas\\ORM', $bar);
     $this->assertInstanceOf('Gas\\Data', $bar->record);
     // Check result
     $this->assertEquals($bar->id, '1');
     $this->assertEquals($bar->name, 'Mr. Bar');
     $this->assertEquals($bar->email, '*****@*****.**');
     $this->assertEquals($bar->username, 'bar');
 }
function select()
{
    $rows = Model\User::find();
    foreach ($rows as $row) {
        $row->actions = "{'username': '******'}";
    }
    return $rows;
}
Esempio n. 4
0
 public function __construct(PDO $db, $key = 'user_id')
 {
     if (isset($_SESSION[$key])) {
         if ($user = Model\User::find(array($key => $_SESSION[$key]))) {
             $this->user = new Model\User($user);
         }
     }
 }
Esempio n. 5
0
 public function testFindSingle()
 {
     // Find user with id `1`
     $user1 = Model\User::find(1);
     // Consist
     $this->assertInstanceOf('Gas\\ORM', $user1);
     $this->assertInstanceOf('Gas\\Data', $user1->record);
     // Check result
     $this->assertEquals($user1->id, '1');
     $this->assertEquals($user1->name, 'John Doe');
     $this->assertEquals($user1->email, '*****@*****.**');
     $this->assertEquals($user1->username, 'johndoe');
 }
 public function testCallbackSave()
 {
     // Create new resource with preserved value for username
     $data = array('id' => 10, 'name' => 'Mr. Foo', 'username' => 'administrator', 'email' => '*****@*****.**');
     $foo = Model\User::make($data);
     // In corresponding model, there is `_before_save` callback
     // to prevent new users register using `administrator` as their username
     $foo->save();
     unset($foo);
     // Get the last created entry
     $foo = Model\User::find(10);
     // Consist
     $this->assertInstanceOf('Gas\\ORM', $foo);
     $this->assertInstanceOf('Gas\\Data', $foo->record);
     // Since the before_save already make sure that username can not contain
     // `administrator`, it turn into `member`
     $this->assertEquals($foo->username, 'member');
 }
Esempio n. 7
0
 public function index()
 {
     $id = auth()->getUser()->id;
     $this->form_validation->set_rules('email', 'Email', 'required|valid_email');
     $this->form_validation->set_rules('first_name', 'First Name', 'required');
     // $this->form_validation->set_rules('last_name', 'Last Name', 'required');
     // $this->form_validation->set_rules('address', 'Alamat', 'required');
     // $this->form_validation->set_rules('province', 'Propinsi', 'required');
     // $this->form_validation->set_rules('city', 'Kota', 'required');
     // $this->form_validation->set_rules('kecamatan', 'Kecamatan', 'required');
     // $this->form_validation->set_rules('desa', 'Desa/Kelurahan', 'required');
     if ($this->form_validation->run() == FALSE) {
         $user = Model\User::find($id);
         $data['user'] = $user;
         $source = $this->wilayah->getSource();
         $profile = $user->profile;
         $profile->wilayah = $source->getParentByDesa($profile->desa_id);
         $data['profile'] = $user->profile;
         $this->template->inject_partial('script', $this->wilayah->script(site_url('user/wilayah')));
         $this->template->build('edit', $data);
     } else {
         $user = array('email' => $this->input->post('email'));
         $profile = array('first_name' => set_value('first_name'), 'last_name' => set_value('last_name'), 'gender' => set_value('gender'), 'tempat_lahir' => set_value('tempat_lahir'), 'tanggal_lahir' => set_value('tanggal_lahir'), 'address' => set_value('address'), 'desa_id' => set_value('desa'));
         $res = $this->model->update($id, $user, $profile);
         $action = $this->input->post('avatar[action]');
         $avatar = $this->input->post('avatar[src]');
         if ($action === 'upload') {
             $this->model->setAvatar($id, $avatar);
         } elseif ($action === 'remove') {
             $this->model->removeAvatar($id);
         }
         if ($res == TRUE) {
             set_message_success('User berhasil diperbarui.');
             redirect('profile');
         } else {
             set_message_error('User gagal diperbarui.');
             redirect('profile');
         }
     }
 }
Esempio n. 8
0
 public function group_edit($f3, $params)
 {
     $f3->set("title", $f3->get("dict.groups"));
     $group = new \Model\User();
     $group->load(array("id = ? AND deleted_date IS NULL AND role = 'group'", $params["id"]));
     $f3->set("group", $group);
     $members = new \Model\Custom("user_group_user");
     $f3->set("members", $members->find(array("group_id = ? AND deleted_date IS NULL", $group->id)));
     $users = new \Model\User();
     $f3->set("users", $users->find("deleted_date IS NULL AND role != 'group'", array("order" => "name ASC")));
     $this->_render("admin/groups/edit.html");
 }
Esempio n. 9
0
 public function testManyToManyFinder()
 {
     // Find a many-to-many record
     $user1_jobs = Model\User::find(1)->job();
     $this->assertInternalType('array', $user1_jobs);
     $this->assertNotEmpty($user1_jobs);
     // Vice-versa
     $job1_users = Model\Job::find(1)->user();
     $this->assertInternalType('array', $job1_users);
     $this->assertNotEmpty($job1_users);
 }
Esempio n. 10
0
 /**
  * GET /issues/@id/watchers
  * AJAX call for issue watchers
  *
  * @param \Base $f3
  * @param array $params
  */
 public function single_watchers($f3, $params)
 {
     $watchers = new \Model\Custom("issue_watcher_user");
     $f3->set("watchers", $watchers->find(array("issue_id = ?", $params["id"])));
     $users = new \Model\User();
     $f3->set("users", $users->find("deleted_date IS NULL AND role != 'group'", array("order" => "name ASC")));
     $this->_printJson(array("total" => count($f3->get("watchers")), "html" => $this->_cleanJson(\Helper\View::instance()->render("issues/single/watchers.html"))));
 }
Esempio n. 11
0
 public function testDeleteByReference()
 {
     // Find user `2` and `3` and make sure they exists
     $user2 = Model\User::find(2);
     $user3 = Model\User::find(3);
     // Consist
     $this->assertInstanceOf('Gas\\ORM', $user2);
     $this->assertInstanceOf('Gas\\Data', $user2->record);
     $this->assertInstanceOf('Gas\\ORM', $user3);
     $this->assertInstanceOf('Gas\\Data', $user3->record);
     // Unset
     unset($user2, $user3);
     // Delete above users
     Model\User::delete(2, 3);
     // Find user `2` and `3` once more time
     $user2 = Model\User::find(2);
     $user3 = Model\User::find(3);
     // At this moment, user `2` and `3` should not exists anymore
     $this->assertEmpty($user2);
     $this->assertEmpty($user3);
 }
Esempio n. 12
0
 public function testHasManyThroughCustom()
 {
     // Find user with id `1`
     $user1 = Model\User::find(1);
     // Consist
     $this->assertInstanceOf('Gas\\ORM', $user1);
     $this->assertInstanceOf('Gas\\Data', $user1->record);
     // Check result
     $this->assertEquals($user1->id, '1');
     $this->assertEquals($user1->name, 'John Doe');
     $this->assertEquals($user1->email, '*****@*****.**');
     $this->assertEquals($user1->username, 'johndoe');
     // Grab related role(s)
     $user1_roles = $user1->role();
     // Should contain 2 roles
     $this->assertCount(2, $user1_roles);
     foreach ($user1_roles as $role) {
         // Consist
         $this->assertInstanceOf('Gas\\ORM', $role);
         $this->assertInstanceOf('Gas\\Data', $role->record);
         // Check results
         // This should be role with id `2` and `3`
         switch ($role->id) {
             case '2':
                 $this->assertEquals($role->name, 'Moderator');
                 break;
             case '3':
                 $this->assertEquals($role->name, 'Member');
                 break;
         }
     }
 }
Esempio n. 13
0
<?php

/**
 *  due_alerts.php
 *  Sends alerts to users with issues due today
 */
require_once "base.php";
$user = new \Model\User();
$users = $user->find();
foreach ($users as $u) {
    $u->sendDueAlert();
}