-
Notifications
You must be signed in to change notification settings - Fork 136
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refs #1377
- Loading branch information
Showing
15 changed files
with
252 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
application/data/migrations/20190307043537_AddResourceTitle.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?php | ||
namespace Omeka\Db\Migrations; | ||
|
||
use Doctrine\DBAL\Connection; | ||
use Omeka\Db\Migration\MigrationInterface; | ||
|
||
class AddResourceTitle implements MigrationInterface | ||
{ | ||
public function up(Connection $conn) | ||
{ | ||
$conn->exec(' | ||
ALTER TABLE resource ADD title VARCHAR(190) DEFAULT NULL; | ||
CREATE INDEX title ON resource (title); | ||
ALTER TABLE resource_template ADD title_property_id INT DEFAULT NULL; | ||
ALTER TABLE resource_template ADD CONSTRAINT FK_39ECD52E724734A3 FOREIGN KEY (title_property_id) REFERENCES property (id) ON DELETE SET NULL; | ||
CREATE INDEX IDX_39ECD52E724734A3 ON resource_template (title_property_id);'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
<?php | ||
namespace Omeka\Api\Adapter; | ||
|
||
use Doctrine\Common\Collections\Criteria; | ||
use Omeka\Api\Request; | ||
use Omeka\Entity\Property; | ||
use Omeka\Entity\Resource; | ||
|
||
class ResourceTitleHydrator | ||
{ | ||
/** | ||
* Hydrate the title of the resource entity. | ||
* | ||
* Attempts to get the title value of the resource template's title property | ||
* first. If that's not available, attempts to get the title value of the | ||
* dcterms:title property. | ||
* | ||
* @param Request $request | ||
* @param Resource $entity | ||
* @param AbstractResourceEntityAdapter $adapter | ||
*/ | ||
public function hydrate(Request $request, Resource $entity, | ||
AbstractResourceEntityAdapter $adapter | ||
) { | ||
$title = null; | ||
$resourceTemplate = $entity->getResourceTemplate(); | ||
if ($resourceTemplate && $resourceTemplate->getTitleProperty()) { | ||
$titleProperty = $resourceTemplate->getTitleProperty(); | ||
$title = $this->getResourceTitle($titleProperty, $entity); | ||
} | ||
if (null === $title) { | ||
$titleProperty = $adapter->getPropertyByTerm('dcterms:title'); | ||
$title = $this->getResourceTitle($titleProperty, $entity); | ||
} | ||
$entity->setTitle($title); | ||
} | ||
|
||
/** | ||
* Get the resource title. | ||
* | ||
* @param Property $titleProperty | ||
* @param Resource $entity | ||
* @return string|null | ||
*/ | ||
public function getResourceTitle(Property $titleProperty, Resource $entity) | ||
{ | ||
$criteria = Criteria::create() | ||
->where(Criteria::expr()->eq('property', $titleProperty)) | ||
->andWhere(Criteria::expr()->neq('value', null)) | ||
->andWhere(Criteria::expr()->neq('value', '')) | ||
->setMaxResults(1); | ||
$titleValues = $entity->getValues()->matching($criteria); | ||
return $titleValues->isEmpty() ? null : $titleValues->first()->getValue(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.