diff --git a/docroot/sites/all/modules/contrib/diff/CHANGELOG.txt b/docroot/sites/all/modules/contrib/diff/CHANGELOG.txt old mode 100755 new mode 100644 diff --git a/docroot/sites/all/modules/contrib/diff/DiffEngine.php b/docroot/sites/all/modules/contrib/diff/DiffEngine.php old mode 100755 new mode 100644 diff --git a/docroot/sites/all/modules/contrib/diff/LICENSE.txt b/docroot/sites/all/modules/contrib/diff/LICENSE.txt old mode 100755 new mode 100644 diff --git a/docroot/sites/all/modules/contrib/diff/css/diff.boxes.css b/docroot/sites/all/modules/contrib/diff/css/diff.boxes.css old mode 100755 new mode 100644 diff --git a/docroot/sites/all/modules/contrib/diff/css/diff.default.css b/docroot/sites/all/modules/contrib/diff/css/diff.default.css old mode 100755 new mode 100644 diff --git a/docroot/sites/all/modules/contrib/diff/diff.admin.inc b/docroot/sites/all/modules/contrib/diff/diff.admin.inc old mode 100755 new mode 100644 diff --git a/docroot/sites/all/modules/contrib/diff/diff.api.php b/docroot/sites/all/modules/contrib/diff/diff.api.php old mode 100755 new mode 100644 diff --git a/docroot/sites/all/modules/contrib/diff/diff.css b/docroot/sites/all/modules/contrib/diff/diff.css old mode 100755 new mode 100644 diff --git a/docroot/sites/all/modules/contrib/diff/diff.diff.inc b/docroot/sites/all/modules/contrib/diff/diff.diff.inc old mode 100755 new mode 100644 diff --git a/docroot/sites/all/modules/contrib/diff/diff.info b/docroot/sites/all/modules/contrib/diff/diff.info old mode 100755 new mode 100644 diff --git a/docroot/sites/all/modules/contrib/diff/diff.install b/docroot/sites/all/modules/contrib/diff/diff.install old mode 100755 new mode 100644 diff --git a/docroot/sites/all/modules/contrib/diff/diff.module b/docroot/sites/all/modules/contrib/diff/diff.module old mode 100755 new mode 100644 diff --git a/docroot/sites/all/modules/contrib/diff/diff.pages.inc b/docroot/sites/all/modules/contrib/diff/diff.pages.inc old mode 100755 new mode 100644 diff --git a/docroot/sites/all/modules/contrib/diff/diff.theme.inc b/docroot/sites/all/modules/contrib/diff/diff.theme.inc old mode 100755 new mode 100644 diff --git a/docroot/sites/all/modules/contrib/diff/diff.tokens.inc b/docroot/sites/all/modules/contrib/diff/diff.tokens.inc old mode 100755 new mode 100644 diff --git a/docroot/sites/all/modules/contrib/diff/includes/file.inc b/docroot/sites/all/modules/contrib/diff/includes/file.inc old mode 100755 new mode 100644 diff --git a/docroot/sites/all/modules/contrib/diff/includes/image.inc b/docroot/sites/all/modules/contrib/diff/includes/image.inc old mode 100755 new mode 100644 diff --git a/docroot/sites/all/modules/contrib/diff/includes/list.inc b/docroot/sites/all/modules/contrib/diff/includes/list.inc old mode 100755 new mode 100644 diff --git a/docroot/sites/all/modules/contrib/diff/includes/node.inc b/docroot/sites/all/modules/contrib/diff/includes/node.inc old mode 100755 new mode 100644 diff --git a/docroot/sites/all/modules/contrib/diff/includes/number.inc b/docroot/sites/all/modules/contrib/diff/includes/number.inc old mode 100755 new mode 100644 diff --git a/docroot/sites/all/modules/contrib/diff/includes/taxonomy.inc b/docroot/sites/all/modules/contrib/diff/includes/taxonomy.inc old mode 100755 new mode 100644 diff --git a/docroot/sites/all/modules/contrib/diff/includes/text.inc b/docroot/sites/all/modules/contrib/diff/includes/text.inc old mode 100755 new mode 100644 diff --git a/docroot/sites/all/modules/contrib/diff/js/diff.js b/docroot/sites/all/modules/contrib/diff/js/diff.js old mode 100755 new mode 100644 diff --git a/docroot/sites/all/modules/contrib/diff/readme.txt b/docroot/sites/all/modules/contrib/diff/readme.txt old mode 100755 new mode 100644 diff --git a/docroot/sites/all/modules/custom/pp_frontpage/plugins/content_types/about.inc b/docroot/sites/all/modules/custom/pp_frontpage/plugins/content_types/about.inc index d530be3..44b3887 100644 --- a/docroot/sites/all/modules/custom/pp_frontpage/plugins/content_types/about.inc +++ b/docroot/sites/all/modules/custom/pp_frontpage/plugins/content_types/about.inc @@ -5,15 +5,7 @@ $plugin = array( 'title' => t('Project description for main page'), 'single' => TRUE, 'category' => t('PP'), - 'hook theme' => array( - 'pp_frontpage_about' => array( - 'path' => drupal_get_path('module', 'pp_frontpage') . '/plugins/content_types', - 'template' => 'about', - 'variables' => array( - 'text' => NULL, - ), - ), - ), + 'hook theme' => 'pp_front_page_about_content_type_theme' ); @@ -25,16 +17,18 @@ function pp_frontpage_about_content_type_render() { $block->module = 'pp_frontpage'; $block->title = ''; $block->id = 'about_block'; - $block->content = ' -
-

- ' . t('PPDORG is a project that scans Drupal.org contributions and prepare reports about contributions, grouped by country parameter.') . '
- ' . t('Current version investigate Drupal communities of the eastern Europe') . ' -

- '; $block->content = array( '#theme' => 'pp_frontpage_about', ); - return $block; } + +function pp_front_page_about_content_type_theme(&$theme, $plugin) { + $theme['pp_frontpage_about'] = array( + 'variables' => array( + 'logo' => '', + ), + 'path' => $plugin['path'], + 'template' => 'about' + ); +} diff --git a/docroot/sites/all/modules/custom/pp_frontpage/plugins/content_types/about.tpl.php b/docroot/sites/all/modules/custom/pp_frontpage/plugins/content_types/about.tpl.php index a2d539f..4f114a3 100644 --- a/docroot/sites/all/modules/custom/pp_frontpage/plugins/content_types/about.tpl.php +++ b/docroot/sites/all/modules/custom/pp_frontpage/plugins/content_types/about.tpl.php @@ -1 +1,5 @@ -

TEST of THEME

\ No newline at end of file +
+

+
+ +

\ No newline at end of file diff --git a/docroot/sites/all/modules/custom/pp_frontpage/plugins/content_types/community_month_activity.inc b/docroot/sites/all/modules/custom/pp_frontpage/plugins/content_types/community_month_activity.inc new file mode 100644 index 0000000..20a69e1 --- /dev/null +++ b/docroot/sites/all/modules/custom/pp_frontpage/plugins/content_types/community_month_activity.inc @@ -0,0 +1,61 @@ + t('Community this month activity'), + 'single' => TRUE, + 'category' => t('PP'), + 'required context' => new ctools_context_required('title','taxonomy_term'), + 'hook theme' => 'pp_frontpage_community_month_activity_content_type_theme' +); + +function pp_frontpage_community_month_activity_content_type_render($subtype, $conf, $panel_args, $context) { + // Localising of user group display to. + if (isset($context) && isset($context->data) && isset($context->data->tid)) { + $user_lists_tid = $context->data->tid; + + $block = new stdClass(); + $block->module = 'pp_frontpage'; + $block->title = t('Users activity this month'); + $query = db_select('ppgetstat', 'p') + ->fields('p', array('doid', 'timestamp', 'type')) + ->condition('p.user_group_tid', $user_lists_tid) + ->condition('p.timestamp', mktime(0,0,0, 1 , 1, date('Y')-1), '>=') + ->execute() + ->fetchAll(); + $doids = $day_stat = array(); + foreach ($query as $temp) { + if (isset($doids[$temp->doid])) { + $doids[$temp->doid]++; + } else { + $doids[$temp->doid] = 1; + } + $day_stat[date('Y-m-d', $temp->timestamp)]++; + + } + + dpm($day_stat); + $users = _ppgetstat_get_users_by_doids(array_keys($doids)); + $doids = asort($doids); + drupal_add_js('http://d3js.org/d3.v3.min.js', 'external'); + drupal_add_js(drupal_get_path('module','pp_frontpage') . '/plugins/content_types/js/month_activity.js'); + drupal_add_js(array('pp_frontpage' => array('community_tid' => $user_lists_tid)), 'setting'); + $block = new stdClass(); + $block->module = 'pp_frontpage'; + $block->title = 'Timeline'; + $block->id = 'pp_frontpage_month_activity'; + $block->content = array( + '#theme' => 'pp_frontpage_month_activity', + ); + return $block; + } +} + +function pp_frontpage_community_month_activity_content_type_theme(&$theme, $plugin) { + $theme['pp_frontpage_month_activity'] = array( + 'variables' => array( + 'logo' => '', + ), + 'path' => $plugin['path'], + 'template' => 'month_activity' + ); +} diff --git a/docroot/sites/all/modules/custom/pp_frontpage/plugins/content_types/community_quality.inc b/docroot/sites/all/modules/custom/pp_frontpage/plugins/content_types/community_quality.inc index 0787d16..dfcfeb0 100644 --- a/docroot/sites/all/modules/custom/pp_frontpage/plugins/content_types/community_quality.inc +++ b/docroot/sites/all/modules/custom/pp_frontpage/plugins/content_types/community_quality.inc @@ -5,6 +5,7 @@ $plugin = array( 'single' => TRUE, 'category' => t('PP'), 'required context' => new ctools_context_required('title', 'taxonomy_term'), + 'hook theme' => 'pp_front_page_community_quality_content_type_theme' ); /** @@ -31,91 +32,79 @@ function pp_frontpage_community_quality_content_type_render( $block = new stdClass(); $block->module = 'pp_frontpage'; - $block->title = t('Community statistic'); - + $block->content = ''; // Getting info for showing count of individual members at this country. $members_stat = _ppgetstat_get_individual_members(); - $all_user_query = db_select('node', 'n'); - $all_user_query->innerJoin( + // Query for global count uids, attached to the country. + $query = db_select('node', 'n'); + $query->innerJoin( 'field_data_field_user_lists', 'fu', 'fu.entity_id = n.nid' ); - $all_user_query->condition('n.type', 'user'); - $all_user_query->condition('fu.field_user_lists_tid', $user_lists_tid); - $all_user_query->addExpression('COUNT(n.nid)'); - $all_user_result = $all_user_query->execute(); - $all_user_count = $all_user_result->fetchField(); + $query->fields('fu', array('field_user_lists_tid')); + $query->addExpression('COUNT(fu.field_user_lists_tid)', 'gc'); + $query->condition('fu.field_user_lists_tid', $user_lists_tid); + $query->orderBy('gc', 'DESC'); + $all_user_count = $query->countQuery()->execute()->fetchField(); + // Getting active by commits statistics $active_by_commits_query = db_select('ppgetstat', 'pp'); - $active_by_commits_query->innerJoin( - 'field_data_field_user_id', - 'fn', - 'fn.field_user_id_value = pp.doid' - ); - $active_by_commits_query->innerJoin( - 'field_data_field_user_lists', - 'fu', - 'fu.entity_id = fn.entity_id' - ); $active_by_commits_query->condition('pp.type', PPGETSTAT_TYPE_COMMITS); - $active_by_commits_query->condition( - 'fu.field_user_lists_tid', - $user_lists_tid - ); + $active_by_commits_query->condition('pp.user_group_tid', $user_lists_tid); + $active_by_commits_query->fields('pp',array('user_group_tid')); + $active_by_commits_query->addExpression('COUNT(pp.doid)', 'ac'); + + $active_by_commits_query->groupBy('pp.user_group_tid'); $active_by_commits_query->groupBy('pp.doid'); - $active_by_commits_query->addExpression('COUNT(pp.doid)'); - $active_by_commits_count = $active_by_commits_query->execute()->fetchField( - ); + $active_by_commits_count = $active_by_commits_query->countQuery()->execute()->fetchField(); - $active_by_comments_query = db_select('ppgetstat', 'pp'); - $active_by_comments_query->innerJoin( - 'field_data_field_user_id', - 'fn', - 'fn.field_user_id_value = pp.doid' - ); - $active_by_comments_query->innerJoin( - 'field_data_field_user_lists', - 'fu', - 'fu.entity_id = fn.entity_id' - ); - $active_by_comments_query->condition('pp.type', PPGETSTAT_TYPE_COMMITS); - $active_by_comments_query->condition( - 'fu.field_user_lists_tid', - $user_lists_tid - ); - $active_by_comments_query->groupBy('pp.doid'); - $active_by_comments_query->addExpression('COUNT(pp.doid)'); - $active_by_comments_count = $active_by_comments_query->execute() - ->fetchField(); + $active_by_comments_count = 0; $individual_members_count = $members_stat['members_country_count'][$country]; + if ($all_user_count > 0) { - $block->content = '
- -
'; + ) * 100, + '#active_commenters_p' => number_format( + $active_by_comments_count / $all_user_count, + 2 + ) * 100, + '#assoc_individual_members_p' => number_format( + $individual_members_count / $all_user_count, + 2 + ) * 100 + ); } return $block; } } + +/** + * hook_theme callback for this plugin. + */ +function pp_front_page_community_quality_content_type_theme(&$theme, $plugin) { + $theme['pp_frontpage_community_quality'] = array( + 'variables' => array( + 'total' => 0, + 'active_committers' => 0, + 'active_commenters' => 0, + 'assoc_individual_members' => 0, + 'active_committers_p' => 0, + 'active_commenters_p' => 0, + 'assoc_individual_members_p' => 0 + ), + 'path' => $plugin['path'] . '/templates/', + 'template' => 'community_quality' + ); +} diff --git a/docroot/sites/all/modules/custom/pp_frontpage/plugins/content_types/global_countries_members.inc b/docroot/sites/all/modules/custom/pp_frontpage/plugins/content_types/global_countries_members.inc index b122cdd..a3c2376 100644 --- a/docroot/sites/all/modules/custom/pp_frontpage/plugins/content_types/global_countries_members.inc +++ b/docroot/sites/all/modules/custom/pp_frontpage/plugins/content_types/global_countries_members.inc @@ -48,30 +48,20 @@ function pp_frontpage_global_countries_members_content_type_render($subtype, $co // Getting active by commits statistics - $active_by_commits_query = db_select('field_data_field_user_lists', 'fu'); - $active_by_commits_query->innerJoin( - 'field_data_field_user_id', - 'fn', - 'fu.entity_id = fn.entity_id' - ); - $active_by_commits_query->innerJoin( - 'ppgetstat', - 'pp', - 'pp.doid = fn.field_user_id_value' - ); + $active_by_commits_query = db_select('ppgetstat', 'pp'); $active_by_commits_query->condition('pp.type', PPGETSTAT_TYPE_COMMITS); - $active_by_commits_query->fields('fu',array('field_user_lists_tid')); + $active_by_commits_query->fields('pp',array('user_group_tid')); $active_by_commits_query->addExpression('COUNT(pp.doid)', 'ac'); - $active_by_commits_query->groupBy('fu.field_user_lists_tid'); + $active_by_commits_query->groupBy('pp.user_group_tid'); $active_by_commits_query->groupBy('pp.doid'); $active_by_commits = $active_by_commits_query->execute()->fetchAll(); $active_commits = array(); foreach ($active_by_commits as $temp) { - if (!empty($active_commits[$temp->field_user_lists_tid])) { - $active_commits[$temp->field_user_lists_tid]++; + if (!empty($active_commits[$temp->user_group_tid])) { + $active_commits[$temp->user_group_tid]++; } else { - $active_commits[$temp->field_user_lists_tid] = 1; + $active_commits[$temp->user_group_tid] = 1; } } diff --git a/docroot/sites/all/modules/custom/pp_frontpage/plugins/content_types/global_top_contributors.inc b/docroot/sites/all/modules/custom/pp_frontpage/plugins/content_types/global_top_contributors.inc new file mode 100644 index 0000000..d5cf61d --- /dev/null +++ b/docroot/sites/all/modules/custom/pp_frontpage/plugins/content_types/global_top_contributors.inc @@ -0,0 +1,95 @@ + t('Global statistics: top contributors.'), + 'single' => TRUE, + 'category' => t('PP'), +); + +/** +* Render of global communities size statistics. + */ +function pp_frontpage_global_top_contributors_content_type_render($subtype, $conf, $panel_args) { + $block = new stdClass(); + $block->module = 'pp_frontpage'; + $block->title = t('Top contributors of all countries.'); + + $vocab = taxonomy_vocabulary_machine_name_load('users_list'); + $terms = taxonomy_get_tree($vocab->vid); + foreach ($terms as $t) { + $terms_data[$t->tid] = taxonomy_term_load($t->tid); + } + + // Getting active by commits statistics + $active_by_commits_query = db_select('ppgetstat', 'pp'); + $active_by_commits_query->condition('pp.type', PPGETSTAT_TYPE_COMMITS); + $active_by_commits_query->fields('pp',array('doid', 'user_group_tid')); + $active_by_commits_query->addExpression('COUNT(pp.doid)', 'ac'); + $active_by_commits_query->groupBy('pp.doid'); + $active_by_commits_query->range(0, 100); + $active_by_commits_query->orderBy('ac', 'DESC'); + + $active_by_commits = $active_by_commits_query->execute()->fetchAll(); + foreach ($active_by_commits as $temp) { + $top_stat[$temp->doid] = $temp; + $doids[] = $temp->doid; + $groupd_tids[] = $temp->user_group_tid; + } + + $rows = array(); + + $query = db_select('node', 'n'); + $query->innerJoin('field_data_field_user_id', 'fu', 'n.nid=fu.entity_id'); + $query->fields('n', array('nid')); + $query->fields('fu', array('field_user_id_value')); + $query->condition('fu.field_user_id_value', $doids, 'IN'); + $result = $query->execute()->fetchAll(); + foreach ($result as $temp) { + $nids[] = $temp->nid; + $nid_map[$temp->nid]= $temp->field_user_id_value; + } + $nodes = node_load_multiple($nids); + + foreach ($nodes as $node) { + $dorg_users[$nid_map[$node->nid]] = $node; + } + $i = 1;$country_group = array(); + foreach ($active_by_commits as $temp) { + $doid = $temp->doid; + $node = $dorg_users[$doid]; + $flag = ''; + $term = $terms_data[$temp->user_group_tid]; + + if (!empty($term->field_logo)) { + $field_logo = field_get_items('taxonomy_term', $term, 'field_logo'); + $flag = theme('image_style', array( + 'style_name' => '48x', + 'path'=> $field_logo[0]['uri'], + )); + } + + $rows[] = array( + $i, + $flag, + l($terms_data[$temp->user_group_tid]->name,'taxonomy/term/' . $temp->user_group_tid), + l($node->title, 'http://drupal.org/user/' . $nid_map[$node->nid]), + $temp->ac, + ); + $i++; + if (isset($country_group[$term->name])) { + $country_group[$term->name]++; + } else { + $country_group[$term->name] = 1; + } + } + + $render_array = array( + '#theme' => 'table', + '#header' => array(t('Position'),t('Country'), t('Country'), t('Username'), t('Count of commit')), + '#rows' => $rows + ); + + $block->content = $render_array; + + return $block; +} \ No newline at end of file diff --git a/docroot/sites/all/modules/custom/pp_frontpage/plugins/content_types/js/month_activity.js b/docroot/sites/all/modules/custom/pp_frontpage/plugins/content_types/js/month_activity.js new file mode 100644 index 0000000..1ad9e59 --- /dev/null +++ b/docroot/sites/all/modules/custom/pp_frontpage/plugins/content_types/js/month_activity.js @@ -0,0 +1,73 @@ +(function ($) { + $(document).ready(function() { + var width = 1100, + height = 200, + cellSize = 20; // cell size + + var percent = d3.format(".1%"), + format = d3.time.format("%Y-%m-%d"); + + var svg = d3.select("#pp_frontpage_month_activity").selectAll("svg") + .data(d3.range(2015, 2017)) + .enter().append("svg") + .attr("width", width) + .attr("height", height) + .attr("class", "RdYlGn") + .append("g") + .attr("transform", "translate(" + ((width - cellSize * 53) / 2) + "," + (height - cellSize * 7 - 1) + ")"); + + svg.append("text") + .attr("transform", "translate(-6," + cellSize * 3.5 + ")rotate(-90)") + .style("text-anchor", "middle") + .text(function(d) { return d; }); + + var rect = svg.selectAll(".day") + .data(function(d) { return d3.time.days(new Date(d, 0, 1), new Date(d + 1, 0, 1)); }) + .enter().append("rect") + .attr("class", "day") + .attr("width", cellSize) + .attr("height", cellSize) + .attr("x", function(d) { return d3.time.weekOfYear(d) * cellSize; }) + .attr("y", function(d) { return d.getDay() * cellSize; }) + .datum(format); + + rect.append("title") + .text(function(d) { return d; }); + + svg.selectAll(".month") + .data(function(d) { return d3.time.months(new Date(d, 0, 1), new Date(d + 1, 0, 1)); }) + .enter().append("path") + .attr("class", "month") + .attr("d", monthPath); + console.log(Drupal.settings.pp_frontpage.community_tid); + d3.json("/group_calendar_stat/" + Drupal.settings.pp_frontpage.community_tid, function(error, json) { + + if (error) throw error; + data = json; + max_value = d3.entries(data) + .sort(function(a, b) { return d3.descending(a.value, b.value); }) + [0].value; + + rect.filter(function(d) { return d in data; }) + .style("fill",function(d) { + return "rgba(43,169,224," + data[d]/max_value + ")"; + }).append("text").text( + function(d){return data[d];} + ) + .select("title") + .text(function(d) { return d + ": " + data[d]; }); + }); + + function monthPath(t0) { + var t1 = new Date(t0.getFullYear(), t0.getMonth() + 1, 0), + d0 = t0.getDay(), w0 = d3.time.weekOfYear(t0), + d1 = t1.getDay(), w1 = d3.time.weekOfYear(t1); + return "M" + (w0 + 1) * cellSize + "," + d0 * cellSize + + "H" + w0 * cellSize + "V" + 7 * cellSize + + "H" + w1 * cellSize + "V" + (d1 + 1) * cellSize + + "H" + (w1 + 1) * cellSize + "V" + 0 + + "H" + (w0 + 1) * cellSize + "Z"; + } + + }); +})(jQuery); \ No newline at end of file diff --git a/docroot/sites/all/modules/custom/pp_frontpage/plugins/content_types/month_activity.tpl.php b/docroot/sites/all/modules/custom/pp_frontpage/plugins/content_types/month_activity.tpl.php new file mode 100644 index 0000000..984c8ab --- /dev/null +++ b/docroot/sites/all/modules/custom/pp_frontpage/plugins/content_types/month_activity.tpl.php @@ -0,0 +1,27 @@ + +

test

+
\ No newline at end of file diff --git a/docroot/sites/all/modules/custom/pp_frontpage/plugins/content_types/most.inc b/docroot/sites/all/modules/custom/pp_frontpage/plugins/content_types/most.inc index e7c82d8..a88b2cf 100755 --- a/docroot/sites/all/modules/custom/pp_frontpage/plugins/content_types/most.inc +++ b/docroot/sites/all/modules/custom/pp_frontpage/plugins/content_types/most.inc @@ -41,8 +41,7 @@ function pp_frontpage_most_content_type_render($subtype, $conf, $panel_args, $co ) . ''; $query = 'SELECT pp.doid, SUM(pp.items) as counter FROM {ppgetstat} pp ' . 'INNER JOIN field_data_field_user_id fn ON fn.field_user_id_value = pp.doid ' - . 'INNER JOIN field_data_field_user_lists fu ON fu.entity_id = fn.entity_id ' - . 'WHERE pp.type = :type AND pp.timestamp > :timestamp AND fu.field_user_lists_tid = :user_list_tid ' + . 'WHERE pp.type = :type AND pp.timestamp > :timestamp AND pp.user_group_tid = :user_list_tid ' . 'GROUP BY pp.doid ORDER BY counter DESC LIMIT 0,200'; $last_thee_months = REQUEST_TIME - PPGETSTAT_DEFAULT_TIME_PERIOD_FOR_SCANNING; diff --git a/docroot/sites/all/modules/custom/pp_frontpage/plugins/content_types/templates/community_quality.tpl.php b/docroot/sites/all/modules/custom/pp_frontpage/plugins/content_types/templates/community_quality.tpl.php new file mode 100644 index 0000000..3d6d37c --- /dev/null +++ b/docroot/sites/all/modules/custom/pp_frontpage/plugins/content_types/templates/community_quality.tpl.php @@ -0,0 +1,16 @@ +
+ +
\ No newline at end of file diff --git a/docroot/sites/all/modules/custom/pp_frontpage/pp_frontpage.module b/docroot/sites/all/modules/custom/pp_frontpage/pp_frontpage.module index 13baa4d..06adeb9 100755 --- a/docroot/sites/all/modules/custom/pp_frontpage/pp_frontpage.module +++ b/docroot/sites/all/modules/custom/pp_frontpage/pp_frontpage.module @@ -6,16 +6,18 @@ */ /** - * Implements hook_theme(). + * Implements hook_menu(). */ -/*function pp_frontpage_theme() { - return array( - 'about_block' => array( - 'render element' => 'data', - 'template' => 'plugins/templates/about_block' - ), +function pp_frontpage_menu() { + $items['group_calendar_stat/%'] = array( + 'title' => 'Commits Tsv', + 'description' => 'user group months statistics.', + 'page callback' => 'pp_frontpage_calendar_stat', + 'page arguments' => array(1), + 'access arguments' => array('access content'), ); -}*/ + return $items; +} /** * Implements hook_ctools_plugin_directory(). @@ -25,3 +27,30 @@ function pp_frontpage_ctools_plugin_directory($owner, $plugin_type) { return 'plugins/content_types'; } } + +/** + * Render callback for calendar stat csv output. + */ +function pp_frontpage_calendar_stat($user_lists_tid) { + $query = db_select('ppgetstat', 'p') + ->fields('p', array('doid', 'timestamp', 'type')) + ->condition('p.user_group_tid', $user_lists_tid) + ->condition('p.timestamp', mktime(0,0,0, 1 , 1, date('Y')-1), '>=') + ->execute() + ->fetchAll(); + $doids = $day_stat = array(); + foreach ($query as $temp) { + if (isset($doids[$temp->doid])) { + $doids[$temp->doid]++; + } else { + $doids[$temp->doid] = 1; + } + $day_stat[date('Y-m-d', $temp->timestamp)]++; + + } + + + $users = _ppgetstat_get_users_by_doids(array_keys($doids)); + + return drupal_json_output($day_stat); +} diff --git a/docroot/sites/all/modules/custom/ppgetstat/ppcmnt/ppcmnt.module b/docroot/sites/all/modules/custom/ppgetstat/ppcmnt/ppcmnt.module index bfbbcd2..01b8558 100755 --- a/docroot/sites/all/modules/custom/ppgetstat/ppcmnt/ppcmnt.module +++ b/docroot/sites/all/modules/custom/ppgetstat/ppcmnt/ppcmnt.module @@ -11,33 +11,41 @@ define('PPGETSTAT_TYPE_COMMENTS', 3); /** * Implements hook_ppgetstat_stats_job(). */ -function ppcmnt_ppgetstat_stats_job($user_node) { - $doid = $user_node->field_user_id[LANGUAGE_NONE][0]['value']; +function ppcmnt_ppgetstat_stats_job($users, $force = FALSE) { + if (!is_array($users)) { + $users = array($users); + } + foreach ($users as $user) { + $doid = $user['doid']; - $last_scan_week = db_query('SELECT timestamp FROM {ppgetstat} WHERE doid = :doid AND type = :type ORDER BY timestamp DESC LIMIT 1', - array(':doid' => $doid, ':type' => PPGETSTAT_TYPE_COMMENTS) - )->fetchField(); + $last_scan_week = db_query('SELECT timestamp FROM {ppgetstat} WHERE doid = :doid AND type = :type ORDER BY timestamp DESC LIMIT 1', + array(':doid' => $doid, ':type' => PPGETSTAT_TYPE_COMMENTS) + )->fetchField(); - $last_comment_timestamp = variable_get('ppgetstat_ppcmnt_last_comment_timestamp', array($doid => array())); + $last_comment_timestamp = variable_get('ppgetstat_ppcmnt_last_comment_timestamp', array($doid => array())); - $last_comment_timestamp[$doid] = array($last_scan_week => 0); + $last_comment_timestamp[$doid] = array($last_scan_week => 0); - $last_scan = max(array( - REQUEST_TIME - PPGETSTAT_DEFAULT_TIME_PERIOD_FOR_SCANNING, - $last_comment_timestamp[$doid][$last_scan_week], - )); + $last_scan = max(array( + REQUEST_TIME - PPGETSTAT_DEFAULT_TIME_PERIOD_FOR_SCANNING, + $last_comment_timestamp[$doid][$last_scan_week], + )); - if ($last_scan > REQUEST_TIME - 24 * 60 * 60) { - return; - } + if (!$force) { + if ($last_scan > REQUEST_TIME - 24 * 60 * 60) { + return; + } + } - $job = array( - 'generate_urls_callback' => '_ppcmnt_get_comments_tracking_urls', - 'parse_pages_callback' => '_ppcmnt_parse_post_page', - 'doid' => $doid, - 'do_nickname' => $user_node->title, - 'last_scan' => $last_scan, - ); + + $job[] = array( + 'generate_urls_callback' => '_ppcmnt_get_comments_tracking_urls', + 'parse_pages_callback' => '_ppcmnt_parse_post_page', + 'doid' => $doid, + 'do_nickname' => $user['do_nickname'], + 'last_scan' => $last_scan, + ); + } return $job; } diff --git a/docroot/sites/all/modules/custom/ppgetstat/ppgetstat.install b/docroot/sites/all/modules/custom/ppgetstat/ppgetstat.install index f2ab632..b655575 100755 --- a/docroot/sites/all/modules/custom/ppgetstat/ppgetstat.install +++ b/docroot/sites/all/modules/custom/ppgetstat/ppgetstat.install @@ -72,3 +72,61 @@ function ppgetstat_uninstall() { $vars = $vars->condition('name', 'ppgetstat%', 'LIKE'); $vars->execute(); } + +/** + * Add new column to the ppgetstat table. + */ +function ppgetstat_update_7001() { + + $spec = array( + 'type' => 'int', + 'description' => 'A link to the main user group taxonomy term', + 'not null' => FALSE, + ); + db_add_field('ppgetstat', 'user_group_tid', $spec); +} + +/** + * Add right ud_tid values to the ppgetstat table. + */ +function ppgetstat_update_7002(&$sandbox) { + if (!isset($sandbox['total'])) { + $sandbox['total'] = db_select('ppgetstat', 'p')->countQuery()->execute()->fetchField(); + $sandbox['current'] = 0; + } + $items_per_page = 50; + $query = db_select('ppgetstat', 'p') + ->fields('p', array('id', 'doid')) + ->range($sandbox['current'], $items_per_page) + ->execute() + ->fetchAll(); + $ids_map = $doids = array(); + foreach ($query as $item) { + $ids_map[$item->id] = $item->doid; + $doids[] = $item->doid; + } + + $mapping_query = db_select('field_data_field_user_id', 'fdoid'); + $mapping_query->innerJoin('field_data_field_user_lists', 'ful', 'fdoid.entity_id = ful.entity_id'); + $mapping_query->fields('fdoid', array('field_user_id_value')); + $mapping_query->fields('ful', array('field_user_lists_tid')); + $mapping_query->condition('fdoid.field_user_id_value', array_unique($doids), 'IN'); + $map_result = $mapping_query->execute()->fetchAll(); + foreach ($map_result as $item) { + $ids_map_result[$item->field_user_id_value] = $item->field_user_lists_tid; + } + + foreach ($ids_map as $ppgetstat_id => $ppgetstat_doid) { + db_update('ppgetstat') + ->fields(array('user_group_tid' => $ids_map_result[$ppgetstat_doid])) + ->condition('id', $ppgetstat_id) + ->execute(); + $sandbox['current']++; + } + + $sandbox['#finished'] = ($sandbox['current'] / $sandbox['total']); + if ($sandbox['#finished'] === 1) { + drupal_set_message(t('Ppgetstat items updated: @items.', + array('@items' => $sandbox['total']))); + } +} diff --git a/docroot/sites/all/modules/custom/ppgetstat/ppgetstat.module b/docroot/sites/all/modules/custom/ppgetstat/ppgetstat.module index 1f41fdd..adb52db 100755 --- a/docroot/sites/all/modules/custom/ppgetstat/ppgetstat.module +++ b/docroot/sites/all/modules/custom/ppgetstat/ppgetstat.module @@ -6,7 +6,7 @@ */ define('PPGETSTAT_USER_NODE_TYPE', 'user'); // Number of users queued to be scanned per cron run. -define('PPGETSTAT_STATSJOBS_PROCESS_NUMBER', 100); +define('PPGETSTAT_STATSJOBS_PROCESS_NUMBER', 250); // Number of calls to drupal.org per cron run. define('PPGETSTAT_DORGSCRAPPING_PROCESS_NUMBER', 270); // If no stats available we scan commits for last 12 years. @@ -65,6 +65,16 @@ function ppgetstat_menu() { 'file' => 'ppgetstat.pages.inc', ); + $items['admin/config/services/restart_country_scan'] = array( + 'title' => 'Restart country scan', + 'page callback' => 'drupal_get_form', + 'page arguments' => array('ppgetstat_rescan'), + 'access arguments' => array('administer site configuration'), + 'weight' => -21, + 'type' => MENU_NORMAL_ITEM, + 'file' => 'ppgetstat.pages.inc', + ); + return $items; } @@ -129,8 +139,9 @@ function ppgetstat_cron() { $cron_process_user_queue = _ppgetstat_cron_process_users_queue(); // Create items in stats_jobs queue. - if (!$cron_create_users_queue && !$cron_process_user_queue) { - $cron_create_stats_jobs = _ppgetstat_cron_createItem_stats_jobs(); + if (!$cron_create_users_queue || !$cron_process_user_queue) { + $cron_create_stats_jobs = false; + //$cron_create_stats_jobs = _ppgetstat_cron_createItem_stats_jobs(); // If new scan jobs are not created, we could run process jobs. if (!$cron_create_stats_jobs) { // Process items from stats_jobs queue. @@ -179,7 +190,7 @@ function _ppgetstat_cron_create_users_queue($force = FALSE, $scan_term = NULL) { $r = _ppgetstat_api_call('https://www.drupal.org/','api-d7/user.json', $variables); $last_url = parse_url($r->last); parse_str($last_url['query'], $params); - for ($i = $params['page'] - 1; $i >= 0; $i--) { + for ($i = $params['page']; $i >= 0; $i--) { $queue->createItem(array( $variables, $i, $term->tid )); @@ -235,10 +246,11 @@ function _ppgetstat_cron_createItem_stats_jobs() { $queue = DrupalQueue::get('stats_jobs'); $scan_users = array(); - foreach (_ppgetstats_get_all_users() as $nid => $doid) { + foreach (_ppgetstats_get_all_users() as $nid => $temp) { $scan_users[] = array( 'nid' => $nid, - 'doid' => $doid, + 'doid' => $temp['doid'], + 'do_nickname' => $temp['do_nickname'], ); } @@ -263,26 +275,20 @@ function _ppgetstat_cron_createItem_stats_jobs() { /** * Implements hook_ppgetstat_stats_job(). */ -function ppgetstat_ppgetstat_stats_job($users) { +function ppgetstat_ppgetstat_stats_job(array $users, $force = FALSE) { $job = array(); foreach ($users as $user) { $doid = $user['doid']; - $last_scan_week = db_query('SELECT timestamp FROM {ppgetstat} WHERE doid = :doid AND type = :type ORDER BY timestamp DESC LIMIT 1', + $last_scan = db_query('SELECT timestamp FROM {ppgetstat} WHERE doid = :doid AND type = :type ORDER BY timestamp DESC LIMIT 1', array(':doid' => $doid, ':type' => PPGETSTAT_TYPE_COMMITS) )->fetchField(); - $last_commit_timestamp = variable_get('ppgetstat_ppgetstat_last_commit_timestamp', array($doid => array())); - $last_commit_timestamp[$doid] = array($last_scan_week => 0); - //@TODO Rim this, because filtering is already exist at _ppgetstat_cron_createItem_stats_jobs(). - $last_scan = max(array( - REQUEST_TIME - PPGETSTAT_DEFAULT_TIME_PERIOD_FOR_SCANNING, - $last_commit_timestamp[$doid][$last_scan_week], - )); - - if ($last_scan > REQUEST_TIME - 24 * 60 * 60) { - return; + if ($force) { + if ($last_scan > REQUEST_TIME - 24 * 60 * 60) { + return; + } } $job[] = array( @@ -343,21 +349,19 @@ function _ppgetstat_cron_processItem_stats_jobs() { * Get all published user nodes. */ function _ppgetstats_get_all_users() { - $query = new EntityFieldQuery(); - $result = $query - ->entityCondition('entity_type', 'node') - ->entityCondition('bundle', PPGETSTAT_USER_NODE_TYPE) - ->propertyCondition('status', 1) - ->execute(); + $query = db_select('node', 'n'); $query->innerJoin('field_data_field_user_id', 'fu', 'n.nid=fu.entity_id'); - $query->fields('n', array('nid')); + $query->fields('n', array('nid', 'title')); $query->fields('fu', array('field_user_id_value')); $result = $query->execute()->fetchAll(); if (!empty($result)) { $return = array(); foreach ($result as $item) { - $return[$item->nid] = $item->field_user_id_value; + $return[$item->nid] = array( + 'doid' => $item->field_user_id_value, + 'do_nickname' => $item->title, + ); } return $return; } else { @@ -427,7 +431,9 @@ function _ppgetstat_get_node_link_by_doid($doid) { */ function _ppgetstat_get_code_tracking_urls($data) { $last_scan = $data['last_scan']; - $doids = $data['doids']; + + $doids = array($data['doid']); + // Number of pages to scan before check it is empty. $pages_block = 7; $urls = array(); @@ -570,6 +576,7 @@ function _ppgetstat_cron_remove_cached_pages() { */ function _ppgetstat_parse_commits($page_content, $data) { $last_scan = $data['last_scan']; + if (empty($page_content)) { throw new Exception('Empty page content.'); } @@ -594,23 +601,10 @@ function _ppgetstat_parse_commits($page_content, $data) { break; } - $period_timestamp = $commit_timestamp - ($commit_timestamp % PPGETSTAT_TIME_PERIOD_GRANULARITY); - $last_commits = variable_get('ppgetstat_ppgetstat_last_commit_timestamp', array($data['doid'] => array($period_timestamp => 0))); - - // Save latest commit's date per week into variable. - if ($first_commit_timestamp || empty($last_commits[$data['doid']][$period_timestamp])) { - $first_commit_timestamp = FALSE; - - if (empty($last_commits[$data['doid']][$period_timestamp]) || $commit_timestamp > $last_commits[$data['doid']][$period_timestamp]) { - $last_commits[$data['doid']][$period_timestamp] = $commit_timestamp; - variable_set('ppgetstat_ppgetstat_last_commit_timestamp', $last_commits); - } - } - - if (!isset($commits_counter_array[$period_timestamp])) { - // $commits_counter_array[$period_timestamp] = 0; - } - $commits_counter_array[$period_timestamp][] = $commit_hash; + $commits_counter_array[] = array( + 'hash' => $commit_hash, + 'timestamp' => $commit_timestamp, + ); $commits_counter++; } @@ -620,7 +614,7 @@ function _ppgetstat_parse_commits($page_content, $data) { } $commits_counter_array['#type'] = PPGETSTAT_TYPE_COMMITS; - + watchdog('_ppdorg_debug_2', print_r($commits_counter_array,1)); return $commits_counter_array; } @@ -630,14 +624,23 @@ function _ppgetstat_parse_commits($page_content, $data) { function _ppgetstat_save_counters($counters_array, $doid) { $type = $counters_array['#type']; unset($counters_array['#type']); + $query = db_select('field_data_field_user_id', 'fdoid'); + $query->innerJoin('field_data_field_user_lists', 'fl', 'fdoid.entity_id = fl.entity_id'); + $query->condition('fdoid.field_user_id_value', $doid); + $query->fields('fl', array('field_user_lists_tid')); + $user_group_tid = $query->execute()->fetchField(); + + foreach ($counters_array as $commit) { - foreach ($counters_array as $period => &$commits) { - foreach ($commits as &$hash) { db_merge('ppgetstat') - ->key(array('doid' => $doid, 'hash' => $hash)) - ->fields(array('type' => $type, 'timestamp' => $period, 'items' => 1)) + ->key(array('doid' => $doid, 'hash' => $commit['hash'])) + ->fields(array( + 'type' => $type, + 'timestamp' => $commit['timestamp'], + 'items' => 1, + 'user_group_tid' => $user_group_tid + )) ->execute(); - } } } @@ -798,6 +801,41 @@ function _ppgetstat_sync_user_list_step($variables, $page, $tid) { } +/** + * Helper function that is checking - is existed user changed or not. + * We are using this function for next purposes: + * - avoid hard node_save action without any new information; + * - write new revision for understanding differenced between user data now and + * in the past. + * @param $old + * @param $new + * @param $params_to_scan + */ +function _ppgetstat_node_diff($old, $new, $params_to_scan) { + if (!empty($params_to_scan)) { + foreach ($params_to_scan as $param) { + $old_value = $old->{$param}; + $new_value = $new->{$param}; + if (is_array($old_value) && (is_array($new_value))) { + + if (strcmp(serialize($old_value), serialize($new_value)) != 0) { + return TRUE; + } else { + return FALSE; + } + } else { + if ($old_value != $new_value) { + return TRUE; + } else { + return FALSE; + } + } + } + } else { + // If we dont have plan to compare - thinking that new node has new info. + return TRUE; + } +} /** * Helper function that process d.org users list and add/update that object to * user nodes. @@ -823,7 +861,7 @@ function _ppgetstat_process_dorg_users($users_data, $doids, $tid) { $node->type = 'user'; node_object_prepare($node); } else { - $node = node_load($existed_users[$uid]); + $old_node = $node = node_load($existed_users[$uid]); } $node->title = $users_data[$uid]->name; @@ -867,7 +905,27 @@ function _ppgetstat_process_dorg_users($users_data, $doids, $tid) { } } - node_save($node); + if (!empty($node->nid)) { + /*if (_ppgetstat_node_diff($old_node, $node, + array( + 'field_job_titles', + 'field_organisations', + 'field_mentors', + 'title' + ) + )) {*/ + // Uf user has updated something at profile - adding new revision. + $node->revision = 1; + $node->log = 'User rescan: ' . date('Y-m-d H:i'); + watchdog('dorg_users_import', 'Updating user @user', array('@user' => l($node->title, 'node/' . $node->nid))); + node_save($node); + //} + } else { + node_save($node); + watchdog('dorg_users_import', 'Adding new user @user', array('@user'=> l($node->title, 'node/' . $node->nid))); + + } + } } diff --git a/docroot/sites/all/modules/custom/ppgetstat/ppgetstat.pages.inc b/docroot/sites/all/modules/custom/ppgetstat/ppgetstat.pages.inc index 4ec0263..dee3fda 100755 --- a/docroot/sites/all/modules/custom/ppgetstat/ppgetstat.pages.inc +++ b/docroot/sites/all/modules/custom/ppgetstat/ppgetstat.pages.inc @@ -176,10 +176,7 @@ function ppgetstat_reset_form_submit($form, $form_state) { } } -/** - * Form builder for reset stats form. - */ -function ppgetstat_sync_user_list($form, $form_state) { +function _ppgetstat_list_form_element() { // Getting list of all available users list for analyzing. $user_lists_vocab = taxonomy_vocabulary_machine_name_load('users_list'); $terms = taxonomy_get_tree($user_lists_vocab->vid); @@ -189,11 +186,20 @@ function ppgetstat_sync_user_list($form, $form_state) { foreach ($terms as $term) { $options[$term->tid] = $term->name; } - $form['users_list'] = array( + + return array( '#type' => 'select', - '#title' => t('Select users group scan to'), + '#title' => t('Select users group'), '#options' => $options, ); +} + +/** + * Form builder for reset stats form. + */ +function ppgetstat_sync_user_list($form, $form_state) { + + $form['users_list'] = _ppgetstat_list_form_element(); $form['direct_user'] = array( '#type' => 'textfield', @@ -236,3 +242,48 @@ function ppgetstat_sync_user_list_submit(array $form, array &$form_state) { drupal_set_message(t('You are not selected any import criteria.'), 'warning'); } } + +function ppgetstat_rescan(array $form, array $form_state) { + $form['users_list'] = _ppgetstat_list_form_element(); + $count = db_select('ppgetstat', 'p')->countQuery()->execute()->fetchCol(); + $form['submit'] = array( + '#type' => 'submit', + '#value' => t('test request') + ); + + return $form; +} + +function ppgetstat_rescan_submit(array $form, array &$form_state) { + $user_list_tid = $form_state['values']['users_list']; + $queue = DrupalQueue::get('stats_jobs'); + $scan_users = array(); + $query = db_select('field_data_field_user_id', 'fdoid'); + $query->innerJoin('field_data_field_user_lists', 'fl', 'fdoid.entity_id = fl.entity_id'); + $query->condition('fl.field_user_lists_tid', $user_list_tid); + $query->innerJoin('node', 'n', 'n.nid = fdoid.entity_id'); + $query->fields('n', array('title')); + $query->fields('fdoid', array('entity_id', 'field_user_id_value')); + $result = $query->execute()->fetchAll(); + foreach ($result as $item) { + $scan_users[] = array( + 'nid' => $item->entity_id, + 'doid' => $item->field_user_id_value, + 'do_nickname' => $item->title, + ); + } + + $quant = array_chunk($scan_users, PPGETSTAT_STAT_JOB_QUANTIFICATION); + foreach ($quant as $items) { + // Invoke hook so all modules can use it to provide jobs. + foreach (module_implements('ppgetstat_stats_job') as $module) { + $jobs = module_invoke($module, 'ppgetstat_stats_job', $items, TRUE); + if (!empty($jobs)) { + foreach ($jobs as $job) { + $queue->createItem($job); + } + } + } + } + +} diff --git a/docroot/sites/all/themes/custom/ppdorg_bootstrap/logo-large.png b/docroot/sites/all/themes/custom/ppdorg_bootstrap/logo-large.png new file mode 100644 index 0000000..3583c98 Binary files /dev/null and b/docroot/sites/all/themes/custom/ppdorg_bootstrap/logo-large.png differ