1. PHP / Говнокод #18856

    −11

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    38. 38
    39. 39
    40. 40
    41. 41
    42. 42
    43. 43
    44. 44
    45. 45
    46. 46
    47. 47
    48. 48
    public function find_all() {
            $result = parent::find_all();
    
            if ($result->count() > 0) {
                $parents_id = queryToArray::from($result->as_array())
                    ->where(function ($prod) {
                        return $prod->sys_type == 'PARENT';
                    })
                    ->select(function($k, $v) { return $v->id; })
                    ->result();
                if (count($parents_id)) {
                    $prices = unserialize(
                        Cache::instance()->get_or_call(
                            'prices_'.implode(':', $parents_id),
                             Date::HOUR * 6,
                            function() use ($parents_id) {
                                return serialize(
                                    queryToArray::from(
                                        DB::query(
                                            Database::SELECT, 
                                            'SELECT parent.id as id, (SELECT min(price) FROM products as child WHERE child.parent_id = parent.id AND child.shop_state IN (\'publicated\', \'booked\')) as min, (SELECT max(price) FROM products as child WHERE child.parent_id = parent.id AND child.shop_state IN (\'publicated\', \'booked\')) as max FROM products as parent WHERE parent.id IN :ids')
                                        ->param(':ids', $parents_id)
                                        ->execute()
                                        ->as_array())
                                    ->select(function ($k, $v) { 
                                        return array(
                                            'key' => $v['id'], 
                                            'value' => 
                                            array(
                                                'min' => (float) $v['min'], 
                                                'max' => (float) $v['max']));
    
                                    })
                                    ->result());
                        }));
                    
                    $products = $result->as_array();
                    foreach ($products as $product) {
                        if (isset($prices[$product->id])) {
                            $this->_set_prices($product, $prices[$product->id]);
                        }
                    }
                    return new Database_Result_Local($products, Database::instance()->last_query, $products[0]);
                }
            }
    
            return $result;
        }

    Запостил: Strannik1941, 12 Октября 2015

    Комментарии (4) RSS

    Добавить комментарий