Pārlūkot izejas kodu

ticket 48 adding a checkbox to the tripalpane field group type to allow for easy hide or show on page load formatting

Shawna Spoor 7 gadi atpakaļ
vecāks
revīzija
bc277a7c83

+ 82 - 99
tripal_chado/api/modules/tripal_chado.cv.api.inc

@@ -455,46 +455,41 @@ function tripal_update_cvtermpath_loop($origin, $child_id, $cv_id, $type_id, $de
           'pathdistance' => $depth,
         ));
       $rows = $query->execute();
-
-
-      // Build the ID.
-      $children_id = $origin.'|'.$child_id.'|'.$cv_id.'|'.$type_id;
-
-      // Now check if the most recent entry already exists in the array.
-      if($increment_of_depth != 0){
-        // Search the $array_of_children for the new $child_id in the build_id column.
-        foreach ($array_of_children as $key => $val) {
-          if ($val['build_id'] == $children_id) {
-            $possible_loop_start = $val;
-            //watchdog('debug', '<pre>tripal_update_cvtermpath_loop_checker  $val: '. print_r($val, TRUE) .'</pre>');
-            // If the search returns something check for a possible loop.
-            //if(!empty($possible_loop_starts)){
-              //foreach($possible_loop_starts as $possible_loop_start){
-                // Call the loop checker function.
-                $result_of_loop_checker = tripal_update_cvtermpath_loop_checker($origin, $child_id, $cv_id, $type_id, $depth, $increment_of_depth, 0, $possible_loop_start, array(), $depth);
-            //watchdog('debug', '<pre>$result_of_loop_checker  $val: '. print_r($result_of_loop_checker, TRUE) .'</pre>');
-            //die();
-            if($result_of_loop_checker == TRUE){
-              watchdog('debug', 'Loop found exit the loop function');
-              exit;
-               // }
-              //}
+      if($rows) {
+        // Build the ID.
+        $children_id = $origin . '|' . $child_id . '|' . $cv_id . '|' . $type_id;
+        // Now check if the most recent entry already exists in the array.
+        if ($increment_of_depth != 0) {
+          // Search the $array_of_children for the new $child_id in the build_id column.
+          foreach ($array_of_children as $key => $val) {
+            if ($val['build_id'] == $children_id) {
+              // If the search returns something check for a possible loop.
+              $result_of_loop_checker = tripal_update_cvtermpath_loop_checker($origin, $child_id, $cv_id, $type_id, $depth, $increment_of_depth, 0, $val, [], $depth);
+              watchdog('debug', '<pre>tripal_update_cvtermpath_loop  $result_of_loop_checker: ' . print_r($result_of_loop_checker, TRUE) . '</pre>');
+              if ($result_of_loop_checker) {
+                watchdog('debug', 'Loop found exit the loop function');
+                break;
+              }
             }
           }
         }
-      }
-      // Then add that new entry to the $array_of_children.
-      $array_of_children[$increment_of_depth] =  array('build_id'=>$children_id, 'depth' => $depth);
-
-      $query = db_select('cvterm_relationship', 'cvtr')
-        ->fields('cvtr')
-        ->condition('cvtr.object_id', $child_id, '=')
-        ->execute();
-      $cterm = $query->fetchAll();
-
-      foreach ($cterm as $item) {
-        $increment_of_depth++;
-        tripal_update_cvtermpath_loop($origin, $item->subject_id, $cv_id, $item->type_id, $depth + 1, $increment_of_depth, $array_of_children);
+        // Then add that new entry to the $array_of_children.
+        $array_of_children[$increment_of_depth] = [
+          'build_id' => $children_id,
+          'depth' => $depth
+        ];
+
+        $query = db_select('cvterm_relationship', 'cvtr')
+          ->fields('cvtr')
+          ->condition('cvtr.object_id', $child_id, '=')
+          ->execute();
+        $cterm = $query->fetchAll();
+
+        foreach ($cterm as $item) {
+          watchdog('message', '<pre>$loop_status: ' . print_r($loop_status, TRUE) . '</pre>');
+          $increment_of_depth++;
+          tripal_update_cvtermpath_loop($origin, $item->subject_id, $cv_id, $item->type_id, $depth + 1, $increment_of_depth, $array_of_children);
+        }
       }
     }
   }
@@ -502,7 +497,6 @@ function tripal_update_cvtermpath_loop($origin, $child_id, $cv_id, $type_id, $de
     watchdog_exception('tripal_ds', $e);
     return FALSE;
   }
-
 }
 
 /**
@@ -520,36 +514,6 @@ function tripal_update_cvtermpath_loop($origin, $child_id, $cv_id, $type_id, $de
  * @return bool
  */
 function tripal_update_cvtermpath_loop_checker($origin, $child_id, $cv_id, $type_id, $depth, $increment_of_depth, $distance_between_parent_child, $possible_start_of_loop, $array_of_possible_loop, $depth_at_start_of_loop){
-  //watchdog('debug', '<pre>$array_of_possible_loop: '. print_r($array_of_possible_loop, TRUE) .'</pre>');
-  //watchdog('debug', '<pre>$array_of_possible_loop: '. print_r($array_of_possible_loop, TRUE) .'</pre>');
-
-  if ($distance_between_parent_child > 0){
-      // Search the $array_of_children for the new $child_id in the build_id column.
-      //$possible_loop_starts = array_keys(array_column($array_of_possible_loop,
-    // 'build_id'), $possible_start_of_loop);
-      foreach ($array_of_possible_loop as $key => $val) {
-       // watchdog('debug', '<pre>$start_of_loop: '. print_r($possible_start_of_loop['depth'], TRUE) .'</pre>');
-       // watchdog('debug', '<pre>$depth_at_start_of_loop: '. print_r($depth_at_start_of_loop, TRUE) .'</pre>');
-
-        if ($val['build_id'] === $possible_start_of_loop['build_id']) {
-          $possible_loop_starts = $val;
-         // watchdog('debug', '<pre>$loop_starts: '. print_r($possible_loop_starts['depth'], TRUE) .'</pre>');
-
-          // If the search returns something check for a possible loop.
-          if (!empty($possible_loop_starts)) {
-            //  $array_of_possible_loop now contains the suspected loop. Call
-            // this function again and check the next entry against the array
-            // if the 1st entry is the same, check the next entry, if all items
-            // in the array match, it's a loop, kill it.
-            $result = tripal_update_cvtermpath_loop_checker_traverse($origin, $child_id, $cv_id, $type_id, $depth, $increment_of_depth, $possible_start_of_loop, $array_of_possible_loop, array(), 0);
-            if($result == TRUE){
-              return TRUE;
-            }
-          }
-        }
-      }
-    }
-
     chado_set_active('chado');
     $query = db_select('cvterm_relationship', 'cvtr')
       ->fields('cvtr')
@@ -558,49 +522,68 @@ function tripal_update_cvtermpath_loop_checker($origin, $child_id, $cv_id, $type
     $cterm = $query->fetchAll();
 
     foreach ($cterm as $item){
-      //watchdog('debug', '<pre>tripal_ds_preprocess_TripalEntity $item ' . print_r($item, TRUE) . '</pre>');
+      if ($distance_between_parent_child > 0){
+        // Search the $array_of_children for the new $child_id in the build_id column.
+        foreach ($array_of_possible_loop as $key => $val) {
+          if ($val['build_id'] === $possible_start_of_loop['build_id']) {
+            $possible_loop_starts = $val;
+            // If the search returns something check for a possible loop.
+            if (!empty($possible_loop_starts)) {
+              $result = tripal_update_cvtermpath_loop_checker_traverse($origin, $child_id, $cv_id, $type_id, $depth, $increment_of_depth, $possible_start_of_loop, $array_of_possible_loop, array(), 0);
+              watchdog('debug', '<pre>tripal_update_cvtermpath_loop_checker  $result: '. print_r($result, TRUE) .'</pre>');
+              if(!empty($result)){
+                return $result;
+              }
+            }
+          }
+        }
+      }
+      elseif($loop_found !== TRUE){}
       $increment_of_depth++;
       $distance_between_parent_child++;
       $children_id = $origin .'|' .$item->subject_id .'|' .$cv_id.'|' .$item->type_id;
-      $array_of_possible_loop[$distance_between_parent_child] = array('build_id' => $children_id, 'depth' => $depth);
-      tripal_update_cvtermpath_loop_checker($origin, $item->subject_id, $cv_id, $item->type_id, $depth + 1, $increment_of_depth, $distance_between_parent_child, $possible_start_of_loop, $array_of_possible_loop, $depth_at_start_of_loop);
+      $array_of_possible_loop[$distance_between_parent_child] = array('build_id' => $children_id);
+      $result = tripal_update_cvtermpath_loop_checker($origin, $item->subject_id, $cv_id, $item->type_id, $depth + 1, $increment_of_depth, $distance_between_parent_child, $possible_start_of_loop, $array_of_possible_loop, $depth_at_start_of_loop);
+      if($result !== FALSE){
+        return $result;
+      }
     }
-
   return FALSE;
 }
 
 function tripal_update_cvtermpath_loop_checker_traverse($origin, $child_id, $cv_id, $type_id, $depth, $increment_of_depth, $possible_start_of_loop, $array_of_possible_loop, $traverse_of_loop, $increment){
-  if ($increment > 0){
-    watchdog('debug', '<pre>$traverse_of_loop: '. print_r($traverse_of_loop, TRUE) .'</pre>');
-    watchdog('debug', '<pre>$array_of_possible_loop: '. print_r($array_of_possible_loop, TRUE) .'</pre>');
-    // If the search returns something compare values.
-    if($array_of_possible_loop === $traverse_of_loop){
-      watchdog('debug', 'LOOP');
-
-      //Report the loop.
-      return TRUE;
+    if($increment > 10){
+      die();
     }
-  }
-  chado_set_active('chado');
-  $query = db_select('cvterm_relationship', 'cvtr')
-    ->fields('cvtr')
-    ->condition('cvtr.object_id', $child_id, '=')
-    ->execute();
-  $cterm = $query->fetchAll();
+    chado_set_active('chado');
+    $query = db_select('cvterm_relationship', 'cvtr')
+      ->fields('cvtr')
+      ->condition('cvtr.object_id', $child_id, '=')
+      ->execute();
+    $cterm = $query->fetchAll();
 
-  foreach ($cterm as $item){
-    //watchdog('debug', '<pre>tripal_ds_preprocess_TripalEntity $item ' . print_r($item, TRUE) . '</pre>');
-    $increment_of_depth++;
-    $increment++;
-    $children_id = $origin .'|' .$item->subject_id .'|' .$cv_id.'|' .$item->type_id;
-    $traverse_of_loop[$increment] = array('build_id' => $children_id, 'depth' => $depth - 2);
-    tripal_update_cvtermpath_loop_checker_traverse($origin, $item->subject_id, $cv_id, $item->type_id, $depth + 1, $increment_of_depth, $possible_start_of_loop, $array_of_possible_loop, $traverse_of_loop, $increment);
-  }
-  return FALSE;
+    foreach ($cterm as $item){
+      if($array_of_possible_loop === $traverse_of_loop){
+        watchdog('debug', '<pre>$array_of_possible_loop: '. print_r($array_of_possible_loop, TRUE) .'</pre>');
+        watchdog('debug', '<pre>$traverse_of_loop: '. print_r($traverse_of_loop, TRUE) .'</pre>');
+        watchdog('debug', 'LOOP');
+        //Report the loop.
+        return $item;
+      }
+      elseif($array_of_possible_loop != $traverse_of_loop) {
+        $increment_of_depth++;
+        $increment++;
+        $children_id = $origin . '|' . $item->subject_id . '|' . $cv_id . '|' . $item->type_id;
+        $traverse_of_loop[$increment] = ['build_id' => $children_id];
+        $result = tripal_update_cvtermpath_loop_checker_traverse($origin, $item->subject_id, $cv_id, $item->type_id, $depth + 1, $increment_of_depth, $possible_start_of_loop, $array_of_possible_loop, $traverse_of_loop, $increment);
+        if($result !== FALSE){
+          return $result;
+        }
+      }
+    }
+    return FALSE;
 }
 
-
-
 /*
  *
  * @param $origin

+ 42 - 3
tripal_ds/includes/tripal_ds.field_formatter.inc

@@ -8,19 +8,51 @@ function tripal_ds_field_group_formatter_info() {
       'tripalpane' => array(
         'label' => t('Tripal Pane'),
         'description' => t('This fieldgroup renders the inner content in a Tripal Pane with the title as legend.'),
-        'instance_settings' => array('description' => '', 'classes' => '', 'id' => ''),
+        'instance_settings' => array('description' => '', 'classes' => '', 'id' => '', 'hide' => 1),
       ),
     ),
      'display' => array(
         'tripalpane' => array(
           'label' => t('Tripal Pane'),
           'description' => t('This fieldgroup renders the inner content in a Tripal Pane with the title as legend.'),
-          'instance_settings' => array('description' => '', 'classes' => '', 'id' => ''),
+          'instance_settings' => array('description' => '', 'classes' => '', 'id' => '', 'hide' => 1),
         ),
       ),
   );
 }
+/**
+ * Implements hook_field_group_format_settings().
+ *
+ * @params Object $group The group object.
+ * @return Array $form The form element for the format settings.
+ */
+function tripal_ds_field_group_format_settings($group) {
+  // Add a wrapper for extra settings to use by others.
+  $form = array(
+    'instance_settings' => array(
+      '#tree' => TRUE,
+      '#weight' => 2,
+    ),
+  );
+
+  $field_group_types = field_group_formatter_info();
+  $mode = $group->mode == 'form' ? 'form' : 'display';
+  $formatter = $field_group_types [$mode][$group->format_type];
 
+  // Add optional instance_settings.
+  switch ($group->format_type) {
+    case 'tripalpane':
+      $form['instance_settings']['hide'] = array(
+        '#title' => t('Hide panel on page load'),
+        '#type' => 'checkbox',
+        '#default_value' => isset($group->format_settings['instance_settings']['hide']) ? $group->format_settings['instance_settings']['hide'] : $formatter['instance_settings']['hide'],
+        '#weight' => 2,
+      );
+      break;
+  }
+
+  return $form;
+}
 /*
  * Implements field_group_pre_render_<format-type>.
  * Format type: Tripalpane.
@@ -34,8 +66,15 @@ function tripal_ds_field_group_pre_render(&$element, $group, &$form) {
     case 'tripalpane':
       $group_name = $group->group_name;
       $description = $group->format_settings['instance_settings']['description'];
+      $hide = isset($group->format_settings['instance_settings']['hide']) ? $group->format_settings['instance_settings']['hide'] : 'none';
       $classes = $group->format_settings['instance_settings']['classes'];
-      $element['#prefix'] = '<div class="tripal_pane-fieldset-'.$group_name.' '.$group_name.' tripal_pane '.$classes.'"> <span class="field-group-format-title">' . check_plain(t($group->label)) . '</span>';
+      if ($hide == '1') {
+        $element['#prefix'] = '<div class="tripal_pane-fieldset-'.$group_name.' '.$group_name.' tripal_pane '.$classes.' hideTripalPane"> <span class="field-group-format-title">' . check_plain(t($group->label)) . '</span>';
+      }
+      else {
+        $element['#prefix'] = '<div class="tripal_pane-fieldset-'.$group_name.' '.$group_name.' tripal_pane '.$classes.'"> <span class="field-group-format-title">' . check_plain(t($group->label)) . '</span>';
+
+      }
       if (!empty($description)) {
         $element['#prefix'] .= '<div class="description">' . $description . '</div>';
       }

+ 9 - 4
tripal_ds/includes/tripal_ds.field_group.inc

@@ -27,6 +27,7 @@ function _summary_field_group_info($bundle_name, $fields){
         'id' => 'tripal_ds-fieldset-group_summary_tripalpane',
         'classes' => 'group-summary-tripalpane field-group-tripalpane',
         'description' => '',
+        'hide' => 0,
       ),
     ),
   );
@@ -93,8 +94,9 @@ function _prop_field_group_info($bundle_name, $fields){
       'label' => 'Properties',
       'instance_settings' => array(
         'id' => 'tripal_ds-fieldset-group_prop_tripalpane',
-        'classes' => 'hideTripalPane group-prop-tripalpane field-group-tripalpane',
+        'classes' => 'group-prop-tripalpane field-group-tripalpane',
         'description' => '',
+        'hide' => 1,
       ),
     ),
   );
@@ -160,8 +162,9 @@ function _data_sequence_field_group_info($bundle_name, $fields){
       'label' => 'Data Sequences',
       'instance_settings' => array(
         'id' => 'tripal_ds-fieldset-group_sequence_tripalpane',
-        'classes' => 'hideTripalPane group-sequence-tripalpane field-group-tripalpane ',
+        'classes' => 'group-sequence-tripalpane field-group-tripalpane ',
         'description' => '',
+        'hide' => 1,
       ),
     ),
   );
@@ -230,8 +233,9 @@ function _additional_fields_field_group_info($bundle_name, $field_label, $group_
       'label' => $field_label,
       'instance_settings' => array(
         'id' => 'tripal_ds-fieldset-'.$group_field_name,
-        'classes' =>'hideTripalPane '.$group_field_name.' field-group-tripalpane',
+        'classes' => $group_field_name.' field-group-tripalpane',
         'description' => '',
+        'hide' => 1,
       ),
     ),
   );
@@ -263,8 +267,9 @@ function _publication_prop_field_group_info($bundle_name, $fields){
       'label' => 'Properties',
       'instance_settings' => array(
         'id' => 'tripal_ds-fieldset-group_prop_tripalpane',
-        'classes' => 'hideTripalPane group-prop-tripalpane field-group-tripalpane',
+        'classes' => 'group-prop-tripalpane field-group-tripalpane',
         'description' => '',
+        'hide' => 1,
       ),
     ),
   );