Skip to content
This repository has been archived by the owner on Mar 9, 2020. It is now read-only.

Commit

Permalink
adding Corp/MemberTrackingExtended.php and Corp/MemberTrackingExtende…
Browse files Browse the repository at this point in the history
…d.xsd
  • Loading branch information
stephenmg12 committed Jun 22, 2014
1 parent 76585e5 commit 4197813
Show file tree
Hide file tree
Showing 2 changed files with 278 additions and 0 deletions.
237 changes: 237 additions & 0 deletions lib/Database/Corp/MemberTrackingExtended.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,237 @@
<?php
/**
* Contains AccountBalance class.
*
* PHP version 5.3
*
* LICENSE:
* This file is part of 1.1.x-WIP
* Copyright (C) 2014 Michael Cummings
*
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General
* Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
* details.
*
* You should have received a copy of the GNU Lesser General Public License along with this program. If not, see
* <http://www.gnu.org/licenses/>.
*
* You should be able to find a copy of this license in the LICENSE.md file. A copy of the GNU GPL should also be
* available in the GNU-GPL.md file.
*
* @copyright 2014 Michael Cummings
* @license http://www.gnu.org/copyleft/lesser.html GNU LGPL
* @author Michael Cummings <mgcummings@yahoo.com>
* @author Stephen Gulick <stephenmg12@gmail.com>
*/
namespace Yapeal\Database\Corp;

use PDO;
use PDOException;
use Yapeal\Database\AbstractCommonEveApi;
use Yapeal\Database\AttributesDatabasePreserver;
use Yapeal\Database\DatabasePreserverInterface;
use Yapeal\Xml\EveApiPreserverInterface;
use Yapeal\Xml\EveApiReadWriteInterface;
use Yapeal\Xml\EveApiRetrieverInterface;
use Yapeal\Xml\EveApiXmlModifyInterface;

/**
* Class AccountBalance
*/
class MemberTracking extends AbstractCommonEveApi
{
/**
* @var int $mask
*/
private $mask = 2048;
/**
* @param EveApiReadWriteInterface $data
* @param EveApiRetrieverInterface $retrievers
* @param EveApiPreserverInterface $preservers
* @param int $interval
*/
public function autoMagic(
EveApiReadWriteInterface $data,
EveApiRetrieverInterface $retrievers,
EveApiPreserverInterface $preservers,
$interval
) {
$this->getLogger()
->info(
sprintf(
'Starting autoMagic for %1$s/%2$s',
$this->getSectionName(),
$this->getApiName()
)
);
$active = $this->getActiveCorporations();
if (empty($active)) {
$this->getLogger()
->info('No active characters found');
return;
}
$preserver = new AttributesDatabasePreserver(
$this->getPdo(),
$this->getLogger(),
$this->getCsq()
);
foreach ($active as $corp) {
/**
* @var EveApiReadWriteInterface|EveApiXmlModifyInterface $data
*/
$data->setEveApiSectionName(strtolower($this->getSectionName()))
->setEveApiName($this->getApiName());
if ($this->cacheNotExpired(
$this->getApiName(),
$this->getSectionName(),
$corp['corporationID']
)
) {
continue;
}
$corp['extended'] = 1;
$data->setEveApiArguments($corp)
->setEveApiXml();
$retrievers->retrieveEveApi($data);
if ($data->getEveApiXml() === false) {
$mess = sprintf(
'Could NOT retrieve any data from Eve API %1$s/%2$s for %3$s division %4$s',
strtolower($this->getSectionName()),
$this->getApiName(),
$corp['corporationID']
);
$this->getLogger()
->debug($mess);
continue;
}
$this->transformRowset($data);
if ($this->isInvalid($data)) {
$mess = sprintf(
'The data retrieved from Eve API %1$s/%2$s for %3$s division %4$s is invalid',
strtolower($this->getSectionName()),
$this->getApiName(),
$corp['corporationID']
);
$this->getLogger()
->warning($mess);
$data->setEveApiName('Invalid' . $this->getApiName());
$preservers->preserveEveApi($data);
continue;
}
$preservers->preserveEveApi($data);
$this->preserve(
$data->getEveApiXml(),
$corp['corporationID'],
$preserver
);
$this->updateCachedUntil($data, $interval, $corp['corporationID']);
}
}
/**
* @return string
*/
protected function getSectionName()
{
if (empty($this->sectionName)) {
$this->sectionName = basename(str_replace('\\', '/', __DIR__));
}
return $this->sectionName;
}
/**
* @return string
*/
protected function getApiName()
{
if (empty($this->apiName)) {
$this->apiName = basename(str_replace('\\', '/', __CLASS__));
}
return $this->apiName;
}
/**
* @return array
*/
protected function getActiveCorporations()
{
$sql = $this->csq->getActiveRegisteredCorporations($this->getMask());
$this->getLogger()
->debug($sql);
try {
$stmt = $this->getPdo()
->query($sql);
return $stmt->fetchAll(PDO::FETCH_ASSOC);
} catch (PDOException $exc) {
$mess = 'Could NOT get a list of active corporations';
$this->getLogger()
->warning($mess, array('exception' => $exc));
return array();
}
}
/**
* @return int
*/
protected function getMask()
{
return $this->mask;
}
/**
* @param string $xml
* @param string $ownerID
* @param DatabasePreserverInterface $preserver
*
* @return self
*/
protected function preserve(
$xml,
$ownerID,
DatabasePreserverInterface $preserver = null
) {
if (is_null($preserver)) {
$preserver = new AttributesDatabasePreserver(
$this->getPdo(),
$this->getLogger(),
$this->getCsq()
);
}
$this->preserverToMemberTracking($preserver, $xml, $ownerID, $key);
return $this;
}
/**
* @param DatabasePreserverInterface $preserver
* @param string $xml
* @param string $ownerID
* @param int $key
*
* @return self
*/
protected function preserverToMemberTracking(
DatabasePreserverInterface $preserver,
$xml,
$ownerID
) {
$columnDefaults = array(
'ownerID' => $ownerID,
'characterID' => null,
'name' => null,
'startDateTime' => null,
'baseID' => null,
'base' => null,
'title' => null,
'logonDateTime' => null,
'logoffDateTime' => null,
'locationID' => null,
'location' => null,
'shipTypeID' => null,
'shipType' => null,
'roles' => null,
'grantableRoles' => null
);
$preserver->setTableName('corpMemberTracking')
->setColumnDefaults($columnDefaults)
->preserveData($xml);
return $this;
}
}
41 changes: 41 additions & 0 deletions lib/Database/Corp/MemberTrackingExtended.xsd
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema attributeFormDefault="unqualified"
elementFormDefault="qualified"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:include schemaLocation="../common.xsd"/>
<xs:complexType name="rowType">
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute type="eveIDType" name="characterID"/>
<xs:attribute type="xs:string" name="name"/>
<xs:attribute type="eveNEDTType" name="startDateTime"/>
<xs:attribute type="eveIDType" name="baseID"/>
<xs:attribute type="xs:string" name="title"/>
<xs:attribute type="eveNEDTType" name="logonDateTime"/>
<xs:attribute type="eveNEDTType" name="logoffDateTime"/>
<xs:attribute type="eveIDType" name="locationID"/>
<xs:attribute type="xs:string" name="location"/>
<xs:attribute type="eveIDType" name="shipTypeID"/>
<xs:attribute type="eveIDType" name="shipType"/>
<xs:attribute type="eveIDType" name="shipTypeID"/>
<xs:attribute type="eveIDType" name="roles"/>
<xs:attribute type="eveIDType" name="grantableRoles"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
<xs:complexType name="resultType">
<xs:sequence>
<xs:element name="members">
<xs:complexType>
<xs:sequence>
<xs:element type="rowType"
name="row"
minOccurs="0"
maxOccurs="unbounded"/>
</xs:sequence>
<xs:attributeGroup ref="rowsetAttrs"/>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:schema>

0 comments on commit 4197813

Please sign in to comment.