($library['lists'][$listId]['totalWeight'] !== 0), ]); $this->show = $show; $this->units = renderUnits($library['totalUnit']); $this->currencySymbol = $library['currencySymbol']; $this->totalUnit = $library['totalUnit']; $this->listName = $library['lists'][$listId]['name']; $this->listDescription = $parsedown->text($library['lists'][$listId]['description']); $this->listTotalQty = $library['lists'][$listId]['totalQty']; $this->listTotalWeight = $library['lists'][$listId]['totalWeight']; $this->listTotalWeightDisplay = mgToWeight($library['lists'][$listId]['totalWeight'], $library['totalUnit']); foreach ( $library['lists'] as $id => $list ) { $this->lists[] = [ 'id' => $list['id'], 'name' => $list['name'], 'active' => ($id == $listId) ]; } $list = $library['lists'][$listId]; $chartData = [ 'points' => [], 'total' => 0, ]; foreach ( $list['categoryIds'] as $id ) { $categoryId = array_search($id, $categoryIds); $points = []; $category = $library['categories'][$categoryId]; $category['items'] = []; $category['subtotalWeightDisplay'] = mgToWeight($category['subtotalWeight'], $library['totalUnit']); foreach ( $category['categoryItems'] as $item ) { $itemId = array_search($item['itemId'], $itemIds); $item = array_merge($item, $library['items'][$itemId]); $item['displayWeight'] = mgToWeight($item['weight'], $item['authorUnit']); $item['units'] = renderUnits($item['authorUnit']); $itemWeight = ($item['weight'] * $item['qty']); $itemName = $item['name'].': '.mgToWeight($item['weight'], $item['authorUnit']).' '.$item['authorUnit']; $category['items'][] = $item; // calculate chartData if ( $itemWeight == 0 ) continue; if ( $item['qty'] > 1 ) $itemName .= ' x '.$item['qty']; $points[] = [ 'id' => $item['id'], 'value' => $itemWeight, 'name' => $itemName, 'percent' => ($itemWeight / $category['subtotalWeight']), ]; } $this->categories[] = $category; //calculate chartData if ( $list['totalWeight'] == 0 ) continue; $chartData['total'] += $category['subtotalWeight']; $chartData['points'][] = [ 'id' => $category['id'], 'name' => $category['name'].': '.mgToWeight($category['subtotalWeight'], $library['totalUnit']).' '.$library['totalUnit'], 'color' => $category['color'], 'total' => $category['subtotalWeight'], 'points' => $points, 'visiblePoints' => false, ]; } //calculate chartData if ( $chartData['total'] !== 0 ) { foreach ( $chartData['points'] as $id => $point ) { $chartData['points'][$id]['percent'] = ($point['total'] / $chartData['total']); } $this->chartData = rawurlencode(json_encode($chartData)); } else { $this->chartData = false; } } }