Skip to content

Commit

Permalink
#27 uodated docs
Browse files Browse the repository at this point in the history
  • Loading branch information
TobiasFranek committed Jul 7, 2018
1 parent 80af3ce commit fae1867
Show file tree
Hide file tree
Showing 9 changed files with 202 additions and 242 deletions.
21 changes: 5 additions & 16 deletions docs/AdvancedUsage/AddingAnCustomInstance.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
By adding a custom Instance you are able to execute API requests with different users or different servers than the default and the admin one.

First you have to know what is an instance.
For every Configuration f.e. default or admin there will be a new Webuntis object created which is the instance and if you need admin right for your command the ExecutionHandler executes the command with the admin instance.
For every Configuration f.e. default or admin there will be a new Webuntis object created which is the instance and if you need admin rights for your command the ExecutionHandler executes the command with the admin instance.

So this is important if you want f.e. an dev instance or you want an instance that is from another server.

## Creating a new ConfigurationModelInterface

first you want to create a new ConfigurationModelInterface like this.
First you want to create a new ConfigurationModelInterface like this.

```php
interface YourModelInterface extends ConfigurationModelInterface {
Expand All @@ -20,8 +20,8 @@ interface YourModelInterface extends ConfigurationModelInterface {

## Creating a custom Model

now you have to create a custom Model how to do this, can you learn [here](CreatingAnCustomModel.md).
if you have your custom Model you new to implement your newly created ConfigurationModelInterface.
Now you have to create a custom Model, if you don't know how to do this, view this [link](CreatingAnCustomModel.md).
If you have your custom Model you new to implement your newly created ConfigurationModelInterface.
```php
class YouCustomModel extends AbstractModel implements YourModelInterface {
//your code
Expand All @@ -30,17 +30,6 @@ class YouCustomModel extends AbstractModel implements YourModelInterface {

## Adding your Configuration

if you already have a WebuntisConfiguration object you can simply add an instance like this, otherwise you can add it like the admin or default configuration which is shown at the [beginning](/docs/BasicUsage/Configuration.md).

```php
$yourConfigObj->addConfig([
'yourinstance' => [
'server' => 'yourserver',
'school' => 'yourschool',
'username' => 'yourusername',
'passsword' => 'yourpassword'
]
])
```
Now you have to add your configuration like your admin and default instance, how to do this you see at the [beginning](/docs/BasicUsage/Configuration.md).

now everytime you execute a query with your model this instance will be used.
12 changes: 5 additions & 7 deletions docs/AdvancedUsage/AddingAnCustomType.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

By adding an custom type you can influence how the model handles certain values.

First you have to create an type class that implements TypeInterface, like this:
First you have to create an type class that implements the TypeInterface, like this:

```php
class YourType implements TypeInterface {
Expand Down Expand Up @@ -46,15 +46,13 @@ class YourType implements TypeInterface {
}
```

you have to add and also code these methods, because there are used to handle the things for the models.
The execute() method takes a model, data and field properties. With that information the method() sets an model value with the right value from the data array, these relations between the data array and the model are defined in the yml configuration.

the execute() method takes a model, data and field properties with that information the method() sets an model value with the right value from the data array, these relations between the data array and the model are defined in the yml configuration
The generateTypeWithConsole() returns an array that resembles your yml configuration for that type, it will be used to autogenerate Models.

the generateTypeWithConsole() return an array that resembles your yml configuration for that type
getName() and getType() returns the type f.e \DateTime::class and the name f.e. 'date'.

getName() and getType() return the type f.e \DateTime::class and the name f.e. 'date'

to add the type to the existing one you have to add it to the certain yml configuration of the model like this:
To add the type to the existing one you have to add it to the certain yml configuration of the model like this:

```yml
Webuntis\Models\Classes:
Expand Down
216 changes: 42 additions & 174 deletions docs/AdvancedUsage/AdvancedUsage.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,7 @@ to execute your own api request in you custom Repository is pretty easy.
just write this:

```php
use Webuntis\Util\ExecutionHandler;

$result = ExecutionHandler::execute($this, []);
$result = $this->executionHandler->execute($this, []);
```

this method returns the result of the api request as an array of the parsed objects.
Expand All @@ -62,9 +60,43 @@ the params are:
you just have to add a line into the yml config of the model you want that repo for.

with that line:
```yml

repositoryClass: Your\Path\Repository

## Caching

See [Caching](Caching.md)

# Creating an custom Model

Why would you create a custom Model? It is simple, what if you want different fields or you want to add a Model that doesn't exist yet.

First you have to learn how a Model is assembled every model inherits from the AbstractModel. But it is important to know that you implement the right Interfaces because the Interfaces say if the Model is cacheable or needs admin rights to execute an certain command.

If you have installed the package over composer you can use this command:

```shell
php vendor/tfranek/webuntis/bin/console.php webuntis:generate:model
```

Follow the instruction in the console.

## Types

For the models there are different types and these are defined as types, types that are integrated in the core are:

* int - resembles the int type
* string - is a string
* date - is a \DateTime that consist of on date
* mergeTimeAndDate - is a type that merges time and date to one \DateTime
* model - is an subordinate object that need parameter to find it in the api
* modelCollection - is an collection of subordinate objects

## YML Configuration

All your configuration that you set(fieldnames, custom repos) are saved in .yml files with these files the class can automatically generate a parse() function to assign the right api value to the right model values.


# Caching

You can create an cache instance like this:
Expand All @@ -77,12 +109,11 @@ $cache = $cacheBuilder->create();

with this caching instance you can do everything the [doctrine MemcachedCache](http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/caching.html) class can.

If you want to have another Caching method you can simply add it by yourself.
If you want to have another Caching method (like f.e. filebased caching) you can simply add it by yourself.

* create an caching class (like the MemcachedCache from doctrine with fetch, save etc.)
* create a CacheBuilderRoutine where you define how the Caching Instance is created like Webuntis\CacheBuilder\Routines\MemcacheRoutine
* add the routine to the general config off your application
* when you run $cacheBuilder->create() after you will get your Caching Instance and not the default one

```php
'default' => [
Expand All @@ -109,188 +140,25 @@ If you want to have another Caching method you can simply add it by yourself.
]
```

in this routine you get the cache config part passed. That means you have full control of the cache config f.e. you could delete host and port and add username and password.
In this routine you get the cache config part passed. That means you have full control of the cache config f.e. you could delete host and port and add username and password.

there are 2 console command that affect the cache:
There are 2 console command that affect the cache:

```shell
php vendor/tfranek/webuntis/bin/console.php webuntis:cache:clear [optional port for the memcached server] [optional host for the memcached server]
```

follow the instructions and you can easy clear the cache.
This command is for clearing the memcache.

```shell
php vendor/tfranek/webuntis/bin/console.php webuntis:cache:build [<server>] [<school>] [<adminusername>] [<adminpassword>] [<defaultusername>] [<defaultpassword>] [<memcachedhost>] [<memcachedport>] these are optional
```

with this command you can build the cache so that the user doesn't have to do it.
follow the instructions and you can easy build the cache.
With this command you can build the cache so that the user doesn't have to do it.

with the option --exclude you can exclude multiple Models like this:
With the option --exclude you can exclude multiple Models like this:

```shell
php vendor/tfranek/webuntis/bin/console.php webuntis:cache:build --exclude=Students --exclude=Teachers
```

## Types

For the models there are different types and these are defined as types, types that are integrated in the core are:

* int - resembles the int type
* string - is a string
* date - is a \DateTime that consist of on date
* mergeTimeAndDate - is a type that merges time and date to one \DateTime
* model - is an subordinate object that need parameter to find it in the api
* modelCollection - is an collection of subordinate objects

## YML Configuration

All your configuration that you set(fieldnames, custom repos) are saved in .yml files with these files the class can automatically generate a parse() function to assign the right api value to the right model values.

# Adding an custom Instance

By adding a custom Instance you are able to execute API requests with different users or different servers than the default and the admin one.

First you have to know what is an instance.
For every Configuration f.e. default or admin there will be a new Webuntis object created which is the instance and if you need admin right for your command the ExecutionHandler executes the command with the admin instance.

So this is important if you want f.e. an dev instance or you want an instance that is from another server.

## Creating a new ConfigurationModelInterface

first you want to create a new ConfigurationModelInterface like this.

```php
interface YourModelInterface extends ConfigurationModelInterface {
// the CONFIG_NAME is the name of your instance
const CONFIG_NAME = 'yourinstance';
}
```

## Creating a custom Model

now you have to create a custom Model how to do this, can you learn [here](CreatingAnCustomModel.md).
if you have your custom Model you new to implement your newly created ConfigurationModelInterface.
```php
class YouCustomModel extends AbstractModel implements YourModelInterface {
//your code
}
```

## Adding your Configuration

if you already have a WebuntisConfiguration object you can simply add an instance like this, otherwise you can add it like the admin or default configuration which is shown at the [beginning](/docs/BasicUsage/Configuration.md).

```php
$yourConfigObj->addConfig([
'yourinstance' => [
'server' => 'yourserver',
'school' => 'yourschool',
'username' => 'yourusername',
'passsword' => 'yourpassword'
]
])
```

now everytime you execute a query with your model this instance will be used.

# Adding an custom Type

By adding an custom type you can influence how the model handles certain values.

First you have to create an type class that implements TypeInterface, like this:

```php
class YourType implements TypeInterface {

/**
* executes an certain parsing part
* @param AbstractModel $model
* @param $data
* @param $field
*/
public static function execute(AbstractModel &$model, $data, $field) {
//todo code
}

/**
* asks for the params according to the type and return an array with the field information
* @param OutputInterface $output
* @param InputInterface $input
* @param $helper
* @return array
*/
public static function generateTypeWithConsole(OutputInterface $output, InputInterface $input, $helper) {
//todo code
}

/**
* return name of the type
* @return string
*/
public static function getName() {
//todo code
}

/**
* return type of the Type Class
* @return string
*/
public static function getType() {
//todo code
}
}
```

you have to add and also code these methods, because there are used to handle the things for the models.

the execute() method takes a model, data and field properties with that information the method() sets an model value with the right value from the data array, these relations between the data array and the model are defined in the yml configuration

the generateTypeWithConsole() return an array that resembles your yml configuration for that type

getName() and getType() return the type f.e \DateTime::class and the name f.e. 'date'

to add the type to the existing one you have to add it to the certain yml configuration of the model like this:

```yml
Webuntis\Models\Classes:
repositoryClass: null
fields:
name:
type: string
api:
name: name
fullName:
type: string
api:
name: longName
additionalTypes:
yourtypename: Your\Namespace\To\The\Class
```
after this you can start using that custom Type
# Caching
There are some things to know about caching the caching instance you cann simply access with:
```php
self::getCache();
```

with this caching instance you can do everything the [doctrine MemcachedCache](http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/caching.html) class can

there are 2 console command that affect the cache:

```shell
php vendor/tfranek/webuntis/bin/console.php webuntis:cache:clear [optional port for the memcached server] [optional host for the memcached server]
```

follow the instructions and you can easy clear the cache.

```shell
php vendor/tfranek/webuntis/bin/console.php webuntis:cache:build [<server>] [<school>] [<adminusername>] [<adminpassword>] [<defaultusername>] [<defaultpassword>] [<memcachedhost>] [<memcachedport>] these are optional
```

with this command you can build the cache so that the user doesn't have to do it.
follow the instructions and you can easy build the cache.
Loading

0 comments on commit fae1867

Please sign in to comment.