Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ function _pp_comparing_users_data($users, $types, $dates) {
$db_data = $query->execute()->fetchAllAssoc('timestamp');

$beginning = (!empty($dates['from'])) ? $dates['from'] : REQUEST_TIME - PPGETSTAT_DEFAULT_TIME_PERIOD_FOR_SCANNING;
$timestamp = $beginning - ($beginning % PPGETSTAT_TIME_PERIOD_GRANULARITY);
$timestamp = $beginning - ($beginning % PPGETSTAT_TIME_WEEK_GRANULARITY);

$till_time = !empty($dates['till']) ? $dates['till'] : REQUEST_TIME;
while ($timestamp < $till_time) {
Expand All @@ -134,7 +134,7 @@ function _pp_comparing_users_data($users, $types, $dates) {
$table_data[$timestamp]['timestamp'] = format_date($timestamp, 'custom', 'j M y');
$table_data[$timestamp][$doid] = $commits;

$timestamp += PPGETSTAT_TIME_PERIOD_GRANULARITY;
$timestamp += PPGETSTAT_TIME_WEEK_GRANULARITY;
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,107 +20,12 @@ $plugin = array(
*/
function pp_frontpage_adduser_content_type_render($subtype, $conf, $panel_args, $context) {
$block = new stdClass();

$block->title = t('Add users');
$block->module = 'pp_frontpage';
$block->title = t('Add user');

$form = drupal_get_form('pp_frontpage_adduser');
$output = '<div class="add-user-form">' . drupal_render($form) . '</div>';
$form = menu_execute_active_handler('admin/config/services/sync_user_list', FALSE);
$block->content = '<div class="add-user-form">' . drupal_render($form) . '</div>';

$block->content = $output;
return $block;
}

/**
* Form constructor.
*/
function pp_frontpage_adduser($form, $form_state) {
$form['nickname'] = array(
'#type' => 'textfield',
'#title' => t('Drupal.org username or user ID'),
'#required' => TRUE,
);

$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Add'),
);

return $form;
}

/**
* Validation handler.
*/
function pp_frontpage_adduser_validate($form, &$form_state) {
if (is_numeric($form_state['values']['nickname'])) {
$uid = $form_state['values']['nickname'];

$exists = db_query('SELECT nid FROM {node} LEFT JOIN {field_data_field_user_id} AS fuid ON node.nid = fuid.entity_id WHERE type = :type AND fuid.field_user_id_value = :uid',
array(
':type' => PPGETSTAT_USER_NODE_TYPE,
':uid' => $uid,
))->fetchField();
if (!empty($exists)) {
form_set_error('doid', t('User !link already exists', array(
'!link' => l(t('User with Id=@uid already exists', array('@uid' => $uid)), 'node/' . $exists),
)));
return;
}

$nickname = ppgetstat_get_nick_by_id($uid);
if (empty($nickname)) {
form_set_error('doid', t('There is no such user ID on drupal.org'));
}

$form_state['values']['nickname'] = $nickname;
$form_state['values']['doid'] = $uid;
}
elseif (is_string($form_state['values']['nickname'])) {
$nickname = $form_state['values']['nickname'];

$exists = db_query('SELECT nid FROM {node} WHERE type = :type AND title = :title',
array(
':type' => PPGETSTAT_USER_NODE_TYPE,
':title' => $nickname,
))->fetchField();
if (!empty($exists)) {
form_set_error('nickname', t('User !link already exists', array(
'!link' => l($nickname, 'node/' . $exists),
)));
return;
}

$doid = ppgetstat_get_id_by_nick($nickname);
if (empty($doid)) {
form_set_error('nickname', t('There is no such user on drupal.org'));
}

$form_state['values']['doid'] = $doid;
}

return $form;
}

/**
* Submit handler.
*/
function pp_frontpage_adduser_submit($form, &$form_state) {
$nickname = $form_state['values']['nickname'];
$doid = $form_state['values']['doid'];

$node = (object) array(
'title' => $nickname,
'type' => PPGETSTAT_USER_NODE_TYPE,
'field_user_id' => array(
LANGUAGE_NONE => array(
array('value' => $doid),
)
),
);
node_object_prepare($node);
node_save($node);

drupal_set_message(t('User !link has been created', array(
'!link' => l($nickname, 'node/' . $node->nid),
)));
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?php

$plugin = array(
'title' => t('Community quality'),
'single' => TRUE,
'category' => t('PP'),
'title' => t('Community quality'),
'single' => TRUE,
'category' => t('PP'),
);

/**
Expand All @@ -13,14 +13,10 @@ function pp_frontpage_community_quality_content_type_render($subtype, $conf, $pa
$block = new stdClass();
$block->module = 'pp_frontpage';
$block->title = t('Community statistic');

// Getting info for showing count of individual members at this country.
$members_stat = _ppgetstat_get_individual_members();

//@TODO add user list filtering for future.
$all_user_count = db_select('node', 'n')
->fields('n', array('nid'))
->condition('n.type', 'user')
->condition('type', PPGETSTAT_USER_NODE_TYPE)
->countQuery()
->execute()
->fetchField();
Expand All @@ -40,16 +36,21 @@ function pp_frontpage_community_quality_content_type_render($subtype, $conf, $pa
->countQuery()
->execute()
->fetchField();
$individual_members_count = $members_stat['members_country_count']['Ukraine'];

$block->content = '<div class="bs-callout bs-callout-primary">
<ul>
<li>'.t('Total count').' : <strong>' . $all_user_count . '</strong></li>
<li>'.t('Active committers').' : <strong>' . $active_by_commits_count . ' (' . number_format($active_by_commits_count/$all_user_count, 2)*100 . ')%</strong></li>
<li>'.t('Active commenters').' : <strong>' . $active_by_comments_count . ' (' . number_format($active_by_comments_count/$all_user_count, 2)*100 . ')%</strong></li>
<li>'.t('Individual Assoc members').' : <strong>' . $individual_members_count . ' (' . number_format($individual_members_count/$all_user_count, 2)*100 . ')%</strong></li>
</ul>
</div>';
if ($all_user_count > 0) {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prevented division by zero (when no users in DB).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thx.

// Getting info for showing count of individual members at this country.
$members_stat = _ppgetstat_get_individual_members();
$individual_members_count = $members_stat['members_country_count']['Ukraine'];

$block->content = '<div class="bs-callout bs-callout-primary">
<ul>
<li>'.t('Total count').' : <strong>' . $all_user_count . '</strong></li>
<li>'.t('Active committers').' : <strong>' . $active_by_commits_count . ' (' . number_format($active_by_commits_count/$all_user_count, 2)*100 . ')%</strong></li>
<li>'.t('Active commenters').' : <strong>' . $active_by_comments_count . ' (' . number_format($active_by_comments_count/$all_user_count, 2)*100 . ')%</strong></li>
<li>'.t('Individual Assoc members').' : <strong>' . $individual_members_count . ' (' . number_format($individual_members_count/$all_user_count, 2)*100 . ')%</strong></li>
</ul>
</div>';
}

return $block;
}
Original file line number Diff line number Diff line change
@@ -1,40 +1,37 @@
<?php
/**
* @file
* Individual members by country.
*/

$plugin = array(
'title' => t('Association individual memebers by country stat'),
'title' => t('Association individual members by country'),
'single' => TRUE,
'category' => t('PP'),
);

/**
* Render global individual members statistics.
*/
function pp_frontpage_members_by_country_content_type_render($subtype, $conf, $panel_args, $context) {
function pp_frontpage_members_by_country_content_type_render() {
$block = new stdClass();
$block->module = 'pp_frontpage';
$block->title = t('Drupal Association individual members by country statistics');

// Getting info for showing count of individual members at this country.
$members_stat = _ppgetstat_get_individual_members();
$i = 1; $rows = array();
$rows = array();
$i = 1;

foreach ($members_stat['members_country_count'] as $country => $count) {
$rows[] = array(
$i,
$country,
$count
);
$i++;
$rows[] = array($i++, $country, $count);
}

$block->content = array(
'#theme' => 'table',
'#header' => array(
t('Position'),
t('Country'),
t('Count of members')
),
'#rows' => $rows
'#header' => array(t('Position'), t('Country'), t('Count of members')),
'#rows' => $rows,
);

return $block;
}
}
115 changes: 115 additions & 0 deletions docroot/sites/all/modules/custom/ppgetstat/includes/ppgetstat.api.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
<?php
/**
* @file
* API requests.
*/

/**
* Class APICall.
*/
class APICall {

/**
* @var string
*/
private $url = '';
/**
* @var array
*/
private $query = array();
/**
* @var stdClass
*/
private $result;

/**
* APICall constructor.
*
* @param string $base
* An URL with API.
*/
public function __construct($base = 'https://www.drupal.org') {
$this->url = rtrim($base, '/');
}

/**
* Specify resource of the API.
*
* @param string $resource
* API resource.
*
* @return $this
* APICall instance.
*/
public function resource($resource) {
$this->url .= "/$resource";

return $this;
}

/**
* Configure query.
*
* @param array $variables
* Query parameters.
*
* @return $this
* APICall instance.
*/
public function query(array $variables) {
$this->query = array_merge($this->query, $variables);

return $this;
}

/**
* Get a page of results.
*
* @param int $page
* Page number.
*
* @return $this
* APICall instance.
*/
public function page($page = 0) {
if ($page > 0) {
$this->query['page'] = $page;
}

return $this;
}

/**
* Perform a request to an API.
*
* @param array $options
* Additional options for drupal_http_request().
*
* @return stdClass|bool
* Query result or FALSE.
*/
public function execute($options = array()) {
if (!empty($this->query)) {
$this->url .= '?' . http_build_query($this->query);
}

$this->result = drupal_http_request($this->url, array_merge(array('timeout' => 3000), $options));

return 200 == $this->result->code ? json_decode($this->result->data) : FALSE;
}

/**
* Get waw results of a query.
*
* @return stdClass
* Query result.
*/
public function getRawResult() {
if (empty($this->result)) {
throw new \RuntimeException('You must call the "execute" method firstly.');
}

return $this->result;
}

}
Loading