/** * Get additional content data selected * * @param $result = Query result */ public static function post_find($result) { if ($result !== null) { if (is_array($result)) { foreach ($result as $item) { // It will first check if we already have result in temporary result, // and only execute query if we dont. That way we dont have duplicate queries // Get products $item->get_products = static::lazy_load(function () use($item) { return Model_Products::find(array('where' => array('order_id' => $item->id))); }, $item->id, 'products'); // Get order payments $item->get_payments = static::lazy_load(function () use($item) { return \Payment\Model_Payment::find(array('where' => array('order_id' => $item->id), 'order_by' => array('id' => 'desc'))); }, $item->id, 'payments'); // Get last payment status $item->get_last_payment = static::lazy_load(function () use($item) { $payments = \Payment\Model_Payment::find(array('where' => array('order_id' => $item->id), 'order_by' => array('id' => 'desc'))); return isset($payments[0]) ? $payments[0] : array(); }, $item->id, 'last_payment', 'object'); // Get history $item->get_history = static::lazy_load(function () use($item) { return Model_History::find(array('where' => array('order_id' => $item->id), 'order_by' => array('created_at' => 'desc'))); }, $item->id, 'history'); // Get artworks $item->get_artwork = static::lazy_load(function () use($item) { return Model_Artwork::find(array('where' => array('order_id' => $item->id))); }, $item->id, 'artwork'); // Get artworks status $item->get_artwork_status = static::lazy_load(function () use($item) { $out = array(0, 0); $products = Model_Products::find(array('where' => array('order_id' => $item->id, 'artwork_required' => 1))); if (!$products) { return $out; } $out[0] = count($products); foreach ($products as $product) { if ($product->artwork) { $out[1]++; } } return $out; }, $item->id, 'artwork_status', 'array'); // Get order user object $item->get_user = static::lazy_load(function () use($item) { return \Sentry::user((int) $item->user_id); }, $item->id, 'user', 'object'); } } } // return the result return $result; }
/** * Get additional content data selected * * @param $result = Query result */ public static function post_find($result) { if ($result !== null) { if (is_array($result)) { foreach ($result as $item) { // It will first check if we already have result in temporary result, // and only execute query if we dont. That way we dont have duplicate queries // Get products $item->get_artwork = static::lazy_load(function () use($item) { return Model_Artwork::find(array('where' => array('order_product_id' => $item->id), 'order_by' => array('type' => 'asc'))); }, $item->id, 'artwork'); } } } // return the result return $result; }