private static function buildDbArgs($conds = array()) { extract(array_merge(array('username' => '', 'factory' => '', 'factory_id' => null, 'customer' => null, 'name' => '', 'product_no' => '', 'order_no' => '', 'time_start' => '', 'time_end' => '', 'type' => null, 'state' => null), $conds)); $tables = array(self::$table . ' as o'); $conds = array(); if ($name) { $conds['p.name LIKE ?'] = '%' . $name . '%'; } if ($product_no) { $conds['p.no=?'] = $product_no; } if ($order_no) { $conds['o.order_no=?'] = $order_no; } if ($time_start) { $conds['o.submit_time >= ?'] = $time_start; } if ($time_end) { $conds['o.submit_time <= ?'] = $time_end; } if ($type) { $conds['p.type=?'] = $type; } if ($state) { $conds['o.state=?'] = $state; } else { $conds['o.state <> ?'] = 'InCart'; // for all } if ($username) { $user = User::createByName($username); $customer = $user->instance(); $conds['o.customer=?'] = $customer->id; } if ($factory) { $factory = Factory::createByName($factory); if (empty($factory)) { throw new Exception("cannot find factory: {$factory}"); } $conds['o.factory=?'] = $factory->id; } if ($factory_id) { $conds['o.factory = ?'] = $factory_id; } if ($customer) { if (is_numeric($customer)) { $conds['o.customer=?'] = $customer; } } if ($name || $product_no || $type) { $tables[] = Product::$table . ' as p'; } return compact('conds', 'tables'); }