select('t.id, t.title, t.tmc_type, t.status, t.employee, ta.name, ts.title as storage') ->from(Tmc::tableName() . ' t') ->leftJoin(Accounts::tableName() . ' ta', 'ta.id = t.employee') ->leftJoin(Storage::tableName() . ' ts', 'ts.id = t.storage') ; return $query->all(); } function getTmcsByStatus(int $status) { $query = new Query(); $query->select('t.id, t.title, t.tmc_type, t.status, t.employee, ta.name, ts.title as storage') ->from(Tmc::tableName() . ' t') ->leftJoin(Accounts::tableName() . ' ta', 'ta.id = t.employee') ->leftJoin(Storage::tableName() . ' ts', 'ts.id = t.storage') ->where(['t.status' => $status]) ; return $query->all(); } function sortTmc($tmcs) { $cameras = []; $phones = []; $oilMeters = []; foreach ($tmcs as $tmc) { switch ($tmc['tmc_type']) { case 1: $cameras = addTmc($cameras, $tmc); break; case 2: $oilMeters = addTmc($oilMeters, $tmc); break; case 3: $phones = addTmc($phones, $tmc); break; } } return [$cameras, $phones, $oilMeters]; } function getDataStorages() { $query = new Query(); $query->select('ts.title as storage, ts.warehouse, tw.title as w_title, ts.stack, tstack.title as s_title, ts.tmc, t.title as name, tstat.title as status, tstat.id as id_status, td.issue_date, ta.name AS user') ->from(Storage::tableName() . ' ts') ->leftJoin(Tmc::tableName() . ' t', 'ts.tmc = t.id') ->leftJoin(Log::tableName() . ' td', 'td.tmc = ts.tmc') ->leftJoin(Accounts::tableName() . ' ta', 'ta.id = td.employee') ->leftJoin(TmcStatus::tableName() . ' tstat', 't.status = tstat.id') ->leftJoin(Warehouse::tableName() . ' tw', 'tw.id = ts.warehouse') ->leftJoin(Stack::tableName() . ' tstack', 'tstack.id = ts.stack') ->groupBy('ts.id')//todo: надо ли? ; return $query->all(); } function getDevicesFromRows(array $rows) { /* * [warehouseId => [ * 'title' => string, * 'stacks' => [ * stackId => [ * 'title' => string, * 'tmcs' => [ * key => value, * ... * ] * ], * ... * ], * ... * ] * */ $devices = []; foreach ($rows as $row) { $devices[$row['warehouse']]['title'] = $row['w_title']; $devices[$row['warehouse']]['stacks'][$row['s_title']]['title'] = $row['s_title']; $devices[$row['warehouse']]['stacks'][$row['s_title']]['tmcs'][] = $row; } return $devices; } function sortDevicesAlph(array $devices) { //Сортируем в алфавитном порядке по title стеллажа foreach ($devices as $key => $device) { ksort($device['stacks']); $devices[$key] = $device; } return $devices; }