/** * Fetches data from the Database and rearranges them * * This function executed the Query given and rearranges the Elements into * a flat key => value-Array * * @param String $query The SQL-Query to execute * @param String $key (Standard: "ID") the column-name of the element of * each row that should be the key for the new array-element * @param String $value (Standard: "name") the column-name of the element * of each row that should be the value for the rearranged Array-Element * @return Array The rearranged Array or a void array if SQL-Query returned * nothing */ protected function arrayGetFlattened($query, $key = 'ID', $value = 'name') { $rows = TableMng::query($query); return ArrayFunctions::arrayColumn($rows, $value, $key); }
/** * Displays the change Classteacher form to the User * * Dies displaying the Form */ protected function classteacherChangeDisplay() { $this->_smarty->assign('classteacher', $this->classteacherGet($_GET['ID'])); $this->_smarty->assign('classesOfClassteacher', ArrayFunctions::arrayColumn($this->classesOfActiveSchoolyearAndClassteacherGet($_GET['ID']), 'ClassID')); $this->_smarty->assign('classes', $this->classesOfActiveSchoolyearGet()); $this->displayTpl('changeClassteacher.tpl'); }
/** * Deletes the Classes that were removed in the Change-User-dialog * * @param string $userId The User-ID * @param array $existingClasses A flattened array of classes that the * User already has */ protected function classesDeleteDeleted($userId, $existingClasses) { if (isset($_POST['schoolyearAndClassData'])) { $flatClassInput = ArrayFunctions::arrayColumn($_POST['schoolyearAndClassData'], 'statusId', 'classId'); } else { $flatClassInput = array(); } $stmtDelete = $this->_pdo->prepare('DELETE FROM KuwasysUsersInClasses WHERE UserID = :id AND ClassID = :classId'); foreach ($existingClasses as $exClassId => $exStatusId) { if (!isset($flatClassInput[$exClassId]) || $flatClassInput[$exClassId] != $exStatusId) { $stmtDelete->execute(array(':id' => $userId, ':classId' => $exClassId)); } } }
/** * Fetches the Data for the Soli-Settings Form * * @return Array The fetched data */ protected function soliSettingsDataFetch() { try { $stmt = $this->_pdo->query('SELECT `name`, `value` FROM SystemGlobalSettings WHERE `name` IN("soli_price", "solipriceEnabled", "seperateSoliPrices");'); $data[0] = ArrayFunctions::arrayColumn($stmt->fetchAll(), 'value', 'name'); $stmt = $this->_pdo->query('SELECT * FROM BabeskPriceClasses GROUP BY pc_id'); $data[1] = $stmt->fetchAll(); } catch (PDOException $e) { $this->_interface->dieError(_g('Could not fetch the Data!')); } return $data; }
/** * Displays a MainMenu to the User * * Dies displaying the Main Menu */ protected function mainMenu() { $grades = $this->gradesGetAll(); $this->_smarty->assign('grades', ArrayFunctions::arrayColumn($grades, 'gradename', 'ID')); $this->displayTpl('mainmenu.tpl'); }
/** * Adds Pricegroup-IDs to the elements if they contain pricegroup-names * * Dies displaying a Message on Error * Uses 'pricegroup' => <pricegroupName> * Adds 'pricegroupId' => <pricegroupId> */ protected function pricegroupIdsAppendToColumns() { $allPricegroups = TableMng::query('SELECT ID, LOWER(name) AS name FROM BabeskPriceGroups pg'); $flatPricegroups = ArrayFunctions::arrayColumn($allPricegroups, 'name', 'ID'); foreach ($this->_contentArray as &$con) { if (!empty($con['pricegroup'])) { $pricegroup = $con['pricegroup']; $id = array_search(strtolower($pricegroup), $flatPricegroups); if ($id !== false) { $con['pricegroupId'] = $id; } else { $this->errorDie(_g('Could not find the Pricegroup %1$s!', $pricegroup)); } } } }