Browse Source

Added a function to check if the current lp item is first, both, last or none from lp list - Refs #11192

José Loguercio 8 years ago
parent
commit
0dfdd23a2c
1 changed files with 45 additions and 0 deletions
  1. 45 0
      main/newscorm/learnpath.class.php

+ 45 - 0
main/newscorm/learnpath.class.php

@@ -11114,6 +11114,51 @@ EOD;
 
         return $form->returnForm();
     }
+
+    /**
+     * Check if the current lp item is first, both, last or none from lp list
+     *
+     * @return string
+     */
+    public function isFirstOrLastItem()
+    {
+        if ($this->debug > 0) {
+            error_log('New LP - In learnpath::isFirstOrLastItem', 0);
+        }
+
+        $lpItemId = [];
+        $currentItemId = $this->get_current_item_id();
+
+        $typeListNotToVerify = self::getChapterTypes();
+        foreach ($this->items as $item) {
+            if (!in_array($item->get_type(), $typeListNotToVerify)) {
+                $lpItemId[] = $item->get_id();
+            }
+        }
+
+        $answer = '';
+        $lastLpItemIndex = count($lpItemId) - 1;
+        $position = array_search($currentItemId, $lpItemId);
+
+        switch ($position) {
+            case 0:
+                if (!$lastLpItemIndex) {
+                    $answer = 'both';
+                    break;
+                }
+
+                $answer = 'first';
+                break;
+            case $lastLpItemIndex:
+                $answer = 'last';
+                break;
+            default:
+                $answer = 'none';
+        }
+
+        return $answer;
+    }
+
 }
 
 if (!function_exists('trim_value')) {