Skip to content

Commit

Permalink
Check if project has genus defined - Issue #12 Stock name lookup
Browse files Browse the repository at this point in the history
- Added a check to ensure project has a genus set before loading a page.
  • Loading branch information
reynoldtan committed May 26, 2017
1 parent 78b6edb commit 92298c6
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 4 deletions.
24 changes: 20 additions & 4 deletions rawpheno.module
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ function rawpheno_preprocess_rawpheno_rawdata(&$variables, $hook) {
function rawpheno_preprocess_rawpheno_instructions(&$variables, $hook) {
// Colour scheme, project check and data check.
$rawpheno_load = rawpheno_module_defaults();
list($variables['theme_colour'], $variables['my_projects'], $variables['has_prj'], $variables['has_data']) = $rawpheno_load;
list($variables['theme_colour'], $variables['my_projects'], $variables['has_prj'], $variables['has_data'], $variables['has_genus']) = $rawpheno_load;

// Cross-link instructions page to upload page.
$variables['rel_url'] = url('phenotypes/raw/upload');
Expand All @@ -305,7 +305,7 @@ function rawpheno_preprocess_rawpheno_instructions(&$variables, $hook) {
function rawpheno_preprocess_rawpheno_upload_form_master(&$variables, $hook) {
// Colour scheme, project check and data check.
$rawpheno_load = rawpheno_module_defaults();
list($variables['theme_colour'], $variables['my_projects'], $variables['has_prj'], $variables['has_data']) = $rawpheno_load;
list($variables['theme_colour'], $variables['my_projects'], $variables['has_prj'], $variables['has_data'], $variables['has_genus']) = $rawpheno_load;

// Directory permission used in upload and backup.
$pub_dir = 'public://';
Expand Down Expand Up @@ -349,7 +349,7 @@ function rawpheno_preprocess_rawpheno_upload_form_master(&$variables, $hook) {
function rawpheno_preprocess_rawpheno_backup(&$variables, $hook) {
// Colour scheme, project check and data check.
$rawpheno_load = rawpheno_module_defaults();
list($variables['theme_colour'], $variables['my_projects'], $variables['has_prj'], $variables['has_data']) = $rawpheno_load;
list($variables['theme_colour'], $variables['my_projects'], $variables['has_prj'], $variables['has_data'], $variables['has_genus']) = $rawpheno_load;

// Directory permission used in upload and backup.
$pub_dir = 'public://';
Expand Down Expand Up @@ -378,7 +378,7 @@ function rawpheno_preprocess_rawpheno_backup(&$variables, $hook) {
function rawpheno_preprocess_rawpheno_download(&$variables, $hook) {
// Colour scheme, project check and data check.
$rawpheno_load = rawpheno_module_defaults();
list($variables['theme_colour'], $variables['my_projects'], $variables['has_prj'], $variables['has_data']) = $rawpheno_load;
list($variables['theme_colour'], $variables['my_projects'], $variables['has_prj'], $variables['has_data'], $variables['has_genus']) = $rawpheno_load;

// Cross-link download page to download page.
$variables['rel_url'] = url('phenotypes/raw');
Expand All @@ -404,6 +404,21 @@ function rawpheno_module_defaults() {
$log_user = $GLOBALS['user']->uid;
$my_projects = rawpheno_function_user_project($log_user);

// If project has genus defined.
$my_project_ids = array_keys($my_projects);
$my_project_genus = array();

foreach($my_project_ids as $p_id) {
$genus = rawpheno_function_project_organism($p_id);

if ($genus) {
$my_project_genus[] = $genus;
}
}

// Each project must have a genus, see that is true.
$has_genus = (count($my_project_ids) == count($my_project_genus)) ? 1 : 0;

// Does the module contain project?
$has_project = rawpheno_function_project();

Expand All @@ -415,6 +430,7 @@ function rawpheno_module_defaults() {
$my_projects, // User appointed project.
$has_project, // Module has at least a project.
$has_data, // Module has data.
$has_genus, // All project assigned to user should have genus defined.
);
}

Expand Down
12 changes: 12 additions & 0 deletions theme/rawpheno_pages.tpl.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,18 @@
print tripal_set_message('Administrators, you can create or configure Phenotyping Projects by clicking the link below: <br />' . $link_to_manage_project, TRIPAL_INFO, array('return_html' => TRUE));
unset($form);
}
elseif (!$has_genus) {
// A project has no genus defined.
?>
<div id="container-no-info" class="messages warning">
A project(s) has no genus defined. Please contact the administrator of this website.
</div>
<?php
// Admin: Create and configure projects:
$link_to_manage_project = l('Rawphenotypes: Manage Project', '/admin/tripal/extension/rawphenotypes');
print tripal_set_message('Administrators, you can assign an genus to a project by clicking the link below: <br />' . $link_to_manage_project, TRIPAL_INFO, array('return_html' => TRUE));
unset($form);
}
elseif (!$has_data AND in_array($page_id, array('rawpheno_rawdata', 'rawpheno_download'))) {
// Has project but project has no data associated to it.
// Excempt pages upload, backup and instructions.
Expand Down

0 comments on commit 92298c6

Please sign in to comment.