Skip to content

Instantly share code, notes, and snippets.

@jmas
Created December 28, 2015 23:52
Show Gist options
  • Save jmas/561235b528d342f96c2c to your computer and use it in GitHub Desktop.
Save jmas/561235b528d342f96c2c to your computer and use it in GitHub Desktop.
$users = new Collection('users', 'Users', [
new TextField('name', 'Name'),
new PasswordField('password', 'Password'),
new CheckboxField('role', 'Role', ['guest'=>'Guest', 'admin'=>'Admin']),
], ['admin']);
$tags = new Collection('tags', 'Tags', [
new TextField('label', 'Label'),
new EntryField('author', 'Author'),
]);
$blogPosts = new Collection('blog-posts', 'Blog Posts', [
new TextField('title', 'Title'),
new ImageField('image', 'Image'),
new RichTextField('content', 'Content'),
new EntryField('author', 'Author', $users),
new CollectionField('tags', 'Tags', $tags),
]);
$database = new MysqlDatabase($connectionString);
$collectionBuilder = new CollectionBuilder($database);
$collectionBuilder->applyCollection($users);
$collectionBuilder->applyCollection($tags);
$collectionBuilder->applyCollection($blogPosts);
// dont like
$entryFinder = new EntryFinder($database);
$blogEntriesByAdamSendler = $entryFinder->collection($blogPosts)->find([
'author' => new DatabaseEq('name', 'Adam Sendler'),
])->all();
// dont like
$blogEntriesByAdamSendlerOrAndyNilson = $entryFinder->collection($blogPosts)->find([
'author' => new DatabaseOr([DatabaseEq('name', 'Adam Sendler'), DatabaseEq('name', 'Andy Nilson')]),
])->all();
// dont like
$blogEntriesWithTagsStoryAndFilm = $entryFinder->collection($blogPosts)->find([
'author' => new DatabaseAnd([DatabaseEq('tags.label', 'Story'), DatabaseEq('tags.label', 'Film')]),
])->all();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment