private function _buildQuery() { $treeId = intval($this->getTreeId()); $levels = JoaktreeHelper::getUserAccessLevels(); $displayAccess = JoaktreeHelper::getDisplayAccess(); $query = $this->_db->getQuery(true); // select from persons $query->select(' jpn.id '); $query->select(' jpn.app_id '); $query->select(' MIN( ' . JoaktreeHelper::getSelectFirstName() . ' ) AS firstName '); $query->select(' MIN( ' . JoaktreeHelper::getSelectPatronym() . ' ) AS patronym '); $query->select(' MIN( ' . JoaktreeHelper::getConcatenatedFamilyName() . ' ) AS familyName '); $query->select(' MIN( ' . JoaktreeHelper::getSelectBirthYear() . ' ) AS birthDate '); $query->select(' MIN( ' . JoaktreeHelper::getSelectDeathYear() . ' ) AS deathDate '); $query->from(' #__joaktree_persons jpn '); // select from admin persons $query->innerJoin(JoaktreeHelper::getJoinAdminPersons(false)); // select from tree x persons $query->innerJoin(' #__joaktree_tree_persons jtp ' . ' ON ( jtp.app_id = jpn.app_id ' . ' AND jtp.person_id = jpn.id ' . ' ) '); $query->innerJoin(' #__joaktree_trees jte ' . ' ON ( jte.app_id = jtp.app_id ' . ' AND jte.id = jtp.tree_id ' . ' AND jte.published = true ' . ' AND jte.access IN ' . $levels . ' ' . ' ) '); // select from birth and death $query->leftJoin(JoaktreeHelper::getJoinBirth()); $query->leftJoin(JoaktreeHelper::getJoinDeath()); // Get the WHERE, GROUP BY and ORDER BY clauses for the query $wheres = $this->_buildContentWhere(); foreach ($wheres as $where) { $query->where(' ' . $where . ' '); } $query->group(' jpn.id '); $query->group(' jpn.app_id '); $query->order(' ' . $this->_buildContentOrderBy() . ' '); return $query; }