/** * Given a query string and limits, return an array of matching objects * owned by the current user. Possible return types are ... * - artefact * - view * * Implementations of this search should search across tags for artefacts * and views at a minimum. Ideally the search would also index * title/description and other metadata for these objects. * * NOTE: This implementation of internal search only does artefacts, and * badly at that. See the bug tracker for more information. * * @param string The query string * @param integer How many results to return * @param integer What result to start at (0 == first result) * @param string Type to search for (either 'all' or one of the types above). * */ public static function self_search($querystring, $limit, $offset, $type = 'all') { global $USER; if (trim($querystring) == '') { return false; } // Tokenise the search $querydata = self::search_parse_query($querystring); $sql = "\n SELECT\n a.id, a.artefacttype, a.title, a.description\n FROM\n {artefact} a\n LEFT JOIN {artefact_tag} at ON (at.artefact = a.id)\n WHERE\n a.owner = ?\n AND (\n ({$querydata['0']})\n OR\n (LOWER(at.tag) = ?)\n )"; $count_sql = "\n SELECT\n COUNT(*)\n FROM\n {artefact} a\n LEFT JOIN {artefact_tag} at ON (at.artefact = a.id)\n WHERE\n a.owner = ?\n AND (\n ({$querydata['0']})\n OR\n (LOWER(at.tag) = ?)\n )"; array_unshift($querydata[1], $USER->get('id')); array_push($querydata[1], strtolower($querystring)); $results = array('data' => get_records_sql_array($sql, $querydata[1], $offset, $limit), 'offset' => $offset, 'limit' => $limit, 'count' => get_field_sql($count_sql, $querydata[1])); if ($results['data']) { require_once get_config('docroot') . 'artefact/lib.php'; foreach ($results['data'] as &$result) { $newresult = array(); foreach ($result as $key => &$value) { if ($key == 'id' || $key == 'artefacttype' || $key == 'title' || $key == 'description') { $newresult[$key] = $value; } } $newresult['type'] = 'artefact'; $artefact = artefact_instance_from_id($newresult['id']); $artefactplugin = $artefact->get_plugin_name(); if ($artefactplugin == 'internal' && in_array($artefact->get('artefacttype'), PluginArtefactInternal::get_profile_artefact_types())) { // Profile artefact $newresult['summary'] = $newresult['title']; $newresult['title'] = get_string($artefact->get('artefacttype'), 'artefact.' . $artefactplugin); } else { $newresult['summary'] = $newresult['description']; } $newresult['summary'] = clean_html($newresult['summary']); $result = $newresult; } self::self_search_make_links($results); } return $results; }
public static function rewrite_blockinstance_config(View $view, $configdata) { safe_require('artefact', 'internal'); if ($view->get('owner') !== null) { $artefacttypes = array_diff(PluginArtefactInternal::get_profile_artefact_types(), array('email')); if (!get_record('blocktype_installed', 'active', 1, 'name', 'socialprofile')) { $artefacttypes = array_diff($artefacttypes, array('socialprofile')); } $artefactids = get_column_sql(' SELECT a.id FROM {artefact} a WHERE a.owner = ? AND a.artefacttype IN (' . join(',', array_map('db_quote', $artefacttypes)) . ')', array($view->get('owner'))); $configdata['artefactids'] = $artefactids; if (isset($configdata['email'])) { if ($newemail = get_field('artefact_internal_profile_email', 'artefact', 'principal', 1, 'owner', $view->get('owner'))) { $configdata['email'] = $newemail; } else { unset($configdata['email']); } } if (isset($configdata['profileicon'])) { if ($newicon = get_field('usr', 'profileicon', 'id', $view->get('owner'))) { $configdata['profileicon'] = $newicon; } else { unset($configdata['profileicon']); } } } else { $configdata['artefactids'] = array(); } return $configdata; }