Skip to content

Commit

Permalink
ISMN reporting added.
Browse files Browse the repository at this point in the history
It's possible to export lists of ISMN publishers and their publisher
identifiers, and publications published by ISMN author publishers. Lists
can be exported in Excel or CSV format. #48 #49
  • Loading branch information
petkivim committed Nov 19, 2016
1 parent f86bfce commit ccaeb46
Show file tree
Hide file tree
Showing 9 changed files with 155 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ private function validateDate($dateStr) {
}

private function validateType($type) {
if (!preg_match('/^(MONTHLY|PROGRESS_ISBN|PROGRESS_ISMN|PUBLISHERS|PUBLICATIONS)$/', $type)) {
if (!preg_match('/^(MONTHLY|PROGRESS_ISBN|PROGRESS_ISMN|PUBLISHERS_ISBN|PUBLICATIONS_ISBN|PUBLISHERS_ISMN|PUBLICATIONS_ISMN)$/', $type)) {
return false;
}
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -864,8 +864,10 @@ COM_ISBNREGISTRY_STATISTIC_FIELD_TYPE_DESC="Tuotettavan tilaston tyyppi."
COM_ISBNREGISTRY_STATISTIC_MONTHLY="Kuukausitilasto"
COM_ISBNREGISTRY_STATISTIC_PROGRESS_ISBN="ISBN-tunnuskentät"
COM_ISBNREGISTRY_STATISTIC_PROGRESS_ISMN="ISMN-tunnuskentät"
COM_ISBNREGISTRY_STATISTIC_PUBLISHER_ISBN="Kv-rekisteri (kustantajat)"
COM_ISBNREGISTRY_STATISTIC_PUBLICATION_ISBN="Kv-rekisteri (omakustanteet)"
COM_ISBNREGISTRY_STATISTIC_PUBLISHER_ISBN="Kv-rekisteri (ISBN-kustantajat)"
COM_ISBNREGISTRY_STATISTIC_PUBLICATION_ISBN="Omakustanteet (ISBN)"
COM_ISBNREGISTRY_STATISTIC_PUBLISHER_ISMN="Kv-rekisteri (ISMN-kustantajat)"
COM_ISBNREGISTRY_STATISTIC_PUBLICATION_ISMN="Omakustanteet (ISMN)"
COM_ISBNREGISTRY_STATISTIC_FIELD_BEGIN_LABEL="Aloitusaika"
COM_ISBNREGISTRY_STATISTIC_FIELD_BEGIN_DESC="Tilastointivälin ensimmäinen päivämäärä"
COM_ISBNREGISTRY_STATISTIC_FIELD_END_LABEL="Loppuaika"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@
<option value="MONTHLY">COM_ISBNREGISTRY_STATISTIC_MONTHLY</option>
<option value="PROGRESS_ISBN">COM_ISBNREGISTRY_STATISTIC_PROGRESS_ISBN</option>
<option value="PROGRESS_ISMN">COM_ISBNREGISTRY_STATISTIC_PROGRESS_ISMN</option>
<option value="PUBLISHERS">COM_ISBNREGISTRY_STATISTIC_PUBLISHER_ISBN</option>
<option value="PUBLICATIONS">COM_ISBNREGISTRY_STATISTIC_PUBLICATION_ISBN</option>
<option value="PUBLISHERS_ISBN">COM_ISBNREGISTRY_STATISTIC_PUBLISHER_ISBN</option>
<option value="PUBLICATIONS_ISBN">COM_ISBNREGISTRY_STATISTIC_PUBLICATION_ISBN</option>
<option value="PUBLISHERS_ISMN">COM_ISBNREGISTRY_STATISTIC_PUBLISHER_ISMN</option>
<option value="PUBLICATIONS_ISMN">COM_ISBNREGISTRY_STATISTIC_PUBLICATION_ISMN</option>
</field>
<field
name="begin"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,25 @@ public function getPublicationsWithIsbnIdentifiers($begin, $end, $publisherId =
return $table->getPublicationsWithIsbnIdentifiers($begin, $end, $publisherId);
}

/**
* Returns an array that contains all the publications own by the publisher
* spesified by the publisher id that have at least one ISMN identifier.
* If publisher id is not given, all the publications that have at least
* one ISMN identifier are returned.
* @param JDate $begin begin date
* @param JDate $end end date
* @param integer $publisherId id of the publisher that owns the
* publications
* @return array array of all the publications that have ISMN
* identifier
*/
public function getPublicationsWithIsmnIdentifiers($begin, $end, $publisherId = 0) {
// Get db access
$table = $this->getTable();
// Get publications
return $table->getPublicationsWithIsmnIdentifiers($begin, $end, $publisherId);
}

/**
* Delete all publications related to the publisher identified by
* the given publisher id.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,22 @@ public function getPublishersAndIsbnIdentifiers($begin, $end) {
return $table->getPublishersAndIsbnIdentifiers($begin, $end);
}

/**
* Returns a list of publishers and publisher ISMN identifiers that were
* created or modified between begin date and end date.
* If publisher has multiple identifiers, the publisher is included in the
* list multiple times.
* @param JDate $begin begin date
* @param JDate $end end date
* @return list of publishers
*/
public function getPublishersAndIsmnIdentifiers($begin, $end) {
// Get db access
$table = $this->getTable();
// Return result
return $table->getPublishersAndIsmnIdentifiers($begin, $end);
}

/**
* Returns a list of publishers that belong to the given categories,
* match the has quitted condition and are of the given type (isbn/ismn).
Expand All @@ -183,18 +199,18 @@ public function getPublishersByCategory($categories, $hasQuitted, $type) {
// Loop through publishers by category
foreach ($publishersByCategory as $publisher) {
// Check that the publisher exists in index
if(array_key_exists($publisher->id, $index)) {
if (array_key_exists($publisher->id, $index)) {
// Compare the latest identifier id with the id that was
// returned by publishers by category search.
if($index[$publisher->id] == $publisher->range_id) {
if ($index[$publisher->id] == $publisher->range_id) {
// Add to results if ids match. Publisher may have multiple
// identifiers and only the last one counts. This is why
// we add to results only publishers which latest
// idetifier belongs to the defined category. In this way
// each publisher belongs to one category only.
array_push($results, $publisher);
}
}
}
}
// Return results
return $results;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,15 +85,19 @@ public function getStats($type, $begin, $end) {
$results = $this->getProgressIsbn();
} else if (strcmp($type, 'PROGRESS_ISMN') == 0) {
$results = $this->getProgressIsmn();
} else if (strcmp($type, 'PUBLISHERS') == 0) {
$results = $this->getPublishersStats($begin, $end);
} else if (strcmp($type, 'PUBLICATIONS') == 0) {
$results = $this->getPublicationsStats($begin, $end);
} else if (strcmp($type, 'PUBLISHERS_ISBN') == 0) {
$results = $this->getISBNPublishersStats($begin, $end);
} else if (strcmp($type, 'PUBLICATIONS_ISBN') == 0) {
$results = $this->getISBNPublicationsStats($begin, $end);
} else if (strcmp($type, 'PUBLISHERS_ISMN') == 0) {
$results = $this->getISMNPublishersStats($begin, $end);
} else if (strcmp($type, 'PUBLICATIONS_ISMN') == 0) {
$results = $this->getISMNPublicationsStats($begin, $end);
}
return $results;
}

private function getPublishersStats($begin, $end) {
private function getISBNPublishersStats($begin, $end) {
// Get publisher model
$publisherModel = JModelLegacy::getInstance('publisher', 'IsbnregistryModel');
// Get list of publishers
Expand All @@ -104,7 +108,7 @@ private function getPublishersStats($begin, $end) {
return PublishersHelper::toCSVArray($list);
}

private function getPublicationsStats($begin, $end) {
private function getISBNPublicationsStats($begin, $end) {
// Get component parameters
$params = JComponentHelper::getParams('com_isbnregistry');
// Get the id of the publisher that represents author publishers
Expand All @@ -119,6 +123,32 @@ private function getPublicationsStats($begin, $end) {
return PublicationHelper::toCSVArray($list);
}

private function getISMNPublishersStats($begin, $end) {
// Get publisher model
$publisherModel = JModelLegacy::getInstance('publisher', 'IsbnregistryModel');
// Get list of publishers
$list = $publisherModel->getPublishersAndIsmnIdentifiers($begin, $end);
// Add publications helper file
require_once JPATH_COMPONENT . '/helpers/publishers.php';
// Convert list to CSV array
return PublishersHelper::toCSVArray($list);
}

private function getISMNPublicationsStats($begin, $end) {
// Get component parameters
$params = JComponentHelper::getParams('com_isbnregistry');
// Get the id of the publisher that represents author publishers
$authorPublisherId = $params->get('author_publisher_id_isbn', 0);
// Get publication model
$publicationModel = JModelLegacy::getInstance('publication', 'IsbnregistryModel');
// Get list of publications
$list = $publicationModel->getPublicationsWithIsmnIdentifiers($begin, $end, $authorPublisherId);
// Add publications helper file
require_once JPATH_COMPONENT . '/helpers/publication.php';
// Convert list to CSV array
return PublicationHelper::toCSVArray($list);
}

private function getProgressIsbn() {
// Get ISBN range model
$isbnRangeModel = JModelLegacy::getInstance('isbnrange', 'IsbnregistryModel');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,47 @@ public function getPublicationsWithIsbnIdentifiers($begin, $end, $publisherId =
return $this->_db->loadObjectList();
}

/**
* Returns an array that contains all the publications own by the publisher
* spesified by the publisher id that have at least one ISMN identifier.
* If publisher id is not given, all the publications that have at least
* one ISMN identifier are returned.
* @param JDate $begin begin date
* @param JDate $end end date
* @param integer $publisherId id of the publisher that owns the
* publications
* @return array array of all the publications that have ISMN
* identifier
*/
public function getPublicationsWithIsmnIdentifiers($begin, $end, $publisherId = 0) {
// Initialize variables.
$query = $this->_db->getQuery(true);

// Conditions for which records should be fetched
$conditions = array(
$this->_db->quoteName('p.publication_identifier_type') . ' = ' . $this->_db->quote('ISMN')
);

if ($publisherId > 0) {
array_push($conditions, $this->_db->quoteName('p.publisher_id') . ' = ' . $this->_db->quote($publisherId));
}

// Create the query
$query->select('p.*');
$query->from($this->_db->quoteName($this->_tbl) . ' AS p');
$query->where('((' .
$this->_db->quoteName('p.created') . ' >= ' . $this->_db->quote($begin->toSql()) . ' AND ' .
$this->_db->quoteName('p.created') . ' <= ' . $this->_db->quote($end->toSql()) . ') OR (' .
$this->_db->quoteName('p.modified') . ' >= ' . $this->_db->quote($begin->toSql()) . ' AND ' .
$this->_db->quoteName('p.modified') . ' <= ' . $this->_db->quote($end->toSql()) .
'))');
$query->where($conditions);
$query->order('p.official_name ASC');
$this->_db->setQuery($query);
// Execute query
return $this->_db->loadObjectList();
}

/**
* Delete all publications related to the publisher identified by
* the given publisher id.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,36 @@ public function getPublishersAndIsbnIdentifiers($begin, $end) {
return $this->_db->loadObjectList();
}

/**
* Returns a list of publishers and publisher ISMN identifiers that were
* created or modified between begin date and end date.
* If publisher has multiple identifiers, the publisher is included in the
* list multiple times.
* @param JDate $begin begin date
* @param JDate $end end date
* @return list of publishers
*/
public function getPublishersAndIsmnIdentifiers($begin, $end) {
// Initialize variables.
$query = $this->_db->getQuery(true);

// Conditions
$conditions = array(
$this->_db->quoteName('pir.created') . ' >= ' . $this->_db->quote($begin->toSql()),
$this->_db->quoteName('pir.created') . ' <= ' . $this->_db->quote($end->toSql())
);

// Create the query
$query->select('*');
$query->from($this->_db->quoteName($this->_tbl) . ' AS p');
$query->join('INNER', '#__isbn_registry_publisher_ismn_range AS pir ON p.id = pir.publisher_id');
$query->order('p.official_name ASC');
$query->where($conditions);
$this->_db->setQuery($query);
// Execute query
return $this->_db->loadObjectList();
}

/**
* Returns a list of publishers that belong to the given categories,
* match the has quitted condition and are of the given type (isbn/ismn).
Expand Down
2 changes: 1 addition & 1 deletion src/monograph-publishers/com_isbnregistry/isbnregistry.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

<name>COM_ISBNREGISTRY</name>
<!-- The following elements are optional and free of formatting constraints -->
<creationDate>12 November 2016</creationDate>
<creationDate>19 November 2016</creationDate>
<author>Petteri Kivimäki</author>
<copyright>(C)2015-2016 Petteri Kivimäki</copyright>
<license>http://www.gnu.org/copyright/gpl.html GNU/GPL</license>
Expand Down

0 comments on commit ccaeb46

Please sign in to comment.