/** * @test * @dataProvider provideColumnOrderings */ public function columnOrder($columns, $array, $expected) { $actual = ArrayFunctions::columnOrder($columns, $array); $this->assertInternalType('array', $actual); $this->assertEquals($expected, $actual); $this->assertSame($expected, $actual); }
/** * Fetches from db and returns the group with the given Id * @param int $nodeId The Id of the group * @return Group The group and its children */ protected function subGroupLoadById($nodeId) { try { $res = $this->_pdo->query("SELECT node.ID AS ID, node.name AS name, node.lft AS lft,\n\t\t\t\t\tnode.rgt AS rgt\n\t\t\t\tFROM SystemGroups AS node,\n\t\t\t\t\tSystemGroups AS parent\n\t\t\t\tWHERE node.lft BETWEEN parent.lft AND parent.rgt\n\t\t\t\t\tAND parent.id = {$nodeId}\n\t\t\t\tGROUP BY node.ID\n\t\t\t\tORDER BY node.lft ASC"); $nestedSet = $res->fetchAll(\PDO::FETCH_ASSOC); $data = \ArrayFunctions::nestedSetToArray($nestedSet); return $this->arrayToGroupObj($data[0]); } catch (\PDOException $e) { $this->_logger->log('error loading the groups', 'Notice', Null, json_encode(array('msg' => $e->getMessage()))); return false; } return $data; }
/** * Returns a new array with all elements which have a null value removed. * * @param array $array * @return array */ public static function withoutNullValues(array $array) { $result = []; foreach ($array as $key => $value) { if (is_array($value)) { $result[$key] = ArrayFunctions::withoutNullValues($value); continue; } if ($value !== null) { $result[$key] = $value; } } return $result; }
/** * 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)); } } } }
/** * @test * @param array $a * @param array $b * @param array $expected * @dataProvider mergeArraysProvider */ public function mergeArrays(array $a, array $b, array $expected) { $this->assertEquals($expected, ArrayFunctions::mergeArrays($a, $b)); }
/** * @param array $matrix * @test * @dataProvider provideMatrix */ public function matrixFilterStartsWith(array $matrix) { $this->assertCount(3, $matrix); $filtered = ArrayFunctions::matrixFilterStartswith($matrix, 'foo', 'ba'); $this->assertCount(2, $filtered); }
/** * Checks if something was selected by the user * @param array $choices the choices of the user * @return bool true if a selection exists, false if not */ private function somethingSelectedCheck($choices) { $unit = \ArrayFunctions::firstValue($choices); return $unit !== false && \ArrayFunctions::firstValue($unit) !== false; }