diff options
| author | Jan-Hendrik Willms <tleilax+github@gmail.com> | 2021-07-22 16:07:19 +0200 |
|---|---|---|
| committer | Jan-Hendrik Willms <tleilax+github@gmail.com> | 2021-07-22 16:19:12 +0200 |
| commit | a3da1483a9e689846179159355badfec8073dbec (patch) | |
| tree | 770dcca6bdf5f6f2a11b0e7fcbbeda6919a3fc52 /lib/models/eTask/Task.php | |
current code from svn, revision 62608
Diffstat (limited to 'lib/models/eTask/Task.php')
| -rw-r--r-- | lib/models/eTask/Task.php | 111 |
1 files changed, 111 insertions, 0 deletions
diff --git a/lib/models/eTask/Task.php b/lib/models/eTask/Task.php new file mode 100644 index 0000000..68d4a20 --- /dev/null +++ b/lib/models/eTask/Task.php @@ -0,0 +1,111 @@ +<?php + +namespace eTask; + +/** + * eTask conforming task definition. + * + * @property int id database column + * @property string type database column + * @property string title database column + * @property string description database column + * @property string task database column + * @property string user_id database column + * @property string mkdate database column + * @property string chdate database column + * @property string options database column + * @property User owner belongs_to User + * @property SimpleORMapCollection tests additional field etask\Test + * @property SimpleORMapCollection test_tasks has_many etask\TestTask + * @property SimpleORMapCollection responses has_many etask\Response + * @property JSONArrayobject task serialized database column + * @property JSONArrayobject options serialized database column + */ +class Task extends \SimpleORMap implements \PrivacyObject +{ + use ConfigureTrait; + + /** + * @see SimpleORMap::configure + */ + protected static function configure($config = []) + { + $config['db_table'] = 'etask_tasks'; + + $config['relationTypes'] = self::configureClassNames($config); + + $config['belongs_to']['owner'] = [ + 'class_name' => '\\User', + 'foreign_key' => 'user_id' + ]; + + $config['additional_fields']['tests']['get'] = 'getTests'; + + $config['has_many']['test_tasks'] = [ + 'class_name' => $config['relationTypes']['TestTask'], + 'assoc_foreign_key' => 'task_id', + 'on_delete' => 'delete', + 'on_store' => 'store' + ]; + + $config['has_many']['responses'] = [ + 'class_name' => $config['relationTypes']['Response'], + 'assoc_foreign_key' => 'task_id', + 'on_delete' => 'delete', + 'on_store' => 'store' + ]; + + $config['serialized_fields']['task'] = 'JSONArrayObject'; + $config['serialized_fields']['options'] = 'JSONArrayObject'; + + parent::configure($config); + } + + /** + * Retrieve the tests associated to this task. + * + * @return SimpleORMapCollection the associated tests + */ + public function getTests() + { + $klass = $this->relationTypes['Test']; + + return \SimpleORMapCollection::createFromArray( + $klass::findThru( + $this->id, + [ + 'thru_table' => 'etask_test_tasks', + 'thru_key' => 'task_id', + 'thru_assoc_key' => 'test_id', + 'assoc_foreign_key' => 'id', + 'order_by' => 'ORDER BY etask_tests.chdate ASC' + ] + ) + ); + } + + /** + * Export available data of a given user into a storage object + * (an instance of the StoredUserData class) for that user. + * + * @param StoredUserData $storage object to store data into + */ + public static function exportUserData(\StoredUserData $storage) + { + $sorm = self::findBySQL("user_id = ?", [$storage->user_id]); + if ($sorm) { + $field_data = []; + foreach ($sorm as $row) { + $field_data[] = $row->toRawArray(); + } + if ($field_data) { + $storage->addTabularData(_('eTask Aufgaben'), 'etask_tasks', $field_data); + } + } + + $field_data = \DBManager::get()->fetchAll("SELECT * FROM etask_task_tags WHERE user_id =?", [$storage->user_id]); + if ($field_data) { + $storage->addTabularData(_('eTask Aufgaben Tags'), 'etask_task_tags', $field_data); + } + } +} |
