Example #1
0
 public function getList($pref = NULL)
 {
     // パラメータ範囲チェックと補正(デフォルト:東京)
     if (!($pref >= 1 && $pref <= 47)) {
         $pref = 13;
     }
     $prefLines = $this->find('all', array('conditions' => array('Station.pref_cd' => $pref), 'fields' => array('DISTINCT Station.line_cd', 'Station.line_name')));
     $combineLines = set::combine($prefLines, '{n}.Station.line_cd', '{n}.Station');
     $lineStations = $this->find('all', array('conditions' => array('Station.pref_cd' => $pref), 'fields' => array('Station.line_cd', 'Station.id', 'Station.station_name', 'Station.pref_cd')));
     foreach ($lineStations as $tmpVal) {
         $combineLines[$tmpVal['Station']['line_cd']]['id'][] = $tmpVal['Station']['id'];
         $combineLines[$tmpVal['Station']['line_cd']]['station_name'][] = $tmpVal['Station']['station_name'];
     }
     //debug($combineLines);
     return $combineLines;
 }
Example #2
0
  function index() {

    $this->layout = 'classifiedsIndex';

    // デフォルトパラメータ
    $argsList = Array(
      'page' => 1,
      'dir' => 0,
      'genre' => array(),
      'area' => array(),
      'wage' => array(),
      //'opt' => 0,
      //'parent' => false
		);

    // ソート定義
    $dirList = Array(
      array('Classified.modified' => 'DESC'), // 更新日の新しい順
      array('Classified.eval' => 'DESC'),  // 評価の高い順
      array('Classified.wage' => 'ASC'), // 時間あたり報酬の安い順
      array('Classified.wage' => 'DESC'), // 時間あたり報酬の高い順
      array('Classified.connected' => 'DESC'), // 面接数の多い順
      array('Classified.established' => 'DESC') // 成立数の多い順
		);

    // passedArgs取り込み
    // page
    if (isset($this->passedArgs['page'])) {
      $argsList['page'] = floor($this->passedArgs['page']);
    }
    // dir
    if (isset($this->passedArgs['dir'])) {
      $argsList['dir'] = floor($this->passedArgs['dir']);
      // range check
      if ($argsList['dir'] < 0 || $argsList['dir'] > 5) {
        $argsList['dir'] = 0;
      }
    }
    
    // genre genre指定の場合はcookieを上書き genreがない場合はcookieから読み込み
    if (isset($this->passedArgs['genre'])) {
      $argsList['genre'] = explode(':', $this->passedArgs['genre']);
      // genreの範囲逸脱
      if (isset($this->passedArgs['genre'])) {
        if ($argsList['genre'][0] > 58) {
          $argsList['genre'][0] = 7;
        }
        if ($argsList['genre'][0] >= 13 && $argsList['genre'][0] <= 16) {
          $argsList['genre'][0] = 7;
        }
        if ($argsList['genre'][0] >= 25 && $argsList['genre'][0] <= 28) {
          $argsList['genre'][0] = 7;
        }
        if ($argsList['genre'][0] >= 37 && $argsList['genre'][0] <= 38) {
          $argsList['genre'][0] = 7;
        }
        if ($argsList['genre'][0] >= 47 && $argsList['genre'][0] <= 50) {
          $argsList['genre'][0] = 7;
        }
      }
      
      $writeCookie = Array('genre' => $argsList['genre']);
      $writeCookie = serialize($writeCookie);
      $this->Cookie->write('Genre', $writeCookie, true, '+2 weeks');
    } else {
      $cookieData = $this->Cookie->read('Genre');
      $cookieData = unserialize($cookieData);
      if (isset($cookieData['genre'])) {
				$argsList['genre'] = $cookieData['genre'];
			} else {
        // ほんとうになんにもgenreを指定していない場合
        $argsList['genre'][0] = 7;
      }
    }
    
    
    
    // area area指定の場合はcookieを上書き areaがない場合はcookieから読み込み
    if (isset($this->passedArgs['area'])) {
      $argsList['area'] = explode(':', $this->passedArgs['area']);
      // areaの範囲逸脱 ->  1..856
      if (isset($this->passedArgs['area'])) {
        if ($argsList['area'][0] > 856) {
          $argsList['area'][0] = 2;
        }
      }
      $writeCookie = Array('area' => $argsList['area']);
      $writeCookie = serialize($writeCookie);
      $this->Cookie->write('Area', $writeCookie, true, '+2 weeks');
    } else {
      $cookieData = $this->Cookie->read('Area');
      $cookieData = unserialize($cookieData);
      //debug($cookieData);
      if (isset($cookieData['area'])) {
				$argsList['area'] = $cookieData['area'];
			} else {
        $argsList['area'] = array( 0 ); // area指定がなくcookieにも記録がない場合
      }
    }
    
    
    // wage
    if (isset($this->passedArgs['wage'])) {
      $argsList['wage'] = explode(':', $this->passedArgs['wage']);
    }
    // opt
    if (isset($this->passedArgs['opt'])) {
      $argsList['opt'] = ceil($this->passedArgs['opt']);
    }

    // 親genreのみ指定の場合
    /*
    if ($argsList['genre'][0] <= 6) {
      $argsList['parent'] = true;
      switch ($argsList['genre'][0]) {
        case 1:
          $argsList['genre'] = explode(':', '7:8:9:10:11:12');
          break;
        case 2:
          $argsList['genre'] = explode(':', '19:20:21:22:23:24');
          break;
        case 3:
          $argsList['genre'] = explode(':', '31:32:33:34:35:36');
          break;
        case 4:
          $argsList['genre'] = explode(':', '41:42:43:44:45:46');
          break;
        case 5:
          $argsList['genre'] = explode(':', '53:54:55:56:57:58'); // 引数見直し!!!
          break;
        default:
          $argsList['genre'][0] = 7;
          $argsList['parent'] = false;
          break;
      }
    }
    */
    
    // GenreとAreaのHABTMテーブルをJOINして、GenreとAreaの条件を指定して検索
    // classified_idでDISTINCTして結果出力
    
    if ($argsList['area'][0] == 0) {
      $idList = $this->ClassifiedsGenre->idlists($argsList['genre']);
    } else {
      $idList = $this->AreasClassified->idlists($argsList['area'], $argsList['genre']);
    }
    
    
    /*
    if ($argsList['area'][0] == 0) {

      // area の指定がない場合の検索
      $singleTable = $this->ClassifiedsGenre->find('all', array(
        'fields' => array(
            'DISTINCT ClassifiedsGenre.classified_id'
        ),
        'conditions' => array(
            'ClassifiedsGenre.genre_id' => $argsList['genre']
        )
      ));
      // classifiedIdの抽出
      $idList = Array();
      foreach ($singleTable as $tmpData) {
        $idList[] = $tmpData['ClassifiedsGenre']['classified_id'];
      }

    } else {

      // area がある場合はtable joinして検索
      $joinTable = $this->AreasClassified->find('all', array(
        'joins' => array(
            array(
                'type' => 'inner',
                'table' => 'classifieds_genres',
                'alias' => 'ClassifiedsGenre',
                'conditions' => array(
                    'AreasClassified.classified_id = ClassifiedsGenre.classified_id'
                )
            )
        ),
        'fields' => array(
            'DISTINCT AreasClassified.classified_id'
        ),
        'conditions' => array(
            'AreasClassified.area_id' => $argsList['area'],
            'ClassifiedsGenre.genre_id' => $argsList['genre']
        )
      ));

      // 次の検索に渡すためにclassified_idだけのリストにする
      $idList = Array();
      foreach ($joinTable as $tmpData) {
        $idList[] = $tmpData['AreasClassified']['classified_id'];
      }

    }*/

    //debug($joinTest);
    //debug($idList);
    
    // HABTMバインドを設定
    $this->Classified->bindModel(array('hasAndBelongsToMany' => array('Genre','Area')), false);
    $this->Classified->bindModel(array('belongsTo' => array('User')), false);
    /*
    $results = $this->Classified->find('all', array(
      'conditions' => array(
        //'Classified.option & 2',
        'Classified.wage BETWEEN ? AND ?' => array(1000,1100),
        'Classified.id' => $idList
      )
    ));
    */

    // paginate検索を実行
    // ここでclassified側の検索条件を適用
    $this->paginate = array(
      'limit' => 10,
      'page' => $argsList['page'],
      'order' => $dirList[$argsList['dir']]
    );

    // classified検索条件の設定
    $classifiedConditions = Array();
    if (!empty($argsList['wage'])) {
      $classifiedConditions['Classified.wage BETWEEN ? AND ?'] = $argsList['wage'];
    }
    /*
    if ($argsList['opt'] != 0) {
      $classifiedConditions[] = 'Classified.option & ' . $argsList['opt'];
    }
    */
    $classifiedConditions['Classified.id'] = $idList;
    $classifiedConditions['Classified.user_class'] = TEACHER;
    $classifiedConditions['Classified.stat'] = CPUBLIC;
    //debug($classifiedConditions);

    //$listClassified = $this->paginate($this->Classified, array(
      //'Classified.wage BETWEEN ? AND ?' => array(1000,1100),
      //'Classified.id' => $idList
    //));

    $listClassified = $this->paginate($this->Classified, $classifiedConditions);

    // connectlist検索用の最終classified_idリストを抽出
    $classifiedIds = set::combine($listClassified, '{n}.Classified.id');
		$classifiedIds = array_keys($classifiedIds);
    //debug($classifiedIds);

    // loginデータがあるとして
    // $userInfo取得
		$this->_user();

    //$loginData = Array(
      //'isLogin' => true,
      //'id' => '1',
      //'nickname' => 'sample'
		//);

    // connectlistのデータを検索
    // idが取得できることが前提
    /*
    if (!empty($this->userInfo['id'])) {
      $conditions = Array(
        'conditions' => array(
          'Connectlist.student_id' => $this->userInfo['id'],
          'Connectlist.teacher_cid' => $classifiedIds
				),
				'fields' => array(
          'Connectlist.id','Connectlist.teacher_cid','Connectlist.bookmark','Connectlist.stat'
				)
			);
      
			$listResults = $this->Connectlist->find('all', $conditions);

      // $listResultsをteacher_cidをkeyに組み直し
      $listConnect = Array();
      foreach($listResults as $tmpValue) {
        $listConnect[$tmpValue['Connectlist']['teacher_cid']] = array(
          'id' => $tmpValue['Connectlist']['id'],
          'bookmark' => $tmpValue['Connectlist']['bookmark'],
          'stat' => $tmpValue['Connectlist']['stat']
        );
      }
    }

    // $listClassifiedにConnectlistからの値を合成
    foreach($listClassified as $tmpKey => $tmpValue) {
			if(isset($listConnect[$tmpValue['Classified']['id']])) {
        $listClassified[$tmpKey]['Classified']['connect_id'] = $listConnect[$tmpValue['Classified']['id']]['id'];
				$listClassified[$tmpKey]['Classified']['connect_stat'] = $listConnect[$tmpValue['Classified']['id']]['stat'];
				$listClassified[$tmpKey]['Classified']['connect_bookmark'] = $listConnect[$tmpValue['Classified']['id']]['bookmark'];
			} else {
        $listClassified[$tmpKey]['Classified']['connect_id'] = 0;
				$listClassified[$tmpKey]['Classified']['connect_stat'] = 0;
				$listClassified[$tmpKey]['Classified']['connect_bookmark'] =0;
			}
		}
    */
    
    // view用データ作成
    $viewData = array();
    $viewData['genre'] = $this->Genre->getGenreName($argsList['genre'][0]);
    if ($argsList['area'][0] != 0) {
      //$viewData['area'] = $this->Area->find('first', array('conditions' => array('Area.id' => $argsList['area'][0])));
      $viewData['area'] = $this->Area->getAreaName($argsList['area'][0]);
    }
    
    //debug($argsList);
    
    $this->set('listClassified', $listClassified);
    $this->set('argsList', $argsList);
    $this->set('viewData', $viewData);

    $this->set('areaParentValue', $this->Area->getAreaParentValue());
    $this->set('areaValue', $this->Area->getAreaValue());
    
    $this->set('path', $this->Genre->getLinkParam($argsList['genre'][0], $viewData['genre']['parent_genre_id']));
    
    $this->set('userInfo', $this->userInfo);
    
    //$voidView = FALSE;
    //$this->set('voidView', $voidView);

  }
	function index($mode = Null) {
    // layout指定
		$this->layout = 'connectlistsIndex';

		// $userInfo取得
		$this->_user();

    // paginateの準備
    $this->paginate = array(
      'limit' => 10,
      'order' => array('Connectlist.modified' => 'DESC')
    );

    //
    switch ($mode) {
      case BOOKMARK:
        $indexMode = ($this->userInfo['class'] == STUDENT ? BOOKMARK : ALL);
        break;
      case ARCHIVE:
        $indexMode = ARCHIVE;
        break;
      case CONNECTLIST:
        $indexMode = ($this->userInfo['class'] == STUDENT ? CONNECTLIST : ALL);
        break;
      default:
        $indexMode = ALL;
        break;
    }

    // 受け渡し用変数宣言
    $listList = Array();

    if ($this->userInfo['class'] == STUDENT) { // 生徒の場合
      switch ($indexMode) {
        case CONNECTLIST:
          $listData = $this->paginate($this->Connectlist, array(
            'Connectlist.student_id' => $this->userInfo['id'],
            'Connectlist.bookmark' => 0,
            'NOT Connectlist.archive & 2'
          ));
          break;
        case BOOKMARK:
          $listData = $this->paginate($this->Connectlist, array(
            'Connectlist.student_id' => $this->userInfo['id'],
            'Connectlist.bookmark' => STUDENT,
          ));
          break;
        case ARCHIVE:
          $listData = $this->paginate($this->Connectlist, array(
            'Connectlist.student_id' => $this->userInfo['id'],
            'Connectlist.archive & 2'
          ));
          break;
        default:
          $listData = $this->paginate($this->Connectlist, array(
            'Connectlist.student_id' => $this->userInfo['id'],
            'NOT Connectlist.archive & 2'
          ));
          break;
      }
      // classifiedId / userId のリストを取得
      $classifiedIds = set::combine($listData, '{n}.Connectlist.teacher_cid');
      $classifiedIds = array_keys($classifiedIds);
      $userIds = set::combine($listData, '{n}.Connectlist.teacher_id');
      $userIds = array_keys($userIds);

    } else if ($this->userInfo['class'] == TEACHER) { // 先生の場合 CONNECTLIST ARCHIVEのみ
      if ($indexMode != ARCHIVE) {
        $listData = $this->paginate($this->Connectlist, array(
          'Connectlist.teacher_id' => $this->userInfo['id'],
          'Connectlist.bookmark' => 0,
          'NOT Connectlist.archive & 1'
        ));
      } else {
        $listData = $this->paginate($this->Connectlist, array(
          'Connectlist.teacher_id' => $this->userInfo['id'],
          'Connectlist.archive & 1'
        ));
      }
      // classifiedId / userId のリストを取得
      $classifiedIds = set::combine($listData, '{n}.Connectlist.student_cid');
      $classifiedIds = array_keys($classifiedIds);
      $userIds = set::combine($listData, '{n}.Connectlist.student_id');
      $userIds = array_keys($userIds);
      
    }

    // Classifiedクエリ
    $classifiedData = $this->Classified->find('all', array(
      'conditions' => array(
        'Classified.id' => $classifiedIds
      )
    ));

    // Classified.idで組み直し
    $classifiedList = Array();
    foreach ($classifiedData as $tmpKey => $tmpValue) {
      $classifiedList[$tmpValue['Classified']['id']] = Array(
        'Classified' => $tmpValue['Classified']
      );
    }

    // Userクエリ
    $userData = $this->User->find('all', array(
      'conditions' => array(
        'User.id' => $userIds
      )
    ));

    // User.idで組み直し
    $userList = Array();
    foreach ($userData as $tmpKey => $tmpValue) {
      $userList[$tmpValue['User']['id']] = Array(
        'User' => $tmpValue['User']
      );
    }

    // Connectlistの順序で配列を合成
    if ($this->userInfo['class'] == STUDENT) { // 生徒の場合
      foreach ($listData as $tmpKey => $tmpValue) {
        $listList[$tmpKey] = Array(
          'Connectlist' => $tmpValue['Connectlist'],
          'Classified' => $classifiedList[$tmpValue['Connectlist']['teacher_cid']]['Classified'],
          'User' => $userList[$tmpValue['Connectlist']['teacher_id']]['User']
        );
      }
    } else if ($this->userInfo['class'] == TEACHER) { // 先生の場合 CONNECTLIST ARCHIVEのみ
      foreach ($listData as $tmpKey => $tmpValue) {
        $listList[$tmpKey] = Array(
          'Connectlist' => $tmpValue['Connectlist'],
          'Classified' => $classifiedList[$tmpValue['Connectlist']['student_cid']]['Classified'],
          'User' => $userList[$tmpValue['Connectlist']['student_id']]['User']
        );
      }
    }

    $this->set('listList', $listList);
    $this->set('indexMode', $indexMode);
    $this->set('userInfo', $this->userInfo);
    
	}