array('className' => 'Geo', 'conditions' => array('Geo.type' => '1')) ); */ var $validate = array( 'email' => array('mail' => array( 'rule' => array('email', true), 'allowEmpty' => false, 'message' => 'Проверьте правильность Email!'), 'unique' => array( 'rule' => 'isUnique', 'message' => 'В базе данных уже существует пользователь с таким Email.Eсли Вы уже регистрировались, но забыли пароль - воспользуйтесь функцией "забыли пароль".')), 'fname' => array( 'between' => array( 'rule' => array('between', 2, 25), 'message' => 'Пожалуйста укажите имя')), 'gender' => array( 'rule' => array('comparison', '>', 0), 'message' => 'Вы мужчина или женщина ?'), ); private function array_normalise( $array, $class ) { $array_temp = array(); foreach ($array as $element){ $array_temp[$class][] = $element[$class]; } return $array_temp; } function get_user_for_list($limit, $page){ $start = ($page-1)*$limit; $sql = 'SELECT `User`.`id`,`User`.`fname`, `User`.`sname`,`User`.`gender`,`User`.`img`, `Profile`.`profession`,`Profile`.`title`, `City`.`name`, `Education`.`year_end`, `School`.`id`,`School`.`name`, `Uni`.`id`, `Uni`.`name` FROM `users` AS `User` LEFT JOIN profiles AS `Profile` ON ( `User`.`id` = `Profile`.`id`) LEFT JOIN `geos` AS `Geo` ON ( `User`.`id` = `Geo`.`user_id`) LEFT JOIN `cities` AS `City` ON (`Geo`.`city_id` = `City`.`id`) LEFT JOIN `educations` AS `Education` ON (`User`.`id` = `Education`.`user_id`) LEFT JOIN `schools` AS `School` ON ( `Education`.`type` = 1 AND `Education`.`school_id` = `School`.`id` ) LEFT JOIN `unis` AS `Uni` ON ( `Education`.`type` = 3 AND `Education`.`school_id` = `Uni`.`id` ) WHERE `User`.`img` <> "" GROUP BY `User`.`id` ORDER BY `User`.`updated` desc LIMIT '.$start.','.$limit; return $this->query( $sql ); } function __paginate( $conditions, $fields, $order, $limit , $page = 1) { return $this->get_user_for_list($limit, $page); } function __paginateCount() { $sql = 'SELECT count(id) c FROM users WHERE img <> ""'; $r = $this->query($sql); return $r[0][0]['c']; } function get_all_gropus_name($user_id){ $sql = 'SELECT `Group`.`id`, `Group`.`name` FROM `groups_users` AS `GroupsUser` LEFT JOIN `groups` AS `Group` ON (`GroupsUser`.`group_id` = `Group`.`id`) WHERE `GroupsUser`.`user_id` = '.$user_id.' AND `GroupsUser`.`accept` = 1'; $groups = $this->query( $sql ); $groups = $this->array_normalise($groups, 'Group'); $sql = 'SELECT `City`.`id`, `City`.`name` FROM `geos` AS `Geo` LEFT JOIN `cities` AS `City` ON (`Geo`.`city_id` = `City`.`id`) WHERE user_id ='.$user_id; $cities = $this->query( $sql ); $cities = $this->array_normalise($cities, 'City'); $sql = 'SELECT `Uni`.`id`,`Uni`.`shortname`,`Uni`.`name` FROM `educations` AS `Education` LEFT JOIN `unis` AS `Uni` ON (`Education`.`school_id` = `Uni`.`id`) WHERE user_id = '.$user_id.' and type = 3'; $unis = $this->query( $sql ); $unis = $this->array_normalise($unis, 'Uni'); $sql = 'SELECT `School`.`id`,`School`.`name` FROM `educations` AS `Education` LEFT JOIN `schools` AS `School` ON (`Education`.`school_id` = `School`.`id`) WHERE user_id = '.$user_id.' and type = 1'; $schools = $this->query( $sql ); $schools = $this->array_normalise($schools, 'School'); // TODO tschools return array_merge($groups, $cities, $unis, $schools); } function get($id = null){ $this->id = $id; return $this->read(); } function search($data){ $sql = 'SELECT DISTINCT User.id, User.created, User.fname, User.sname, User.img, User.is_online, City.name from users User,cities City,geos where User.sname LIKE "%'.$data['sname'].'%" AND User.fname LIKE "%'.$data['fname'].'%" AND User.id = geos.user_id AND geos.type = 1 AND geos.city_id = City.id'; if ($data['country_id'] > 0) $sql .= ' AND geos.country_id = '.$data['country_id']; $sql .= ' limit 0,20 '; $this->query('INSERT INTO users_search(user_id,name,created ) values('.$data['user_id'].',"'.$data['sname'].','.$data['fname'].'",now())'); return $this->query( $sql ); } function kogo_iskali(){ return $this->query('select name from users_search order by id desc limit 0,100'); } function getCityID($id = null){ $city_id = $this->query("select city_id from geos where user_id = $id AND type = 1 "); //debug($city_id); return $city_id[0]['geos']['city_id']; } function get_latest($limit=5) { //$this->recursive = -1; $this->Behaviors->attach('Containable'); $this->bindModel(array('hasOne' => array('Geo'))); $this->Geo->bindModel(array('belongsTo' => array('City'))); //$this->Geo->bindModel(array('belongsTo' => array('Country')));'is_active = 1', $users = $this->find('all',array( 'order'=>array( 'User.id' => 'desc'), 'limit' => $limit, 'recursive' => 2, 'fields'=> array('User.id','created','fname','sname','img','is_online'), 'conditions' => array('img <> ""'), 'contain'=>array( 'Geo'=>array('conditions'=> array('type'=>1),'fields'=>array('Geo.id')), 'Geo.City'=>array('conditions'=> array(''),'fields'=>'name')) )); return $users; } function get_best($limit=5) { //$this->recursive = -1; $this->Behaviors->attach('Containable'); $this->bindModel(array('hasOne' => array('Profile'=>array('className'=>'Profile','foreignKey'=> 'id')))); $this->bindModel(array('hasOne' => array('Geo'))); $this->Geo->bindModel(array('belongsTo' => array('City'))); //$this->Geo->bindModel(array('belongsTo' => array('Country')));'is_active = 1', $users = $this->find('all',array( 'order'=> 'RAND()', 'limit' => $limit, 'recursive' => 2, 'fields'=> array('id','created','fname','sname','img','is_online'), 'conditions' => array('img <> ""','Profile.count_views > ' => 120), 'contain'=>array( 'Profile'=>array(), 'Geo'=>array('conditions'=> array('type'=>1),'fields'=>array('Geo.id')), 'Geo.City'=>array('conditions'=> array(''),'fields'=>'name')) )); return $users; } function look_too($user_id){ $query = 'SELECT DISTINCT user_id FROM guests WHERE guest_id IN (SELECT guest_id FROM guests WHERE user_id ='.$user_id.') limit 0,5'; return $this->query($query); } function what_is_empty($user_id) { return $this->query("select count(id) c from educations where user_id = $user_id AND type = 1"); } }