Skip to content

Commit

Permalink
Add ability to assign URIs to Publishers. (#77)
Browse files Browse the repository at this point in the history
  • Loading branch information
demiankatz authored Sep 4, 2020
1 parent 4e2e5c2 commit 1440a65
Show file tree
Hide file tree
Showing 9 changed files with 187 additions and 0 deletions.
9 changes: 9 additions & 0 deletions data/migrations/20200904-001-add-publishers-uris.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
CREATE TABLE `Publishers_URIs` (
`Sequence_ID` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
`Publisher_ID` int(11) NOT NULL,
`Predicate_ID` int(11) NOT NULL,
`URI` varchar(2048) NOT NULL,
PRIMARY KEY (`Sequence_ID`),
FOREIGN KEY (`Publisher_ID`) REFERENCES `Publishers` (`Publisher_ID`),
FOREIGN KEY (`Predicate_ID`) REFERENCES `Predicates` (`Predicate_ID`)
) ENGINE=INNODB DEFAULT CHARSET=utf8;
18 changes: 18 additions & 0 deletions data/mysql.sql
Original file line number Diff line number Diff line change
Expand Up @@ -1025,6 +1025,24 @@ CREATE TABLE `Publishers_Imprints` (
) ENGINE=INNODB DEFAULT CHARSET=utf8;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `Publishers_URIs`
--

DROP TABLE IF EXISTS `Publishers_URIs`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `Publishers_URIs` (
`Sequence_ID` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
`Publisher_ID` int(11) NOT NULL,
`Predicate_ID` int(11) NOT NULL,
`URI` varchar(2048) NOT NULL,
PRIMARY KEY (`Sequence_ID`),
FOREIGN KEY (`Publisher_ID`) REFERENCES `Publishers` (`Publisher_ID`),
FOREIGN KEY (`Predicate_ID`) REFERENCES `Predicates` (`Predicate_ID`)
) ENGINE=INNODB DEFAULT CHARSET=utf8;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `Recent_Reviews`
--
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ public function indexAction()
->getAddressesForPublisher($view->publisherObj->Publisher_ID);
$view->imprints = $this->getDbTable('publishersimprints')
->getImprintsForPublisher($view->publisherObj->Publisher_ID);
$view->predicates = $this->getDbTable('predicate')->getList();
$view->uris = $this->getDbTable('publishersuris')
->getURIsForPublisher($view->publisherObj->Publisher_ID);
$view->setTemplate('geeby-deeby/edit-publisher/edit-full');
}
return $view;
Expand Down Expand Up @@ -158,4 +161,21 @@ public function imprintAction()
);
}
}

/**
* Deal with URIs
*
* @return mixed
*/
public function uriAction()
{
$extras = ($pid = $this->params()->fromPost('predicate_id'))
? ['Predicate_ID' => $pid] : [];
return $this->handleGenericLink(
'publishersuris', 'Publisher_ID', 'URI',
'uris', 'getURIsForPublisher',
'geeby-deeby/edit-publisher/uri-list.phtml',
$extras
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ protected function addPrimaryResourceToGraph($graph, $view,
'publisher', ['id' => $view->publisher['Publisher_ID']]
);
$pub = $graph->resource($uri, $class);
foreach ($view->uris as $uri) {
$pub->add($uri->Predicate, $graph->resource($uri->URI));
}
return $pub;
}

Expand Down Expand Up @@ -130,6 +133,7 @@ protected function getPublisherViewModel()
);
$view->series = $this->getDbTable('seriespublishers')
->getSeriesForPublisher($id);
$view->uris = $this->getDbTable('publishersuris')->getURIsForPublisher($id);
return $view;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ class PluginManager extends \GeebyDeeby\ServiceManager\AbstractPluginManager
'publisher' => 'GeebyDeeby\Db\Table\Publisher',
'publishersaddresses' => 'GeebyDeeby\Db\Table\PublishersAddresses',
'publishersimprints' => 'GeebyDeeby\Db\Table\PublishersImprints',
'publishersuris' => 'GeebyDeeby\Db\Table\PublishersURIs',
'recentreviews' => 'GeebyDeeby\Db\Table\RecentReviews',
'role' => 'GeebyDeeby\Db\Table\Role',
'series' => 'GeebyDeeby\Db\Table\Series',
Expand Down
99 changes: 99 additions & 0 deletions module/GeebyDeeby/src/GeebyDeeby/Db/Table/PublishersURIs.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
<?php
/**
* Table Definition for Publishers_URIs
*
* PHP version 5
*
* Copyright (C) Demian Katz 2020.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2,
* as published by the Free Software Foundation.
*
* 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* @category GeebyDeeby
* @package Db_Table
* @author Demian Katz <demian.katz@villanova.edu>
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @link https://github.com/demiankatz/Geeby-Deeby Main Site
*/
namespace GeebyDeeby\Db\Table;

use Zend\Db\Adapter\Adapter;
use Zend\Db\RowGateway\RowGateway;

/**
* Table Definition for Publishers_URIs
*
* @category GeebyDeeby
* @package Db_Table
* @author Demian Katz <demian.katz@villanova.edu>
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @link https://github.com/demiankatz/Geeby-Deeby Main Site
*/
class PublishersURIs extends Gateway
{
/**
* Constructor
*
* @param Adapter $adapter Database adapter
* @param PluginManager $tm Table manager
* @param RowGateway $rowObj Row prototype object (null for default)
*/
public function __construct(Adapter $adapter, PluginManager $tm,
RowGateway $rowObj = null
) {
parent::__construct($adapter, $tm, $rowObj, 'Publishers_URIs');
}

/**
* Get a list of URIs for the specified publisher.
*
* @param int $publisherID Publisher ID
*
* @return mixed
*/
public function getURIsForPublisher($publisherID)
{
$callback = function ($select) use ($publisherID) {
$select->join(
['pr' => 'Predicates'],
'Publishers_URIs.Predicate_ID = pr.Predicate_ID'
);
$select->where->equalTo('Publisher_ID', $publisherID);
};
return $this->select($callback);
}

/**
* Get a list of publishers for the specified URI.
*
* @param string $uri URI
*
* @return mixed
*/
public function getPublishersForURI($uri)
{
$callback = function ($select) use ($uri) {
$select->join(
['p' => 'Publishers'],
'Publishers_URIs.Publisher_ID = p.Publisher_ID'
);
$select->join(
['pr' => 'Predicates'],
'Publishers_URIs.Predicate_ID = pr.Predicate_ID'
);
$select->order(['Publisher_Name']);
$select->where->equalTo('URI', $uri);
};
return $this->select($callback);
}
}
12 changes: 12 additions & 0 deletions module/GeebyDeeby/view/geeby-deeby/edit-publisher/edit-full.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
<ul class="nav nav-tabs">
<li class="active"><a href="#addr-tab" data-toggle="tab"><span>Addresses</span></a></li>
<li><a href="#imprints-tab" data-toggle="tab"><span>Imprints</span></a></li>
<li><a href="#uris-tab" data-toggle="tab"><span>URIs</span></a></li>
</ul>
<div class="tab-content">
<div id="addr-tab" class="tab-pane active">
Expand Down Expand Up @@ -34,4 +35,15 @@
<?=$this->render('geeby-deeby/edit-publisher/imprint-list.phtml')?>
</div>
</div>

<div id="uris-tab" class="tab-pane active">
<form onsubmit="Publisher.link('URI'); return false;">
<?=$this->render('geeby-deeby/edit-predicate/select.phtml')?>
<label>URI: <input type="text" id="uri" /></label>
<input type="submit" value="Add URI" />
</form>
<div id="uri_list">
<?=$this->render('geeby-deeby/edit-publisher/uri-list.phtml')?>
</div>
</div>
</div>
18 changes: 18 additions & 0 deletions module/GeebyDeeby/view/geeby-deeby/edit-publisher/uri-list.phtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php if (isset($uris) && count($uris) > 0): ?>
<?php foreach ($uris as $current): ?>
<table class="list_item">
<tr>
<td><a href="<?=$this->escapeHtmlAttr($current['URI'])?>"><?=$this->escapeHtml($current['URI'])?></a> (<?=$this->escapeHtml($current['Predicate_Abbrev'])?>)</td>
<td>
<?=$this->iconButton(
'trash',
"Publisher.unlink('URI', '" . addslashes($current['URI']) . "')",
'Unlink ' . $current['URI']
)?>
</td>
</tr>
</table>
<?php endforeach; ?>
<?php else: ?>
No URIs defined.
<?php endif; ?>
6 changes: 6 additions & 0 deletions public/js/edit_publishers.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ var PublisherEditor = function() {
'saveFields': {
'imprint': { 'id': '#Imprint', 'emptyError': 'Imprint must not be blank.' }
}
},
'URI': {
'uriField': { 'id': '#uri', 'emptyError': 'Please specify a valid URL.' },
'saveFields': {
'predicate_id': { 'id': '#Predicate_ID' }
}
}
};
};
Expand Down

0 comments on commit 1440a65

Please sign in to comment.