params['data']['Geo']['city_id']; $unis = $this->School->find('list', array('fields'=>array('School.name'), 'conditions' => array('city_id = '.intval($city_id)), 'order'=>array('School.name'=>'ASC'))); if ($this->params['requested']){return $unis;} $this->set('option',$unis); $this->set('empty',9); $this->render('/com/options'); } function index() { $geouni = array(); $this->pageTitle ='ОДНОКЛАССНИКИ :: Список школ на нашем сайте :: Поиск выпускников одноклассников одногруппников земляков '; if (isset($this->passedArgs[0]) && is_numeric($this->passedArgs[0]) && !isset($this->passedArgs[1]) ) { $country_id = intval($this->passedArgs[0]); $this->Session->del('region_id'); $geouni = array('country_id' => intval($country_id)); } if (isset($this->passedArgs[1]) && is_numeric($this->passedArgs[1]) || $this->Session->check('region_id')) { if (isset($this->passedArgs[1])) { $region_id = intval($this->passedArgs[1]); $this->Session->write('region_id', $region_id); } else { $region_id = $this->Session->read('region_id'); } if (isset($this->passedArgs[0])) $country_id =intval($this->passedArgs[0]); else $country_id = 0; $geouni = array('region_id' => intval($region_id),'country_id' => intval($country_id)); // 'cache'=>'1 day' $this->School->Behaviors->attach('Containable'); $this->School->bindModel(array('belongsTo' => array('City'))); $this->paginate = array( 'order'=>array('School.name' => 'asc'), 'conditions'=> array('City.region_id' => intval($region_id)), 'limit' => 30, 'fields'=> array('School.id','School.name','School.count'), 'contain'=>array('City'=>array('conditions'=> array(), 'fields'=> array('City.name')) )); $unis = $this->paginate(); $this->set('unis',$unis); $this->pageTitle ='ОДНОКЛАССНИКИ :: Список школ на нашем сайте :: выбор региона '.$region_id .':: Поиск выпускников одноклассников одногруппников земляков '; } $this->set('geouni',$geouni); $this->keywords_for_layout = 'ОДНОКЛАССНИКИ, одногруппники , Поиск выпускников одноклассников одногруппников земляков'; $this->description_for_layout = 'Список школ на нашем сайте :: Поиск выпускников одноклассников одногруппников земляков'; $this->elements_right = array('info/school'=>array()); } function view($id = null){ if(!is_numeric($id))$this->cakeError('error404'); $this->School->bindModel(array('belongsTo' => array('City'))); $this->School->City->bindModel(array('belongsTo' => array('Region'))); $this->School->City->bindModel(array('belongsTo' => array('Country'))); $this->School->recursive = 2; $this->School->bindModel(array('hasAndBelongsToMany' => array('User' =>array('className' => 'User', 'joinTable' => 'educations', 'foreignKey' => 'school_id', 'conditions' => array('type = 1'), 'associationForeignKey'=> 'user_id' )), 'hasMany' => array('Comment'=>array('conditions' => array('class' => 'School'), 'foreignKey'=>'foreign_id')))); $this->School->id = $id; $this->School->recursive = 2; $group = $this->School->read(); //debug($group); $this->set('group',$group); $this->elements_right = array('scoolmenu'=> array('entity'=>$group['School'])); $this->pageTitle = 'Школа '.$group['School']['name'].' '.$group['City']['name'].' '.$group['City']['Region']['name'].' '.$group['City']['Country']['name'].' | бывшие выпускники и одноклассники'; $this->keywords_for_layout = $group['School']['name'].' :: '.$group['City']['Country']['name'].' :: '.$group['City']['Region']['name'].' :: '.$group['City']['name'].' :: '.' бывшие выпускники и одноклассники'; $this->description_for_layout = 'открытая группа одноклассников и выпускников из '.$group['School']['name'].' :: '.$group['City']['Country']['name'].' :: '.$group['City']['Region']['name'].' :: '.$group['City']['name'].' :: '.'бывшие выпускники и одноклассники'; } } 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"); } }