Commit 68a2a795 authored by Romain Loth's avatar Romain Loth
parent cb8f9988
## This is the legacy comex app cleaned and ready for future refactoring
## comex app ready for future refactoring
It contains:
- an html index based on old bootstrap
......@@ -9,13 +9,57 @@ It contains:
- the python server is in comex_install/ dir
- run it with `python3 main.py` and reverse-proxy its host:port to `/comexAPI` location
- the twjs is in a legacy version, downloadable at [commit 11e7d77](https://github.com/moma/tinawebJS/tree/11e7d77b71ae096b7fad2cfbd716c3c724966ad2)
#### Installation
------
### Installation
1. clone this repo
2. get the tinawebJS contents into `./tinawebJS`
3. get the community.db sqlite3 database into `./`
#### TODOES for future refactoring
1. remove the legacy links to csregistry.org
2. replace the registration/profile pages with the new [regcomex app server](https://github.com/moma/regcomex)
3. replace community.db PDO connections by the new comex_shared MySQL tables
2. replace the registration/profile pages with the new [regcomex app server](https://github.com/moma/regcomex) [DONE]
3. replace community.db PDO connections by the new comex_shared MySQL tables [IN PROGRESS]
------
### DB structure
###### Overview
- `scholars` is the main table, with a **doors_uid** as primary key
- email is also unique in this table
- we have three related tables
- `affiliations` (directly pointed by an **affiliation_id** in scholars table)
- `keywords` (pointed by an intermediate user id <=> keyword id table `sch_kw`)
- `linked_ids` (not used yet, to join the uid with external ids like ORCID)
###### More info
Full table structure is described in [this documentation file](https://github.com/moma/regcomex/blob/c5badbc/doc/table_specifications.md).
###### Exemple queries
```SQL
-- ==========================
-- FOR SCHOLAR + AFFILIATIONS
-- ==========================
SELECT
scholars.*,
affiliations.*,
FROM scholars
LEFT JOIN affiliations
ON affiliation_id = affid
-- ==================================
-- FOR SCHOLAR + KEYWORDS IN ONE LINE
-- ==================================
SELECT
scholars.*,
COUNT(keywords.kwid) AS keywords_nb,
GROUP_CONCAT(kwstr) AS keywords_list
FROM scholars
JOIN sch_kw
ON doors_uid = uid
JOIN keywords
ON sch_kw.kwid = keywords.kwid
GROUP BY uid ;
```
......@@ -2,11 +2,9 @@
During rewrite we deactivated some retrieval to match the new sql tables from registration:
- tables organizations, labs don't exist => TODO RESTORE in `directory_content.php` (and therefore empty arrays are passed to `labs_list.php` and `orga_list.php`)
- tables organizations, labs are not separated and their detailed addresses don't exist => TODO RESTORE in `directory_content.php` (and therefore incomplete info are passed to `labs_list.php` and `orga_list.php`)
- in `search_scholar.php`, column nb_keywords doesn't exist (and now keywords are never 0) => TODO RESTORE
- in `print_directory.php`, all the following columns are now ignored: 'css_voter', 'css_member', 'status', 'lab2', 'affiliation2', 'address', 'city', 'postal_code', 'phone', 'mobile', 'fax', 'affiliation_acronym' => TODO RESTORE
- in `print_directory.php`, all the following columns are now ignored: 'nb_keywords', 'css_voter', 'css_member', 'keywords_ids', 'status', 'homepage', 'lab2', 'affiliation2', 'homepage', **'position'** (used in `stats_prep_from_array.php`), 'photo_url', 'address', 'city', 'postal_code', 'phone', 'mobile', 'fax', 'affiliation_acronym' => TODO RESTORE
- in `print_scholar_directory.php`
- similar changes as above
- additional change to keywords_ids search in old "scholars2terms" table => becomes `LIKE` search in keywords: TODO index
This diff is collapsed.
......@@ -3,20 +3,29 @@ comex helper backend to create json graphs from sqlite3 db
TODO integrate with new regcomex server
"""
from extractDataCustom import extract as SQLite
from extractDataCustom import MyExtractor as MySQL
from flask import Flask
from flask import request
from flask import Flask, request
from json import dumps
from os import environ
# ============= app creation ==============
app = Flask(__name__)
# ============= read environ ==============
MY_SQL_HOST = environ.get('SQL_HOST', '172.17.0.2')
# ================= views =================
# @app.route("/getJSON") # route renamed
@app.route("/comexAPI")
def main():
db=SQLite('../community.db')
# db=SQLite('../community.db')
db=MySQL(MY_SQL_HOST)
if 'query' in request.args:
# TODO fix ('refine' button)
# query is a json {cat:filtervalue} , not an executable SQL query !!
filteredquery = request.args['query']
scholars = db.getScholarsList("filter",filteredquery)
else:
......
......@@ -80,7 +80,8 @@ foreach ($scholars as $scholar) {
// echo "<p>no match :(</p>";
}
echo "<p>mimetype:".$mimeguess."</p>";
// debug
// echo "<p>mimetype:".$mimeguess."</p>";
$content .= '<img style="margin: 7px 10px 10px 0px" src="data:'.$mimeguess.';base64,'.$perhaps_decoded.'"/>';
}
......@@ -91,7 +92,7 @@ foreach ($scholars as $scholar) {
}
}
$content .= '<h2 >' . $scholar['title'] . ' ' . $scholar['first_name'] . ' ' . $scholar['initials'] . ' ' . $scholar['last_name'] .
$content .= '<h2 >' . $scholar['title'] . ' ' . $scholar['first_name'] . ' ' . $scholar['mid_initial'] . ' ' . $scholar['last_name'] .
' <small> - ' . $scholar['country'] . '</small></h2>';
......@@ -224,39 +225,40 @@ if (strcmp(substr($orga_query, 0,2),'OR')==0){
// liste des labs ////////
//////////////////////////
$labs = array();
// TODO RESTORE
// sort($lab_list);
// foreach ($lab_list as $name) {
// if ((trim($name)) != NULL) {
// $sql = 'SELECT * FROM labs where name="' . $name . '" OR acronym="' . $name . '"';
// //echo $sql.'<br/>';
// foreach ($base->query($sql) as $row) {
// //echo 'toto';
// $info = array();
// $info['unique_id'] = $row['id'];
// $info['name'] = $row['name'];
// $info['acronym'] = $row['acronym'];
// $info['homepage'] = $row['homepage'];
// $info['keywords'] = $row['keywords'];
// $info['country'] = $row['country'];
// $info['address'] = $row['address'];
// $info['organization'] = $row['organization'];
// $info['organization2'] = $row['organization2'];
// $orga_list[] = $row['organization'];
// $orga_list[] = $row['organization2'];
// $info['object'] = $row['object'];
// $info['methods'] = $row['methods'];
// $info['director'] = $row['director'];
// $info['admin'] = $row['admin'];
// $info['phone'] = $row['phone'];
// $info['fax'] = $row['fax'];
// $info['login'] = $row['login'];
// //print_r($info);
// $labs[$row['id']] = $info;
// }
// }
// }
sort($lab_list);
foreach ($lab_list as $name) {
if ((trim($name)) != NULL) {
// $sql = 'SELECT * FROM affiliations where team_lab="' . $name . '" OR acronym="' . $name . '"';
$sql = 'SELECT * FROM affiliations WHERE team_lab="' . $name . '"';
//echo $sql.'<br/>';
foreach ($base->query($sql) as $row) {
//echo 'toto';
$info = array();
$info['unique_id'] = $row['affid'];
$info['name'] = $row['team_lab'];
// TODO RESTORE
// $info['acronym'] = $row['acronym'];
// $info['homepage'] = $row['homepage'];
// $info['keywords'] = $row['keywords'];
// $info['country'] = $row['country'];
// $info['address'] = $row['address'];
// $info['organization'] = $row['organization'];
// $info['organization2'] = $row['organization2'];
// $orga_list[] = $row['organization'];
// $orga_list[] = $row['organization2'];
// $info['object'] = $row['object'];
// $info['methods'] = $row['methods'];
// $info['director'] = $row['director'];
// $info['admin'] = $row['admin'];
// $info['phone'] = $row['phone'];
// $info['fax'] = $row['fax'];
// $info['login'] = $row['login'];
//print_r($info);
$labs[$row['id']] = $info;
}
}
}
//print_r($labs);
......@@ -265,39 +267,43 @@ $labs = array();
//////////////////////////
// liste des organizations ////////
//////////////////////////
// debug
// $content .= var_dump($orga_list) ;
$organiz = array();
// TODO RESTORE
// sort($orga_list);
// foreach ($orga_list as $name) {
// if ((trim($name))!=NULL){
// $sql = "SELECT * FROM organizations where name='" . $name. "' OR acronym='".$name."'";
//
// $temp=true;
// foreach ($base->query($sql) as $row) {
// if ($temp){
// $info = array();
// $info['unique_id'] = $row['id'];
// $info['name'] = $row['name'];
// $info['acronym'] = $row['acronym'];
// $info['homepage'] = $row['homepage'];
// $info['keywords'] = $row['keywords'];
// $info['country'] = $row['country'];
// $info['street'] = $row['street'];
// $info['city'] = $row['city'];
// $info['state'] = $row['state'];
// $info['postal_code'] = $row['postal_code'];
// $info['fields'] = $row['fields'];
// $info['admin'] = $row['admin'];
// $info['phone'] = $row['phone'];
// $info['fax'] = $row['fax'];
// $info['login'] = $row['login'];
// $organiz[$row['id']] = $info;
// $temp=false;
// }
// }
// }
//
// }
sort($orga_list);
foreach ($orga_list as $name) {
if ((trim($name))!=NULL){
$sql = "SELECT * FROM affiliations WHERE org='" . $name. "'";
$temp=true;
foreach ($base->query($sql) as $row) {
if ($temp){
$info = array();
$info['unique_id'] = $row['affid'];
$info['name'] = $row['org'];
// TODO RESTORE
// $info['acronym'] = $row['acronym'];
// $info['homepage'] = $row['homepage'];
// $info['keywords'] = $row['keywords'];
// $info['country'] = $row['country'];
// $info['street'] = $row['street'];
// $info['city'] = $row['city'];
// $info['state'] = $row['state'];
// $info['postal_code'] = $row['postal_code'];
// $info['fields'] = $row['fields'];
// $info['admin'] = $row['admin'];
// $info['phone'] = $row['phone'];
// $info['fax'] = $row['fax'];
// $info['login'] = $row['login'];
$organiz[$row['affid']] = $info;
$temp=false;
}
}
}
}
......
......@@ -207,10 +207,10 @@ $(function(){
<!--<a id="printname" href="#"> <strong>PRINT</strong></a>-->
</p>
<br/><br/>
<i class="icon-user"></i> <strong>You cannot find yourself</strong> in the database, want update your data or keywords ? <a href="/regcomex">Edit your profile</a>, the database is updated every 30 min.
<i class="icon-user"></i> <strong>You cannot find yourself</strong> in the database, want update your data or keywords ? <a href="/regcomex">Edit your profile</a>, the database is updated instantly.
<button id="register" class="btn btn-mini btn-info">
Edit you profile !
Register
</button>
<br/><br/>
......@@ -220,7 +220,7 @@ $(function(){
<i class="icon-info-sign"></i> View our <a href="tips.html">tips</a> for best experience. This directory is <strong>open</strong> to everybody working in the field of Complex Systems science and Complexity science. Map and explore communities or generate a printable version of their directory.
Updated every few minutes.
<br/>
<!-- <i class="icon-list-alt"></i> Personal data are given on a voluntary basis and people are responsible for the validity and integrity of their data. <br/>
<i class="icon-repeat"></i> Suggestions or comments ? <a href="http://moma.csregistry.org/feedback" target="BLANK">Please feedback.</a> <br/>
......
......@@ -189,7 +189,7 @@ $(document).ready(function() {
hide(".hero-unit");
return $("#welcome").fadeOut("slow", function() {
show("#loading", "fast");
return window.location.href="explorerjs.html?nodeidparam=" + ui.item.id;
return window.location.href='explorerjs.html?type="uid"&nodeidparam="' + ui.item.id + '"';
//return loadGraph("get_scholar_graph.php?login=" + ui.item.id);
});
});
......@@ -239,7 +239,7 @@ $(document).ready(function() {
return $("#welcome").fadeOut("slow", function() {
show("#loading", "fast");
return collectFilters(function(query) {
return window.location.href="explorerjs.html?nodeidparam=" + query;
return window.location.href='explorerjs.html?type="filter"&nodeidparam="' + query +'"';
//return loadGraph("getgraph.php?query=" + query);
});
});
......
......@@ -6,6 +6,10 @@ $content .='<br/>
<br/>';
$orga_count = 0;
// debug
// $content .= var_dump($organiz) ;
foreach ($organiz as $orga) {
if ($loop % 100){
......
......@@ -117,7 +117,9 @@ $query_details='<ul>';
$f = "";// requête
$labfilter='';
if ($tags) {
echo '<p style="color:white">MATCHING ON tags<p>';
// debug
// echo '<p style="color:white">MATCHING ON tags<p>';
if (sizeof($tags) > 0) {
$f .= 'AND (';
}
......@@ -139,8 +141,10 @@ if ($tags) {
}
if ($keywords) {
echo '<p style="color:white">MATCHING ON keywords<p>';
if (sizeof($keywords) > 0) {
// debug
// echo '<p style="color:white">MATCHING ON keywords<p>';
if (sizeof($keywords) > 0) {
$f .= 'AND (';
}
$query_details.='<li><strong>Working on: </strong>';
......@@ -153,15 +157,17 @@ if ($keywords) {
$query_details.=$word.', ';
if ($i > 0)
$f .= " OR ";
$f .= 'keywords LIKE "%' . $word . '%" ';
$f .= 'keywords_list LIKE "%' . $word . '%" ';
$i++;
}
}
$f .= ") ";
}
if ($countries) {
echo '<p style="color:white">MATCHING ON countries<p>';
if (sizeof($countries) > 0) {
// debug
// echo '<p style="color:white">MATCHING ON countries<p>';
if (sizeof($countries) > 0) {
$f .= 'AND (';
}
$query_details.='<li><strong>In the following country: </strong>';
......@@ -179,7 +185,8 @@ if ($countries) {
$f .= ") ";
}
if ($laboratories) {
echo '<p style="color:white">MATCHING ON labs<p>';
// debug
// echo '<p style="color:white">MATCHING ON labs<p>';
if (sizeof($laboratories) > 0) {
$f .= 'AND (';
}
......@@ -198,8 +205,10 @@ if ($laboratories) {
}
if ($organizations) {
echo '<p style="color:white">MATCHING ON organizations<p>';
if (sizeof($organizations) > 0) {
// debug
// echo '<p style="color:white">MATCHING ON organizations<p>';
if (sizeof($organizations) > 0) {
$f .= 'AND (';
}
$query_details.='<li><strong>In the organization named : </strong>';
......@@ -210,7 +219,7 @@ if ($organizations) {
if ($org == "") continue;
$query_details.=$org.', ';
$f .= 'institution LIKE "%' . $org . '%" ';
$f .= 'org LIKE "%' . $org . '%" ';
//'affiliation LIKE "%' . $org . '% OR affiliation2 LIKE "%' . $org . '%"';
$i++;
}
......@@ -236,14 +245,36 @@ $imsize = 150;
$content='';
if (strlen($f)>0){
$sql = "SELECT * FROM comex_registrations where " . " " . $f.' ORDER BY last_name';
}else{
$sql = "SELECT * FROM comex_registrations ORDER BY last_name";
// filtered query
if (strlen($f)>0) {
$filter = "WHERE {$f}";
}
//echo $sql.'<br/>';
echo '<p style="color:white">query:'. $sql ."<p>";
// unfiltered query
else {
$filter = "";
}
$sql = <<< END_QUERY
SELECT * FROM
(SELECT
scholars.*,
affiliations.*,
COUNT(keywords.kwid) AS keywords_nb,
GROUP_CONCAT(keywords.kwid) AS keywords_ids,
GROUP_CONCAT(kwstr) AS keywords_list
FROM scholars
JOIN sch_kw
ON doors_uid = uid
JOIN keywords
ON sch_kw.kwid = keywords.kwid
LEFT JOIN affiliations
ON affiliation_id = affid
GROUP BY doors_uid) AS full_scholars_info
{$filter}
END_QUERY;
// debug
// echo '<p style="color:white">query:'. $sql ."<p>";
// liste des chercheurs
$scholars = array();
......@@ -252,30 +283,31 @@ $scholars = array();
foreach ($base->query($sql) as $row) {
// TODO RESTORE
$info = array();
$info['unique_id'] = $row['doors_uid'];
$info['first_name'] = $row['first_name'];
$info['initials'] = $row['initials'];
$info['mid_initial'] = (strlen($row['middle_name']) ? substr($row['middle_name'],0,1)."." : "");
$info['last_name'] = $row['last_name'];
$info['initials'] = $row['initials'];
// retrieved from secondary table and GROUP_CONCATenated
$info['keywords_ids'] = explode(',', $row['keywords_ids']);
$info['nb_keywords'] = $row['keywords_nb'];
$info['keywords'] = $row['keywords_list'];
// => TODO RESTORE
// $info['nb_keywords'] = $row['nb_keywords'];
// $info['css_voter'] = $row['css_voter'];
// $info['css_member'] = $row['css_member'];
// $info['keywords_ids'] = explode(',', $row['keywords_ids']);
$info['keywords'] = $row['keywords'];
// $info['status'] = $row['status'];
$info['record_status'] = $row['record_status']; // TODO use this one
$info['country'] = $row['country'];
// $info['homepage'] = $row['homepage'];
$info['homepage'] = $row['home_url'];
$info['lab'] = $row['team_lab'];
$info['affiliation'] = $row['institution'];
$info['affiliation'] = $row['org'];
// $info['lab2'] = $row['lab2'];
// $info['affiliation2'] = $row['affiliation2'];
// $info['homepage'] = $row['homepage'];
$info['title'] = $row['jobtitle'];
$info['position'] = $row['jobtitle'];
// $info['photo_url'] = $row['photo_url'];
$info['title'] = $row['hon_title'];
$info['position'] = $row['position'];
$info['photo_url'] = $row['pic_url'];
$info['pic_file'] = $row['pic_file'];
$info['interests'] = $row['interests_text'];
// $info['address'] = $row['address'];
......@@ -290,9 +322,12 @@ foreach ($base->query($sql) as $row) {
/// stats
include ('stat-prep_from_array.php');///
// debug
// $content .= var_dump($scholars) ;
include ("directory_content.php");
// liste des chercheurs
......
......@@ -77,32 +77,39 @@ $base = new PDO($dsn, $user, $pass, $opt);
if ($login) {
if (sizeof($login) > 0) {
// liste des chercheurs
$sql = "SELECT keywords,last_name,first_name FROM comex_registrations WHERE doors_uid='" . $login . "'";
foreach ($base->query($sql) as $row) {
$keywords = explode(',', $row['keywords']);
$scholar_array = array();
// nom du chercheur $target_name
$sql0 = "SELECT last_name,first_name FROM scholars WHERE doors_uid='" . $login . "'";
foreach ($base->query($sql0) as $row) {
// always one record by design of uid
$target_name=$row['first_name'].' '.$row['last_name'];
foreach ($keywords as $keyword) {
if (strlen($keyword) > 0) {
// TODO RESTORE index keywords
// $sql2 = "SELECT * FROM scholars2terms where term_id=" . trim($keywords_id);
$sql2 = "SELECT doors_uid FROM comex_registrations WHERE keywords LIKE \"%" . trim($keyword)."%\"";
// echo($sql2."<br/>");
foreach ($base->query($sql2) as $row) {
if (array_key_exists($row['doors_uid'], $scholar_array)){
$scholar_array[$row['doors_uid']] += 1;
}else{
$scholar_array[$row['doors_uid']] = 1;
}
}
}
}
}
// liste des chercheurs
// old way in two steps without a scholars <=> keywords table
// $sql1 = "SELECT keywords,last_name,first_name FROM scholars WHERE doors_uid='" . $login . "'";
// $sql2 = "SELECT uid FROM sch_kw JOIN keywords ON sch_kw.kwid = keywords.kwid WHERE kwstr LIKE \"%" . trim($keyword)."%\"";
// new way in one query
$sql1 = <<< HERE_QUERY
SELECT second_level.uid
FROM sch_kw
LEFT JOIN sch_kw
AS second_level
ON sch_kw.kwid = second_level.kwid
WHERE sch_kw.uid = "{$login}"
AND second_level.uid != sch_kw.uid
GROUP BY second_level.uid ;
HERE_QUERY;
foreach ($base->query($sql1) as $row) {
if (array_key_exists($row['uid'], $scholar_array)){
$scholar_array[$row['uid']] += 1;
}else{
$scholar_array[$row['uid']] = 1;
}
}
}
}
......@@ -116,31 +123,53 @@ $scholar_id_array=array_keys($scholar_array);
$scholars = array();
//
foreach ($scholar_id_array as $scholar_id){
$sql = "SELECT * FROM comex_registrations where doors_uid='" . $scholar_id. "'";
$sql = <<< END_QUERY
SELECT
scholars.*,
affiliations.*,
COUNT(keywords.kwid) AS keywords_nb,
GROUP_CONCAT(keywords.kwid) AS keywords_ids,
GROUP_CONCAT(kwstr) AS keywords_list
FROM scholars
JOIN sch_kw
ON doors_uid = uid
JOIN keywords
ON sch_kw.kwid = keywords.kwid
LEFT JOIN affiliations
ON affiliation_id = affid
WHERE doors_uid = "{$scholar_id}"
GROUP BY doors_uid
END_QUERY;
// echo var_dump($scholar_id)."<br/>" ;
//$query = "SELECT * FROM scholars";
foreach ($base->query($sql) as $row) {
$info = array();
$info['unique_id'] = $row['doors_uid'];
$info['first_name'] = $row['first_name'];
$info['initials'] = $row['initials'];
$info['mid_initial'] = (strlen($row['middle_name']) ? substr($row['middle_name'],0,1)."." : "");
$info['last_name'] = $row['last_name'];
// $info['nb_keywords'] = $row['nb_keywords'];
// $info['css_voter'] = $row['css_voter'];
// $info['css_member'] = $row['css_member'];
// $info['keywords_ids'] = explode(',', $row['keywords_ids']);
$info['keywords'] = $row['keywords'];
$info['initials'] = $row['initials'];
// retrieved from secondary table and GROUP_CONCATenated
$info['keywords_ids'] = explode(',', $row['keywords_ids']);
$info['nb_keywords'] = $row['keywords_nb'];
$info['keywords'] = $row['keywords_list'];
// $info['status'] = $row['status'];
$info['record_status'] = $row['record_status']; // TODO use this one
$info['country'] = $row['country'];
// $info['homepage'] = $row['homepage'];
$info['homepage'] = $row['home_url'];
$info['lab'] = $row['team_lab'];
$info['affiliation'] = $row['institution'];
$info['affiliation'] = $row['org'];
// $info['lab2'] = $row['lab2'];
// $info['affiliation2'] = $row['affiliation2'];
// $info['homepage'] = $row['homepage'];
$info['title'] = $row['jobtitle'];
$info['position'] = $row['jobtitle'];
// $info['photo_url'] = $row['photo_url'];
$info['title'] = $row['hon_title'];
$info['position'] = $row['position'];
$info['photo_url'] = $row['pic_url'];
$info['pic_file'] = $row['pic_file'];
$info['interests'] = $row['interests_text'];
// $info['address'] = $row['address'];
......
......@@ -21,17 +21,19 @@ if ($category == 'country' || $category == 'countries') {
$query = 'LIKE upper(\''.strtoupper($q).'\')';
} elseif ($category == 'organization' || $category == 'organizations') {
// POSSIBLE: `concat(institution, ", ", IFNULL(team_lab, ""))``
// POSSIBLE: `concat(institution, ", ", IFNULL(team_lab, ""))`
// (change in $cat here and in print_directory args downstream)
$cat = 'institution';
$cat = 'org';
$query = 'LIKE upper(\''.strtoupper($q).'\')';
} elseif ($category == 'keyword' || $category == 'keywords') {
$cat = "keywords";
$cat = "keywords_list";
$query = 'LIKE upper(\''.strtoupper($q).'\')';
} elseif ($category == 'tag' || $category == 'tags') {
$cat = "tags";
}
elseif ($category == 'tag' || $category == 'tags') {
$cat = "community_hashtags";
$query = 'LIKE upper(\''.strtoupper($q).'\')';
} elseif ($category == 'labs' || $category == 'laboratories' || $category == 'laboratory') {
}
elseif (v == 'labs' || $category == 'laboratories' || $category == 'laboratory') {
$cat = "team_lab";
$query = 'LIKE upper(\''.strtoupper($q).'\')';
} else {
......@@ -47,13 +49,44 @@ function filter_word($value) {
return ! in_array(strtolower($value),$filtered);
}
$req = "SELECT ".$cat." AS clef, count(".$cat.") AS value FROM comex_registrations WHERE ".$cat." ".$query." GROUP BY ".$cat." ORDER BY value DESC";
// old way
// $req = "SELECT ".$cat." AS clef, count(".$cat.") AS value FROM scholars WHERE ".$cat." ".$query." GROUP BY ".$cat." ORDER BY value DESC";
// TODO differentiate req's target cols earlier: above in "if ($category == X)"
$req = <<<END_QUERY
SELECT
{$cat} AS clef,
count({$cat}) AS value
FROM (
SELECT
-- we create all needed cats for the outer select
-- ==============================================
scholars.doors_uid,
scholars.country,
scholars.community_hashtags,
affiliations.org,
affiliations.team_lab,
GROUP_CONCAT(kwstr) AS keywords_list
FROM scholars
JOIN sch_kw
ON scholars.doors_uid = sch_kw.uid
JOIN keywords
ON sch_kw.kwid = keywords.kwid
LEFT JOIN affiliations
ON scholars.affiliation_id = affiliations.affid
GROUP BY doors_uid
) AS full_scholars_info
WHERE {$cat} {$query} -- <== our filter
GROUP BY $cat
ORDER BY value DESC ;
END_QUERY;
// echo $req;
$results = array();
$i = 0;
foreach ($base->query($req) as $row) {
$nb = $row['value'];
if ($cat == "keywords" || $cat == "tags") {
if ($cat == "keywords_list" || $cat == "tags") {
//echo "in keywords\n";
$words = explode(",", $row["clef"]);
foreach ($words as $word) {
......@@ -84,7 +117,7 @@ foreach ($base->query($req) as $row) {
} else {
$results[ $word ] = intval($nb);
}
}
}
}
}
......
......@@ -21,7 +21,7 @@ $q = "%".sanitize_input($login)."%";
$query = 'concat(first_name, " ", IFNULL(middle_name,""), " ", last_name) LIKE "%'.$q.'%"';
$req = "SELECT doors_uid, email, first_name, last_name, keywords FROM comex_registrations WHERE ".$query." GROUP BY doors_uid";
$req = "SELECT doors_uid, first_name, middle_name, last_name FROM scholars WHERE ".$query." GROUP BY doors_uid";
// echo "req: ".$req.";";
$results = array();
$i = 0;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment