function display($tpl = null) { // Get data from the model $items =& $this->get('Items'); $menus = JoaktreeHelper::getMenus('joaktree'); $this->assignRef('items', $items); $this->assignRef('menus', $menus); parent::display($tpl); }
function getJoaktreeList() { $related = array(); $jt_likes = array(); // we only searching for persons when currently one article is shown if ($this->_option == 'com_content' && $this->_view == 'article' && $this->_id) { $params = JComponentHelper::getParams('com_joaktree'); $indArticleLink = (int) $params->get('indArticleLink', 9); // we only searching for persons when Joaktree setting is set if ($indArticleLink != 0) { $displayAccess = JoaktreeHelper::getDisplayAccess(); $userAccess = JoaktreeHelper::getUserAccess(); $accessLevels = JoaktreeHelper::getUserAccessLevels(); // select the meta keywords from the item $query = $this->_db->getQuery(true); $query->select(' metakey '); $query->from(' #__content '); $query->where(' id = ' . (int) $this->_id . ' '); $this->_db->setQuery($query); if ($metakey = trim($this->_db->loadResult())) { // explode the meta keys on a comma $keys = explode(',', $metakey); // assemble any non-blank word(s) foreach ($keys as $key) { $key = trim($key); if ($key) { // no commas $jt_likes[] = $this->_db->escape($key); } } } // process the "jt_likes" - search in joaktree tables if (count($jt_likes)) { // select from Joaktree tables $query->clear(); $query->select(' jpn.app_id '); $query->select(' jpn.id '); $query->select(' CONCAT_WS( ' . $this->_db->quote(' ') . ' ' . ' , jpn.firstName ' . ' , jpn.namePreposition ' . ' , jpn.familyName ' . ' ) AS title '); $query->select(' NULL AS created '); $query->select(' jan.default_tree_id AS catid '); $query->select(' NULL AS cat_access '); $query->select(' NULL AS cat_state '); $query->from(' #__joaktree_persons jpn '); $query->innerJoin(' #__joaktree_admin_persons jan ' . ' ON ( jan.app_id = jpn.app_id ' . ' AND jan.id = jpn.id ' . ' AND jan.published = 1 ' . ' AND jan.page = 1 ' . ' AND ( (jan.living = false AND ' . $displayAccess['NAMEname']->notLiving . ' = 2 ) ' . ' OR (jan.living = true AND ' . $displayAccess['NAMEname']->living . ' = 2 ) ' . ' ) ' . ' ) '); $query->innerJoin(' #__joaktree_trees jte ' . ' ON ( jte.app_id = jan.app_id ' . ' AND jte.id = jan.default_tree_id ' . ' AND jte.published = true ' . ' AND jte.access IN ' . $accessLevels . ' ' . ' ) '); // section to set the where-clause if ($indArticleLink == 9) { // 9: All options $query->where(' jpn.id = "' . implode('" OR jpn.id = "', $jt_likes) . '" ' . ' OR CONCAT_WS( ' . $this->_db->quote('!') . ' ' . ' , jpn.app_id ' . ' , jpn.id ' . ' ) = "' . implode('" OR CONCAT_WS( ' . $this->_db->quote('!') . ' ' . ' , jpn.app_id ' . ' , jpn.id ' . ' ) = "', $jt_likes) . '" ' . ' OR CONCAT_WS( ' . $this->_db->quote(' ') . ' ' . ' , jpn.firstName ' . ' , jpn.namePreposition ' . ' , jpn.familyName ' . ' ) ' . ' LIKE "%' . implode('%" OR CONCAT_WS( ' . $this->_db->quote(' ') . ' ' . ' , jpn.firstName ' . ' , jpn.namePreposition ' . ' , jpn.familyName ' . ' ) LIKE "%', $jt_likes) . '%" '); } if ($indArticleLink == 1) { // 1: By ID $query->where(' jpn.id = "' . implode('" OR jpn.id = "', $jt_likes) . '" ' . ' OR CONCAT_WS( ' . $this->_db->quote('!') . ' ' . ' , jpn.app_id ' . ' , jpn.id ' . ' ) = "' . implode('" OR CONCAT_WS( ' . $this->_db->quote('!') . ' ' . ' , jpn.app_id ' . ' , jpn.id ' . ' ) = "', $jt_likes) . '" '); } if ($indArticleLink == 2) { // 2: By first name $query->where(' jpn.firstName ' . ' LIKE "%' . implode('%" OR jpn.firstName LIKE "%', $jt_likes) . '%" '); } if ($indArticleLink == 3) { // 3: By family name $query->where(' CONCAT_WS( ' . $this->_db->quote(' ') . ' ' . ' , jpn.namePreposition ' . ' , jpn.familyName ' . ' ) ' . ' LIKE "%' . implode('%" OR CONCAT_WS( ' . $this->_db->quote(' ') . ' ' . ' , jpn.namePreposition ' . ' , jpn.familyName ' . ' ) LIKE "%', $jt_likes) . '%" '); } if ($indArticleLink == 4 or $indArticleLink == 5) { // 4: By first + family name; 5: All names $query->where(' CONCAT_WS( ' . $this->_db->quote(' ') . ' ' . ' , jpn.firstName ' . ' , jpn.namePreposition ' . ' , jpn.familyName ' . ' ) ' . ' LIKE "%' . implode('%" OR CONCAT_WS( ' . $this->_db->quote(' ') . ' ' . ' , jpn.firstName ' . ' , jpn.namePreposition ' . ' , jpn.familyName ' . ' ) LIKE "%', $jt_likes) . '%" '); } // end section for setting where-clause -> continue with creating the query $query->order(' CONCAT_WS( ' . $this->_db->quote(' ') . ' ' . ' , jpn.firstName ' . ' , jpn.namePreposition ' . ' , jpn.familyName ' . ' ) '); $this->_db->setQuery($query); $temp = $this->_db->loadObjectList(); if (count($temp)) { // get menuId & technology $menus = JoaktreeHelper::getMenus('joaktree'); $technology = JoaktreeHelper::getTechnology(); $linkBase = 'index.php?option=com_joaktree&view=joaktree&tech=' . $technology . ''; foreach ($temp as $row) { $menuItemId = $menus[$row->catid]; $row->route = JRoute::_($linkBase . '&Itemid=' . $menuItemId . '&treeId=' . $row->catid . '&personId=' . $row->app_id . '!' . $row->id); $row->robot = $technology == 'a' ? '' : 'rel="noindex, nofollow"'; $related[] = $row; } } unset($temp); } } } return $related; }
public function getMenus() { static $_menuTreeId = array(); // retrieve the menu item ids - if not done yet if (count($_menuTreeId) == 0) { $_menuTreeId = JoaktreeHelper::getMenus('joaktreelist'); } return $_menuTreeId; }
private function getMapItems() { // check for overriding options $this->checkOptions(); // get info about database setting $maxInfo = $this->getMaxInfo(); switch ($this->params['selection']) { case "person": $query = self::getQueryPerson(); break; case "tree": // continue // continue case "location": // continue // continue default: $query = self::getQueryTree(); break; } $this->_db->setQuery($query); $mapItems = $this->_db->loadObjectList(); // prepare information for interactive map if ($this->params['service'] == 'interactivemap') { $menus = JoaktreeHelper::getMenus('joaktree'); $linkBase = 'index.php?option=com_joaktree' . '&view=joaktree' . '&tech=' . JoaktreeHelper::getTechnology() . '&Itemid=' . $menus[$this->params['tree_id']]; $robot = JoaktreeHelper::getTechnology() == 'a' ? '' : 'rel="noindex, nofollow"'; for ($i = 0; $i < count($mapItems); $i++) { $indMore = strlen($mapItems[$i]->information) > $maxInfo; $tmps1 = explode('|', $mapItems[$i]->information); if ($indMore) { // remove the last element array_pop($tmps1); } $info = array(); foreach ($tmps1 as $tmp1) { $tmps2 = explode('#', $tmp1); $name = count($tmps2) ? htmlspecialchars(array_shift($tmps2), ENT_QUOTES) : '....'; $id = count($tmps2) ? array_shift($tmps2) : null; $event = count($tmps2) ? JText::_(array_shift($tmps2)) : ''; //$dateRaw = (count($tmps2)) ? array_shift($tmps2) : null); $date = count($tmps2) ? ' ' . JoaktreeHelper::displayDate(array_shift($tmps2)) : ''; $def_tree = count($tmps2) ? array_shift($tmps2) : null; if ($id && ($this->params['selection'] == 'tree' || $this->params['selection'] == 'location')) { $href = JRoute::_($linkBase . '&treeId=' . $this->params['tree_id'] . '&personId=' . $this->params['app_id'] . '!' . $id); $info[] = '<a href="' . $href . '" target="_top" ' . $robot . ' >' . $name . '</a> (' . $event . $date . ')'; } else { if ($id && $this->params['selection'] == 'person' && $def_tree) { $href = JRoute::_($linkBase . '&treeId=' . (int) $def_tree . '&personId=' . $this->params['app_id'] . '!' . $id); $info[] = '<a href="' . $href . '" target="_top" ' . $robot . ' >' . $name . '</a> (' . $event . $date . ')'; } else { $info[] = $name . ' (' . $event . $date . ')'; } } } if ($indMore) { // add text $info[] = JText::_('JT_ANDMORE'); } $mapItems[$i]->information = implode('<br />', $info); unset($info); } } return $mapItems; }
public function getList($moduleId) { $moduleId = (int) $moduleId; $params = $this->getModuleParams($moduleId); $periodType = $params->get('periodType'); $limit = (int) $params->get('searchlimit', 10); $userAccessLevels = JoaktreeHelper::getUserAccessLevels(); $personStatus = $params->get('personStatus', 0); $showTitle = $params->get('showHeading', 1); $today = getdate(); if ($params->get('freeChoice')) { // only when user is allowed to enter a day/month we are checking these values. $day = JoaktreeHelper::getDay(); $month = JoaktreeHelper::getMonth(); } // for titles we want to know if we have day and/or months from the front end $indUI = !isset($day) && !isset($month) || $day == 0 && $month == 0 ? false : true; // if day and/or month is not set, we use today's info $day = !isset($day) || $day == 0 ? $today['mday'] : $day; $month = !isset($month) || $month == 0 ? $today['mon'] : $month; if ($showTitle == 1) { if (!$indUI) { // nothing from front end -> use standard titles switch ($periodType) { case 2: // continue // continue case 3: $this->_title = JText::_('JTMOD_TMYA_HEADING_THISMONTH'); break; case 4: // continue // continue case 5: $this->_title = JText::_('JTMOD_TMYA_HEADING_THISWEEK'); break; case 0: // continue // continue case 1: // continue // continue default: $this->_title = JText::_('JTMOD_TMYA_HEADING_TODAY'); break; } } else { // use information from front end switch ($periodType) { case 2: // continue // continue case 3: $this->_title = JText::_($this->getMonthName($month)); break; case 4: // continue // continue case 5: // continue // continue case 0: // continue // continue case 1: // continue // continue default: $this->_title = $day . ' ' . JText::_($this->getMonthName($month)); break; } } } else { $this->_title = null; } switch ($periodType) { case 2: // continue // continue case 3: $this->_buttonText = JText::_('JTMOD_TMYA_HEADING_THISMONTH'); break; case 4: // continue // continue case 5: $this->_buttonText = JText::_('JTMOD_TMYA_HEADING_THISWEEK'); break; case 0: // continue // continue case 1: // continue // continue default: $this->_buttonText = JText::_('JTMOD_TMYA_HEADING_TODAY'); break; } $result = array(); $displayAccess = JoaktreeHelper::getDisplayAccess(); $userAccess = JoaktreeHelper::getUserAccess(); $where = $this->_buildContentWhere($day, $month, $today['year']); $order = $this->_buildOrderBy(); // retrieve person events $query = '( SELECT CONCAT_WS(' . $this->_db->quote(' ') . ' ' . ' , jpn.firstName ' . ' , jpn.namePreposition ' . ' , jpn.familyName ' . ' ) AS name ' . ', jet.app_id AS appId ' . ', jet.person_id AS personId ' . ', jan.default_tree_id AS treeId ' . ', IF ( ( jet.code = ' . $this->_db->Quote('EVEN') . ' ) ' . ' , IFNULL( jet.type, jet.code ) ' . ' , jet.code ' . ' ) AS code ' . ', jet.eventdate ' . ', DATE_FORMAT(STR_TO_DATE(eventdate, "%d %M %Y"), "%m%d") AS sortingdate ' . ', SUBSTR( RTRIM(jet.eventdate), -4 ) AS eventyear ' . ', jpn.familyName AS familyName ' . 'FROM #__joaktree_person_events jet ' . 'JOIN #__joaktree_persons jpn ' . 'ON ( jpn.app_id = jet.app_id ' . ' AND jpn.id = jet.person_id ' . ' ) ' . 'JOIN #__joaktree_admin_persons jan ' . 'ON ( jan.app_id = jpn.app_id ' . ' AND jan.id = jpn.id ' . ' AND jan.published = true ' . ($personStatus == 0 ? 'AND jan.living = false ' : ' ') . ($personStatus == 1 ? 'AND jan.living = true ' : ' ') . ' AND ( (jan.living = false AND ' . $displayAccess['NAMEname']->notLiving . ' = 2 ) ' . ' OR (jan.living = true AND ' . $displayAccess['NAMEname']->living . ' = 2 ) ' . ' ) ' . ' ) ' . 'JOIN #__joaktree_trees jte ' . 'ON ( jte.app_id = jan.app_id ' . ' AND jte.id = jan.default_tree_id ' . ' AND jte.published = true ' . ' AND jte.access IN ' . $userAccessLevels . ' ' . ' ) ' . 'JOIN #__joaktree_display_settings jds ' . 'ON ( jds.code = jet.code ' . ' AND jds.level = ' . $this->_db->quote('person') . ' ' . ' AND jds.published = true ' . ' AND ( (jan.living = false AND jds.access IN ' . $userAccessLevels . ') ' . ' OR (jan.living = true AND jds.accessLiving IN ' . $userAccessLevels . ') ' . ' ) ' . ' ) ' . $where . ' ) ' . 'UNION ' . '( SELECT CONCAT_WS(' . $this->_db->quote(' + ') . ' ' . ' , CONCAT_WS(' . $this->_db->quote(' ') . ' ' . ' , jpn1.firstName ' . ' , jpn1.namePreposition ' . ' , jpn1.familyName ' . ' ) ' . ' , CONCAT_WS(' . $this->_db->quote(' ') . ' ' . ' , jpn2.firstName ' . ' , jpn2.namePreposition ' . ' , jpn2.familyName ' . ' ) ' . ' ) AS name ' . ', jet.app_id AS appId ' . ', jet.person_id_1 AS personId ' . ', jan1.default_tree_id AS treeId ' . ', IF ( ( jet.code = ' . $this->_db->Quote('EVEN') . ' ) ' . ' , IFNULL( jet.type, jet.code ) ' . ' , jet.code ' . ' ) AS code ' . ', jet.eventdate ' . ', DATE_FORMAT(STR_TO_DATE(eventdate, "%d %M %Y"), "%m%d") AS sortingdate ' . ', SUBSTR( RTRIM(jet.eventdate), -4 ) AS eventyear ' . ', jpn1.familyName AS familyName ' . 'FROM #__joaktree_relation_events jet ' . 'JOIN #__joaktree_persons jpn1 ' . 'ON ( jpn1.app_id = jet.app_id ' . ' AND jpn1.id = jet.person_id_1 ' . ' ) ' . 'JOIN #__joaktree_admin_persons jan1 ' . 'ON ( jan1.app_id = jpn1.app_id ' . ' AND jan1.id = jpn1.id ' . ' AND jan1.published = true ' . ($personStatus == 0 ? 'AND jan1.living = false ' : ' ') . ($personStatus == 1 ? 'AND jan1.living = true ' : ' ') . ' AND ( (jan1.living = false AND ' . $displayAccess['NAMEname']->notLiving . ' = 2 ) ' . ' OR (jan1.living = true AND ' . $displayAccess['NAMEname']->living . ' = 2 ) ' . ' ) ' . ' ) ' . 'JOIN #__joaktree_trees jte1 ' . 'ON ( jte1.app_id = jan1.app_id ' . ' AND jte1.id = jan1.default_tree_id ' . ' AND jte1.published = true ' . ' AND jte1.access IN ' . $userAccessLevels . ' ' . ' ) ' . 'JOIN #__joaktree_persons jpn2 ' . 'ON ( jpn2.app_id = jet.app_id ' . ' AND jpn2.id = jet.person_id_2 ' . ' ) ' . 'JOIN #__joaktree_admin_persons jan2 ' . 'ON ( jan2.app_id = jpn2.app_id ' . ' AND jan2.id = jpn2.id ' . ' AND jan2.published = true ' . ($personStatus == 0 ? 'AND jan2.living = false ' : ' ') . ($personStatus == 1 ? 'AND jan2.living = true ' : ' ') . ' AND ( (jan2.living = false AND ' . $displayAccess['NAMEname']->notLiving . ' = 2 ) ' . ' OR (jan2.living = true AND ' . $displayAccess['NAMEname']->living . ' = 2 ) ' . ' ) ' . ' ) ' . 'JOIN #__joaktree_trees jte2 ' . 'ON ( jte2.app_id = jan2.app_id ' . ' AND jte2.id = jan2.default_tree_id ' . ' AND jte2.published = true ' . ' AND jte2.access IN ' . $userAccessLevels . ' ' . ' ) ' . 'JOIN #__joaktree_display_settings jds ' . 'ON ( jds.code = jet.code ' . ' AND jds.level = ' . $this->_db->quote('relation') . ' ' . ' AND jds.published = true ' . ' AND ( ( jan1.living = false ' . ' AND jan2.living = false ' . ' AND jds.access IN ' . $userAccessLevels . ' ' . ' ) ' . ' OR ( ( jan1.living = true ' . ' OR jan2.living = true ' . ' ) ' . ' AND jds.accessLiving IN ' . $userAccessLevels . ' ' . ' ) ' . ' ) ' . ' ) ' . $where . ' ) ' . $order . ' '; $this->_db->setQuery($query, 0, $limit); $temp = $this->_db->loadObjectList(); if (count($temp)) { // get menuId & technology $menus = JoaktreeHelper::getMenus('joaktree'); $technology = JoaktreeHelper::getTechnology(); $linkBase = 'index.php?option=com_joaktree&view=joaktree&tech=' . $technology . ''; $robot = $technology == 'a' ? '' : 'rel="noindex, nofollow"'; foreach ($temp as $row) { $menuItemId = $menus[$row->treeId]; $row->route = JRoute::_($linkBase . '&Itemid=' . $menuItemId . '&treeId=' . $row->treeId . '&personId=' . $row->appId . '!' . $row->personId); $row->robot = $robot; $row->yearsago = $today['year'] - (int) $row->eventyear; $tmp = ucwords(strtolower($row->eventdate)); $row->eventday = substr(JoaktreeHelper::convertDateTime($tmp), 0, -4); $row->eventdate = JoaktreeHelper::displayDate($row->eventdate); $row->code = JText::_($row->code); $result[] = $row; } } unset($temp); return $result; }
public static function getList($numberInList) { // get cookie $params = JComponentHelper::getParams('com_joaktree'); $indCookie = $params->get('indCookies', false); if (!$indCookie) { return false; } // array to return $person = array(); // we fetch the cookie $cookie = new JInputCookie(); $tmp = $cookie->get('jt_last_persons', '', 'string'); // prepare the array if ($tmp) { $cookieList = (array) json_decode(base64_decode($tmp)); } else { $cookieList = array(); } if (count($cookieList)) { $db = JFactory::getDBO(); $query = $db->getQuery(true); // get user access info $levels = JoaktreeHelper::getUserAccessLevels(); // set up maximum number of items $maxItem = count($cookieList) > $numberInList ? $numberInList : count($cookieList); // get menuId & technology $menus = JoaktreeHelper::getMenus('joaktree'); $linkBase = 'index.php?option=com_joaktree&view=joaktree'; for ($i = 0; $i < $maxItem; $i++) { $query->clear(); // item is a string separated by !: app_id, person_id, tree_id; $elements = explode('!', array_shift($cookieList)); // retrieve person $app_id = array_shift($elements); $person_id = array_shift($elements); $tree_id = array_shift($elements); if (!empty($app_id) && !empty($person_id) && !empty($tree_id)) { $query->select(JoaktreeHelper::getConcatenatedFullName() . ' AS fullName '); $query->from(' #__joaktree_persons jpn '); $query->where(' jpn.app_id = ' . $app_id . ' '); $query->where(' jpn.id = ' . $db->Quote($person_id) . ' '); // join with admin persons $query->innerJoin(JoaktreeHelper::getJoinAdminPersons(true)); // join with trees $query->innerJoin(' #__joaktree_tree_persons jtp ' . ' ON ( jtp.app_id = jpn.app_id ' . ' AND jtp.person_id = jpn.id ' . ' AND jtp.tree_id = ' . $tree_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 . ' ' . ' ) '); // fetch from database $db->setQuery($query); $tmpPerson = $db->loadObject(); if ($tree_id && isset($menus[$tree_id])) { $menuItemId = $menus[$tree_id]; $tmpPerson->route = JRoute::_($linkBase . '&Itemid=' . $menuItemId . '&treeId=' . $tree_id . '&personId=' . $app_id . '!' . $person_id); $tmpPerson->robot = ''; } else { $tmpPerson->route = 0; $tmpPerson->robot = ''; } if (!empty($tmpPerson->fullName)) { $person[] = $tmpPerson; } unset($tmpPerson); } } } return $person; }
function onContentSearch($text, $phrase = '', $ordering = '', $areas = null) { $db =& JFactory::getDBO(); $linkBase = 'index.php?option=com_joaktree&view=joaktree'; //If the array is not correct, return it: if (is_array($areas)) { if (!array_intersect($areas, array_keys($this->onContentSearchAreas()))) { return array(); } } //And define the parameters. For example like this.. $limit = $this->params->def('search_limit', 50); if (is_array($areas)) { // check whether names are searched $names = in_array('joaktreeName', $areas) ? 1 : 0; $patronym = in_array('joaktreeName', $areas) ? $this->params->def('search_patronyms', 0) : 0; // check whether notes are searched $notes = in_array('joaktreeNote', $areas) ? $this->params->def('search_notes', 0) : 0; } else { $names = 1; $notes = $this->params->def('search_notes', 0); $patronym = $this->params->def('search_patronyms', 0); } $linkType = $this->params->def('link_option', 1); //Use the function trim to delete spaces in front of or at the back of the searching terms $text = trim($text); //Return Array when nothing was filled in if ($text == '') { return array(); } //replace joaktree $searchJoaktree = JText::_('JTSRCH_GENEALOGY'); $searchNotes = JText::_('JTSRCH_NOTES'); // user access $userAccessLevels = JoaktreeHelper::getUserAccessLevels(); $displayAccess = JoaktreeHelper::getDisplayAccess(); //After this, you have to add the database part. $wheres = array(); switch ($phrase) { //search exact case 'exact': $text = $db->Quote('%' . $db->escape($text, true) . '%', false); // search in names table $whereNames = array(); $whereNames[] = 'LOWER(CONCAT_WS(' . $db->Quote(' ') . ',jpn.firstName,jpn.namePreposition,jpn.familyName)) LIKE ' . $text; $whereNames[] = 'LOWER(CONCAT_WS(' . $db->Quote(' ') . ',jpn.firstName,jpn.patronym,jpn.namePreposition,jpn.familyName)) LIKE ' . $text; $whereName = '(' . implode(') OR (', $whereNames) . ')'; // search in person-notes table $wherePerNote = 'LOWER(jpe.value) LIKE ' . $text . ' OR LOWER(jne.value) LIKE ' . $text; // search in person-notes table $whereRelNote = 'LOWER(jre.value) LIKE ' . $text . ' OR LOWER(jne.value) LIKE ' . $text; break; //search all or any //search all or any case 'all': case 'any': //set default //set default default: $words = explode(' ', $text); $whereNames = array(); $whereNotes = array(); $wherePerNotes = array(); $whereRelNotes = array(); foreach ($words as $word) { $word = $db->Quote('%' . $db->escape($word, true) . '%', false); if ($patronym == 1) { $whereNames[] = 'LOWER(jpn.firstName) LIKE ' . $word . 'OR LOWER(jpn.patronym) LIKE ' . $word . 'OR LOWER(jpn.namePreposition) LIKE ' . $word . 'OR LOWER(jpn.familyName) LIKE ' . $word; } else { $whereNames[] = 'LOWER(jpn.firstName) LIKE ' . $word . 'OR LOWER(jpn.namePreposition) LIKE ' . $word . 'OR LOWER(jpn.familyName) LIKE ' . $word; } $wherePerNotes[] = 'LOWER(jpe.value) LIKE ' . $word . ' OR LOWER(jne.value) LIKE ' . $word; $whereRelNotes[] = 'LOWER(jre.value) LIKE ' . $word . ' OR LOWER(jne.value) LIKE ' . $word; } $whereName = '(' . implode($phrase == 'all' ? ') AND (' : ') OR (', $whereNames) . ')'; $wherePerNote = '(' . implode($phrase == 'all' ? ') AND (' : ') OR (', $wherePerNotes) . ')'; $whereRelNote = '(' . implode($phrase == 'all' ? ') AND (' : ') OR (', $whereRelNotes) . ')'; break; } //ordering of the results switch ($ordering) { //alphabetic, ascending case 'alpha': $order = 'jpn.familyName ASC, jpn.firstName ASC'; break; //oldest first //oldest first case 'oldest': //popular first //popular first case 'popular': //newest first //newest first case 'newest': //default setting: alphabetic, ascending //default setting: alphabetic, ascending default: $order = 'jpn.familyName ASC, jpn.firstName ASC'; } //the database query; $query = ''; if ($names == 1 && $notes == 1) { $query .= '( '; } if ($names == 1) { $query .= 'SELECT CONCAT_WS(' . $db->Quote(' ') . ' ' . ' , jpn.firstName ' . ($patronym == 1 ? ', jpn.patronym ' : '') . ' , jpn.namePreposition ' . ' , jpn.familyName ' . ' ) AS title ' . ', CONCAT_WS( " / " ' . ' , ' . $db->Quote($searchJoaktree) . ' ' . ' , jte.name ' . ' ) AS section ' . ', jpn.lastUpdateTimeStamp AS created ' . ', "' . $linkType . '" AS browsernav ' . ', jpn.app_id AS app_id ' . ', jpn.id AS person_id ' . ', jte.id AS tree_id ' . ', IF ( (jan.living = true AND ' . $displayAccess['BIRTperson']->living . ' = 1) ' . ' , ' . $db->Quote(JText::_('JTSRCH_ALTERNATIVE')) . ' ' . ' , birth.eventDate ' . ' ) AS birthDate ' . ', IF ( (jan.living = true AND ' . $displayAccess['DEATperson']->living . ' = 1) ' . ' , ' . $db->Quote(JText::_('JTSRCH_ALTERNATIVE')) . ' ' . ' , death.eventDate ' . ' ) AS deathDate ' . ', NULL AS value ' . 'FROM #__joaktree_persons AS jpn ' . 'JOIN #__joaktree_admin_persons AS jan ' . 'ON ( jan.app_id = jpn.app_id ' . ' AND jan.id = jpn.id ' . ' AND jan.published = true ' . ' AND ( (jan.living = false AND ' . $displayAccess['NAMEname']->notLiving . ' = 2 ) ' . ' OR (jan.living = true AND ' . $displayAccess['NAMEname']->living . ' = 2 ) ' . ' ) ' . ' ) ' . 'LEFT JOIN #__joaktree_trees AS jte ' . 'ON ( jte.app_id = jan.app_id ' . ' AND jte.id = jan.default_tree_id ' . ' AND jte.published = true ' . ' AND jte.access IN ' . $userAccessLevels . ' ) ' . 'LEFT JOIN #__joaktree_person_events birth ' . 'ON ( birth.app_id = jpn.app_id ' . ' AND birth.person_id = jpn.id ' . ' AND birth.code = ' . $db->Quote('BIRT') . ' ' . ' AND ( (jan.living = false AND ' . $displayAccess['BIRTperson']->notLiving . ' > 0 ) ' . ' OR (jan.living = true AND ' . $displayAccess['BIRTperson']->living . ' > 0 ) ' . ' ) ' . ' ) ' . 'LEFT JOIN #__joaktree_person_events death ' . 'ON ( death.app_id = jpn.app_id ' . ' AND death.person_id = jpn.id ' . ' AND death.code = ' . $db->Quote('DEAT') . ' ' . ' AND ( (jan.living = false AND ' . $displayAccess['DEATperson']->notLiving . ' > 0 ) ' . ' OR (jan.living = true AND ' . $displayAccess['DEATperson']->living . ' > 0 ) ' . ' ) ' . ' ) ' . 'WHERE ( ' . $whereName . ' ) ' . ' '; } if ($names == 1 && $notes == 1) { $query .= ') UNION ( '; } if ($notes == 1) { // person notes $query .= 'SELECT CONCAT_WS(' . $db->Quote(' ') . ' ' . ' , jpn.firstName ' . ($patronym == 1 ? ', jpn.patronym ' : '') . ' , jpn.namePreposition ' . ' , jpn.familyName ' . ' ) AS title ' . ', CONCAT_WS( " / " ' . ' , ' . $db->Quote($searchJoaktree) . ' ' . ' , jte.name ' . ' , CONCAT_WS(' . $db->Quote(' ') . ' ' . ' , jpn.firstName ' . ($patronym == 1 ? ', jpn.patronym ' : '') . ' , jpn.namePreposition ' . ' , jpn.familyName ' . ' ) ' . ' , ' . $db->Quote($searchNotes) . ' ' . ' ) AS section ' . ', jpn.lastUpdateTimeStamp AS created ' . ', "' . $linkType . '" AS browsernav ' . ', jpn.app_id AS app_id ' . ', jpn.id AS person_id ' . ', jte.id AS tree_id ' . ', NULL AS birthDate ' . ', NULL AS deathDate ' . ', IF( jne.value IS NOT NULL ' . ' , jne.value ' . ' , jpe.value ' . ' ) AS value ' . 'FROM #__joaktree_person_notes AS jpe ' . 'JOIN #__joaktree_persons AS jpn ' . 'ON ( jpn.app_id = jpe.app_id ' . ' AND jpn.id = jpe.person_id ' . ' ) ' . 'JOIN #__joaktree_admin_persons AS jan ' . 'ON ( jan.app_id = jpn.app_id ' . ' AND jan.id = jpn.id ' . ' AND jan.published = true ' . ' AND ( ( jan.living = false ' . ' AND ' . $displayAccess['NAMEname']->notLiving . ' = 2 ' . ' AND ' . $displayAccess['NOTEperson']->notLiving . ' = 2 ' . ' ) ' . ' OR ( jan.living = true ' . ' AND ' . $displayAccess['NAMEname']->living . ' = 2 ' . ' AND ' . $displayAccess['NOTEperson']->living . ' = 2 ' . ' ) ' . ' ) ' . ' ) ' . 'JOIN #__joaktree_trees AS jte ' . 'ON ( jte.app_id = jan.app_id ' . ' AND jte.id = jan.default_tree_id ' . ' AND jte.published = true ' . ' AND jte.access IN ' . $userAccessLevels . ' ) ' . 'LEFT JOIN #__joaktree_notes AS jne ' . 'ON ( jne.app_id = jpe.app_id ' . ' AND jne.id = jpe.note_id ' . ' ) ' . 'WHERE ( ' . $wherePerNote . ' ) '; } // Order by name if ($names == 1 && $notes == 1) { $query .= ') '; } $query .= 'ORDER BY title '; //. $order; //Set query $db->setQuery($query, 0, $limit); $rows = $db->loadObjectList(); $menuJoaktree = JoaktreeHelper::getMenus('joaktree'); $menu =& JSite::getMenu(); $menuActive =& $menu->getActive(); $menuActId = isset($menuActive) ? $menuActive->id : null; foreach ($rows as $key => $row) { $tmp = ''; //The 'output' of the displayed link if (!empty($rows[$key]->tree_id)) { $rows[$key]->href = JRoute::_($linkBase . '&Itemid=' . $menuJoaktree[$rows[$key]->tree_id] . '&treeId=' . $rows[$key]->tree_id . '&personId=' . $rows[$key]->app_id . '!' . $rows[$key]->person_id); } else { // look for first child $query = 'SELECT jrn.app_id AS app_id ' . ', jrn.person_id_1 AS person_id ' . ', jte.id AS tree_id ' . ', jrn.type AS relation ' . 'FROM #__joaktree_relations AS jrn ' . 'JOIN #__joaktree_admin_persons AS jan ' . 'ON ( jan.app_id = jrn.app_id ' . ' AND jan.id = jrn.person_id_1 ' . ' AND jan.published = true ' . ' AND ( ( jan.living = false ' . ' AND ' . $displayAccess['NAMEname']->notLiving . ' = 2 ' . ' ) ' . ' OR ( jan.living = true ' . ' AND ' . $displayAccess['NAMEname']->living . ' = 2 ' . ' ) ' . ' ) ' . ' ) ' . 'JOIN #__joaktree_trees AS jte ' . 'ON ( jte.app_id = jan.app_id ' . ' AND jte.id = jan.default_tree_id ' . ' AND jte.published = true ' . ' AND jte.access IN ' . $userAccessLevels . ' ) ' . 'WHERE jrn.app_id = ' . $rows[$key]->app_id . ' ' . 'AND jrn.person_id_2 = ' . $db->Quote($rows[$key]->person_id) . ' ' . 'AND jrn.orderNumber_2 = 1 '; //Set query $db->setQuery($query); $child = $db->loadObject(); if ($child) { $rows[$key]->href = JRoute::_($linkBase . '&Itemid=' . (!empty($child->tree_id) ? $menuJoaktree[$child->tree_id] : $menuActId) . '&treeId=' . (!empty($child->tree_id) ? $child->tree_id : '') . '&personId=' . $child->app_id . '!' . $child->person_id); } else { // situation that the child is still living ... $rows[$key]->href = '#'; } } if (!empty($rows[$key]->birthDate)) { $tmp .= JText::_('JTSRCH_BORN') . ': '; $tmp .= JoaktreeHelper::displayDate($rows[$key]->birthDate) . '; '; } if (!empty($rows[$key]->deathDate)) { $tmp .= JText::_('JTSRCH_DIED') . ': '; $tmp .= JoaktreeHelper::displayDate($rows[$key]->deathDate) . '; '; } if (!empty($rows[$key]->value)) { $tmp .= $rows[$key]->value; } $rows[$key]->text = $tmp; } return $rows; }