public function getProjectPromo($uid) { global $DB; require_once $_SERVER['DOCUMENT_ROOT'] . "/classes/professions.php"; $user_specs = professions::GetProfessionsByUser2($uid, true); if ($user_specs) { $category = implode(", ", $user_specs['prof_group']); $subcategory = implode(", ", $user_specs['prof']); } $sql = "SELECT \n p.id, p.post_date as create_date, p.cost, p.priceby, p.currency, p.name AS project_name, NULL AS cat_name, NULL AS subcat_name,\n p.kind, p.end_date, p.budget_type,\n co.country_name, ci.city_name, p.descr, e.uname as e_name, e.usurname as e_surname, e.login as e_login \n FROM projects p\n INNER JOIN employer e ON e.uid = p.user_id \n LEFT JOIN country co ON co.id = p.country \n LEFT JOIN city ci ON ci.id = p.city \n LEFT JOIN projects_blocked pb ON pb.project_id = p.id \n WHERE \n p.pro_only = true \n AND pb.project_id IS NULL\n AND p.cost > 0\n AND budget_type = 3\n AND p.closed = false\n AND p.kind <> 9 \n AND e.is_banned < 1::bit\n AND p.post_date > DATE_TRUNC('hour', now() - interval '2 day')\n " . (!empty($user_specs) ? " AND EXISTS (SELECT 1 from project_to_spec WHERE project_id = p.id AND (subcategory_id IN ({$subcategory}) OR ( category_id IN ({$category}) AND subcategory_id = 0 )))" : "") . "\n ORDER BY RANDOM() LIMIT 20"; $result = $DB->cache(300)->rows($sql); if ($result) { if (count($result) > 3) { //выбираем произвольно первые 3 проекта из запроса $rnd = array_rand($result, 3); return array($result[$rnd[0]], $result[$rnd[1]], $result[$rnd[2]]); } else { return $result; } } else { return false; } }