Example #1
0
 function onContentSearch($text, $phrase = '', $ordering = '', $areas = null)
 {
     $db = JFactory::getDbo();
     require_once JPATH_SITE . '/components/com_joomleague/joomleague.core.php';
     // load plugin params info
     $plugin = JPluginHelper::getPlugin('search', 'joomleague');
     $search_clubs = $this->params->def('search_clubs', 1);
     $search_teams = $this->params->def('search_teams', 1);
     $search_players = $this->params->def('search_players', 1);
     $search_playgrounds = $this->params->def('search_playgrounds', 1);
     $search_staffs = $this->params->def('search_staffs', 1);
     $search_referees = $this->params->def('search_referees', 1);
     $search_projects = $this->params->def('search_projects', 1);
     $text = trim($text);
     if ($text == '') {
         return array();
     }
     $wheres = array();
     switch ($phrase) {
         case 'any':
         default:
             $words = explode(' ', $text);
             $wheres = array();
             $wheresteam = array();
             $whereperson = array();
             $whereplayground = array();
             $whereproject = array();
             if ($search_clubs) {
                 foreach ($words as $word) {
                     $word = $db->Quote('%' . $db->getEscaped($word, true) . '%', false);
                     $wheres2 = array();
                     $wheres2[] = 'c.name LIKE ' . $word;
                     $wheres2[] = 'c.alias LIKE ' . $word;
                     $wheres2[] = 'c.location LIKE ' . $word;
                     $wheres[] = implode(' OR ', $wheres2);
                 }
             }
             if ($search_teams) {
                 foreach ($words as $word) {
                     $word = $db->Quote('%' . $db->getEscaped($word, true) . '%', false);
                     $wheres2 = array();
                     $wheres2[] = 't.name LIKE ' . $word;
                     $wheresteam[] = implode(' OR ', $wheres2);
                 }
             }
             if ($search_players || $search_referees || $search_staffs) {
                 foreach ($words as $word) {
                     $word = $db->Quote('%' . $db->getEscaped($word, true) . '%', false);
                     $wheres2 = array();
                     $wheres2[] = 'pe.firstname LIKE ' . $word;
                     $wheres2[] = 'pe.lastname LIKE ' . $word;
                     $wheres2[] = 'pe.nickname LIKE ' . $word;
                     $whereperson[] = implode(' OR ', $wheres2);
                 }
             }
             if ($search_playgrounds) {
                 foreach ($words as $word) {
                     $word = $db->Quote('%' . $db->getEscaped($word, true) . '%', false);
                     $wheres2 = array();
                     $wheres2[] = 'pl.name LIKE ' . $word;
                     $wheres2[] = 'pl.city LIKE ' . $word;
                     $whereplayground[] = implode(' OR ', $wheres2);
                 }
             }
             if ($search_projects) {
                 foreach ($words as $word) {
                     $word = $db->Quote('%' . $db->getEscaped($word, true) . '%', false);
                     $wheres2 = array();
                     $wheres2[] = 'prj.name LIKE ' . $word;
                     $whereproject[] = implode(' OR ', $wheres2);
                 }
             }
             $where = '(' . implode($phrase == 'all' ? ') AND (' : ') OR (', $wheres) . ')';
             $whereteam = '(' . implode($phrase == 'all' ? ') AND (' : ') OR (', $wheresteam) . ')';
             $whereperson = '(' . implode($phrase == 'all' ? ') AND (' : ') OR (', $whereperson) . ')';
             $whereplayground = '(' . implode($phrase == 'all' ? ') AND (' : ') OR (', $whereplayground) . ')';
             $whereproject = '(' . implode($phrase == 'all' ? ') AND (' : ') OR (', $whereproject) . ')';
             break;
     }
     $rows = array();
     if ($search_clubs) {
         $query = "SELECT 'Club' as section, c.name AS title," . " c.founded AS created," . " c.country," . " c.logo_big AS picture," . " CONCAT( ' Address: ',c.address,' ',c.zipcode,' ',c.location,' Phone: ',c.phone,' Fax: ',c.fax,' E-Mail: ',c.email) AS text," . " pt.project_id AS project_id, c.id AS club_id, " . " '' AS href," . " '2' AS browsernav " . " FROM #__joomleague_club AS c" . " LEFT JOIN #__joomleague_team AS t ON c.id = t.club_id" . " LEFT JOIN #__joomleague_project_team AS pt ON pt.team_id = t.id" . " WHERE ( " . $where . " ) " . " GROUP BY c.name ORDER BY c.name";
         $db->setQuery($query);
         $list = $db->loadObjectList();
         for ($i = 0; $i < count($list); $i++) {
             $list[$i]->href = JoomLeagueHelperRoute::getClubInfoRoute($list[$i]->project_id, $list[$i]->club_id);
         }
         $rows[] = $list;
     }
     if ($search_teams) {
         $query = "SELECT 'Team' as section, t.name AS title," . " t.checked_out_time AS created, t.notes AS text, t.id AS team_id, " . " CONCAT( ' Info: ',t.info , ' Notes: ', t.notes ) AS text," . " pt.project_id AS project_id, " . " pt.picture AS picture, " . " '' AS href, c.country AS country, " . " '2' AS browsernav" . " FROM #__joomleague_team AS t " . " LEFT JOIN #__joomleague_project_team AS pt ON pt.team_id = t.id" . " LEFT JOIN #__joomleague_club AS c ON t.club_id = c.id" . " WHERE ( " . $whereteam . " ) " . " GROUP BY t.name ORDER BY t.name";
         $db->setQuery($query);
         $list = $db->loadObjectList();
         for ($i = 0; $i < count($list); $i++) {
             $list[$i]->href = JoomLeagueHelperRoute::getTeamInfoRoute($list[$i]->project_id, $list[$i]->team_id);
         }
         $rows[] = $list;
     }
     if ($search_players) {
         $query = "SELECT 'Person' as section, REPLACE(CONCAT(pe.firstname, ' \\'', pe.nickname, '\\' ' , pe.lastname ),'\\'\\'','') AS title," . " pe.birthday AS created," . " pe.country," . " pe.picture AS picture, " . " CONCAT( ' Birthday:',pe.birthday , ' Notes:', pe.notes ) AS text," . " pt.project_id AS project_id, pt.team_id as team_id, pe.id as person_id, " . " '' AS href," . " '2' AS browsernav" . " FROM #__joomleague_person AS pe" . " LEFT JOIN #__joomleague_team_player AS tp" . " ON tp.person_id = pe.id" . " LEFT JOIN #__joomleague_project_team AS pt ON pt.id = tp.projectteam_id" . " WHERE ( " . $whereperson . " ) " . " AND pe.published = '1' " . " GROUP BY pe.lastname, pe.firstname, pe.nickname " . " ORDER BY pe.lastname,pe.firstname,pe.nickname";
         $db->setQuery($query);
         $list = $db->loadObjectList();
         for ($i = 0; $i < count($list); $i++) {
             $list[$i]->href = JoomLeagueHelperRoute::getPlayerRoute($list[$i]->project_id, $list[$i]->team_id, $list[$i]->person_id);
         }
         $rows[] = $list;
     }
     if ($search_staffs) {
         $query = "SELECT 'Staff' as section, REPLACE(CONCAT(pe.firstname, ' \\'', pe.nickname, '\\' ' , pe.lastname ),'\\'\\'','') AS title," . " pe.birthday AS created," . " pe.country," . " pe.picture AS picture, " . " CONCAT( ' Birthday:',pe.birthday , ' Notes:', pe.notes ) AS text," . " pt.project_id AS project_id, pt.team_id as team_id, pe.id as person_id, " . " '' AS href," . " '2' AS browsernav" . " FROM #__joomleague_person AS pe" . " LEFT JOIN #__joomleague_team_staff AS ts" . " ON ts.person_id = pe.id " . " LEFT JOIN #__joomleague_project_team AS pt" . " ON pt.id = tp.projectteam_id" . " WHERE ( " . $whereperson . " ) " . " AND pe.published = '1' " . " GROUP BY pe.lastname, pe.firstname, pe.nickname " . " ORDER BY pe.lastname,pe.firstname,pe.nickname";
         $db->setQuery($query);
         $list = $db->loadObjectList();
         for ($i = 0; $i < count($list); $i++) {
             $list[$i]->href = JoomLeagueHelperRoute::getStaffRoute($list[$i]->project_id, $list[$i]->team_id, $list[$i]->person_id);
         }
         $rows[] = $list;
     }
     if ($search_referees) {
         $query = "SELECT 'Referee' as section, REPLACE(CONCAT(pe.firstname, ' \\'', pe.nickname, '\\' ' , pe.lastname ),'\\'\\'','') AS title," . " pe.birthday AS created," . " pe.country," . " pe.picture AS picture, " . " CONCAT( 'Birthday:', pe.birthday, ' Notes:', pe.notes ) AS text," . " pt.project_id AS project_id, pe.id as person_id, " . " ''AS href," . " '2' AS browsernav" . " FROM #__joomleague_person AS pe" . " LEFT JOIN #__joomleague_project_referee AS pr" . " ON pr.person_id = pe.id" . " WHERE ( " . $whereperson . " ) " . " AND pe.published = '1' " . " AND pr.published = '1' " . " GROUP BY pe.lastname, pe.firstname, pe.nickname " . " ORDER BY pe.lastname,pe.firstname,pe.nickname";
         $db->setQuery($query);
         $list = $db->loadObjectList();
         for ($i = 0; $i < count($list); $i++) {
             $list[$i]->href = JoomLeagueHelperRoute::getRefereeRoute($list[$i]->project_id, $list[$i]->team_id, $list[$i]->person_id);
         }
         $rows[] = $list;
     }
     if ($search_playgrounds) {
         $query = "SELECT 'Playground' as section, pl.name AS title," . " pl.checked_out_time AS created," . " pl.country," . " pl.picture AS picture, " . " pl.notes AS text," . " pt.project_id AS project_id, pl.id as playground_id, " . " '' AS href," . " '2' AS browsernav" . " FROM #__joomleague_playground AS pl" . " LEFT JOIN #__joomleague_club AS c" . " ON c.id = pl.club_id" . " LEFT JOIN #__joomleague_match AS m" . " ON m.playground_id = pl.id" . " LEFT JOIN #__joomleague_round AS r" . " ON m.round_id = r.id" . " WHERE ( " . $whereplayground . " ) " . " GROUP BY pl.name ORDER BY pl.name ";
         $db->setQuery($query);
         $list = $db->loadObjectList();
         for ($i = 0; $i < count($list); $i++) {
             $list[$i]->href = JoomLeagueHelperRoute::getPlaygroundRoute($list[$i]->project_id, $list[$i]->playgroundid);
         }
         $rows[] = $list;
     }
     if ($search_projects) {
         $query = "SELECT 'Project' as section, prj.name AS title," . " prj.checked_out_time AS created," . " l.country," . " prj.picture AS picture, " . " prj.project_id AS project_id, " . " '' AS href," . " '2' AS browsernav" . " FROM #__joomleague_project AS prj" . " LEFT JOIN #__joomleague_league AS l" . " ON l.id = prj.league_id" . " WHERE ( " . $whereproject . " ) " . " GROUP BY prj.name ";
         " ORDER BY prj.name ";
         $db->setQuery($query);
         $list = $db->loadObjectList();
         for ($i = 0; $i < count($list); $i++) {
             $list[$i]->href = JoomLeagueHelperRoute::getRankingRoute($list[$i]->project_id);
         }
         $rows[] = $list;
     }
     $results = array();
     if (count($rows)) {
         foreach ($rows as $row) {
             if ($row) {
                 foreach ($row as $output) {
                     if ($output->country) {
                         $flag = Countries::getCountryFlag($output->country);
                         $output->flag = $flag;
                         $output->text = $flag . ' ' . $output->text;
                     }
                     if ($output->picture) {
                         $output->text = '<p><img style="float: left;" src="' . $output->picture . '" alt="" width="50" height="" >' . $output->text . '</p>';
                     }
                 }
             }
         }
         foreach ($rows as $row) {
             $results = array_merge($results, (array) $row);
         }
     }
     return $results;
 }
Example #2
0
    public function onContentPrepare($context, &$row, &$params, $page = 0)
    {
        $db = JFactory::getDbo();
        if (JString::strpos($row->text, 'jl_player') === false) {
            return true;
        }
        $regex = "#{jl_player}(.*?){/jl_player}#s";
        if (preg_match_all($regex, $row->text, $matches) > 0) {
            require_once JPATH_SITE . '/components/com_joomleague/joomleague.core.php';
            foreach ($matches[0] as $match) {
                $name = preg_replace("/{.+?}/", "", $match);
                $aname = explode(" ", html_entity_decode($name));
                $firstname = $aname[0];
                $lastname = $aname[1];
                $query = '	SELECT	pr.id AS pid,
								tp.person_id,
								tp.id AS tpid,
								pt.project_id,
								pr.firstname,
								pr.lastname,
								p.name AS project_name,
								s.name AS season_name,
								t.name AS team_name,
								pos.name AS position_name,
								tp.project_position_id,
								t.id AS team_id,
								pt.id AS ptid,
								pos.id AS posID,
								CASE WHEN CHAR_LENGTH(t.alias) THEN CONCAT_WS(\':\',t.id,t.alias) ELSE t.id END AS team_slug,
								CASE WHEN CHAR_LENGTH(p.alias) THEN CONCAT_WS(\':\',p.id,p.alias) ELSE p.id END AS project_slug
						FROM #__joomleague_person AS pr
						INNER JOIN #__joomleague_team_player AS tp ON tp.person_id=pr.id
						INNER JOIN #__joomleague_project_team AS pt ON pt.id=tp.projectteam_id
						INNER JOIN #__joomleague_team AS t ON t.id=pt.team_id
						INNER JOIN #__joomleague_project AS p ON p.id=pt.project_id
						INNER JOIN #__joomleague_season AS s ON s.id=p.season_id
						INNER JOIN #__joomleague_league AS l ON l.id=p.league_id
						INNER JOIN #__joomleague_project_position AS ppos ON ppos.id=tp.project_position_id
						INNER JOIN #__joomleague_position AS pos ON pos.id=ppos.position_id
						WHERE pr.firstname = ' . $db->Quote($firstname) . ' 
						AND	pr.lastname = ' . $db->Quote($lastname) . '
						AND p.published=1
						AND tp.published=1
						AND pr.published = 1
						ORDER BY p.id DESC';
                // run query
                $db->setQuery($query);
                $rows = $db->loadObjectList();
                // get result
                // replace only if project id set
                if (isset($rows[0]->project_id)) {
                    $personid = $rows[0]->pid;
                    $projectid = $rows[0]->project_id;
                    $teamid = $rows[0]->team_id;
                    $url = JoomLeagueHelperRoute::getPlayerRoute($projectid, $teamid, $personid, null);
                    $link = '<a class="player" href="' . $url . '">';
                    $row->text = preg_replace("#{jl_player}" . $name . "{/jl_player}#s", $link . $name . "</a>", $row->text);
                } else {
                    $row->text = preg_replace("#{jl_player}" . $name . "{/jl_player}#s", $name, $row->text);
                }
            }
            return true;
        }
    }