Skip to content

Commit

Permalink
MNT Fix linting issues
Browse files Browse the repository at this point in the history
  • Loading branch information
GuySartorelli committed Nov 6, 2023
1 parent 4f79962 commit 5b70d19
Show file tree
Hide file tree
Showing 130 changed files with 3,535 additions and 2,130 deletions.
4 changes: 3 additions & 1 deletion en/00_Getting_Started/00_Server_Requirements.md
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,9 @@ Silverstripe CMS uses SwiftMailer to send email messages. New installations setu
You _must_ ensure emails are being sent from your _production_ environment. You can do this by testing that the ***Lost password*** form available at `/Security/lostpassword` sends an email to your inbox, or with the following code snippet that can be run via a `SilverStripe\Dev\BuildTask`:
```php
$email = new SilverStripe\Control\Email\Email('[email protected]', '[email protected]', 'My test subject', 'My email body text');
use SilverStripe\Control\Email\Email;
$email = Email::create('[email protected]', '[email protected]', 'My test subject', 'My email body text');
$email->send();
```

Expand Down
62 changes: 39 additions & 23 deletions en/02_Developer_Guides/00_Model/01_Data_Model_and_ORM.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,14 @@ along with any [relationships](relations) defined as `$has_one`, `$has_many`, `$

Let's look at a simple example:

**app/src/Player.php**
**app/src/Model/Player.php**

```php
namespace App\Model;

use SilverStripe\ORM\DataObject;

class Player extends DataObject
class Player extends DataObject
{
private static $db = [
'PlayerNumber' => 'Int',
Expand Down Expand Up @@ -76,13 +78,17 @@ automatically set on the `DataObject`.
* Created: A date/time field set to the creation date of this record
* LastEdited: A date/time field set to the date this record was last edited through `write()`

**app/src/Player.php**
**app/src/Model/Player.php**

```php
namespace App\Model;

use SilverStripe\ORM\DataObject;

class Player extends DataObject
class Player extends DataObject
{
private static string $table_name = 'Player';

private static $db = [
'PlayerNumber' => 'Int',
'FirstName' => 'Varchar(255)',
Expand Down Expand Up @@ -179,7 +185,6 @@ $members = Player::get()->filter([
])->sort('Surname');

// returns a `DataList` containing all the `Player` records that have the `FirstName` of 'Sam'

```

[info]
Expand Down Expand Up @@ -229,7 +234,7 @@ echo $players->Count();
```php
$players = Player::get();

foreach($players as $player) {
foreach ($players as $player) {
echo $player->FirstName;
}
```
Expand All @@ -239,7 +244,7 @@ Notice that we can step into the loop safely without having to check if `$player
```php
$players = Player::get();

if($players->exists()) {
if ($players->exists()) {
// do something here
}
```
Expand Down Expand Up @@ -291,14 +296,14 @@ However you might have several entries with the same `FirstName` and would like
```php
$players = Players::get()->sort([
'FirstName' => 'ASC',
'LastName'=>'ASC'
'LastName' => 'ASC'
]);
```

You can also sort randomly. Using the `DB` class, you can get the random sort method per database type.

```php
$random = DB::get_conn()->random();
$random = DB::get_conn()->random();
$players = Player::get()->sort($random);
```

Expand Down Expand Up @@ -338,9 +343,7 @@ $players = Player::get()->filter('FirstName', 'Sam');
Or if you want to find both Sam and Sig.

```php
$players = Player::get()->filter(
'FirstName', ['Sam', 'Sig']
);
$players = Player::get()->filter('FirstName', ['Sam', 'Sig']);

// SELECT * FROM Player WHERE FirstName IN ('Sam', 'Sig')
```
Expand Down Expand Up @@ -461,7 +464,7 @@ for each record, if the callback returns true, this record will be added to the
The below example will get all `Players` aged over 10.

```php
$players = Player::get()->filterByCallback(function($item, $list) {
$players = Player::get()->filterByCallback(function ($item, $list) {
return ($item->Age() > 10);
});
```
Expand Down Expand Up @@ -576,9 +579,10 @@ For instance, the below model will be stored in the table name `BannerImage`

```php
namespace SilverStripe\BannerManager;

use SilverStripe\ORM\DataObject;

class BannerImage extends DataObject
class BannerImage extends DataObject
{
private static $table_name = 'BannerImage';
}
Expand Down Expand Up @@ -615,7 +619,7 @@ table and column.
use SilverStripe\ORM\Queries\SQLSelect;
use SilverStripe\ORM\DataObject;

public function countDuplicates($model, $fieldToCheck)
public function countDuplicates($model, $fieldToCheck)
{
$table = DataObject::getSchema()->tableForField($model, $field);
$query = new SQLSelect();
Expand Down Expand Up @@ -673,11 +677,12 @@ Define the default values for all the `$db` fields. This example sets the "Statu
whenever a new object is created.

```php
namespace App\Model;

use SilverStripe\ORM\DataObject;

class Player extends DataObject
class Player extends DataObject
{

private static $defaults = [
"Status" => 'Active',
];
Expand All @@ -698,13 +703,23 @@ time.
For example, suppose we have the following set of classes:

```php
use SilverStripe\CMS\Model\SiteTree;
namespace {

class Page extends SiteTree
{
use SilverStripe\CMS\Model\SiteTree;

class Page extends SiteTree
{
// ...
}
}
class NewsPage extends Page
```

```php
namespace App\PageType;

use Page;

class NewsPage extends Page
{
private static $db = [
'Summary' => 'Text'
Expand All @@ -722,7 +737,8 @@ SilverStripe\CMS\Model\SiteTree:
LastEdited: Datetime
Title: Varchar
Content: Text
NewsPage:

App\PageType\NewsPage:
ID: Int
Summary: Text
```
Expand All @@ -732,7 +748,7 @@ Accessing the data is transparent to the developer.
```php
$news = NewsPage::get();

foreach($news as $article) {
foreach ($news as $article) {
echo $article->Title;
}
```
Expand Down
Loading

0 comments on commit 5b70d19

Please sign in to comment.