/** * Generate module contents * * @return void */ public function run() { include_once Component::path('com_resources') . DS . 'tables' . DS . 'resource.php'; $database = \App::get('db'); //Get the admin configured settings $filters = array('limit' => 1, 'start' => 0, 'type' => trim($this->params->get('type')), 'sortby' => 'random', 'minranking' => trim($this->params->get('minranking')), 'tag' => trim($this->params->get('tag')), 'access' => 'public', 'toolState' => 7); $row = null; // No - so we need to randomly choose one // Initiate a resource object $rr = new \Components\Resources\Tables\Resource($database); // Get records $rows = $rr->getRecords($filters, false); if (count($rows) > 0) { $row = $rows[0]; } $this->cls = trim($this->params->get('moduleclass_sfx')); $this->txt_length = trim($this->params->get('txt_length')); // Did we get any results? if ($row) { $config = Component::params('com_resources'); // Resource $id = $row->id; include_once Component::path('com_resources') . DS . 'helpers' . DS . 'html.php'; $path = DS . trim($config->get('uploadpath', '/site/resources'), DS); $path = \Components\Resources\Helpers\Html::build_path($row->created, $row->id, $path); if ($row->type == 7) { include_once Component::path('com_tools') . DS . 'tables' . DS . 'version.php'; $tv = new \Components\Tools\Tables\Version($database); $versionid = $tv->getVersionIdFromResource($id, 'current'); $picture = $this->getToolImage($path, $versionid); } else { $picture = $this->getImage($path); } $thumb = $path . DS . $picture; if (!is_file(PATH_APP . $thumb)) { $thumb = DS . trim($config->get('defaultpic')); } $row->typetitle = trim(stripslashes($row->typetitle)); if (substr($row->typetitle, -1, 1) == 's' && substr($row->typetitle, -3, 3) != 'ies') { $row->typetitle = substr($row->typetitle, 0, strlen($row->typetitle) - 1); } $this->id = $id; $this->thumb = $thumb; } $this->row = $row; require $this->getLayoutPath(); }
/** * 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(); }