diff options
| author | Greg Roach <fisharebest@gmail.com> | 2015-06-07 21:03:00 +0100 |
|---|---|---|
| committer | Greg Roach <fisharebest@gmail.com> | 2015-06-07 21:03:32 +0100 |
| commit | 7bd2dc1975abbb849d469d48352bbcc45c637c7e (patch) | |
| tree | 8e0d3c141b3e733e469d46ea5ecef0bb4c2f3bee /app/Module/ClippingsCart | |
| parent | 00e7c669bcfdbb90384095b127dfb7bebf8d9e1c (diff) | |
| download | webtrees-7bd2dc1975abbb849d469d48352bbcc45c637c7e.tar.gz webtrees-7bd2dc1975abbb849d469d48352bbcc45c637c7e.tar.bz2 webtrees-7bd2dc1975abbb849d469d48352bbcc45c637c7e.zip | |
Fix #596 clippings cart sessions broken
Diffstat (limited to 'app/Module/ClippingsCart')
| -rw-r--r-- | app/Module/ClippingsCart/ClippingsCartController.php | 32 |
1 files changed, 17 insertions, 15 deletions
diff --git a/app/Module/ClippingsCart/ClippingsCartController.php b/app/Module/ClippingsCart/ClippingsCartController.php index 30dd81d7a0..014430236d 100644 --- a/app/Module/ClippingsCart/ClippingsCartController.php +++ b/app/Module/ClippingsCart/ClippingsCartController.php @@ -65,6 +65,9 @@ class ClippingsCartController { /** @var int The number of descendent generations to add */ public $level3; + /** @var string[][] The contents of the cart */ + private $cart; + /** * Create the clippings controller */ @@ -72,9 +75,10 @@ class ClippingsCartController { global $WT_TREE; // Our cart is an array of items in the session - $cart = Session::get('cart', array()); - if (!array_key_exists($WT_TREE->getTreeId(), $cart)) { - $cart[$WT_TREE->getTreeId()] = array(); + $this->cart = Session::get('cart', array()); + + if (!array_key_exists($WT_TREE->getTreeId(), $this->cart)) { + $this->cart[$WT_TREE->getTreeId()] = array(); } $this->action = Filter::get('action'); @@ -156,12 +160,12 @@ class ClippingsCartController { $this->addFamilyDescendancy($family, $this->level3); } } - uksort($cart[$WT_TREE->getTreeId()], array($this, 'compareClippings')); + uksort($this->cart[$WT_TREE->getTreeId()], array($this, 'compareClippings')); } } elseif ($this->action === 'remove') { - unset($cart[$WT_TREE->getTreeId()][$this->id]); + unset($this->cart[$WT_TREE->getTreeId()][$this->id]); } elseif ($this->action === 'empty') { - $cart[$WT_TREE->getTreeId()] = array(); + $this->cart[$WT_TREE->getTreeId()] = array(); } elseif ($this->action === 'download') { $media = array(); $mediacount = 0; @@ -201,7 +205,7 @@ class ClippingsCartController { break; } - foreach (array_keys($cart[$WT_TREE->getTreeId()]) as $xref) { + foreach (array_keys($this->cart[$WT_TREE->getTreeId()]) as $xref) { $object = GedcomRecord::getInstance($xref, $WT_TREE); // The object may have been deleted since we added it to the cart.... if ($object) { @@ -209,19 +213,19 @@ class ClippingsCartController { // Remove links to objects that aren't in the cart preg_match_all('/\n1 ' . WT_REGEX_TAG . ' @(' . WT_REGEX_XREF . ')@(\n[2-9].*)*/', $record, $matches, PREG_SET_ORDER); foreach ($matches as $match) { - if (!array_key_exists($match[1], $cart[$WT_TREE->getTreeId()])) { + if (!array_key_exists($match[1], $this->cart[$WT_TREE->getTreeId()])) { $record = str_replace($match[0], '', $record); } } preg_match_all('/\n2 ' . WT_REGEX_TAG . ' @(' . WT_REGEX_XREF . ')@(\n[3-9].*)*/', $record, $matches, PREG_SET_ORDER); foreach ($matches as $match) { - if (!array_key_exists($match[1], $cart[$WT_TREE->getTreeId()])) { + if (!array_key_exists($match[1], $this->cart[$WT_TREE->getTreeId()])) { $record = str_replace($match[0], '', $record); } } preg_match_all('/\n3 ' . WT_REGEX_TAG . ' @(' . WT_REGEX_XREF . ')@(\n[4-9].*)*/', $record, $matches, PREG_SET_ORDER); foreach ($matches as $match) { - if (!array_key_exists($match[1], $cart[$WT_TREE->getTreeId()])) { + if (!array_key_exists($match[1], $this->cart[$WT_TREE->getTreeId()])) { $record = str_replace($match[0], '', $record); } } @@ -266,7 +270,6 @@ class ClippingsCartController { } } } - Session::put('cart', $cart); if ($this->IncludeMedia === "yes") { $this->media_list = $media; @@ -284,6 +287,7 @@ class ClippingsCartController { $this->download_data = $filetext; $this->downloadClipping(); } + Session::put('cart', $this->cart); } /** @@ -344,14 +348,12 @@ class ClippingsCartController { */ public function addClipping(GedcomRecord $record) { if ($record->canShowName()) { - $cart = Session::get('cart'); - $cart[$record->getTree()->getTreeId()][$record->getXref()] = true; + $this->cart[$record->getTree()->getTreeId()][$record->getXref()] = true; // Add directly linked records preg_match_all('/\n\d (?:OBJE|NOTE|SOUR|REPO) @(' . WT_REGEX_XREF . ')@/', $record->getGedcom(), $matches); foreach ($matches[1] as $match) { - $cart[$record->getTree()->getTreeId()][$match] = true; + $this->cart[$record->getTree()->getTreeId()][$match] = true; } - Session::put('cart', $cart); } } |
