diff options
Diffstat (limited to 'lib/models/InstitutePlanColumn.php')
| -rw-r--r-- | lib/models/InstitutePlanColumn.php | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/lib/models/InstitutePlanColumn.php b/lib/models/InstitutePlanColumn.php new file mode 100644 index 0000000..b5ec876 --- /dev/null +++ b/lib/models/InstitutePlanColumn.php @@ -0,0 +1,72 @@ +<?php +/** + * InstitutePlanColumn + * model class for table institute_plan_columns + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License, or (at your option) any later version. + * + * @author Timo Hartge <hartge@data-quest.de> + * @license GPL2 or any version + * @since Stud.IP 4.5 + * * + * + * @property array $id alias for pk + * @property string $range_id database column + * @property int $column database column + * @property string|null $name database column + * @property int $visible database column + * @property int $mkdate database column + * @property int $chdate database column + */ +class InstitutePlanColumn extends SimpleORMap +{ + protected static function configure($config = []) + { + $config['db_table'] = 'institute_plan_columns'; + parent::configure($config); + } + + public static function findByInstitute($institute_id) + { + return self::findBySQL('range_id=?', [$institute_id]); + } + + /** + * returns the last column for given institute + * + * @param string $institut_id + * + * @return InstitutePlanColumn last column + */ + public static function getLastColumnOfInstitute($institute_id) + { + return self::findOneBySQL('range_id=? ORDER BY `column` DESC', [$institute_id]); + } + + /** + * Sets the visibility of multiple columns for given institute + * + * @param string $institut_id + * @param array $columns_change column number to be changed + * @param int $visibility 0 or 1 + * + * @return int number of changes + */ + public static function setVisbilities($institute_id, $columns_change, $visibility) + { + $changes = 0; + foreach (self::findBySQL('range_id=?', [$institute_id]) as $plan_column) { + if (in_array($plan_column->column, $columns_change)) { + $plan_column->visible = $visibility; + if ($plan_column->store()) { + $changes++; + } + } + } + return $changes; + } + +} |
