function opigno_statistics_group_insert in Opigno Statistics App 7
1 call to opigno_statistics_group_insert()
- opigno_statistics_app_exit in ./
opigno_statistics_app.module - Implements hook_exit().
File
- ./
opigno_statistics_app.module, line 316 - Module file. Defines module hooks.
Code
function opigno_statistics_group_insert($gid, $nid, $month_year) {
$group_category = array();
if (db_table_exists("field_data_opigno_course_categories")) {
$group_categories = db_query('SELECT opigno_course_categories_tid FROM {field_data_opigno_course_categories} WHERE entity_id = :entity_id and entity_type = :entity_type and deleted = :deleted ', array(
':entity_id' => $gid,
':entity_type' => "node",
':deleted' => 0,
));
foreach ($group_categories as $group_category_term) {
$group_category_name = db_query('SELECT name FROM {taxonomy_term_data} WHERE tid = :tid', array(
':tid' => $group_category_term->opigno_course_categories_tid,
))
->fetchField();
if ($group_category_name) {
$group_category[$group_category_term->opigno_course_categories_tid] = $group_category_name;
}
}
}
if (empty($group_category)) {
$group_category[0] = "NONE";
}
$group_node = node_load($gid);
if ($group_node != false) {
foreach ($group_category as $category_id => $category_name) {
db_merge('opigno_statistics_group')
->key(array(
'group_nid' => $gid,
'month_year' => $month_year,
'category_taxonomy_term_id' => $category_id,
))
->fields(array(
'category_taxonomy_term_name' => $category_name,
'group_title' => $group_node->title,
'group_type' => $group_node->type,
))
->expression('page_views', 'page_views + :inc', array(
':inc' => 1,
))
->execute();
}
}
global $user;
$user_with_og = user_load($user->uid);
//Increment page_view for all classes of user
foreach ($user_with_og->og_user_node[LANGUAGE_NONE] as $og_user_node) {
$target_node = node_load($og_user_node['target_id']);
if ($target_node != false && $target_node->type === 'class') {
db_merge('opigno_statistics_group')
->key(array(
'group_nid' => $target_node->nid,
'month_year' => $month_year,
'category_taxonomy_term_id' => 0,
))
->fields(array(
'category_taxonomy_term_name' => 'NONE',
'group_title' => $target_node->title,
'group_type' => $target_node->type,
))
->expression('page_views', 'page_views + :inc', array(
':inc' => 1,
))
->execute();
}
}
}