Exemplo n.º 1
0
 /**
  * Loads items.xml and items.otb files.
  * 
  * <p>
  * This method loads both items.xml and items.otb files. Both of them has to be in given directory.
  * </p>
  * 
  * @version 0.1.3
  * @param string $path Path to data/items directory.
  * @throws E_OTS_FileLoaderError When error occurs during file operation.
  * @throws DOMException On DOM operation error.
  */
 public function loadItems($path)
 {
     $empty = false;
     // loads items.xml cache
     if (isset($this->cache) && $this->cache instanceof IOTS_ItemsCache) {
         $this->items = $this->cache->readItems(md5_file($path . '/items.xml'));
     }
     // checks if cache is loaded
     if (empty($this->items)) {
         // marks list to be saved in new cache
         $empty = true;
         // lodas XML file
         $xml = new DOMDocument();
         $xml->load($path . '/items.xml');
         // reads items info
         foreach ($xml->documentElement->getElementsByTagName('item') as $tag) {
             // composes basic item info
             $item = new OTS_ItemType($tag->getAttribute('id'));
             $item->setName($tag->getAttribute('name'));
             // reads attributes
             foreach ($tag->getElementsByTagName('attribute') as $attribute) {
                 $item->setAttribute($attribute->getAttribute('key'), $attribute->getAttribute('value'));
             }
             $this->items[$item->getId()] = $item;
         }
     }
     // loads items.otb
     $this->loadFile($path . '/items.otb');
     // parses loaded file
     $this->parse();
     // saves cache
     if ($empty && isset($this->cache) && $this->cache instanceof IOTS_ItemsCache) {
         $this->cache->writeItems(md5_file($path . '/items.xml'), $this->items);
     }
 }
Exemplo n.º 2
0
 /**
  * Loads items.xml and items.otb files.
  * 
  * <p>
  * This method loads both items.xml and items.otb files. Both of them has to be in given directory.
  * </p>
  * 
  * @version 0.2.0+SVN
  * @since 0.0.8
  * @param string $path Path to data/items directory.
  * @throws E_OTS_FileLoaderError When error occurs during file operation.
  * @throws DOMException On DOM operation error.
  */
 public function loadItems($path)
 {
     // checksum for cache driver
     $md5 = md5_file($path . '/items.xml');
     $empty = false;
     // loads items.xml cache
     if (isset($this->cache) && $this->cache instanceof IOTS_ItemsCache && $this->cache->hasItems($md5)) {
         $this->items = $this->cache->readItems($md5);
     }
     // checks if cache is loaded
     if (empty($this->items)) {
         // marks list to be saved in new cache
         $empty = true;
         // lodas XML file
         $xml = new DOMDocument();
         $xml->load($path . '/items.xml');
         // reads items info
         foreach ($xml->documentElement->getElementsByTagName('item') as $tag) {
             // composes basic item info
             if ($tag->getAttribute('id')) {
                 $item = new OTS_ItemType($tag->getAttribute('id'));
                 $item->setName($tag->getAttribute('name'));
                 // reads attributes
                 foreach ($tag->getElementsByTagName('attribute') as $attribute) {
                     $item->setAttribute($attribute->getAttribute('key'), $attribute->getAttribute('value'));
                 }
                 $this->items[$item->getId()] = $item;
             } else {
                 if ($tag->getAttribute('fromid') && $tag->getAttribute('toid')) {
                     $from = (int) $tag->getAttribute('fromid');
                     $to = (int) $tag->getAttribute('toid');
                     for ($current = $from; $current <= $to; $current++) {
                         $item = new OTS_ItemType($current);
                         $item->setName($tag->getAttribute('name'));
                         // reads attributes
                         foreach ($tag->getElementsByTagName('attribute') as $attribute) {
                             $item->setAttribute($attribute->getAttribute('key'), $attribute->getAttribute('value'));
                         }
                         $this->items[$current] = $item;
                     }
                 } else {
                     throw new Exception('Item tag could not be parsed. Its probably retarded and its parents never loved it.');
                 }
             }
         }
     }
     // loads items.otb
     $this->loadFile($path . '/items.otb');
     // parses loaded file
     $this->parse();
     // saves cache
     if ($empty && isset($this->cache) && $this->cache instanceof IOTS_ItemsCache && !$this->cache->hasItems($md5)) {
         $this->cache->writeItems($md5, $this->items);
     }
 }