Example #1
0
 /**
  * Process a list of the document
  * @param $numberingInfo
  * @param $container
  * @param $paragraph
  * @param $key
  */
 public function processList($numberingInfo, $container, $paragraph, $key, $listNumId)
 {
     //Extract List Properties
     $abstractNum = $this->getAbstractNum($numberingInfo);
     $listProperties = $this->extractListProperties($abstractNum, $numberingInfo);
     //If this is set to true a new list container should be created
     $newListActivator = false;
     echo $this->listNumId;
     echo "-------------------";
     echo $numberingInfo['numId'];
     echo "<br/>";
     if ($listNumId != $numberingInfo['numId']) {
         echo "Activado " . "<br/>";
         $newListActivator = true;
     }
     $levelCount = $numberingInfo['lvl'];
     //Check if the list level state has change
     if ($this->listLevelState != $levelCount) {
         //Create new list
         $newList = new HTMLElement(HTMLElement::UL);
         $newList->setAttribute('style', 'list-style-type:' . $listProperties['type']);
         //Get last ul element to add the new list ul container
         $lastContainer = $container->getLastElement();
         for ($i = 0; $i < $this->listLevelState; $i++) {
             $lastContainer = $lastContainer->getLastElement();
         }
         //Add new list in the last container
         if (is_object($lastContainer)) {
             $lastContainer->addInnerElement($newList);
         }
     }
     //Assign new list level state and num id
     $this->listLevelState = $numberingInfo['lvl'];
     $this->listNumId = $numberingInfo['numId'];
     //        echo $this->listLevelState;
     //        echo "-------------------";
     //        echo $this->listNumId;
     //        echo "<br/>";
     // Parse list item
     $listItemHTMLElement = $this->parseList($paragraph);
     $listItemHTMLElement->setId($key);
     //Check if the container has a last element to avoid non object exception
     if (is_object($container->getLastElement()) and !$newListActivator) {
         //Assign the tag name
         $containerLastElement = $container->getLastElement()->getTagName();
     } elseif ($newListActivator) {
         //Add another level list
         $containerLastElement = "innerul";
     } else {
         //Set default in case the container has no inner elements
         $containerLastElement = "text";
     }
     // Check if the actual container has a list container as last element
     if ($containerLastElement == "ul") {
         //Initialize last container
         $lastContainer = $container->getLastElement();
         //Find current list element
         for ($i = 0; $i < $this->listLevelState; $i++) {
             if (is_object($lastContainer)) {
                 $lastContainer = $lastContainer->getLastElement();
             }
         }
         //Check if the container is fill
         if (is_object($lastContainer)) {
             $listItemHTMLElement->setId($key);
             $lastContainer->addInnerElement($listItemHTMLElement);
         }
     } elseif ($containerLastElement == 'innerul' or $containerLastElement != "ul") {
         //Create a new list container
         $listContainer = new HTMLElement(HTMLElement::UL);
         $listContainer->setId($key);
         //Set list type style
         $listContainer->setAttribute('style', 'list-style-type:' . $listProperties['type'] . ';' . 'margin-left:' . $listProperties['indentation'] . 'px');
         //Fill the list with the first li item
         $firstItemId = $key + 1;
         $listItemHTMLElement->setId($firstItemId);
         $listContainer->addInnerElement($listItemHTMLElement);
         //Set the list to the container
         $container->addInnerElement($listContainer);
     }
 }