/** * Validate data * * @return boolean True if data is valid */ public function check() { $this->uid = intval($this->uid); if (!$this->uid) { $this->setError(\Lang::txt('Entry must have a user ID.')); } $this->type = trim($this->type); if (!$this->type) { $this->setError(\Lang::txt('Entry must have a type (e.g., deposit, withdraw).')); } $this->category = trim($this->category); if (!$this->category) { $this->setError(\Lang::txt('Entry must have a category.')); } if ($this->getError()) { return false; } $this->referenceid = intval($this->referenceid); $this->amount = intval($this->amount); $this->balance = intval($this->balance); if (!$this->created) { $this->created = \Date::toSql(); } return true; }
/** * Build search query and add it to the $results * * @param object $request \Components\Search\Models\Basic\Request * @param object &$results \Components\Search\Models\Basic\Result\Set * @param object $authz \Components\Search\Models\Basic\Authorization * @return void */ public static function onSearch($request, &$results, $authz) { $now = Date::toSql(); $terms = $request->get_term_ar(); $weight = '(match(be.title, be.content) against (\'' . join(' ', $terms['stemmed']) . '\'))'; $addtl_where = array(); foreach ($terms['mandatory'] as $mand) { $addtl_where[] = "(be.title LIKE '%{$mand}%' OR be.content LIKE '%{$mand}%')"; } foreach ($terms['forbidden'] as $forb) { $addtl_where[] = "(be.title NOT LIKE '%{$forb}%' AND be.content NOT LIKE '%{$forb}%')"; } $addtl_where[] = "(be.publish_up <= '{$now}')"; $addtl_where[] = "(be.publish_down = '0000-00-00 00:00:00' OR (be.publish_down != '0000-00-00 00:00:00' AND be.publish_down > '{$now}'))"; $addtl_where[] = '(be.access IN (0,' . implode(',', User::getAuthorisedViewLevels()) . '))'; $rows = new \Components\Search\Models\Basic\Result\Sql("SELECT\n\t\t\t\tbe.id,\n\t\t\t\tbe.title,\n\t\t\t\tbe.content AS description,\n\t\t\t\t(CASE WHEN be.scope_id > 0 AND be.scope='group' THEN\n\t\t\t\t\tconcat('index.php?option=com_groups&cn=', g.cn, '&active=blog&scope=', extract(year from be.created), '/', extract(month from be.created), '/', be.alias)\n\t\t\t\tWHEN be.scope='member' AND be.scope_id > 0 THEN\n\t\t\t\t\tconcat('index.php?option=com_members&id=', be.created_by, '&active=blog&task=', extract(year from be.created), '/', extract(month from be.created), '/', be.alias)\n\t\t\t\tELSE\n\t\t\t\t\tconcat('index.php?option=com_blog&year=', extract(year from be.created), '&month=', extract(month from be.created), '&alias=', be.alias)\n\t\t\t\tEND) AS link,\n\t\t\t\t{$weight} AS weight,\n\t\t\t\t'Blog Entry' AS section,\n\t\t\t\tbe.created AS date,\n\t\t\t\tu.name AS contributors,\n\t\t\t\tbe.created_by AS contributor_ids\n\t\t\tFROM `#__blog_entries` be\n\t\t\tINNER JOIN `#__users` u ON u.id = be.created_by\n\t\t\tLEFT JOIN `#__xgroups` AS g ON g.gidNumber=be.scope_id AND be.scope='group'\n\t\t\tWHERE\n\t\t\t\tbe.state=1 AND\n\t\t\t\t{$weight} > 0" . ($addtl_where ? ' AND ' . join(' AND ', $addtl_where) : '')); if (($rows = $rows->to_associative()) instanceof \Components\Search\Models\Basic\Result\Blank) { return; } $id_map = array(); foreach ($rows as $idx => $row) { $id_map[$row->get('id')] = $idx; } $comments = new \Components\Search\Models\Basic\Result\Sql("SELECT\n\t\t \tCASE WHEN bc.anonymous THEN 'Anonymous Comment' ELSE concat('Comment by ', u.name) END AS title,\n\t\t\tbc.content AS description,\n\t\t\tconcat('index.php?option=com_members&id=', be.created_by, '&active=blog&task=', extract(year from be.created), '/', extract(month from be.created), '/', be.alias) AS link,\n\t\t\tbc.created AS date,\n\t\t\t'Comments' AS section,\n\t\t\tbc.entry_id\n\t\t\tFROM `#__blog_comments` bc\n\t\t\tINNER JOIN `#__blog_entries` be\n\t\t\t\tON be.id = bc.entry_id\n\t\t\tINNER JOIN `#__users` u\n\t\t\t\tON u.id = bc.created_by\n\t\t\tWHERE bc.entry_id IN (" . implode(',', array_keys($id_map)) . ")\n\t\t\tORDER BY bc.created"); foreach ($comments->to_associative() as $comment) { $rows->at($id_map[$comment->get('entry_id')])->add_child($comment); } $results->add($rows); }
/** * Create method for this handler * * @return array of assets created **/ public function create() { // Include needed files require_once PATH_CORE . DS . 'components' . DS . 'com_courses' . DS . 'models' . DS . 'asset.php'; require_once PATH_CORE . DS . 'components' . DS . 'com_courses' . DS . 'tables' . DS . 'asset.association.php'; // Create our asset table object $asset = new \Components\Courses\Models\Asset(); // Grab the incoming content $content = Request::getVar('content', '', 'default', 'none', 2); // Get everything ready to store // Check if vars are already set (i.e. by a sub class), before setting them here $asset->set('title', !empty($this->asset['title']) ? $this->asset['title'] : strip_tags(substr($content, 0, 25))); $asset->set('type', !empty($this->asset['type']) ? $this->asset['type'] : 'text'); $asset->set('subtype', !empty($this->asset['subtype']) ? $this->asset['subtype'] : 'content'); $asset->set('content', !empty($this->asset['content']) ? $this->asset['content'] : $content); $asset->set('url', !empty($this->asset['url']) ? $this->asset['url'] : ''); $asset->set('graded', !empty($this->asset['graded']) ? $this->asset['graded'] : 0); $asset->set('grade_weight', !empty($this->asset['grade_weight']) ? $this->asset['grade_weight'] : ''); $asset->set('created', \Date::toSql()); $asset->set('created_by', App::get('authn')['user_id']); $asset->set('course_id', Request::getInt('course_id', 0)); $asset->set('state', 0); // Check whether asset should be graded if ($graded = Request::getInt('graded', false)) { $asset->set('graded', $graded); $asset->set('grade_weight', 'homework'); } // Save the asset if (!$asset->store()) { return array('error' => 'Asset save failed'); } // If we're saving progress calculation var if ($progress = Request::getInt('progress_factors', false)) { $asset->set('progress_factors', array('asset_id' => $asset->get('id'), 'section_id' => Request::getInt('section_id', 0))); $asset->store(); } // Create asset assoc object $assocObj = new Tables\AssetAssociation($this->db); $this->assoc['asset_id'] = $asset->get('id'); $this->assoc['scope'] = Request::getCmd('scope', 'asset_group'); $this->assoc['scope_id'] = Request::getInt('scope_id', 0); // Save the asset association if (!$assocObj->save($this->assoc)) { return array('error' => 'Asset association save failed'); } // Get the url to return to the page $course_id = Request::getInt('course_id', 0); $offering_alias = Request::getCmd('offering', ''); $course = new \Components\Courses\Models\Course($course_id); $course->offering($offering_alias); $url = Route::url($course->offering()->link() . '&asset=' . $asset->get('id')); $url = rtrim(str_replace('/api', '', Request::root()), '/') . '/' . ltrim($url, '/'); $files = array('asset_id' => $asset->get('id'), 'asset_title' => $asset->get('title'), 'asset_type' => $asset->get('type'), 'asset_subtype' => $asset->get('subtype'), 'asset_url' => $url, 'asset_state' => $asset->get('state'), 'scope_id' => $this->assoc['scope_id']); $return_info = array('asset_id' => $asset->get('id'), 'asset_title' => $asset->get('title'), 'asset_type' => $asset->get('type'), 'asset_subtype' => $asset->get('subtype'), 'asset_url' => $url, 'course_id' => $asset->get('course_id'), 'offering_alias' => $offering_alias, 'scope_id' => $this->assoc['scope_id'], 'files' => array($files)); // Return info return array('assets' => $return_info); }
/** * Method to handle an error condition. * * @param Exception &$error The Exception object to be handled. * @return void */ public static function handleError(&$error) { $renderer = new \Hubzero\Error\Renderer\Page(App::get('document'), App::get('template')->template, App::get('config')->get('debug')); // Make sure the error is a 404 and we are not in the administrator. if (!App::isAdmin() and $error->getCode() == 404) { // Render the error page. $renderer->render($error); } // Get the full current URI. $uri = JURI::getInstance(); $current = $uri->toString(array('scheme', 'host', 'port', 'path', 'query', 'fragment')); // Attempt to ignore idiots. if (strpos($current, 'mosConfig_') !== false || strpos($current, '=http://') !== false) { // Render the error page. $renderer->render($error); } // See if the current url exists in the database as a redirect. $db = App::get('db'); $db->setQuery('SELECT ' . $db->quoteName('new_url') . ', ' . $db->quoteName('published') . ' FROM ' . $db->quoteName('#__redirect_links') . ' WHERE ' . $db->quoteName('old_url') . ' = ' . $db->quote($current), 0, 1); $link = $db->loadObject(); // If no published redirect was found try with the server-relative URL if (!$link or $link->published != 1) { $currRel = $uri->toString(array('path', 'query', 'fragment')); $db->setQuery('SELECT ' . $db->quoteName('new_url') . ', ' . $db->quoteName('published') . ' FROM ' . $db->quoteName('#__redirect_links') . ' WHERE ' . $db->quoteName('old_url') . ' = ' . $db->quote($currRel), 0, 1); $link = $db->loadObject(); } // If a redirect exists and is published, permanently redirect. if ($link and $link->published == 1) { App::redirect($link->new_url, null, null, true, false); } else { $referer = empty($_SERVER['HTTP_REFERER']) ? '' : $_SERVER['HTTP_REFERER']; $db->setQuery('SELECT id FROM ' . $db->quoteName('#__redirect_links') . ' WHERE old_url= ' . $db->quote($current)); $res = $db->loadResult(); if (!$res) { // If not, add the new url to the database. $query = $db->getQuery(true); $query->insert($db->quoteName('#__redirect_links'), false); $columns = array($db->quoteName('old_url'), $db->quoteName('new_url'), $db->quoteName('referer'), $db->quoteName('comment'), $db->quoteName('hits'), $db->quoteName('published'), $db->quoteName('created_date')); $query->columns($columns); $query->values($db->Quote($current) . ', ' . $db->Quote('') . ' ,' . $db->Quote($referer) . ', ' . $db->Quote('') . ',1,0, ' . $db->Quote(Date::toSql())); $db->setQuery($query); $db->query(); } else { // Existing error url, increase hit counter $query = $db->getQuery(true); $query->update($db->quoteName('#__redirect_links')); $query->set($db->quoteName('hits') . ' = ' . $db->quoteName('hits') . ' + 1'); $query->where('id = ' . (int) $res); $db->setQuery((string) $query); $db->query(); } // Render the error page. $renderer->render($error); } }
/** * Get expiration info. Since this is a base class it gets the expiration from the default fallback place. Most * subscription model products will override this method to get the info from the right place * * @param void * @return Object */ public function getExpiration() { $now = Date::toSql(); $sql = 'SELECT `crtmExpires`, IF(`crtmExpires` < \'' . $now . '\', 0, 1) AS `crtmActive` FROM `#__cart_memberships` m LEFT JOIN `#__cart_carts` c ON m.`crtId` = c.`crtId` WHERE m.`pId` = ' . $this->_db->quote($this->pId) . ' AND c.`uidNumber` = ' . $this->_db->quote($this->uId); $this->_db->setQuery($sql); $membershipInfo = $this->_db->loadAssoc(); return $membershipInfo; }
/** * Up **/ public function up() { // Create versions table if (!$this->db->tableExists('#__publication_curation_versions')) { $query = "CREATE TABLE `#__publication_curation_versions` (\n\t\t\t `id` int(11) NOT NULL AUTO_INCREMENT,\n\t\t\t `type_id` int(11) NOT NULL DEFAULT '0',\n\t\t\t `version_number` int(11) NOT NULL DEFAULT '0',\n\t\t\t `created` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',\n\t\t\t `curation` text NOT NULL,\n\t\t\t PRIMARY KEY (`id`),\n\t\t\t KEY `idx_type_id_version_number` (`type_id`,`version_number`)\n\t\t\t) ENGINE=MyISAM DEFAULT CHARSET=utf8;"; $this->db->setQuery($query); $this->db->query(); } // Add column to versions table and populate with historic data if ($this->db->tableExists('#__publication_versions')) { // Add curation_version_id column if (!$this->db->tableHasField('#__publication_versions', 'curation_version_id')) { $query = "ALTER TABLE `#__publication_versions` ADD COLUMN `curation_version_id` int(11)"; $this->db->setQuery($query); $this->db->query(); } // Get versions with saved curation if ($this->db->tableHasField('#__publication_versions', 'curation') && $this->db->tableHasField('#__publication_master_types', 'curation')) { $query = "SELECT DISTINCT(v.curation), t.id as type_id, t.curation as master_curation "; $query .= "FROM `#__publication_versions` AS v "; $query .= "JOIN `#__publications` AS p ON p.id = v.publication_id "; $query .= "JOIN `#__publication_master_types` AS t ON t.id = p.master_type "; $query .= "WHERE v.curation IS NOT NULL "; $query .= "AND v.curation != '' "; $query .= "AND v.accepted !='" . $this->db->getNullDate() . "' "; $query .= "ORDER BY v.accepted ASC"; $this->db->setQuery($query); $results = $this->db->loadObjectList(); if ($results && count($results) > 0) { $path = PATH_CORE . DS . 'components' . DS . 'com_publications' . DS . 'tables' . DS . 'curation.version.php'; include_once $path; foreach ($results as $result) { // Determine version number $query = "SELECT MAX(version_number) FROM `#__publication_curation_versions` WHERE type_id=" . $this->db->quote($result->type_id); $this->db->setQuery($query); $versionNumber = $this->db->loadResult(); $versionNumber = intval($versionNumber) + 1; $stq = new \Components\Publications\Tables\CurationVersion($this->db); $stq->type_id = $result->type_id; $stq->created = Date::toSql(); $stq->version_number = $versionNumber; $stq->curation = $result->curation; if ($stq->store()) { $query = "UPDATE `#__publication_versions` SET `curation_version_id`=" . $stq->id . " WHERE `curation`=" . $this->db->quote($result->curation); $this->db->setQuery($query); $this->db->query(); } } } } } }
/** * Overloaded Check method. Verify we have all needed things to save */ public function check() { // make sure we have content $this->word = trim($this->word); if (!$this->word) { $this->setError(\Lang::txt('Entry must contain some content.')); return false; } if (!$this->created) { $this->created = \Date::toSql(); } return true; }
/** * Retrieve records for items tagged with specific tags * * @param array $tags Tags to match records against * @param mixed $limit SQL record limit * @param integer $limitstart SQL record limit start * @param string $sort The field to sort records by * @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 onTagView($tags, $limit = 0, $limitstart = 0, $sort = '', $areas = null) { $response = array('name' => $this->_name, 'title' => Lang::txt('PLG_TAGS_BLOGS'), 'total' => 0, 'results' => null, 'sql' => ''); if (empty($tags)) { return $response; } $database = App::get('db'); $ids = array(); foreach ($tags as $tag) { $ids[] = $tag->get('id'); } $ids = implode(',', $ids); $now = Date::toSql(); // Build the query $e_count = "SELECT COUNT(f.id) FROM (SELECT e.id, COUNT(DISTINCT t.tagid) AS uniques"; $e_fields = "SELECT e.id, e.title, e.alias, NULL AS itext, e.content AS ftext, e.state, e.created, e.created_by,\n\t\t\t\t\tNULL AS modified, e.publish_up, e.publish_down, CONCAT('index.php?option=com_blog&task=view&id=', e.id) AS href,\n\t\t\t\t\t'blogs' AS section, COUNT(DISTINCT t.tagid) AS uniques, e.params, e.scope AS rcount, u.name AS data1,\n\t\t\t\t\te.scope_id AS data2, NULL AS data3 "; $e_from = " FROM #__blog_entries AS e, #__tags_object AS t, #__users AS u"; $e_where = " WHERE e.created_by=u.id AND t.objectid=e.id AND t.tbl='blog' AND t.tagid IN ({$ids})"; if (User::isGuest()) { $e_where .= " AND e.state=1"; } else { $e_where .= " AND e.state>0"; } $e_where .= " AND (e.publish_up = '0000-00-00 00:00:00' OR e.publish_up <= " . $database->quote($now) . ") "; $e_where .= " AND (e.publish_down = '0000-00-00 00:00:00' OR e.publish_down >= " . $database->quote($now) . ") "; $e_where .= " GROUP BY e.id HAVING uniques=" . count($tags); $order_by = " ORDER BY "; switch ($sort) { case 'title': $order_by .= 'title ASC, publish_up'; break; case 'id': $order_by .= "id DESC"; break; case 'date': default: $order_by .= 'publish_up DESC, title'; break; } $order_by .= $limit != 'all' ? " LIMIT {$limitstart},{$limit}" : ""; $database->setQuery($e_count . $e_from . $e_where . ") AS f"); $response['total'] = $database->loadResult(); if ($areas && $areas == $response['name']) { $database->setQuery($e_fields . $e_from . $e_where . $order_by); $response['results'] = $database->loadObjectList(); } else { $response['sql'] = $e_fields . $e_from . $e_where; } return $response; }
/** * Validate data * * @return void */ public function check() { $this->token = trim($this->token); if (!$this->token) { $this->setError(\Lang::txt('Entry must contain a token.')); return false; } if (!$this->created) { $this->created = \Date::toSql(); } if ($this->id) { $this->modified = $this->modified ? $this->modified : \Date::toSql(); } return true; }
/** * Overloaded store method for the notes table. * * @param boolean $updateNulls Toggle whether null values should be updated. * * @return boolean True on success, false on failure. * * @since 2.5 */ public function store($updateNulls = false) { // Initialise variables. $date = Date::toSql(); $userId = User::get('id'); if (empty($this->id)) { // New record. $this->created_time = $date; $this->created_user_id = $userId; } else { // Existing record. $this->modified_time = $date; $this->modified_user_id = $userId; } // Attempt to store the data. return parent::store($updateNulls); }
/** * Retrieve records for items tagged with specific tags * * @param array $tags Tags to match records against * @param mixed $limit SQL record limit * @param integer $limitstart SQL record limit start * @param string $sort The field to sort records by * @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 onTagView($tags, $limit = 0, $limitstart = 0, $sort = '', $areas = null) { $response = array('name' => $this->_name, 'title' => Lang::txt('PLG_TAGS_CITATIONS'), 'total' => 0, 'results' => null, 'sql' => ''); if (empty($tags)) { return $response; } $database = App::get('db'); $ids = array(); foreach ($tags as $tag) { $ids[] = $tag->get('id'); } $ids = implode(',', $ids); $now = Date::toSql(); // Build the query $e_count = "SELECT COUNT(f.id) FROM (SELECT e.id, COUNT(DISTINCT t.tagid) AS uniques"; $e_fields = "SELECT e.id, e.title, e.author, e.booktitle, e.doi, e.published, e.created, e.year, e.month, e.isbn, e.journal, e.url as href,\n\t\t\t\t\t'citations' AS section, COUNT(DISTINCT t.tagid) AS uniques, e.volume, e.number, e.type, e.pages, e.publisher "; $e_from = " FROM #__citations AS e, #__tags_object AS t"; //", #__users AS u"; $e_where = " WHERE t.objectid=e.id AND t.tbl='citations' AND t.tagid IN ({$ids})"; //e.uid=u.id AND $e_where .= " AND e.published=1 AND e.id!='' "; $e_where .= " GROUP BY e.id HAVING uniques=" . count($tags); $order_by = " ORDER BY "; switch ($sort) { case 'title': $order_by .= 'title ASC, created'; break; case 'id': $order_by .= "id DESC"; break; case 'date': default: $order_by .= 'created DESC, title'; break; } $order_by .= $limit != 'all' ? " LIMIT {$limitstart},{$limit}" : ""; $database->setQuery($e_count . $e_from . $e_where . ") AS f"); $response['total'] = $database->loadResult(); if ($areas && $areas == $response['name']) { $database->setQuery($e_fields . $e_from . $e_where . $order_by); $response['results'] = $database->loadObjectList(); } else { $response['sql'] = $e_fields . $e_from . $e_where; } return $response; }
/** * Validate data * * @return boolean True if valid, false if not */ public function check() { if (trim($this->rating) == '') { $this->setError(\Lang::txt('Your review must have a rating.')); } if (!$this->resource_id) { $this->setError(\Lang::txt('Review entry missing Resource ID.')); } if ($this->getError()) { return false; } if (!$this->created || $this->created == '0000-00-00 00:00:00') { $this->created = \Date::toSql(); } $this->user_id = $this->user_id ?: \User::get('id'); return true; }
/** * Validate data * * @return boolean True if data is valid */ public function check() { $this->itemid = intval($this->itemid); if (!$this->itemid) { $this->setError(\Lang::txt('Entry must have an item ID.')); } $this->category = trim($this->category); if (!$this->category) { $this->setError(\Lang::txt('Entry must have a category.')); } if ($this->getError()) { return false; } if (!$this->date) { $this->date = \Date::toSql(); } return true; }
/** * Validate data * * @return boolean True if valid, False if not */ public function check() { $this->name = trim($this->name); if ($this->name == '') { $this->setError(\Lang::txt('Name field is required for import.')); return false; } $this->type = trim($this->type); if ($this->type == '') { $this->setError(\Lang::txt('Type field is required for import.')); return false; } if (!$this->id) { $this->created_at = $this->created_at ?: \Date::toSql(); $this->created_by = $this->created_by ?: \User::get('id'); } return true; }
/** * Validate data * * @return boolean True if data is valid */ public function check() { if (trim($this->rating) == '') { $this->setError(Lang::txt('Your review must have a rating.')); return false; } if (!$this->publication_id) { $this->setError(\Lang::txt('Review entry missing Publication ID.')); } if ($this->getError()) { return false; } if (!$this->created || $this->created == $this->_db->getNullDate()) { $this->created = \Date::toSql(); } $this->created_by = $this->created_by ?: \User::get('id'); return true; }
/** * Check if page was viewed recently * * @param integer $toolid Project tool id * @param integer $userid User id * @return mixed Return string or NULL */ public function checkView($toolid = 0, $userid = 0) { if (!intval($toolid) || !intval($userid)) { return false; } $now = Date::toSql(); $lastView = NULL; if ($this->loadView($toolid, $userid)) { $lastView = $this->viewed; } else { $this->parent_id = $toolid; $this->userid = $userid; } // Record new viewing time for future comparison $this->viewed = $now; $this->store(); return $lastView; }
/** * Retrieve records for items tagged with specific tags * * @param array $tags Tags to match records against * @param mixed $limit SQL record limit * @param integer $limitstart SQL record limit start * @param string $sort The field to sort records by * @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 onTagView($tags, $limit = 0, $limitstart = 0, $sort = '', $areas = null) { $response = array('name' => $this->_name, 'title' => Lang::txt('PLG_TAGS_EVENTS'), 'total' => 0, 'results' => null, 'sql' => ''); if (empty($tags)) { return $response; } $database = App::get('db'); $ids = array(); foreach ($tags as $tag) { $ids[] = $tag->get('id'); } $ids = implode(',', $ids); $now = Date::toSql(); // Build the query $e_count = "SELECT COUNT(f.id) FROM (SELECT e.id, COUNT(DISTINCT t.tagid) AS uniques"; $e_fields = "SELECT e.id, e.title, NULL AS alias, NULL AS itext, e.content AS ftext, e.state, e.created, e.created_by,\n\t\t\t\t\t\tNULL AS modified, e.publish_up, e.publish_down, CONCAT('index.php?option=com_events&task=details&id=', e.id) AS href,\n\t\t\t\t\t\t'events' AS section, COUNT(DISTINCT t.tagid) AS uniques, e.params, NULL AS rcount, NULL AS data1,\n\t\t\t\t\t\tNULL AS data2, NULL AS data3 "; $e_from = " FROM #__events AS e, #__tags_object AS t"; $e_where = " WHERE e.state=1 AND t.objectid=e.id AND t.tbl='events' AND t.tagid IN ({$ids})"; $e_where .= " GROUP BY e.id HAVING uniques=" . count($tags); $order_by = " ORDER BY "; switch ($sort) { case 'title': $order_by .= 'title ASC, publish_up'; break; case 'id': $order_by .= "id DESC"; break; case 'date': default: $order_by .= 'publish_up DESC, title'; break; } $order_by .= $limit != 'all' ? " LIMIT {$limitstart},{$limit}" : ""; $database->setQuery($e_count . $e_from . $e_where . ") AS f"); $response['total'] = $database->loadResult(); if ($areas && $areas == $response['name']) { $database->setQuery($e_fields . $e_from . $e_where . $order_by); $response['results'] = $database->loadObjectList(); } else { \Hubzero\Document\Assets::addComponentStylesheet('com_events'); $response['sql'] = $e_fields . $e_from . $e_where; } return $response; }
/** * Retrieve records for items tagged with specific tags * * @param array $tags Tags to match records against * @param mixed $limit SQL record limit * @param integer $limitstart SQL record limit start * @param string $sort The field to sort records by * @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 onTagView($tags, $limit = 0, $limitstart = 0, $sort = '', $areas = null) { $response = array('name' => $this->_name, 'title' => Lang::txt('PLG_TAGS_KB'), 'total' => 0, 'results' => null, 'sql' => ''); if (empty($tags)) { return $response; } $database = App::get('db'); $ids = array(); foreach ($tags as $tag) { $ids[] = $tag->get('id'); } $ids = implode(',', $ids); $now = Date::toSql(); // Build the query $e_count = "SELECT COUNT(f.id) FROM (SELECT e.id, COUNT(DISTINCT t.tagid) AS uniques"; $e_fields = "SELECT e.id, e.title, e.alias, e.fulltxt AS itext, e.fulltxt AS ftext, e.state, e.created, e.created_by, e.modified, e.created AS publish_up,\n\t\t\t\t\tNULL AS publish_down, CONCAT('index.php?option=com_kb&category=&alias=', e.alias) AS href, 'kb' AS section, COUNT(DISTINCT t.tagid) AS uniques,\n\t\t\t\t\tNULL AS params, e.helpful AS rcount, cc.alias AS data1, c.alias AS data2, NULL AS data3 "; $e_from = " FROM #__kb_articles AS e\n\t\t\t\t\tLEFT JOIN #__categories AS cc ON cc.id = e.category\n\t\t\t\t\tLEFT JOIN #__tags_object AS t ON t.objectid=e.id AND t.tbl='kb' AND t.tagid IN ({$ids})"; $e_where = " WHERE e.state=1 AND e.access IN (" . implode(',', User::getAuthorisedViewLevels()) . ")"; $e_where .= " GROUP BY e.id HAVING uniques=" . count($tags); $order_by = " ORDER BY "; switch ($sort) { case 'title': $order_by .= 'title ASC, created'; break; case 'id': $order_by .= "id DESC"; break; case 'date': default: $order_by .= 'created DESC, title'; break; } $order_by .= $limit != 'all' ? " LIMIT {$limitstart},{$limit}" : ""; $database->setQuery($e_count . $e_from . $e_where . ") AS f"); $response['total'] = $database->loadResult(); if ($areas && $areas == $response['name']) { $database->setQuery($e_fields . $e_from . $e_where . $order_by); $response['results'] = $database->loadObjectList(); } else { $response['sql'] = $e_fields . $e_from . $e_where; } return $response; }
/** * Check if a user is an employer * * @param string $uid Parameter description (if any) ... * @param integer $admin Parameter description (if any) ... * @return boolean Return description (if any) ... */ public function isEmployer($uid, $admin = 0) { if ($uid === NULL) { return false; } $now = \Date::toSql(); $query = "SELECT e.id FROM {$this->_tbl} AS e "; if (!$admin) { $query .= "JOIN #__users_points_subscriptions AS s ON s.id=e.subscriptionid AND s.uid=e.uid "; $query .= "WHERE e.uid = " . $this->_db->quote($uid) . " AND s.status=1"; $query .= " AND s.expires > " . $this->_db->quote($now) . " "; } else { $query .= "WHERE e.uid = 1"; } $this->_db->setQuery($query); if ($this->_db->loadResult()) { return true; } return false; }
/** * Validate data * * @return boolean True if data is valid */ public function check() { $this->title = trim($this->title); if (!$this->title) { $this->setError(\Lang::txt('Please provide a title.')); return false; } if (!$this->alias) { $this->alias = str_replace(' ', '-', strtolower($this->title)); } $this->alias = preg_replace("/[^a-zA-Z0-9\\-]/", '', $this->alias); if (!$this->id) { $this->created = \Date::toSql(); $this->created_by = \User::get('id'); } else { $this->modified = \Date::toSql(); $this->modified_by = \User::get('id'); } return true; }
/** * Data validation * * @return boolean True on success, False on error */ public function check() { $this->title = trim($this->title); $this->description = trim($this->description); if (!$this->title) { $this->setError(\Lang::txt('PLG_RESOURCES_SPONSORS_MISSING_TITLE')); return false; } if (!$this->alias) { $this->alias = strtolower($this->title); } $this->alias = preg_replace("/[^a-zA-Z0-9\\-]/", '', $this->alias); if (!$this->id) { $this->created = \Date::toSql(); $this->created_by = \User::get('id'); } else { $this->modified = \Date::toSql(); $this->modified_by = \User::get('id'); } return true; }
/** * Override the check function to do a little input cleanup * * @return return true */ public function check() { $this->course_id = intval($this->course_id); if (!$this->course_id) { $this->setError(Lang::txt('Please provide a course ID.')); return false; } $this->title = trim($this->title); if (!$this->title) { $this->setError(Lang::txt('Please provide a title.')); return false; } if (!isset($this->type) && !$this->url && $this->content) { $this->type = 'text'; $this->subtype = 'note'; } if (!$this->id) { $this->state = isset($this->state) ? $this->state : 1; $this->created = Date::toSql(); $this->created_by = User::get('id'); } return true; }
/** * Validate data * * @return boolean True if data is valid */ public function check() { $this->item_id = intval($this->item_id); if (!$this->item_id) { $this->setError(\Lang::txt('Missing item ID.')); return false; } $this->item_type = strtolower(preg_replace("/[^a-zA-Z0-9\\-]/", '', trim($this->item_type))); if (!$this->item_type) { $this->setError(\Lang::txt('Missing item type.')); return false; } if (!$this->created_by) { $this->created_by = \User::get('id'); } if (!$this->email) { $this->email = \User::get('email'); } if (!$this->id) { $this->created = \Date::toSql(); } return true; }
/** * Saves a project * Redirects to main listing * * @param boolean $redirect * @return void */ public function saveTask($redirect = false) { // Check for request forgeries Request::checkToken(); // Config $setup_complete = $this->config->get('confirm_step', 0) ? 3 : 2; // Incoming $formdata = $_POST; $id = Request::getVar('id', 0); $action = Request::getVar('admin_action', ''); $message = rtrim(\Hubzero\Utility\Sanitize::clean(Request::getVar('message', ''))); // Load model $model = new Models\Project($id); if (!$model->exists()) { App::redirect('index.php?option=' . $this->_option, Lang::txt('COM_PROJECTS_NOTICE_ID_NOT_FOUND'), 'error'); } $title = $formdata['title'] ? rtrim($formdata['title']) : $model->get('title'); $type = isset($formdata['type']) ? $formdata['type'] : 1; $model->set('title', $title); $model->set('about', rtrim(\Hubzero\Utility\Sanitize::clean($formdata['about']))); $model->set('type', $type); $model->set('modified', Date::toSql()); $model->set('modified_by', User::get('id')); $model->set('private', Request::getInt('private', 0)); $this->_message = Lang::txt('COM_PROJECTS_SUCCESS_SAVED'); // Was project suspended? $suspended = false; if ($model->isInactive()) { $suspended = $model->table('Activity')->checkActivity($id, Lang::txt('COM_PROJECTS_ACTIVITY_PROJECT_SUSPENDED')); } $subject = Lang::txt('COM_PROJECTS_PROJECT') . ' "' . $model->get('alias') . '" '; $sendmail = 0; // Get project managers $managers = $model->table('Owner')->getIds($id, 1, 1); // Admin actions if ($action) { switch ($action) { case 'delete': $model->set('state', 2); $what = Lang::txt('COM_PROJECTS_ACTIVITY_PROJECT_DELETED'); $subject .= Lang::txt('COM_PROJECTS_MSG_ADMIN_DELETED'); $this->_message = Lang::txt('COM_PROJECTS_SUCCESS_DELETED'); break; case 'suspend': $model->set('state', 0); $what = Lang::txt('COM_PROJECTS_ACTIVITY_PROJECT_SUSPENDED'); $subject .= Lang::txt('COM_PROJECTS_MSG_ADMIN_SUSPENDED'); $this->_message = Lang::txt('COM_PROJECTS_SUCCESS_SUSPENDED'); break; case 'reinstate': $model->set('state', 1); $what = $suspended ? Lang::txt('COM_PROJECTS_ACTIVITY_PROJECT_REINSTATED') : Lang::txt('COM_PROJECTS_ACTIVITY_PROJECT_ACTIVATED'); $subject .= $suspended ? Lang::txt('COM_PROJECTS_MSG_ADMIN_REINSTATED') : Lang::txt('COM_PROJECTS_MSG_ADMIN_ACTIVATED'); $this->_message = $suspended ? Lang::txt('COM_PROJECTS_SUCCESS_REINSTATED') : Lang::txt('COM_PROJECTS_SUCCESS_ACTIVATED'); break; } // Add activity $model->recordActivity($what, 0, '', '', 'project', 0, $admin = 1); $sendmail = 1; } elseif ($message) { $subject .= ' - ' . Lang::txt('COM_PROJECTS_MSG_ADMIN_NEW_MESSAGE'); $sendmail = 1; $this->_message = Lang::txt('COM_PROJECTS_SUCCESS_MESSAGE_SENT'); } // Save changes if (!$model->store()) { $this->setError($model->getError()); return false; } // Incoming tags $tags = Request::getVar('tags', '', 'post'); // Save the tags $cloud = new Models\Tags($model->get('id')); $cloud->setTags($tags, User::get('id'), 1); // Save params $incoming = Request::getVar('params', array()); if (!empty($incoming)) { foreach ($incoming as $key => $value) { if ($key == 'quota' || $key == 'pubQuota') { // convert GB to bytes $value = Helpers\Html::convertSize(floatval($value), 'GB', 'b'); } $model->saveParam($key, $value); } } // Add members if specified $this->model = $model; $this->_saveMember(); // Change ownership $this->_changeOwnership(); // Send message if ($this->config->get('messaging', 0) && $sendmail && count($managers) > 0) { // Email config $from = array(); $from['name'] = Config::get('sitename') . ' ' . Lang::txt('COM_PROJECTS'); $from['email'] = Config::get('mailfrom'); // Html email $from['multipart'] = md5(date('U')); // Message body $eview = new \Hubzero\Mail\View(array('name' => 'emails', 'layout' => 'admin_plain')); $eview->option = $this->_option; $eview->subject = $subject; $eview->action = $action; $eview->project = $model; $eview->message = $message; $body = array(); $body['plaintext'] = $eview->loadTemplate(false); $body['plaintext'] = str_replace("\n", "\r\n", $body['plaintext']); // HTML email $eview->setLayout('admin_html'); $body['multipart'] = $eview->loadTemplate(); $body['multipart'] = str_replace("\n", "\r\n", $body['multipart']); // Send HUB message Event::trigger('xmessage.onSendMessage', array('projects_admin_notice', $subject, $body, $from, $managers, $this->_option)); } Notify::message($this->_message, 'success'); // Redirect to edit view? if ($redirect) { App::redirect(Route::url('index.php?option=' . $this->_option . '&task=edit&id=' . $id, false)); } else { App::redirect(Route::url('index.php?option=' . $this->_option, false)); } }
/** * Save a review * * @return void */ public function savereview() { // Is the user logged in? if (User::isGuest()) { $this->setError(Lang::txt('PLG_PUBLICATIONS_REVIEWS_LOGIN_NOTICE')); return; } $publication =& $this->publication; // Do we have a publication ID? if (!$publication->exists()) { // No ID - fail! Can't do anything else without an ID $this->setError(Lang::txt('PLG_PUBLICATIONS_REVIEWS_NO_RESOURCE_ID')); return; } $database = App::get('db'); // Bind the form data to our object $row = new \Components\Publications\Tables\Review($database); if (!$row->bind($_POST)) { $this->setError($row->getError()); return; } // Perform some text cleaning, etc. $row->id = Request::getInt('reviewid', 0); $row->state = 1; $row->comment = \Hubzero\Utility\Sanitize::stripAll($row->comment); $row->anonymous = $row->anonymous == 1 || $row->anonymous == '1' ? $row->anonymous : 0; $row->created = $row->created ? $row->created : Date::toSql(); $row->created_by = User::get('id'); $message = $row->id ? Lang::txt('PLG_PUBLICATIONS_REVIEWS_EDITS_SAVED') : Lang::txt('PLG_PUBLICATIONS_REVIEWS_REVIEW_POSTED'); // Check for missing (required) fields if (!$row->check()) { $this->setError($row->getError()); return; } // Save the data if (!$row->store()) { $this->setError($row->getError()); return; } // Calculate the new average rating for the parent publication $publication->table()->calculateRating(); $publication->table()->updateRating(); // Process tags $tags = trim(Request::getVar('review_tags', '')); if ($tags) { $rt = new \Components\Publications\Helpers\Tags($database); $rt->tag_object($row->created_by, $publication->get('id'), $tags, 1, 0); } // Get version authors $users = $publication->table('Author')->getAuthors($publication->get('version_id'), 1, 1, true); // Build the subject $subject = Config::get('sitename') . ' ' . Lang::txt('PLG_PUBLICATIONS_REVIEWS_CONTRIBUTIONS'); // Message $eview = new \Hubzero\Plugin\View(array('folder' => 'publications', 'element' => 'reviews', 'name' => 'emails')); $eview->option = $this->_option; $eview->juser = User::getInstance(); $eview->publication = $publication; $message = $eview->loadTemplate(); $message = str_replace("\n", "\r\n", $message); // Build the "from" data for the e-mail $from = array(); $from['name'] = Config::get('sitename') . ' ' . Lang::txt('PLG_PUBLICATIONS_REVIEWS_CONTRIBUTIONS'); $from['email'] = Config::get('mailfrom'); // Send message if (!Event::trigger('xmessage.onSendMessage', array('publications_new_comment', $subject, $message, $from, $users, $this->_option))) { $this->setError(Lang::txt('PLG_PUBLICATIONS_REVIEWS_FAILED_TO_MESSAGE')); } App::redirect(Route::url($publication->link('reviews')), $message); return; }
/** * Process data * * @return void */ protected function _process() { // New project? $new = $this->model->exists() ? false : true; // Are we in setup? $setup = $new || $this->model->inSetup() ? true : false; // Incoming $private = Request::getInt('private', 1); // Save section switch ($this->section) { case 'describe': case 'info': // Incoming $name = trim(Request::getVar('name', '', 'post')); $title = trim(Request::getVar('title', '', 'post')); $name = preg_replace('/ /', '', $name); $name = strtolower($name); // Clean up title from any scripting $title = preg_replace('/\\s+/', ' ', $title); $title = $this->_txtClean($title); // Check incoming data if ($setup && $new && !$this->model->check($name, $this->model->get('id'))) { $this->setError(Lang::txt('COM_PROJECTS_ERROR_NAME_INVALID_OR_EMPTY')); return false; } elseif (!$title) { $this->setError(Lang::txt('COM_PROJECTS_ERROR_TITLE_SHORT_OR_EMPTY')); return false; } if ($this->model->exists()) { $this->model->set('modified', Date::toSql()); $this->model->set('modified_by', User::get('id')); } else { $this->model->set('alias', $name); $this->model->set('created', Date::toSql()); $this->model->set('created_by_user', User::get('id')); $this->model->set('owned_by_group', $this->_gid); $this->model->set('owned_by_user', User::get('id')); $this->model->set('private', $this->config->get('privacy', 1)); } $this->model->set('title', \Hubzero\Utility\String::truncate($title, 250)); $this->model->set('about', trim(Request::getVar('about', '', 'post', 'none', 2))); $this->model->set('type', Request::getInt('type', 1, 'post')); // save advanced permissions if (isset($_POST['private'])) { $this->model->set('private', $private); } if ($setup && !$this->model->exists()) { // Copy params from default project type $objT = $this->model->table('Type'); $this->model->set('params', $objT->getParams($this->model->get('type'))); } // Save changes if (!$this->model->store()) { $this->setError($this->model->getError()); return false; } // Save owners for new projects if ($new) { $this->_identifier = $this->model->get('alias'); // Group owners $objO = $this->model->table('Owner'); if ($this->_gid) { if (!$objO->saveOwners($this->model->get('id'), User::get('id'), 0, $this->_gid, 0, 1, 1, '', $split_group_roles = 0)) { $this->setError(Lang::txt('COM_PROJECTS_ERROR_SAVING_AUTHORS') . ': ' . $objO->getError()); return false; } // Make sure project creator is manager $objO->reassignRole($this->model->get('id'), $users = array(User::get('id')), 0, 1); } elseif (!$objO->saveOwners($this->model->get('id'), User::get('id'), User::get('id'), $this->_gid, 1, 1, 1)) { $this->setError(Lang::txt('COM_PROJECTS_ERROR_SAVING_AUTHORS') . ': ' . $objO->getError()); return false; } } break; case 'team': if ($new) { return false; } // Save team $content = Event::trigger('projects.onProject', array($this->model, 'save', array('team'))); if (isset($content[0]) && $this->next == $this->section) { if (isset($content[0]['msg']) && !empty($content[0]['msg'])) { $this->_setNotification($content[0]['msg']['message'], $content[0]['msg']['type']); } } break; case 'settings': if ($new) { return false; } // Save privacy if (isset($_POST['private'])) { $this->model->set('private', $private); // Save changes if (!$this->model->store()) { $this->setError($this->model->getError()); return false; } } // Save params $incoming = Request::getVar('params', array()); if (!empty($incoming)) { foreach ($incoming as $key => $value) { $this->model->saveParam($key, $value); // If grant information changed if ($key == 'grant_status') { // Meta data for comment $meta = '<meta>' . Date::of('now')->toLocal('M d, Y') . ' - ' . User::get('name') . '</meta>'; $cbase = $this->model->get('admin_notes'); $cbase .= '<nb:sponsored>' . Lang::txt('COM_PROJECTS_PROJECT_MANAGER_GRANT_INFO_UPDATE') . $meta . '</nb:sponsored>'; $this->model->set('admin_notes', $cbase); // Save admin notes if (!$this->model->store()) { $this->setError($this->model->getError()); return false; } $admingroup = $this->config->get('ginfo_group', ''); if (\Hubzero\User\Group::getInstance($admingroup)) { $admins = Helpers\Html::getGroupMembers($admingroup); // Send out email to admins if (!empty($admins)) { Helpers\Html::sendHUBMessage($this->_option, $this->model, $admins, Lang::txt('COM_PROJECTS_EMAIL_ADMIN_REVIEWER_NOTIFICATION'), 'projects_new_project_admin', 'admin', Lang::txt('COM_PROJECTS_PROJECT_MANAGER_GRANT_INFO_UPDATE'), 'sponsored'); } } } } } break; } }
/** * Get top publication tags * * @param integer $limit * @return mixed Return description (if any) ... */ public function getTopTags($limit) { $tj = \Components\Tags\Models\Object::blank(); $sql = "SELECT t.tag, t.raw_tag, t.admin, tj.tagid, tj.objectid, COUNT(tj.tagid) AS tcount "; $sql .= "FROM #__tags AS t "; $sql .= "JOIN " . $tj->getTableName() . " AS tj ON t.id=tj.tagid "; $sql .= "LEFT JOIN #__publication_versions AS V ON V.publication_id=tj.objectid AND tj.tbl='publications' "; $sql .= "WHERE t.id=tj.tagid AND t.admin=0 "; $sql .= "AND tj.tbl=" . $this->_db->quote($this->_tbl) . " "; $sql .= "AND V.state=1 AND V.main=1 AND V.access!=4 "; $sql .= "AND V.published_up < " . $this->_db->quote(Date::toSql()) . " "; $sql .= "AND (V.published_down = '0000-00-00 00:00:00' OR V.published_down > " . $this->_db->quote(Date::toSql()) . ") "; $sql .= "GROUP BY tagid "; $sql .= "ORDER BY tcount DESC "; $sql .= "LIMIT {$limit}"; $this->_db->setQuery($sql); return $this->_db->loadObjectList(); }
// No direct access defined('_HZEXEC_') or die; $canDo = \Components\Collections\Helpers\Permissions::getActions('post'); $text = $this->task == 'edit' ? Lang::txt('JACTION_EDIT') : Lang::txt('JACTION_CREATE'); Toolbar::title(Lang::txt('COM_COLLECTIONS') . ': ' . Lang::txt('COM_COLLECTIONS_POSTS') . ': ' . $text, 'collection.png'); if ($canDo->get('core.edit')) { Toolbar::apply(); Toolbar::save(); Toolbar::spacer(); } Toolbar::cancel(); Toolbar::spacer(); Toolbar::help('collection'); if (!$this->row->get('id')) { $this->row->set('created_by', User::get('id')); $this->row->set('created', Date::toSql()); } ?> <script type="text/javascript"> function submitbutton(pressbutton) { var form = document.adminForm; if (pressbutton == 'cancel') { submitform(pressbutton); return; } <?php echo $this->editor()->save('text'); ?>
/** * Event call to return data for a specific member * * @param object $user User * @param object $member MembersProfile * @return array Return array of html */ private function _getData($what = 'count', $who = null, $filters = array()) { if (!isset($filters['start'])) { $filters['start'] = 0; } if (!isset($filters['limit'])) { $filters['limit'] = 25; } if (!isset($filters['sort']) || !$filters['sort']) { $filters['sort'] = 'enrolled'; } $results = null; $who = strtolower(trim($who)); switch ($who) { case 'student': $now = Date::toSql(); if ($what == 'count') { $this->database->setQuery("SELECT COUNT(*)\n\t\t\t\t\t\tFROM `#__courses` AS c\n\t\t\t\t\t\t\tJOIN `#__courses_members` AS m ON m.course_id=c.id\n\t\t\t\t\t\t\tLEFT JOIN `#__courses_offerings` AS o ON o.id=m.offering_id\n\t\t\t\t\t\t\tLEFT JOIN `#__courses_offering_sections` AS s on s.id=m.section_id\n\t\t\t\t\t\t\tLEFT JOIN `#__courses_roles` AS r ON r.id=m.role_id\n\t\t\t\t\t\tWHERE c.state=1 AND m.user_id=" . (int) $this->member->get('uidNumber') . " AND m.student=1\n\t\t\t\t\t\t\tAND (s.publish_down='0000-00-00 00:00:00' OR s.publish_down < " . $this->database->quote($now) . ") AND s.state=1 AND o.state=1"); $results = $this->database->loadResult(); } else { $this->database->setQuery("SELECT c.id, c.state, c.alias, c.title, o.alias AS offering_alias, o.title AS offering_title, s.alias AS section_alias, s.title AS section_title, s.is_default,\n\t\t\t\t\t\tm.enrolled, s.publish_up AS starts, s.publish_down AS ends\n\t\t\t\t\t\tFROM `#__courses` AS c\n\t\t\t\t\t\t\tJOIN `#__courses_members` AS m ON m.course_id=c.id\n\t\t\t\t\t\t\tLEFT JOIN `#__courses_offerings` AS o ON o.id=m.offering_id\n\t\t\t\t\t\t\tLEFT JOIN `#__courses_offering_sections` AS s on s.id=m.section_id\n\t\t\t\t\t\t\tLEFT JOIN `#__courses_roles` AS r ON r.id=m.role_id\n\t\t\t\t\t\tWHERE c.state=1 AND m.user_id=" . (int) $this->member->get('uidNumber') . " AND m.student=1\n\t\t\t\t\t\t\tAND (s.publish_down='0000-00-00 00:00:00' OR s.publish_down < " . $this->database->quote($now) . ") AND s.state=1 AND o.state=1\n\t\t\t\t\t\tORDER BY " . $filters['sort'] . " ASC LIMIT " . $filters['start'] . "," . $filters['limit']); $results = $this->database->loadObjectList(); } break; case 'manager': if ($what == 'count') { $this->database->setQuery("SELECT COUNT(*)\n\t\t\t\t\t\t\tFROM `#__courses` AS c\n\t\t\t\t\t\t\tJOIN `#__courses_members` AS m ON m.course_id=c.id\n\t\t\t\t\t\t\tLEFT JOIN `#__courses_offerings` AS o ON o.id=m.offering_id\n\t\t\t\t\t\t\tLEFT JOIN `#__courses_offering_sections` AS s on s.id=m.section_id\n\t\t\t\t\t\t\tLEFT JOIN `#__courses_roles` AS r ON r.id=m.role_id\n\t\t\t\t\t\t\tWHERE c.state IN (1, 3) AND m.user_id=" . (int) $this->member->get('uidNumber') . " AND m.student=0 AND r.alias='manager'"); $results = $this->database->loadResult(); } else { $this->database->setQuery("SELECT c.id, c.state, c.alias, c.title, o.alias AS offering_alias, o.title AS offering_title, s.alias AS section_alias, s.title AS section_title, s.is_default,\n\t\t\t\t\t\t\tm.enrolled, r.alias AS role_alias, r.title AS role_title, s.publish_up AS starts, s.publish_down AS ends\n\t\t\t\t\t\t\tFROM `#__courses` AS c\n\t\t\t\t\t\t\tJOIN `#__courses_members` AS m ON m.course_id=c.id\n\t\t\t\t\t\t\tLEFT JOIN `#__courses_offerings` AS o ON o.id=m.offering_id\n\t\t\t\t\t\t\tLEFT JOIN `#__courses_offering_sections` AS s on s.id=m.section_id\n\t\t\t\t\t\t\tLEFT JOIN `#__courses_roles` AS r ON r.id=m.role_id\n\t\t\t\t\t\tWHERE c.state IN (1, 3) AND m.user_id=" . (int) $this->member->get('uidNumber') . " AND m.student=0 AND r.alias='manager'\n\t\t\t\t\t\tORDER BY " . $filters['sort'] . " ASC LIMIT " . $filters['start'] . "," . $filters['limit']); $results = $this->database->loadObjectList(); } break; case 'instructor': if ($what == 'count') { $this->database->setQuery("SELECT COUNT(*)\n\t\t\t\t\t\tFROM `#__courses` AS c\n\t\t\t\t\t\tJOIN `#__courses_members` AS m ON m.course_id=c.id\n\t\t\t\t\t\tLEFT JOIN `#__courses_offerings` AS o ON o.id=m.offering_id\n\t\t\t\t\t\tLEFT JOIN `#__courses_offering_sections` AS s on s.id=m.section_id\n\t\t\t\t\t\tLEFT JOIN `#__courses_roles` AS r ON r.id=m.role_id\n\t\t\t\t\t\tWHERE c.state IN (1, 3) AND m.user_id=" . (int) $this->member->get('uidNumber') . " AND m.student=0 AND r.alias=" . $this->database->Quote('instructor')); $results = $this->database->loadResult(); } else { $this->database->setQuery("SELECT c.id, c.state, c.alias, c.title, o.alias AS offering_alias, o.title AS offering_title, s.alias AS section_alias, s.title AS section_title, s.is_default,\n\t\t\t\t\t\tm.enrolled, r.alias AS role_alias, r.title AS role_title, s.publish_up AS starts, s.publish_down AS ends\n\t\t\t\t\t\tFROM `#__courses` AS c\n\t\t\t\t\t\tJOIN `#__courses_members` AS m ON m.course_id=c.id\n\t\t\t\t\t\tLEFT JOIN `#__courses_offerings` AS o ON o.id=m.offering_id\n\t\t\t\t\t\tLEFT JOIN `#__courses_offering_sections` AS s on s.id=m.section_id\n\t\t\t\t\t\tLEFT JOIN `#__courses_roles` AS r ON r.id=m.role_id\n\t\t\t\t\t\tWHERE c.state IN (1, 3) AND m.user_id=" . (int) $this->member->get('uidNumber') . " AND m.student=0 AND r.alias=" . $this->database->Quote('instructor') . "\n\t\t\t\t\t\tORDER BY " . $filters['sort'] . " ASC LIMIT " . $filters['start'] . "," . $filters['limit']); $results = $this->database->loadObjectList(); } break; case 'ta': if ($what == 'count') { $this->database->setQuery("SELECT COUNT(*)\n\t\t\t\t\t\tFROM `#__courses` AS c\n\t\t\t\t\t\tJOIN `#__courses_members` AS m ON m.course_id=c.id\n\t\t\t\t\t\tLEFT JOIN `#__courses_offerings` AS o ON o.id=m.offering_id\n\t\t\t\t\t\tLEFT JOIN `#__courses_offering_sections` AS s on s.id=m.section_id\n\t\t\t\t\t\tLEFT JOIN `#__courses_roles` AS r ON r.id=m.role_id\n\t\t\t\t\t\tWHERE c.state IN (1, 3) AND m.user_id=" . (int) $this->member->get('uidNumber') . " AND m.student=0 AND r.alias=" . $this->database->Quote('ta')); $results = $this->database->loadResult(); } else { $this->database->setQuery("SELECT c.id, c.state, c.alias, c.title, o.alias AS offering_alias, o.title AS offering_title, s.alias AS section_alias, s.title AS section_title, s.is_default,\n\t\t\t\t\t\tm.enrolled, r.alias AS role_alias, r.title AS role_title, s.publish_up AS starts, s.publish_down AS ends\n\t\t\t\t\t\tFROM `#__courses` AS c\n\t\t\t\t\t\tJOIN `#__courses_members` AS m ON m.course_id=c.id\n\t\t\t\t\t\tLEFT JOIN `#__courses_offerings` AS o ON o.id=m.offering_id\n\t\t\t\t\t\tLEFT JOIN `#__courses_offering_sections` AS s on s.id=m.section_id\n\t\t\t\t\t\tLEFT JOIN `#__courses_roles` AS r ON r.id=m.role_id\n\t\t\t\t\t\tWHERE c.state IN (1, 3) AND m.user_id=" . (int) $this->member->get('uidNumber') . " AND m.student=0 AND r.alias=" . $this->database->Quote('ta') . "\n\t\t\t\t\t\tORDER BY " . $filters['sort'] . " ASC LIMIT " . $filters['start'] . "," . $filters['limit']); $results = $this->database->loadObjectList(); } break; default: if ($what == 'count') { $this->database->setQuery("SELECT COUNT(*)\n\t\t\t\t\t\tFROM `#__courses` AS c\n\t\t\t\t\t\tJOIN `#__courses_members` AS m ON m.course_id=c.id\n\t\t\t\t\t\tLEFT JOIN `#__courses_offerings` AS o ON o.id=m.offering_id\n\t\t\t\t\t\tLEFT JOIN `#__courses_offering_sections` AS s on s.id=m.section_id\n\t\t\t\t\t\tLEFT JOIN `#__courses_roles` AS r ON r.id=m.role_id\n\t\t\t\t\t\tWHERE c.state IN (1, 3) AND m.user_id=" . (int) $this->member->get('uidNumber') . " AND m.student=0 AND r.alias=" . $this->database->Quote($who)); $results = $this->database->loadResult(); } else { $this->database->setQuery("SELECT c.id, c.state, c.alias, c.title, o.alias AS offering_alias, o.title AS offering_title, s.alias AS section_alias, s.title AS section_title, s.is_default,\n\t\t\t\t\t\tm.enrolled, r.alias AS role_alias, r.title AS role_title, s.publish_up AS starts, s.publish_down AS ends\n\t\t\t\t\t\tFROM `#__courses` AS c\n\t\t\t\t\t\tJOIN `#__courses_members` AS m ON m.course_id=c.id\n\t\t\t\t\t\tLEFT JOIN `#__courses_offerings` AS o ON o.id=m.offering_id\n\t\t\t\t\t\tLEFT JOIN `#__courses_offering_sections` AS s on s.id=m.section_id\n\t\t\t\t\t\tLEFT JOIN `#__courses_roles` AS r ON r.id=m.role_id\n\t\t\t\t\t\tWHERE c.state IN (1, 3) AND m.user_id=" . (int) $this->member->get('uidNumber') . " AND r.alias=" . $this->database->Quote($who) . "\n\t\t\t\t\t\tORDER BY " . $filters['sort'] . " ASC LIMIT " . $filters['start'] . "," . $filters['limit']); $results = $this->database->loadObjectList(); } break; } return $results; }
/** * Short description for 'updateTool' * * Long description (if any) ... * * @param string $toolid Parameter description (if any) ... * @param string $newstate Parameter description (if any) ... * @param string $priority Parameter description (if any) ... * @return boolean Return description (if any) ... */ public function updateTool($toolid = NULL, $newstate = NULL, $priority = NULL) { if ($toolid === NULL) { return false; } if ($newstate or $priority) { $query = "UPDATE #__tool SET "; if ($newstate) { $query .= "state=" . $this->_db->quote($newstate) . ", state_changed='" . Date::toSql() . "'"; } if ($newstate && $priority) { $query .= ", "; } if ($priority) { $query .= "priority=" . $this->_db->quote($priority); } $query .= " WHERE id=" . $this->_db->quote($toolid); $this->_db->setQuery($query); if (!$this->_db->query()) { return false; } } return true; }