Exemplo n.º 1
0
 /**
  * Creates a new fit object.
  *
  * @param String $name
  * @param String $shipName
  * @return fit
  */
 protected function getNewFit($shipType, $shipName)
 {
     $result = $this->model->getModel('ship')->getShipsByType($shipType);
     if (count($result) == 0) {
         return false;
     }
     $ship = array_shift($result);
     return new fit($ship['typeName'], $shipName, $ship['typeID'], $ship['groupName'], $this->user->getId());
 }
Exemplo n.º 2
0
 /**
  * Loop trough the different ship categories as defined in the XML and extract the points and ships from
  * each category.
  *
  * Ships are defined by either groups of ships or specific ships, groups of ships are pulled from their associated
  * shipGroup name from the database. Ships are taken by name from the database.
  *
  * Specifically named ships will then be removed from other categories where they where defined via the shipGroup method.
  * A ship can only be defined in one category.
  *
  * @param \SimpleXMLElement $xml
  * @param evemodel $model
  * @return array
  * @throws \Exception
  */
 protected function loadShipPoints(\SimpleXMLElement $xml, evemodel $model)
 {
     $points = array();
     foreach ($xml as $rule) {
         $shipCat = array();
         $shipCat['name'] = (string) $rule->type;
         $shipCat['points'] = (int) $rule->points;
         $shipCat['ships'] = array();
         // ship groups can be defined by either groups or specific ships.
         // If specific ships are defined they will be removed from those listings that defined those ships via groups
         // Get ships by groups
         if (isset($rule->define->group)) {
             foreach ($rule->define->group as $definedGroup) {
                 $shipsRows = $model->getModel('ship')->getShipsByGroup($definedGroup);
                 $ships = array();
                 foreach ($shipsRows as $row) {
                     $ships[$row['typeID']] = $row['typeName'];
                 }
                 // Check trough previous assigned points and remove ships from the list that are already defined.
                 // As a rule, specifically assigned ships get precedence over blanked shipType assigned lists
                 foreach ($points as $prevSetShip) {
                     foreach ($prevSetShip['ships'] as $prevTypeID => $prevShipName) {
                         if (isset($ships[$prevTypeID])) {
                             unset($ships[$prevTypeID]);
                         }
                     }
                 }
                 $shipCat['ships'] = $ships + $shipCat['ships'];
             }
         }
         //  If specific ships are defined we'll take those
         // If not we fetch them from the database by the given type
         if (isset($rule->define->ship)) {
             $shipNames = (array) $rule->define->ship;
             $shipsRows = $model->getModel('ship')->getShipsByType($shipNames);
             $ships = array();
             foreach ($shipsRows as $row) {
                 $ships[$row['typeID']] = $row['typeName'];
             }
             if (count($shipNames) !== count($ships)) {
                 $foundShips = array_map("strtolower", $ships);
                 $notFound = array();
                 foreach ($shipNames as $shipName) {
                     if (!in_array(strtolower($shipName), $foundShips)) {
                         throw new \Exception("Rule XML error ship name '{$shipName}' not found.");
                     }
                 }
             }
             // Check trough previously assigned points and remove ships from their lists that have been found here
             // As a rule, specifically assigned ships get precedence over blanked shipType assigned lists
             foreach ($points as $key => $prevSetShip) {
                 foreach ($prevSetShip['ships'] as $prevTypeID => $prevShipName) {
                     if (isset($ships[$prevTypeID])) {
                         unset($points[$key]['ships'][$prevTypeID]);
                     }
                 }
             }
             unset($prevSetShip);
             $shipCat['ships'] = $ships;
         }
         $points[] = $shipCat;
     }
     return $points;
 }
Exemplo n.º 3
0
 public function parseEFT($fitEFT, evemodel $model)
 {
     $fitEFT = new \ArrayIterator(explode(PHP_EOL, $fitEFT));
     while ($fitEFT->valid()) {
         $fitline = $fitEFT->current();
         // Look for EFT format header
         preg_match('/^\\[([a-zA-Z ]+), (.*)]/', $fitline, $matches);
         $fitEFT->next();
         if (count($matches) !== 0) {
             $type = $matches[1];
             $name = $matches[2];
             $this->type = $type;
             $this->name = $name;
             while ($fitEFT->valid()) {
                 $fitline = $fitEFT->current();
                 if (preg_match('/^\\[([a-zA-Z ]+), (.*)]/', $fitline)) {
                     break;
                 }
                 // Module Name, Charge type
                 preg_match('/([^,]*)(,(.*))?/', $fitline, $matches);
                 $charge = null;
                 $moduleName = $matches[1];
                 // If white line just skip.
                 if (trim($moduleName) !== '') {
                     $module = item::getInstance();
                     $module->hydrate($model->getModel('item')->getItem($moduleName));
                     if ($module->isModule()) {
                         $module->hydrate($model->getModel('item')->getModule($moduleName));
                     }
                     if (!$module->isModule()) {
                         if ($module->getType() == 'Subsystem') {
                             $this->addItem($module);
                         }
                         // Drones, becouse they have a " x#" behind their name
                         // this is really stupid, but meh.
                         if (preg_match('/(^.*) x([0-9]+)$/', $moduleName, $match)) {
                             $module->hydrate($model->getModel('item')->getItem($match[1]));
                             $module->setValue('qty', $match[2]);
                             $this->addItem($module);
                         }
                         $module->hydrate($model->getModel('item')->getItem($moduleName));
                         if ($module->getValue('categoryName') == 'Implant') {
                             $this->addItem($module);
                         }
                     } else {
                         // If we have a charge
                         if (isset($matches[3]) && trim($matches[3]) != '') {
                             $chargeItem = item::getInstance();
                             $chargeItem->hydrate($model->getModel('item')->getItem(trim($matches[3])));
                             $module->setValue('charge', $chargeItem);
                         }
                         $this->addItem($module);
                     }
                 }
                 $fitEFT->next();
             }
         }
     }
 }