Ejemplo n.º 1
0
 public function handle()
 {
     $action = $this->url->get("action", "default");
     $whoops = new \Whoops\Run();
     if ($this->url->get("ajax", false)) {
         $whoops->pushHandler(new \Whoops\Handler\JsonResponseHandler());
     } else {
         $whoops->pushHandler(new \Whoops\Handler\PrettyPageHandler());
     }
     $whoops->register();
     $result = null;
     if (method_exists($this, "handle_" . $action)) {
         $result = call_user_func(array($this, "handle_" . $action));
     } else {
         throw new Exception("Unknown action");
     }
     $output = "";
     if (is_string($result)) {
         $newResult = array('type' => 'transclude', 'content' => $result);
         $result = $newResult;
     }
     switch ($result['type']) {
         case "template":
             $output = $this->twig->renderTemplateToString($result['template'], $result['data']);
             break;
         case "json":
             $this->app->setJsonResponse(true);
             $data = $result['data'];
             $data['flashbag'] = FlashBag::getFlashes();
             $output = json_encode($data);
             break;
         case "redirect":
             $this->app->_requestRedirect($result['url']);
             return;
             break;
         case "transclude":
             $pageMap = [];
             /** @var BasePage $pageItem */
             foreach ($this->app->getPages() as $pageItem) {
                 $pageMap[] = array('id' => $pageItem->getId(), 'name' => $pageItem->getName());
             }
             ValueBag::set("flashbag", FlashBag::getFlashes());
             $data = array('valueBag' => json_encode(ValueBag::getValues()), 'staticRoot' => $this->app->getStaticRoot(), 'pageMap' => $pageMap, 'defaultUrl' => $this->routeGen->defaultRoute(), 'title' => $this->app->getAppName(), 'userParams' => $this->app->getUserParams(), 'pageTitle' => '');
             if ($this->page !== null) {
                 $data['page'] = $this->page;
                 $data['currentId'] = $this->page->getId();
                 $data['pageTitle'] = $this->page->getName();
             } else {
                 $data['currentId'] = -1;
             }
             $data['page_content'] = $result['content'];
             $data['dev'] = false;
             // change to true to load unminified js
             $output = $this->twig->renderTemplateToString("main_page.twig", $data);
             break;
         default:
             throw new Exception("Unknown result type");
     }
     return $output;
 }
Ejemplo n.º 2
0
<?php

use CrudKit\CrudKitApp;
use CrudKit\Data\DummyDataProvider;
use CrudKit\Data\SQLiteDataProvider;
use CrudKit\Pages\BasePage;
use CrudKit\Pages\BasicDataPage;
require "../vendor/autoload.php";
$crud = new CrudKitApp();
$crud->setStaticRoot("/src/static");
$page4 = new BasicDataPage('dummy4');
$page4->setName("SQLITE PAGE");
$sqliteProvider = new SQLiteDataProvider("fixtures/chinook.sqlite");
$sqliteProvider->setTable("Customer");
$sqliteProvider->setPrimaryColumn("a0", "CustomerId");
$sqliteProvider->addColumn("a1", "FirstName", "First Name");
$sqliteProvider->addColumn("a2", "LastName", "Last Name");
$sqliteProvider->addColumn("a3", "City", "City");
$sqliteProvider->addColumn("a4", "Country", "Country");
$sqliteProvider->addColumn("a5", "Email", "Email");
$sqliteProvider->setSummaryColumns(array("a1", "a2"));
$sqliteProvider->manyToOne("a6", "SupportRepId", "Employee", "EmployeeId", "FirstName", "Support Rep");
$page4->setDataProvider($sqliteProvider);
$crud->addPage($page4);
$page5 = new BasicDataPage('dummy5');
$page5->setName("Employees");
$empProvider = new SQLiteDataProvider("fixtures/chinook.sqlite");
$empProvider->setTable("Employee");
$empProvider->setPrimaryColumn("b0", "EmployeeId");
$empProvider->addColumn("b1", "FirstName", "First Name");
$empProvider->addColumn("b2", "LastName", "Last Name");
Ejemplo n.º 3
0
<?php

// Require CrudKit application
require "crudkit/crudkit.php";
use CrudKit\CrudKitApp;
use CrudKit\Pages\HtmlPage;
// Create a new CrudKitApp object
$app = new CrudKitApp();
// Create a new Page, of type "HtmlPage" which allows you to display arbitrary HTML inside
$page = new HtmlPage("mypage1");
// Every page needs to have a unique ID
$page->setName("My First Page");
// setName is available for all pages.
$page->setInnerHtml("This is page # <b>1</b>");
// You can set the HTML of this page, a feature supported by HtmlPage
$app->addPage($page);
$page2 = new HtmlPage("mypage2");
$page2->setName("My Second Page");
$page2->setInnerHtml("This is page # <b>2</b>");
$app->addPage($page2);
// Render the app. This will display the HTML
$app->render();
Ejemplo n.º 4
0
<?php

// Require CrudKit application
require "crudkit/crudkit.php";
use CrudKit\CrudKitApp;
use CrudKit\Pages\SQLiteTablePage;
use CrudKit\Pages\BasicLoginPage;
// Create a new CrudKitApp object
$app = new CrudKitApp();
$app->setAppName("Admin Panel");
$login = new BasicLoginPage();
if ($login->userTriedLogin()) {
    $username = $login->getUserName();
    $password = $login->getPassword();
    // TODO: you should use a better way to validate the password. Even if
    if ($username === 'admin' && $password === 'demo') {
        $login->success();
    } else {
        if ($username === 'user' && $password === 'demo') {
            $app->setReadOnly(true);
            $login->success();
        } else {
            $login->fail("Please check your password");
        }
    }
}
$app->useLogin($login);
$page = new SQLiteTablePage("sqlite2", "fixtures/chinook.sqlite");
$page->setName("Customer Management")->setTableName("Customer")->setRowsPerPage(20)->setPrimaryColumn("CustomerId")->addColumn("FirstName", "First Name", array('required' => true))->addColumn("LastName", "Last Name")->addColumn("City", "City", array('required' => true))->addColumn("Country", "Country")->addColumn("Email", "E-mail")->setSummaryColumns(array("FirstName", "Country"));
$app->addPage($page);
$invoice = new SQLiteTablePage("sqlite1", "fixtures/chinook.sqlite");
Ejemplo n.º 5
0
 public function testHelloWorld()
 {
     $crud = new CrudKitApp();
     $crud->addPage(new BasePage());
     $this->assertEquals($crud->say(), "Hello World");
 }
Ejemplo n.º 6
0
<?php

// Require CrudKit application
require "crudkit/crudkit.php";
use CrudKit\CrudKitApp;
use CrudKit\Pages\MySQLTablePage;
// Create a new CrudKitApp object
$app = new CrudKitApp();
$invoice = new MySQLTablePage("mysql2", "user2", "hunter2", "Chinook", array('charset' => "UTF8"));
$invoice->setName("Invoice")->setPrimaryColumnWithId("a0", "InvoiceId")->setTableName("Invoice")->addColumnWithId("a1", "BillingCity", "City")->addColumnWithId("a2", "BillingCountry", "Country")->addColumnWithId("a3", "Total", "Total")->addColumnWithId("a4", "InvoiceDate", "Date", array())->setSummaryColumns(["a1", "a2", "a3", "a4"]);
$app->addPage($invoice);
$page = new MySQLTablePage("mysql1", "user2", "hunter2", "Chinook", array('charset' => "UTF8"));
$page->setName("Customer Management")->setTableName("Customer")->setPrimaryColumn("CustomerId")->addColumn("FirstName", "First Name")->addColumn("LastName", "Last Name")->addColumn("City", "City")->addColumn("Country", "Country")->addColumn("Email", "E-mail")->setSummaryColumns(array("FirstName", "Country"));
$app->addPage($page);
// Render the app. This will display the HTML
$app->render();
Ejemplo n.º 7
0
<?php

require "vendor/autoload.php";
use CrudKit\CrudKitApp;
use CrudKit\Pages\SQLiteTablePage;
use CrudKit\Pages\BasicLoginPage;
// Create a new CrudKitApp object
$app = new CrudKitApp();
$app->setStaticRoot("static/crudkit/");
$app->setAppName("Admin Panel");
//
// HANDLE LOGIN
//
$login = new BasicLoginPage();
$login->setWelcomeMessage("Use credentials admin/demo or user/demo");
if ($login->userTriedLogin()) {
    $username = $login->getUserName();
    $password = $login->getPassword();
    // TODO: you should use your own authentication scheme here
    if ($username === 'admin' && $password === 'demo') {
        $login->success();
    } else {
        if ($username === 'user' && $password === 'demo') {
            $login->success();
        } else {
            $login->fail("Please check your password (admin/demo) or (user/demo)");
        }
    }
}
$app->useLogin($login);
//