Created
June 20, 2023 15:30
-
-
Save cesarockstar1985/5729129e4a45f3dff650368312b7a829 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// legacy/models/couple.php | |
/** | |
* Returns the search data for bookshelf | |
* | |
* @param string | |
* @param array | |
* @param array | |
* @return | |
* @access protected | |
*/ | |
protected function _findLessons($state, $query, $results = array()) { | |
if ($state == 'before') { | |
$results = $query; | |
$this->unbindAllModels(true); | |
$this->bindModel(array('hasOne' => array( | |
'Female' => array( | |
'className' => 'Users.User', | |
'foreignKey' => false, | |
'type' => 'INNER', | |
'conditions' => array( | |
'Female.id = Couple.female_id')), | |
'Male' => array( | |
'className' => 'Users.User', | |
'foreignKey' => false, | |
'type' => 'INNER', | |
'conditions' => array( | |
'Male.couple_id = Female.couple_id', | |
'Male.id = Couple.male_id')), | |
'FemaleLessonUser' => array( | |
'className' => 'Lessons.LessonsUser', | |
'foreignKey' => false, | |
'type' => 'INNER', | |
'conditions' => array( | |
'FemaleLessonUser.user_id = Female.id')), | |
'MaleLessonUser' => array( | |
'className' => 'Lessons.LessonsUser', | |
'foreignKey' => false, | |
'type' => 'INNER', | |
'conditions' => array( | |
'MaleLessonUser.lesson_id = FemaleLessonUser.lesson_id', | |
'MaleLessonUser.user_id = Male.id')), | |
'Lesson' => array( | |
'className' => 'Lessons.Lesson', | |
'foreignKey' => false, | |
'type' => 'INNER', | |
'conditions' => array( | |
'Lesson.id = MaleLessonUser.lesson_id')), | |
'MaleProfile' => array( | |
'className' => 'Profile', | |
'foreignKey' => false, | |
'type' => 'INNER', | |
'conditions' => array( | |
'MaleProfile.user_id = Male.id')), | |
'FemaleProfile' => array( | |
'className' => 'Profile', | |
'foreignKey' => false, | |
'type' => 'INNER', | |
'conditions' => array( | |
'FemaleProfile.user_id = Female.id')))), false); | |
if (isset($query['operation']) && $query['operation'] == 'count') { | |
$results['fields'] = array('COUNT(*)'); | |
} | |
return $results; | |
} elseif ($state == 'after') { | |
if (isset($query['operation']) && $query['operation'] == 'count') { | |
if (isset($query['group']) && is_array($query['group']) && !empty($query['group'])) { | |
return count($results); | |
} | |
return $results[0][0]['COUNT(*)']; | |
} | |
return $results; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment