Browse Source

Updated API, remove page from collection

markseu 2 years ago
parent
commit
5eab8a20e1
2 changed files with 16 additions and 5 deletions
  1. 14 3
      system/extensions/core.php
  2. 2 2
      system/extensions/update-current.ini

+ 14 - 3
system/extensions/core.php

@@ -2,7 +2,7 @@
 // Core extension, https://github.com/annaesvensson/yellow-core
 
 class YellowCore {
-    const VERSION = "0.8.103";
+    const VERSION = "0.8.104";
     const RELEASE = "0.8.21";
     public $content;        // content files
     public $media;          // media files
@@ -3408,6 +3408,17 @@ class YellowPageCollection extends ArrayObject {
         $this->exchangeArray($array);
     }
     
+    // Remove page from page collection
+    public function remove($page): YellowPageCollection {
+        $array = array();
+        $location = $page->location;
+        foreach ($this->getArrayCopy() as $page) {
+            if ($page->location!=$location) array_push($array, $page);
+        }
+        $this->exchangeArray($array);
+        return $this;
+    }
+    
     // Filter page collection by page setting
     public function filter($key, $value, $exactMatch = true): YellowPageCollection {
         $array = array();
@@ -3493,7 +3504,7 @@ class YellowPageCollection extends ArrayObject {
     // Calculate intersection, remove pages that are not present in another page collection
     public function intersect($input): YellowPageCollection {
         $callback = function ($a, $b) {
-            return strcmp(spl_object_hash($a), spl_object_hash($b));
+            return strcmp($a->location, $b->location);
         };
         $this->exchangeArray(array_uintersect($this->getArrayCopy(), (array)$input, $callback));
         return $this;
@@ -3502,7 +3513,7 @@ class YellowPageCollection extends ArrayObject {
     // Calculate difference, remove pages that are present in another page collection
     public function diff($input): YellowPageCollection {
         $callback = function ($a, $b) {
-            return strcmp(spl_object_hash($a), spl_object_hash($b));
+            return strcmp($a->location, $b->location);
         };
         $this->exchangeArray(array_udiff($this->getArrayCopy(), (array)$input, $callback));
         return $this;

+ 2 - 2
system/extensions/update-current.ini

@@ -11,11 +11,11 @@ Tag: feature
 system/extensions/command.php: command.php, create, update
 
 Extension: Core
-Version: 0.8.103
+Version: 0.8.104
 Description: Core functionality of the website.
 DocumentationUrl: https://github.com/annaesvensson/yellow-core
 DownloadUrl: https://github.com/datenstrom/yellow-extensions/raw/main/downloads/core.zip
-Published: 2022-11-22 22:27:11
+Published: 2023-03-19 19:20:55
 Developer: Mark Seuffert, David Fehrmann
 Tag: feature
 system/extensions/core.php: core.php, create, update