Exemplo n.º 1
0
// create source
$source = new \Mesour\DataGrid\Sources\ArrayGridSource('users', 'id', $data, ['group' => $groups]);
$groupStructure = $source->addTableToStructure('group', 'id');
$groupStructure->addNumber('id');
$groupStructure->addText('name');
$groupStructure->addEnum('type')->addValue('first')->addValue('second');
$dataStrucutre = $source->getDataStructure();
$source->joinField('group', 'group_id', 'name', 'group_name');
$dataStrucutre->addDate('last_login');
$dataStrucutre->addDate('timestamp');
$dataStrucutre->addManyToOne('group', 'group', 'group_id', '{name} ({type})');
$currentUserRole = 'registered';
// create application
$application = new \Mesour\UI\Application('mesourapp');
$application->setRequest($_REQUEST);
$application->setUserRole($currentUserRole);
$application->run();
// authorizator settings
$auth = $application->getAuthorizator();
$auth->addRole('guest');
$auth->addRole('registered', 'guest');
$auth->addResource('menu');
$auth->allow('guest', 'menu', ['first', 'second']);
$auth->allow('registered', 'menu');
$auth->deny('registered', 'menu', 'second');
$grid = new \Mesour\UI\DataGrid('basicDataGrid', $application);
$wrapper = $grid->getWrapperPrototype();
$wrapper->class('my-class');
// TRUE = append
$wrapper->class('my-next-class', true);
$grid->setSource($source);
Exemplo n.º 2
0
    $structure->addText('name', 'Name', $userId)->setTextarea()->setEditPermission('user-editable', 'name-edit');
    $structure->addText('surname', 'Surname', $userId)->setEditPermission('user-editable', 'surname-edit');
    $structure->addText('email', 'Email', $userId)->setEditPermission('user-editable', 'email-edit');
    $structure->addNumber('amount', 'Amount', $userId)->setUnit('EUR')->setDecimalPoint(',')->setThousandSeparator('.')->setDecimals(2)->setEditPermission('user-editable', 'amount-edit');
    $structure->addDate('last_login', 'Last login', $userId)->setFormat('Y-m-d H:i:s')->setEditPermission('user-editable', 'last_login-edit');
    $structure->addEnum('role', 'Role', $userId)->addValue('admin', 'Admin')->addValue('moderator', 'Moderator')->setEditPermission('user-editable', 'role-edit');
    $structure->addBool('has_pro', 'Has PRO', $userId)->setDescription('Has PRO')->setEditPermission('user-editable', 'has_pro-edit');
    $structure->addOneToOne('wallet', 'Wallet', $userId)->enableRemoveRow()->enableCreateNewRow()->setEditPermission('user-editable', 'wallet-edit');
    $structure->addManyToOne('group', 'Group', $userId)->enableEditCurrentRow()->enableEditCurrentRow()->enableCreateNewRow()->setEditPermission('user-editable', 'group-edit')->setRemovePermission('user-editable', 'group-remove')->setCreatePermission('user-editable', 'group-create');
    $structure->addOneToMany('addresses', 'Addresses', $userId)->enableCreateNewRow()->enableRemoveRow()->setEditPermission('user-editable', 'addresses-edit')->setRemovePermission('user-editable', 'addresses-remove')->setCreatePermission('user-editable', 'addresses-create');
    $structure->addManyToMany('companies', 'Companies', $userId)->enableCreateNewRow()->enableRemoveRow()->enableAttachRow()->setEditPermission('user-editable', 'companies-edit')->setRemovePermission('user-editable', 'companies-remove')->setAttachPermission('user-editable', 'companies-attach')->setCreatePermission('user-editable', 'companies-create');
}
// APPLICATION
$application = new \Mesour\UI\Application('mesourApp');
$application->setRequest($_REQUEST);
$application->setUserRole('admin');
$auth = $application->getAuthorizator();
$auth->addRole('guest');
$auth->addRole('registered', 'guest');
$auth->addRole('admin', 'registered');
$auth->addResource('user-editable');
$auth->allow('admin', 'user-editable');
$auth->deny('registered', 'user-editable', 'companies-edit');
$auth->deny('registered', 'user-editable', 'companies-create');
$auth->deny('registered', 'user-editable', 'companies-remove');
$auth->deny('registered', 'user-editable', 'companies-attach');
$application->run();
// EDITABLE
$editable = new \Mesour\UI\Editable('editableTest', $application);
createForUser($structure, 1);
$editable->setDataStructure($structure);