Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor Lesson 20 #110

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Lesson-20-begin/.devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
FROM manuth/silverstripe-dev
RUN curl -s https://getcomposer.org/installer | php
RUN mv composer.phar /usr/bin/composer
6 changes: 6 additions & 0 deletions Lesson-20-begin/.devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"name": "SilverStripe Development",
"dockerComposeFile": "docker-compose.yml",
"service": "silverstripe",
"workspaceFolder": "/var/www/html"
}
27 changes: 27 additions & 0 deletions Lesson-20-begin/.devcontainer/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
version: '3'

services:
silverstripe:
build:
context: .
dockerfile: Dockerfile
environment:
- SS_DATABASE_CHOOSE_NAME=true
- SS_DATABASE_CLASS=MySQLPDODatabase
- SS_DATABASE_SERVER=db
- SS_DATABASE_USERNAME=root
- SS_DATABASE_PASSWORD=root
- SS_ENVIRONMENT_TYPE=dev
- SS_DEFAULT_ADMIN_USERNAME=root
- SS_DEFAULT_ADMIN_PASSWORD=password
ports:
- 8888:80
volumes:
- ..:/var/www/html
db:
image: mysql:5
environment:
- MYSQL_ROOT_PASSWORD=root
volumes:
- ./mysql-data:/var/lib/mysql
- ./initdb.d:/docker-entrypoint-initdb.d
1,699 changes: 1,699 additions & 0 deletions Lesson-20-begin/.devcontainer/initdb.d/database.sql

Large diffs are not rendered by default.

4 changes: 0 additions & 4 deletions Lesson-20-begin/.editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,6 @@ trim_trailing_whitespace = true
[*.md]
trim_trailing_whitespace = false

[*.yml]
indent_size = 2
indent_style = space

[*.{yml,json}]
# The indent size used in the `package.json` file cannot be changed
# https://github.com/npm/npm/pull/3180#issuecomment-16336516
Expand Down
8 changes: 3 additions & 5 deletions Lesson-20-begin/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
/.env
/vendor/
/themes/simple/
/resources/
/public/resources/
/node_modules/


/_resources/
/public/_resources/
.devcontainer/mysql-data/
2 changes: 2 additions & 0 deletions Lesson-20-begin/.htaccess
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
RewriteEngine On
RewriteRule ^(.*)$ public/$1
28 changes: 28 additions & 0 deletions Lesson-20-begin/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
## Overview

Base project folder for a SilverStripe ([http://silverstripe.org](http://silverstripe.org)) installation. Required modules are installed via [http://github.com/silverstripe/recipe-cms](http://github.com/silverstripe/recipe-cms). For information on how to change the dependencies in a recipe, please have a look at [https://github.com/silverstripe/recipe-plugin](https://github.com/silverstripe/recipe-plugin). In addition, installer includes [theme/simple](https://github.com/silverstripe-themes/silverstripe-simple) as a default theme.

## Installation ##

See [installation on different platforms](http://doc.silverstripe.org/framework/en/installation/),
and [installation from source](http://doc.silverstripe.org/framework/en/installation/from-source).

## Bugtracker ##

Bugs are tracked on github.com ([framework issues](https://github.com/silverstripe/silverstripe-framework/issues),
[cms issues](https://github.com/silverstripe/silverstripe-cms/issues)).
Please read our [issue reporting guidelines](https://docs.silverstripe.org/en/4/contributing/issues_and_bugs/).

## Development and Contribution ##

If you would like to make changes to the SilverStripe core codebase, we have an extensive [guide to contributing code](http://doc.silverstripe.org/framework/en/misc/contributing/code).

## Links ##

* [Changelogs](http://doc.silverstripe.org/framework/en/changelogs/)
* [Bugtracker: Framework](https://github.com/silverstripe/silverstripe-framework/issues)
* [Bugtracker: CMS](https://github.com/silverstripe/silverstripe-cms/issues)
* [Bugtracker: Installer](https://github.com/silverstripe/silverstripe-installer/issues)
* [Forums](http://silverstripe.org/forums)
* [Developer Mailinglist](https://groups.google.com/forum/#!forum/silverstripe-dev)
* [License](./LICENSE)
4 changes: 0 additions & 4 deletions Lesson-20-begin/__assets/assets/.gitignore

This file was deleted.

27 changes: 0 additions & 27 deletions Lesson-20-begin/__assets/assets/.htaccess

This file was deleted.

1,658 changes: 0 additions & 1,658 deletions Lesson-20-begin/__assets/database.sql

This file was deleted.

8 changes: 8 additions & 0 deletions Lesson-20-begin/app/_config.php
Original file line number Diff line number Diff line change
@@ -1 +1,9 @@
<?php

use SilverStripe\Security\PasswordValidator;
use SilverStripe\Security\Member;

// remove PasswordValidator for SilverStripe 5.0
$validator = PasswordValidator::create();
// Settings are registered via Injector configuration - see passwords.yml in framework
Member::set_password_validator($validator);
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ Name: myproject
---
SilverStripe\Core\Manifest\ModuleManifest:
project: app

SilverStripe\SiteConfig\SiteConfig:
extensions:
- SilverStripe\Lessons\SiteConfigExtension
- SilverStripe\Example\SiteConfigExtension
1 change: 0 additions & 1 deletion Lesson-20-begin/app/_config/theme.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,3 @@ SilverStripe\View\SSViewer:
themes:
- '$public'
- '$default'

23 changes: 0 additions & 23 deletions Lesson-20-begin/app/composer.json

This file was deleted.

13 changes: 6 additions & 7 deletions Lesson-20-begin/app/src/ArticleCategory.php
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
<?php

namespace SilverStripe\Lessons;
namespace SilverStripe\Example;

use SilverStripe\ORM\DataObject;
use SilverStripe\Forms\FieldList;
use SilverStripe\Forms\TextField;

class ArticleCategory extends DataObject {

class ArticleCategory extends DataObject
{
private static $db = [
'Title' => 'Varchar',
'Title' => 'Varchar'
];

private static $has_one = [
'ArticleHolder' => ArticleHolder::class,
'ArticleHolder' => ArticleHolder::class
];

private static $belongs_many_many = [
'Articles' => ArticlePage::class,
'Articles' => ArticlePage::class
];

public function getCMSFields()
Expand All @@ -33,5 +33,4 @@ public function Link()
'category/'.$this->ID
);
}

}
7 changes: 3 additions & 4 deletions Lesson-20-begin/app/src/ArticleComment.php
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
<?php

namespace SilverStripe\Lessons;
namespace SilverStripe\Example;

use SilverStripe\ORM\DataObject;

class ArticleComment extends DataObject
{

private static $db = [
'Name' => 'Varchar',
'Email' => 'Varchar',
'Comment' => 'Text'
];

private static $has_one = [
'ArticlePage' => ArticlePage::class,
'ArticlePage' => ArticlePage::class
];
}
}
17 changes: 8 additions & 9 deletions Lesson-20-begin/app/src/ArticleHolder.php
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
<?php

namespace SilverStripe\Lessons;
namespace SilverStripe\Example;

use Page;
use SilverStripe\Forms\GridField\GridField;
use SilverStripe\Forms\GridField\GridFieldConfig_RecordEditor;
use Page;

class ArticleHolder extends Page
{
private static $has_many = [
'Categories' => ArticleCategory::class,
private static $allowed_children = [
ArticlePage::class
];

private static $allowed_children = [
ArticlePage::class
];
private static $has_many = [
'Categories' => ArticleCategory::class
];

public function getCMSFields()
{
Expand All @@ -33,9 +33,8 @@ public function Regions ()
{
$page = RegionsPage::get()->first();

if($page) {
if ($page) {
return $page->Regions();
}
}

}
18 changes: 9 additions & 9 deletions Lesson-20-begin/app/src/ArticleHolderController.php
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
<?php

namespace SilverStripe\Lessons;
namespace SilverStripe\Example;

use PageController;
use SilverStripe\ORM\PaginatedList;
use SilverStripe\Control\HTTPRequest;
use PageController;

class ArticleHolderController extends PageController
{
protected $articleList;

private static $allowed_actions = [
'category',
'region',
'date'
];

protected $articleList;

protected function init ()
protected function init()
{
parent::init();

Expand All @@ -25,13 +25,13 @@ protected function init ()
])->sort('Date DESC');
}

public function category (HTTPRequest $r)
public function category(HTTPRequest $r)
{
$category = ArticleCategory::get()->byID(
$r->param('ID')
);

if(!$category) {
if (!$category) {
return $this->httpError(404,'That category was not found');
}

Expand All @@ -50,7 +50,7 @@ public function region (HTTPRequest $r)
$r->param('ID')
);

if(!$region) {
if (!$region) {
return $this->httpError(404,'That region was not found');
}

Expand All @@ -63,7 +63,7 @@ public function region (HTTPRequest $r)
];
}

public function PaginatedArticles ($num = 10)
public function PaginatedArticles($num = 10)
{
return PaginatedList::create(
$this->articleList,
Expand Down
Loading