Esempio n. 1
0
    /**
     * Walk through action and its chained actions tree and remove nodes
     * if they are GoTo actions with an unresolved target.
     *
     * Returns null if root node is deleted or updated action overwise.
     *
     * @todo Give appropriate name and make method public
     *
     * @param Zend_Pdf_Action $action
     * @param boolean $refreshPagesHash  Refresh page collection hashes before processing
     * @return Zend_Pdf_Action|null
     */
    protected function _cleanUpAction(Zend_Pdf_Action $action, $refreshPageCollectionHashes = true)
    {
        if ($this->_pageReferences === null  ||  $refreshPageCollectionHashes) {
            $this->_refreshPagesHash();
        }

        // Named target is an action
        if ($action instanceof Zend_Pdf_Action_GoTo  &&
            $this->resolveDestination($action->getDestination(), false) === null) {
            // Action itself is a GoTo action with an unresolved destination
            return null;
        }

        // Walk through child actions
        $iterator = new RecursiveIteratorIterator($action, RecursiveIteratorIterator::SELF_FIRST);

        $actionsToClean        = array();
        $deletionCandidateKeys = array();
        foreach ($iterator as $chainedAction) {
            if ($chainedAction instanceof Zend_Pdf_Action_GoTo  &&
                $this->resolveDestination($chainedAction->getDestination(), false) === null) {
                // Some child action is a GoTo action with an unresolved destination
                // Mark it as a candidate for deletion
                $actionsToClean[]        = $iterator->getSubIterator();
                $deletionCandidateKeys[] = $iterator->getSubIterator()->key();
            }
        }
        foreach ($actionsToClean as $id => $action) {
            unset($action->next[$deletionCandidateKeys[$id]]);
        }

        return $action;
    }
Esempio n. 2
0
 protected function _cleanUpAction(Zend_Pdf_Action $action, $refreshPageCollectionHashes = true)
 {
     if ($this->_pageReferences === null || $refreshPageCollectionHashes) {
         $this->_refreshPagesHash();
     }
     if ($action instanceof Zend_Pdf_Action_GoTo && $this->resolveDestination($action->getDestination(), false) === null) {
         return null;
     }
     $iterator = new RecursiveIteratorIterator($action, RecursiveIteratorIterator::SELF_FIRST);
     $actionsToClean = array();
     $deletionCandidateKeys = array();
     foreach ($iterator as $chainedAction) {
         if ($chainedAction instanceof Zend_Pdf_Action_GoTo && $this->resolveDestination($chainedAction->getDestination(), false) === null) {
             $actionsToClean[] = $iterator->getSubIterator();
             $deletionCandidateKeys[] = $iterator->getSubIterator()->key();
         }
     }
     foreach ($actionsToClean as $id => $action) {
         unset($action->next[$deletionCandidateKeys[$id]]);
     }
     return $action;
 }