/** * Get module contents * * @return void */ public function run() { include_once Component::path('com_resources') . DS . 'tables' . DS . 'resource.php'; include_once Component::path('com_members') . DS . 'tables' . DS . 'profile.php'; include_once Component::path('com_members') . DS . 'tables' . DS . 'association.php'; include_once Component::path('com_answers') . DS . 'tables' . DS . 'question.php'; include_once Component::path('com_answers') . DS . 'tables' . DS . 'response.php'; include_once Component::path('com_blog') . DS . 'tables' . DS . 'entry.php'; include_once Component::path('com_blog') . DS . 'tables' . DS . 'comment.php'; $this->database = \App::get('db'); // Get the admin configured settings $filters = array(); $filters['limit'] = 5; $filters['start'] = 0; // featured items $tbls = array('resources', 'profiles'); $spots = array(); $spots[0] = trim($this->params->get('spotone')); $spots[1] = trim($this->params->get('spottwo')); $spots[2] = trim($this->params->get('spotthree')); $spots[3] = trim($this->params->get('spotfour')); $spots[4] = trim($this->params->get('spotfive')); $spots[5] = trim($this->params->get('spotsix')); $spots[6] = trim($this->params->get('spotseven')); $numspots = $this->params->get('numspots', 3); // some collectors $activespots = array(); $rows = array(); // styling $cls = trim($this->params->get('moduleclass_sfx')); $txtLength = trim($this->params->get('txt_length')); $start = date('Y-m-d', mktime(0, 0, 0, date('m'), date('d'), date('Y'))) . ' 00:00:00'; $end = date('Y-m-d', mktime(0, 0, 0, date('m'), date('d'), date('Y'))) . ' 23:59:59'; $this->html = ''; $k = 1; $out = ''; for ($i = 0, $n = $numspots; $i < $numspots; $i++) { $spot = $spots[$i]; if ($spot == '') { continue; } $row = null; $out = ''; $tbl = ''; $tbl = $spot == 'tools' || $spot == 'nontools' ? 'resources' : ''; $tbl = $spot == 'members' ? 'profiles' : $tbl; $tbl = $spot == 'topics' ? 'topics' : $tbl; $tbl = $spot == 'itunes' ? 'itunes' : $tbl; $tbl = $spot == 'answers' ? 'answers' : $tbl; $tbl = $spot == 'blog' ? 'blog' : $tbl; $tbl = !$tbl ? array_rand($tbls, 1) : $tbl; // we need to randomly choose one switch ($tbl) { case 'resources': // Initiate a resource object $rr = new \Components\Resources\Tables\Resource($this->database); $filters['start'] = 0; $filters['type'] = $spot; $filters['sortby'] = 'random'; $filters['minranking'] = trim($this->params->get('minranking')); $filters['tag'] = $spot == 'tools' ? trim($this->params->get('tag')) : ''; // tag is set for tools only // Get records $rows[$spot] = isset($rows[$spot]) ? $rows[$spot] : $rr->getRecords($filters, false); break; case 'profiles': // No - so we need to randomly choose one $filters['start'] = 0; $filters['sortby'] = "RAND()"; $filters['search'] = ''; $filters['state'] = 'public'; $filters['authorized'] = false; $filters['tag'] = ''; $filters['contributions'] = trim($this->params->get('min_contributions')); $filters['show'] = trim($this->params->get('show')); $mp = new \Components\Members\Tables\Profile($this->database); // Get records $rows[$spot] = isset($rows[$spot]) ? $rows[$spot] : $mp->getRecords($filters, false); break; case 'topics': // No - so we need to randomly choose one $topics_tag = trim($this->params->get('topics_tag')); $query = "SELECT DISTINCT w.id, w.pagename, w.title "; $query .= " FROM #__wiki_page AS w "; if ($topics_tag) { $query .= " JOIN #__tags_object AS RTA ON RTA.objectid=w.id AND RTA.tbl='wiki' "; $query .= " INNER JOIN #__tags AS TA ON TA.id=RTA.tagid "; } else { $query .= ", #__wiki_version AS v "; } $query .= " WHERE w.access!=1 AND w.scope = '' "; if ($topics_tag) { $query .= " AND (TA.tag='" . $topics_tag . "' OR TA.raw_tag='" . $topics_tag . "') "; } else { $query .= " AND v.pageid=w.id AND v.approved = 1 AND v.pagetext != '' "; } $query .= " ORDER BY RAND() "; $this->database->setQuery($query); $rows[$spot] = isset($rows[$spot]) ? $rows[$spot] : $this->database->loadObjectList(); break; case 'itunes': // Initiate a resource object $rr = new \Components\Resources\Tables\Resource($this->database); $filters['start'] = 0; $filters['sortby'] = 'random'; $filters['tag'] = trim($this->params->get('itunes_tag')); // Get records $rows[$spot] = isset($rows[$spot]) ? $rows[$spot] : $rr->getRecords($filters, false); break; case 'answers': $query = "SELECT C.id, C.subject, C.question, C.created, C.created_by, C.anonymous "; $query .= ", (SELECT COUNT(*) FROM #__answers_responses AS a WHERE a.state!=2 AND a.question_id=C.id) AS rcount "; $query .= " FROM #__answers_questions AS C "; $query .= " WHERE C.state=0 "; $query .= " AND (C.reward > 0 OR C.helpful > 0) "; $query .= " ORDER BY RAND() "; $this->database->setQuery($query); $rows[$spot] = isset($rows[$spot]) ? $rows[$spot] : $this->database->loadObjectList(); break; case 'blog': $filters = array(); $filters['limit'] = 1; $filters['start'] = 0; $filters['state'] = 'public'; $filters['order'] = "RAND()"; $filters['search'] = ''; $filters['scope'] = 'member'; $filters['group_id'] = 0; $filters['authorized'] = false; $filters['sql'] = ''; $mp = new \Components\Blog\Tables\Entry($this->database); $entry = $mp->getRecords($filters); $rows[$spot] = isset($rows[$spot]) ? $rows[$spot] : $entry; break; } if ($rows && count($rows[$spot]) > 0) { $row = $rows[$spot][0]; } // make sure we aren't pulling the same item if ($k != 1 && in_array($spot, $activespots) && $rows && count($rows[$spot]) > 1) { $row = count($rows[$spot]) < $k ? $rows[$spot][$k - 1] : $rows[$spot][1]; // get the next one } // pull info if ($row) { $out = $this->_composeEntry($row, $tbl, $txtLength); $itemid = $this->_composeEntry($row, $tbl, 0, 1); $activespots[] = $spot; } // Did we get any results? if ($out) { $this->html .= '<li class="spot_' . $k . '">' . $out . '</li>' . "\n"; $k++; } } // Output HTML require $this->getLayoutPath(); }
/** * Get a count of all blog entries * * @param string $gid Group alias * @return integer */ public static function getGroupBlogCount($gid) { if (!$gid) { return 0; } $database = App::get('db'); include_once PATH_CORE . DS . 'components' . DS . 'com_blog' . DS . 'tables' . DS . 'entry.php'; $filters = array(); $filters['scope'] = 'group'; $filters['scope_id'] = $gid; $gb = new \Components\Blog\Tables\Entry($database); $total = $gb->find('count', $filters); return $total; }