/**
  * Get the entity type by it's ID
  *
  * @param integer $id
  * @return string
  */
 public static function getEntityTypeByEntityId($id)
 {
     $id = (int) $id;
     $item = Kingboard_EveItem::getByItemId($id);
     if ($item) {
         if ((int) $item->Group['groupID'] === self::$groupIdDeployable) {
             return self::ENTITY_DEPLOYABLE;
         }
         switch ((int) $item->Category['categoryID']) {
             case self::$categoryIdStructure:
                 return self::ENTITY_STRUCTURE;
             case self::$categoryIdNpc:
                 return self::ENTITY_NPC;
         }
     }
     try {
         $api = new Pheal();
         $apiResult = $api->eveScope->CharacterName(array('ids' => $id))->characters->toArray();
         if (is_array($apiResult) && !empty($apiResult)) {
             $name = $apiResult[0]['name'];
             $item = Kingboard_EveItem::getInstanceByCriteria(array('typeName' => $name));
             if ($item) {
                 if ((int) $item->typeID === $id) {
                     return self::ENTITY_NPC;
                 }
             }
             return self::ENTITY_CHARACTER;
         }
     } catch (PhealException $e) {
     }
     return self::ENTITY_UNKNOWN;
 }
 private function ParseItem($row)
 {
     // Build the standard item
     $item = array("typeID" => $row->typeID, "typeName" => @Kingboard_EveItem::getByItemId($row->typeID)->typeName, "flag" => $row->flag, "qtyDropped" => $row->qtyDropped, "qtyDestroyed" => $row->qtyDestroyed);
     // Check for nested items (container)
     if (isset($row['items'])) {
         $item['items'] = array();
         foreach ($row['items'] as $innerRow) {
             $item['items'][] = $this->ParseItem($innerRow);
         }
     }
     return $item;
 }
 /**
  * Find the ID of an item
  * Can be a ship, weapon, drone or any cargo item
  *
  * @throws Kingboard_KillmailParser_KillmailErrorException
  * @param string $name
  * @return integer
  */
 public function getItemId($name)
 {
     // Try in kills collection
     $result = Kingboard_EveItem::getInstanceByCriteria(array('typeName' => $name));
     if ($result) {
         return (int) $result->typeID;
     }
     // Try to find in kills
     /*
             $result  = Kingboard_Kill::findOne(array(
                 'items.typeName' => $name
             ));
     
             if(!empty($kill['items']))
             {
                 foreach ($kill['items'] as $item)
                 {
                     if ($item['typeName'] == $name)
                     {
                         return (int) $item['typeID'];
                     }
                 }
             }*/
     // Not found, try the api
     try {
         return (int) $this->queryNameToIdApi($name);
     } catch (Kingboard_KillmailParser_KillmailErrorException $e) {
     }
     throw new Kingboard_KillmailParser_KillmailErrorException('No item found with the name ' . $name);
 }
 /**
  * Check if a victim has all required data set
  *
  * @param array $victim
  * @return boolean
  */
 public function validateVictim($victim)
 {
     $isStructure = false;
     if (isset($victim['shipType'])) {
         $result = Kingboard_EveItem::getInstanceByCriteria(array('typeName' => $victim['shipType']));
         if ($result) {
             $isStructure = $result->typeName == $victim['shipType'] && (int) $victim['shipTypeID'] === (int) $result->typeID && in_array((int) $result->Group['categoryID'], array(23, 39, 40));
         }
     }
     if (!$isStructure || $victim['characterName'] != '' || $victim['characterID'] > 0) {
         if (!$this->isTypeEntryValid($victim, 'character')) {
             throw new Kingboard_KillmailParser_KillmailErrorException('No character information for victim found');
         }
         if (!$this->validateCharacterName($victim['characterName'])) {
             throw new Kingboard_KillmailParser_KillmailErrorException('Invalid victim character name');
         }
         if (!$this->isIdValid($victim, 'character')) {
             throw new Kingboard_KillmailParser_KillmailErrorException('Invalid character ID for victim');
         }
     }
     if (!$this->isTypeEntryValid($victim, 'corporation')) {
         throw new Kingboard_KillmailParser_KillmailErrorException('No corporation data for victim found');
     }
     if (!$this->isIdValid($victim, 'corporation') || !$this->validateOrganisationName($victim['corporationName'])) {
         throw new Kingboard_KillmailParser_KillmailErrorException('Invalid corporation data for victim');
     }
     if ($this->isTypeEntryValid($victim, 'alliance')) {
         if (!$this->isIdValid($victim, 'alliance') || !$this->validateOrganisationName($victim['allianceName'])) {
             throw new Kingboard_KillmailParser_KillmailErrorException('Invalid alliance data for victim');
         }
     }
     if ($this->isTypeEntryValid($victim, 'faction')) {
         if (!$this->isIdValid($victim, 'faction') || !$this->validateOrganisationName($victim['factionName'])) {
             throw new Kingboard_KillmailParser_KillmailErrorException('Invalid faction data for victim');
         }
     }
     if (empty($victim['damageTaken'])) {
         throw new Kingboard_KillmailParser_KillmailErrorException('Damage taken of victim is missing');
     }
     if (!is_int($victim['damageTaken']) || $victim['damageTaken'] < 1) {
         throw new Kingboard_KillmailParser_KillmailErrorException('Invalid value for taken damage');
     }
     if (!$this->isTypeEntryValid($victim, 'shipType')) {
         throw new Kingboard_KillmailParser_KillmailErrorException('Invalid ship for victim given');
     }
     return true;
 }