diff options
Diffstat (limited to 'app/Module')
| -rw-r--r-- | app/Module/ClippingsCart/ClippingsCartController.php | 32 | ||||
| -rw-r--r-- | app/Module/ClippingsCartModule.php | 2 |
2 files changed, 18 insertions, 16 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); } } diff --git a/app/Module/ClippingsCartModule.php b/app/Module/ClippingsCartModule.php index 10bd9f01ff..d9d91784aa 100644 --- a/app/Module/ClippingsCartModule.php +++ b/app/Module/ClippingsCartModule.php @@ -59,8 +59,8 @@ class ClippingsCartModule extends AbstractModule implements ModuleMenuInterface, $MAX_PEDIGREE_GENERATIONS = $WT_TREE->getPreference('MAX_PEDIGREE_GENERATIONS'); - $cart = Session::get('cart'); $clip_ctrl = new ClippingsCartController; + $cart = Session::get('cart'); $controller = new PageController; $controller |
