Skip to content

Commit

Permalink
#51 added new method "Absences" which represents "getTimetableWithAbs…
Browse files Browse the repository at this point in the history
…ences"#
  • Loading branch information
TobiasFranek committed Feb 5, 2019
1 parent e30c233 commit 8ac641b
Show file tree
Hide file tree
Showing 10 changed files with 1,007 additions and 3 deletions.
28 changes: 28 additions & 0 deletions docs/BasicUsage/BasicUsage.md
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,33 @@ $query->get('ClassRegEvents')->findAll([], null, startDate, endDate, element);

* StatusDataRepository again just a different parse method.

* AbsencesRespoitory allows you to fetch absences from a certain date


```php
$query->get('Absences')->findAll([], null, startDate, endDate, lazy = true|false);
// the lazy operator works like this

// loads all the data and works just as fine
$absence = $query->get('Absences')->findAll([], null, startDate, endDate, lazy = false)[0];
$absence->getTeachers()[0]->getName();

// it loads all the children etc for the absences model
$absences = $query->get('Absences')->findAll([], null, startDate, endDate, lazy = false);
\Webuntis\Serializer\Serializer::serialize($absences)[12]['teachers'][2]->getName()

// now with lazy enabled this happens
$absence = $query->get('Absences')->findAll([], null, startDate, endDate, lazy = true)[0];

// Error: undefined method
$absence->getTeachers()[0]->getName();
// and also all other object only have the base data
// but if you load them:
// everything works as before, but you had to process a lot less data at once
// keep in mind, with this command you have to load one model at a time
$absence->load()->getTeachers()[0]->getName();
```

### Model Usage

These are all the models that exists in the core build:
Expand All @@ -393,6 +420,7 @@ These are all the models that exists in the core build:
* ClassRegEvents - api method: getClassregEvents
* StatusData - api method: getStatusData
* LastImportTime - api method: getLatestImportTime
* Absences - api method: getTimetableWithAbsences

### Serializer

Expand Down
29 changes: 29 additions & 0 deletions docs/BasicUsage/Querys.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

# Querys

Now to the important part, the data fetching.
Expand Down Expand Up @@ -135,6 +136,33 @@ $query->get('ClassRegEvents')->findAll([], null, startDate, endDate, element);

* StatusDataRepository again just a different parse method.

* AbsencesRespoitory allows you to fetch absences from a certain date


```php
$query->get('Absences')->findAll([], null, startDate, endDate, lazy = true|false);
// the lazy operator works like this

// loads all the data and works just as fine
$absence = $query->get('Absences')->findAll([], null, startDate, endDate, lazy = false)[0];
$absence->getTeachers()[0]->getName();

// it loads all the children etc for the absences model
$absences = $query->get('Absences')->findAll([], null, startDate, endDate, lazy = false);
\Webuntis\Serializer\Serializer::serialize($absences)[12]['teachers'][2]->getName()

// now with lazy enabled this happens
$absence = $query->get('Absences')->findAll([], null, startDate, endDate, lazy = true)[0];

// Error: undefined method
$absence->getTeachers()[0]->getName();
// and also all other object only have the base data
// but if you load them:
// everything works as before, but you had to process a lot less data at once
// keep in mind, with this command you have to load one model at a time
$absence->load()->getTeachers()[0]->getName();
```

### Model Usage

These are all the models that exists in the core build:
Expand All @@ -156,6 +184,7 @@ These are all the models that exists in the core build:
* ClassRegEvents - api method: getClassregEvents
* StatusData - api method: getStatusData
* LastImportTime - api method: getLatestImportTime
* Absences - api method: getTimetableWithAbsences

### Serializer

Expand Down
23 changes: 22 additions & 1 deletion src/Configuration/WebuntisConfiguration.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public static function addConfig(array $config) : void
}

/**
* gets the right instance config from given model
* gets the right instance config from a given model
* @param AbstractModel $model
* @return array
*/
Expand All @@ -55,6 +55,27 @@ public static function getConfigByModel(AbstractModel $model) : array
return $config[$configName];
}

/**
* returns the name of the configuration from a given model
* @param AbstractModel $model
* @return string
*/
public static function getConfigNameByModel(AbstractModel $model) : string
{
$config = WebuntisFactory::getConfig();
$model = get_class($model);
$interfaces = class_implements($model);
if (isset($interfaces[ConfigurationModelInterface::class])) {
$configName = $model::CONFIG_NAME;
} else if (isset($config['only_admin']) && $config['only_admin']) {
$configName = 'admin';
} else {
$configName = 'default';
}

return $configName;
}

/**
* gets the current config
* @return array
Expand Down
Loading

0 comments on commit 8ac641b

Please sign in to comment.