/** * Pull a list of records that were created within the time frame ($period) * * @param object $period Time period to pull results for * @param mixed $limit Number of records to pull * @param integer $limitstart Start of records to pull * @param array $areas Active area(s) * @param array $tagids Array of tag IDs * @return array */ public function onWhatsnew($period, $limit = 0, $limitstart = 0, $areas = null, $tagids = array()) { if (is_array($areas) && $limit) { $ars = $this->onWhatsnewAreas(); if (!isset($areas[$this->_name]) && !in_array($this->_name, $areas) && !array_intersect($areas, array_keys($ars['resources']))) { return array(); } } // Do we have a time period? if (!is_object($period)) { return array(); } $database = App::get('db'); // Instantiate some needed objects $rr = new \Components\Resources\Tables\Resource($database); // Build query $filters = array('startdate' => $period->cStartDate, 'enddate' => $period->cEndDate, 'sortby' => 'date'); if (count($tagids) > 0) { $filters['tags'] = $tagids; } $filters['usergroups'] = \Hubzero\User\Helper::getGroups((int) User::get('id', 0), 'all'); // Get categories $categories = $this->_cats; if (!is_array($categories)) { $rt = new \Components\Resources\Tables\Type($database); $categories = $rt->getMajorTypes(); } // Normalize the category names // e.g., "Oneline Presentations" -> "onlinepresentations" $cats = array(); for ($i = 0; $i < count($categories); $i++) { $cats[$categories[$i]->alias] = array(); $cats[$categories[$i]->alias]['id'] = $categories[$i]->id; } $filters['authorized'] = false; if ($limit) { if ($this->_total != null) { $total = 0; $t = $this->_total; foreach ($t as $l) { $total += $l; } if ($total == 0) { return array(); } } $filters['select'] = 'records'; $filters['limit'] = $limit; $filters['limitstart'] = $limitstart; // Check the area of return. If we are returning results for a specific area/category // we'll need to modify the query a bit if (count($areas) == 1 && isset($areas[0]) && $areas[0] != 'resources') { $filters['type'] = $cats[$areas[0]]['id']; } // Get results $database->setQuery($rr->buildPluginQuery($filters)); $rows = $database->loadObjectList(); // Did we get any results? if ($rows) { include_once PATH_CORE . DS . 'components' . DS . 'com_resources' . DS . 'helpers' . DS . 'helper.php'; // Loop through the results and set each item's HREF foreach ($rows as $key => $row) { $resourceEx = new \Components\Resources\Helpers\Helper($row->id, $database); $resourceEx->getContributors(); $rows[$key]->authors = $resourceEx->contributors; if ($row->alias) { $rows[$key]->href = Route::url('index.php?option=com_resources&alias=' . $row->alias); } else { $rows[$key]->href = Route::url('index.php?option=com_resources&id=' . $row->id); } if ($row->itext) { $rows[$key]->text = $rows[$key]->itext; } else { if ($row->ftext) { $rows[$key]->text = $rows[$key]->ftext; } } } } return $rows; } else { $filters['select'] = 'count'; // Get a count $counts = array(); $ares = $this->onWhatsnewAreas(); foreach ($ares as $area => $val) { if (is_array($val)) { foreach ($val as $a => $t) { $filters['type'] = $cats[$a]['id']; $database->setQuery($rr->buildPluginQuery($filters)); $counts[] = $database->loadResult(); } } } // Return the counts $this->_total = $counts; return $counts; } }
/** * [_getResources description] * @param string $type [description] * @param integer $limit [description] * @return [type] [description] */ private function _getResources($type = 'all', $limit = 5) { // database object $database = \App::get('db'); // Instantiate some needed objects $rr = new \Components\Resources\Tables\Resource($database); // Build query $filters = array(); $filters['now'] = date('Y-m-d H:i:s', time() + 0 * 60 * 60); $filters['sortby'] = 'date'; $filters['group'] = $this->group->get('cn'); $filters['access'] = 'all'; $filters['authorized'] = ''; $filters['select'] = 'records'; $filters['limit'] = $limit; $filters['limitstart'] = 0; // Get categories $rt = new \Components\Resources\Tables\Type($database); $categories = $rt->getMajorTypes(); // Normalize the category names // e.g., "Oneline Presentations" -> "onlinepresentations" $cats = array(); for ($i = 0; $i < count($categories); $i++) { $normalized = preg_replace("/[^a-zA-Z0-9]/", '', $categories[$i]->type); $normalized = strtolower($normalized); $cats[$normalized] = array(); $cats[$normalized]['id'] = $categories[$i]->id; } // do we have a type? if (in_array($type, array_keys($cats))) { $filters['type'] = $cats[$type]['id']; } // Get results $database->setQuery($rr->buildPluginQuery($filters)); $rows = $database->loadObjectList(); return $rows; }
/** * Retrieve records for items associated with this group * * @param object $group Group that owns the records * @param unknown $authorized Authorization level * @param mixed $limit SQL record limit * @param integer $limitstart SQL record limit start * @param string $sort The field to sort records by * @param string $access Access level * @param mixed $areas An array or string of areas that should retrieve records * @return mixed Returns integer when counting records, array when retrieving records */ public function getResources($group, $authorized, $limit = 0, $limitstart = 0, $sort = 'date', $access = 'all', $areas = null) { // Check if our area is in the array of areas we want to return results for if (is_array($areas) && $limit) { $ars = $this->getResourcesAreas(); if (!isset($areas[$this->_name]) && !in_array($this->_name, $areas) && !array_intersect($areas, array_keys($ars['resources']))) { return array(); } } // Do we have a member ID? if (!$group->get('cn')) { return array(); } $database = App::get('db'); // Instantiate some needed objects $rr = new \Components\Resources\Tables\Resource($database); // Build query $filters = array(); $filters['now'] = \Date::toSql(); $filters['sortby'] = $sort; $filters['group'] = $group->get('cn'); $filters['access'] = $access; $filters['authorized'] = $authorized; $filters['state'] = array(1); // Get categories $categories = $this->_cats; if (!is_array($categories)) { $rt = new \Components\Resources\Tables\Type($database); $categories = $rt->getMajorTypes(); } // Normalize the category names // e.g., "Oneline Presentations" -> "onlinepresentations" $cats = array(); for ($i = 0; $i < count($categories); $i++) { $normalized = preg_replace("/[^a-zA-Z0-9]/", '', $categories[$i]->type); $normalized = strtolower($normalized); $cats[$normalized] = array(); $cats[$normalized]['id'] = $categories[$i]->id; } if ($limit) { if ($this->_total != null) { $total = 0; $t = $this->_total; foreach ($t as $l) { $total += $l; } } if ($total == 0) { return array(); } $filters['select'] = 'records'; $filters['limit'] = $limit; $filters['limitstart'] = $limitstart; // Check the area of return. If we are returning results for a specific area/category // we'll need to modify the query a bit if (count($areas) == 1 && !isset($areas['resources']) && $areas[0] != 'resources') { $filters['type'] = $cats[$areas[0]]['id']; } // Get results $database->setQuery($rr->buildPluginQuery($filters)); $rows = $database->loadObjectList(); // Did we get any results? if ($rows) { // Loop through the results and set each item's HREF foreach ($rows as $key => $row) { if ($row->alias) { $rows[$key]->href = Route::url('index.php?option=com_resources&alias=' . $row->alias); } else { $rows[$key]->href = Route::url('index.php?option=com_resources&id=' . $row->id); } } } // Return the results return $rows; } else { $filters['select'] = 'count'; // Get a count $counts = array(); $ares = $this->getResourcesAreas(); foreach ($ares as $area => $val) { if (is_array($val)) { $i = 0; foreach ($val as $a => $t) { if ($limitstart == -1) { if ($i == 0) { $database->setQuery($rr->buildPluginQuery($filters)); $counts[] = $database->loadResult(); } else { $counts[] = 0; } } else { $filters['type'] = $cats[$a]['id']; // Execute a count query for each area/category $database->setQuery($rr->buildPluginQuery($filters)); $counts[] = $database->loadResult(); } $i++; } } } // Return the counts $this->_total = $counts; return $counts; } }
/** * Return either a count or an array of the member's contributions * * @param object $member Current member * @param string $option Component name * @param string $authorized Authorization level * @param integer $limit Number of record to return * @param integer $limitstart Record return start * @param string $sort Field to sort records on * @param array $areas Areas to return data for * @return array */ public function onMembersContributions($member, $option, $limit = 0, $limitstart = 0, $sort, $areas = null) { $database = App::get('db'); if (is_array($areas) && $limit) { $ars = $this->onMembersContributionsAreas(); if (!isset($areas[$this->_name]) && !in_array($this->_name, $areas) && !array_intersect($areas, array_keys($ars['resources']))) { return array(); } } // Do we have a member ID? if ($member instanceof \Hubzero\User\Profile) { if (!$member->get('uidNumber')) { return array(); } else { $uidNumber = $member->get('uidNumber'); } } else { if (!$member->uidNumber) { return array(); } else { $uidNumber = $member->uidNumber; } } // Instantiate some needed objects $rr = new \Components\Resources\Tables\Resource($database); // Build query $filters = array(); $filters['author'] = $uidNumber; $filters['sortby'] = $sort; //$filters['authorized'] = $authorized; //$filters['usergroups'] = \Hubzero\User\Helper::getGroups($uidNumber, 'all'); $filters['usergroups'] = $member->getGroups('all'); // Get categories $categories = $this->_cats; if (!is_array($categories)) { $rt = new \Components\Resources\Tables\Type($database); $categories = $rt->getMajorTypes(); } // Normalize the category names // e.g., "Oneline Presentations" -> "onlinepresentations" $cats = array(); $normalized_valid_chars = 'a-zA-Z0-9'; for ($i = 0; $i < count($categories); $i++) { $normalized = preg_replace("/[^{$normalized_valid_chars}]/", "", $categories[$i]->type); $normalized = strtolower($normalized); $cats[$normalized] = array(); $cats[$normalized]['id'] = $categories[$i]->id; } if ($limit) { if ($this->_total != null) { $total = 0; $t = $this->_total; foreach ($t as $l) { $total += $l; } } if ($total == 0) { return array(); } $filters['select'] = 'records'; $filters['limit'] = $limit; $filters['limitstart'] = $limitstart; // Check the area of return. If we are returning results for a specific area/category // we'll need to modify the query a bit //if (count($areas) == 1 && key($areas[0]) != 'resources') { if (count($areas) == 1 && !isset($areas['resources'])) { $filters['type'] = isset($cats[$areas[0]]) ? $cats[$areas[0]]['id'] : 0; } // Get results $database->setQuery($rr->buildPluginQuery($filters)); $rows = $database->loadObjectList(); // Did we get any results? if ($rows) { // Loop through the results and set each item's HREF foreach ($rows as $key => $row) { if ($row->alias) { $rows[$key]->href = Route::url('index.php?option=com_resources&alias=' . $row->alias); } else { $rows[$key]->href = Route::url('index.php?option=com_resources&id=' . $row->id); } } } // Return the results return $rows; } else { $filters['select'] = 'count'; // Get a count $counts = array(); $ares = $this->onMembersContributionsAreas(); foreach ($ares as $area => $val) { if (is_array($val)) { $i = 0; foreach ($val as $a => $t) { if ($limitstart == -1) { if ($i == 0) { $database->setQuery($rr->buildPluginQuery($filters)); $counts[] = $database->loadResult(); } else { $counts[] = 0; } } else { $filters['type'] = $cats[$a]['id']; // Execute a count query for each area/category $database->setQuery($rr->buildPluginQuery($filters)); $counts[] = $database->loadResult(); } $i++; } } } // Return the counts $this->_total = $counts; return $counts; } }