/** * Уникальные по заданному ключу и условию записи из таблицы * * @param $table * @param $condition * @param $field * @return CRecordSet */ public static function getDistinctWithCondition($table, $condition, $field) { $key = $table . "_" . $condition . "_distinct_" . $field; if (!self::getCache()->hasElement($key)) { $q = new CQuery(); $res = new CRecordSet(); $res->setManualAdd(true); $q->select("DISTINCT(" . $field . "), id")->from($table)->condition($condition . " GROUP BY " . $field); $r = $q->execute(); foreach ($r->getItems() as $item) { $record = new CActiveRecord($item); $record->setTable($table); $distinct = self::getById($table, $record->getId()); $res->add($res->getCount(), $distinct); } self::getCache()->add($key, $res); } return self::getCache()->getItem($key); }