Example #1
0
 public static function tests()
 {
     $tests = \Work\Models\Test::get();
     $rows = array();
     foreach ($tests as $test) {
         $test_inputs = \Work\Models\TestInput::where('test_id', '=', $test->test_id)->get();
         $data = array();
         foreach ($test_inputs as $test_input) {
             $input = \Work\Models\Input::where('input_id', '=', $test_input->input_id)->pluck('input');
             if (is_null($input)) {
                 throw new \Exception("No input found for {$test_input->test_input_id}");
             }
             $data[$input] = $test_input->input;
         }
         $controller = \Work\Models\Controller::where('controller_id', '=', $test->controller_id)->pluck('controller');
         list($class, $function) = explode('::', $controller);
         if ($data) {
             $result = $class::$function($data);
         } else {
             $result = $class::$function();
         }
         if ($test->result == $result) {
             $pass = '******';
         } else {
             $pass = '******';
         }
         $rows[] = array($controller, $test->result, $result, $pass);
     }
     $layout = new \Frame\Views\Layout($rows);
     return $layout->render();
 }
Example #2
0
    public function render()
    {
        $key = \Frame\Key::get();
        $user_id = \Work\Models\User::where('session', '=', $_SESSION['frame_key'])->pluck('user_id');
        if (is_null($user_id)) {
            $user_id = 0;
        }
        $target_id = \Work\Models\Target::where('target', '=', $this->target)->pluck('target_id');
        $id = \Work\Models\Navigation::where('user_id', '=', $user_id)->where('type', '=', 'target')->where('navigation', '=', $target_id)->orderBy('navigation_id', 'desc')->pluck('key');
        $attributes = array('type' => 'button', 'id' => $key, 'value' => $this->text);
        $controller_id = \Work\Models\Controller::where('controller', '=', $this->controller)->pluck('controller_id');
        \Work\Models\Navigation::create(array('user_id' => $user_id, 'key' => $key, 'type' => 'controller', 'navigation' => $controller_id));
        $button = $this->build('input', '', $attributes);
        $js = <<<JS
\$('#{$key}').bind('click', function(event) {
    event.preventDefault();
    var ids = [];
    \$('body [id]').each(function() {
        ids.push(\$(this).attr('id'));
    });
    \$.ajax({url: '', type: 'post', dataType: 'json', data: {key: '{$key}', clean: ids, target: '{$id}'}}).success(function(json) {
        if (!json.status || !json.html || json.status != 'COMPLETE') {
            var message = json.message || 'System error, check logs';
            alert(message);
            return false;
        }
        \$('#{$id}').html(json.html);
    });
});
JS;
        $script = $this->build('script', $js);
        //$script = $this->build('script', '$("#'.$key.'").unbind("click").bind("click", function() {$("#'.$id.'").load("?key='.$key.'");})');
        return $button . $script;
    }
Example #3
0
    public function render()
    {
        $columns = array();
        $user_id = \Work\Models\User::where('session', '=', $_SESSION['frame_key'])->pluck('user_id');
        if (is_null($user_id)) {
            $user_id = 0;
        }
        foreach ($this->inputs as $input) {
            $id = \Frame\Key::get();
            if ($input['type'] == 'hidden') {
                if ($user_id) {
                    $store = \Work\Models\Store::where('user_id', '=', $user_id)->where('key', '=', $input['value'])->pluck('store_id');
                } else {
                    $store = \Work\Models\Store::where('key', '=', $input['value'])->pluck('store_id');
                }
                if (is_null($store)) {
                    $hidden = \Frame\Key::get();
                    \Work\Models\Store::create(array('user_id' => $user_id, 'key' => $hidden, 'value' => $input['value']));
                    $input['value'] = $hidden;
                }
            }
            $columns[] = array($input['label'], $this->build('input', '', array('id' => $id, 'name' => $id, 'type' => $input['type'], 'value' => $input['value'])));
            if (is_null($input['input'])) {
                continue;
            }
            $input_id = \Work\Models\Input::where('input', '=', $input['input'])->pluck('input_id');
            \Work\Models\Navigation::create(array('user_id' => $user_id, 'key' => $id, 'type' => 'input', 'navigation' => $input_id));
        }
        $layout = new \Frame\Views\Layout($columns);
        $key = \Frame\Key::get();
        $target_id = \Work\Models\Target::where('target', '=', $this->target)->pluck('target_id');
        if ($target_id) {
            $target = \Work\Models\Navigation::where('user_id', '=', $user_id)->where('type', '=', 'target')->where('navigation', '=', $target_id)->orderBy('navigation_id', 'desc')->pluck('key');
        } else {
            $navigation_id = \Work\Models\Navigation::where('type', '=', 'target')->where('key', '=', $this->target)->pluck('navigation_id');
            if ($navigation_id) {
                $target = $this->target;
            } else {
                $target = null;
            }
        }
        if (is_null($target)) {
            $id = $target = 'body';
        } else {
            $id = "#{$target}";
        }
        $form = $this->build('form', $layout->render(), array('id' => $key));
        $js = <<<JS
\$('#{$key}').submit(function(event) {
    event.preventDefault();
    var hidden = [];
    \$('{$id} [id]').each(function() {
        hidden.push(\$(this).attr('id'));
    });
    console.log(hidden);
    var ids = [];
    \$('body [id]').each(function() {
        if (\$.inArray(\$(this).attr('id'), hidden) >= 0) return true;
        ids.push(\$(this).attr('id'));
    });
    console.log(ids);
    \$.ajax({url: '', type: 'post', dataType: 'json', data: {key: '{$key}', form: \$(this).serializeArray(), target: '{$target}', clean: ids}}).success(function(json) {
        if (!json.status || json.status != 'COMPLETE' || !json.html) {
            var message = json.message || 'System error, check logs';
            alert(message);
            return false;
        }
        \$('{$id}').html(json.html);
    });
});
JS;
        $controller_id = \Work\Models\Controller::where('controller', '=', $this->controller)->pluck('controller_id');
        if (is_null($controller_id)) {
            throw new \Exception("{$this->controller} not found in controller table}");
        }
        \Work\Models\Navigation::create(array('user_id' => $user_id, 'key' => $key, 'type' => 'controller', 'navigation' => $controller_id));
        $script = $this->build('script', $js);
        return $form . $script;
    }
Example #4
0
 private static function permission($user, $controller_id)
 {
     if (isset($user->group)) {
         foreach ($user->group as $group) {
             if (isset($group->pivot->role)) {
                 foreach ($group->pivot->role as $role) {
                     if (isset($role->pivot->controller)) {
                         foreach ($role->pivot->controller as $controller) {
                             if ($controller->pivot->controller_id == $controller_id) {
                                 return $controller->pivot->controller;
                             }
                         }
                     }
                 }
             }
         }
     }
     $controller = \Work\Models\Controller::where('controller_id', '=', $controller_id)->pluck('controller');
     if ($controller) {
         throw new \Frame\Exception("User does not have access to controller {$controller}");
     } else {
         throw new \Exception("Controller {$controller_id} not found");
     }
 }