Advertisement
fahmi_auliya

Advance Search - Yii CDbCriteria

Oct 11th, 2013
204
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.58 KB | None | 0 0
  1. $criteria = new CDbCriteria;
  2. $criteria->with     = array(
  3.     'confirm'       => array(
  4.         'alias'     => 'co',
  5.         'select'    => 'co.confirm_date'
  6.     ),
  7.     'users_group'   => array(
  8.         'alias'     => 'g',
  9.         'select'    => 'g.name'
  10.     ),
  11.     'jobseeker_bio' => array(
  12.         'alias'     => 'b',
  13.         'select'    => 'b.complete_name, b.birth_place, b.status, TIMESTAMPDIFF(YEAR,`b.birth_date`,CURDATE()) AS age'
  14.     ),
  15.     'last_edu'      => array(
  16.         'alias'     => 'e',
  17.         'select'    => 'e.thesis_title, e.role_year, e.finish_year, e.ipk',
  18.     ),
  19.     'jobseeker_bio.origin_province' => array(
  20.         'alias'     => 'op',
  21.         'select'    => 'op.name'
  22.     ),
  23.     'jobseeker_bio.origin_city' => array(
  24.         'alias'     => 'oc',
  25.         'select'    => 'oc.name'
  26.     ),
  27.     'jobseeker_bio.province'    => array(
  28.         'alias'     => 'p',
  29.         'select'    => 'p.name'
  30.     ),
  31.     'jobseeker_bio.city'    => array(
  32.         'alias'     => 'c',
  33.         'select'    => 'c.name'
  34.     ),
  35.     'last_edu.university'   => array(
  36.         'alias'     => 'u',
  37.         'select'    => 'u.name',
  38.     ),
  39.     'last_edu.last_major'   => array(
  40.         'alias'     => 'm',
  41.         'select'    => 'm.name'
  42.     ),
  43.     'last_exp'      => array(
  44.         'alias'     => 'x',
  45.         'select'    => 'x.position, x.role_date, x.exit_date',
  46.     ),
  47.     'last_exp.industry' => array(
  48.         'alias'     => 'i',
  49.         'select'    => 'i.name'
  50.     ),
  51.     'last_exp.vacancy_function' => array(
  52.         'alias'     => 'f',
  53.         'select'    => 'f.name'
  54.     ),
  55.     'last_exp.careerpedia_position' => array(
  56.         'alias'     => 'cp',
  57.         'select'    => 'cp.job_position'
  58.     )
  59. );
  60. $criteria->select = 't.email, t.block, t.register_date';
  61.  
  62. // Search the user group condition
  63. if ($this->users_group_id != null)
  64.     $criteria->compare('t.users_group_id',$this->users_group_id);
  65. else
  66.     $criteria->compare('t.users_group_id',array(4,5,6,7,8));
  67.    
  68. // Search between condition on register date
  69. if ($this->register_date_start != null && $this->register_date_end != null) {
  70.     $start  = date('Y-m-d H:i:s', strtotime($this->register_date_start));
  71.     $end    = date('Y-m-d H:i:s', strtotime($this->register_date_end));
  72.     $criteria->addBetweenCondition('t.register_date', $start, $end);
  73. }
  74.  
  75. $criteria->compare('b.birth_place', $this->birth_place_search, true);
  76. $criteria->compare('b.sex', $this->sex_search);
  77.  
  78. if ($this->city_search != null)
  79.     $criteria->compare('b.city_id', $this->city_search);
  80. else
  81.     $criteria->compare('b.province_id', $this->province_search);
  82.  
  83. if ($this->origin_city_search != null)
  84.     $criteria->compare('b.origin_city_id', $this->origin_city_search);
  85. else
  86.     $criteria->compare('b.origin_province_id', $this->origin_province_search);
  87.  
  88. if ($this->age_start != null && $this->age_end != null)
  89.     $criteria->addBetweenCondition('((YEAR(CURDATE())-YEAR(b.birth_date)) - (RIGHT(CURDATE(),5)<RIGHT(b.birth_date,5)))',$this->age_start,$this->age_end);
  90.  
  91. $criteria->compare('b.status', $this->marital_status_search);
  92.  
  93. $criteria->compare('e.univ_name_id', $this->university_id);
  94. $criteria->compare('e.degree', $this->degree_search);
  95. $criteria->compare('e.ccn_major_id', $this->major_search);
  96. $criteria->compare('e.ccn_major_id', $this->major_search);
  97. $criteria->compare('e.ccn_major_id', $this->major_search);
  98.  
  99. if ($this->role_year_start != null && $this->role_year_end != null)
  100.     $criteria->addBetweenCondition('e.role_year', $this->role_year_start, $this->role_year_end);
  101.  
  102. if ($this->finish_year_start != null && $this->finish_year_end != null)
  103.     $criteria->addBetweenCondition('e.finish_year', $this->finish_year_start, $this->finish_year_end);
  104.  
  105. if ($this->ipk_search != null)
  106.     $criteria->compare('e.ipk', '>= '.$this->ipk_search);
  107.  
  108. $criteria->compare('x.position', $this->job_pos_search);
  109.  
  110. $criteria->compare('t.block',$this->block);
  111.  
  112. if(!isset($_GET['AdvanceSearch_sort']))
  113.     $criteria->order = 't.register_date DESC';
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement