Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
134 changes: 81 additions & 53 deletions code/libraries/joomlatools/plugin/koowa/finder.php
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,11 @@ public function onFinderChangeState($context, $pks, $value)
}
}

protected function isEnabled()
{
return JComponentHelper::isEnabled($this->extension) == true;
}

/**
* Main index function run when indexing happens
*
Expand All @@ -179,25 +184,29 @@ public function onFinderChangeState($context, $pks, $value)
protected function index(FinderIndexerResult $item)
{
// Check if the extension is enabled
if (JComponentHelper::isEnabled($this->extension) == false) {

if (!$this->isEnabled()) {
return;
}

//Add the instructions
foreach ($this->instructions AS $type => $instructions)
if ($item->id)
{
foreach ($instructions AS $instruction) {
$item->addInstruction($type, $instruction);
//Add the instructions
foreach ($this->instructions AS $type => $instructions)
{
foreach ($instructions AS $instruction) {
$item->addInstruction($type, $instruction);
}
}
}

// Add the type taxonomy data.
$item->addTaxonomy('Type', $this->type_title);
// Add the type taxonomy data.
$item->addTaxonomy('Type', $this->type_title);

FinderIndexerHelper::getContentExtras($item);
FinderIndexerHelper::getContentExtras($item);

// Index the item.
$this->indexer->index($item);
// Index the item.
$this->indexer->index($item);
}
}

/**
Expand Down Expand Up @@ -261,6 +270,10 @@ protected function getItem($id)
{
$entity = $this->getModel()->id($id)->fetch();

if ($entity->isNew()) {
$this->remove($id);
}

return $this->getFinderItem($entity);
}

Expand Down Expand Up @@ -309,72 +322,87 @@ protected function getModel()
}

/**
* Turns a KModelEntityInterface object into a finder item
* Finder item getter
*
* @param KModelEntityInterface $entity
* @param array $data The item data
* @return object
*/
protected function getFinderItem(KModelEntityInterface $entity)
protected function _getFinderItem($data = array())
{
$data = $entity->getProperties();

//Get the indexer result item
if (class_exists('JArrayHelper')) {
$item = JArrayHelper::toObject($data, 'FinderIndexerResult');
} else {
$item = \Joomla\Utilities\ArrayHelper::toObject($data, 'FinderIndexerResult');
}

$item->url = $this->getURL($item->id, $this->extension, $this->layout);
$item->route = $this->getLink($entity);
return $item;
}

if (method_exists('FinderIndexerHelper', 'getContentPath')) {
$item->path = FinderIndexerHelper::getContentPath($item->route);
}
/**
* Turns a KModelEntityInterface object into a finder item
*
* @param KModelEntityInterface $entity
* @return object
*/
protected function getFinderItem(KModelEntityInterface $entity)
{
if ($entity->isNew())
{
$item = $this->_getFinderItem($entity->getProperties());

// Trigger the onContentPrepare event.
if ($item->description) {
$item->summary = FinderIndexerHelper::prepareContent($item->description, $item->params);
}
$item->url = $this->getURL($item->id, $this->extension, $this->layout);
$item->route = $this->getLink($entity);

if ($item->publish_on) {
$item->publish_start_date = $item->publish_on;
}
if (method_exists('FinderIndexerHelper', 'getContentPath')) {
$item->path = FinderIndexerHelper::getContentPath($item->route);
}

if ($item->unpublish_on) {
$item->publish_end_date = $item->unpublish_on;
}
// Trigger the onContentPrepare event.
if ($item->description) {
$item->summary = FinderIndexerHelper::prepareContent($item->description, $item->params);
}

// Finder needs the access field
if (!isset($item->access)) {
$item->access = 1;
}
if ($item->publish_on) {
$item->publish_start_date = $item->publish_on;
}

$item->state = $item->enabled;
if ($item->unpublish_on) {
$item->publish_end_date = $item->unpublish_on;
}

// Set the item type.
$item->type_id = $this->type_id;
// Finder needs the access field
if (!isset($item->access)) {
$item->access = 1;
}

// Set the mime type.
$item->mime = $this->mime;
$item->state = $item->enabled;

// Set the item layout.
$item->layout = $this->layout;
// Set the item type.
$item->type_id = $this->type_id;

// Set the extension if present
if (isset($entity->extension)) {
$item->extension = $entity->extension;
}
// Set the mime type.
$item->mime = $this->mime;

if ($entity->isCreatable())
{
// Add the author taxonomy data.
$item->addTaxonomy('Author', $entity->getAuthor()->getName());
// Set the item layout.
$item->layout = $this->layout;

// Add the start date
$item->start_date = $entity->created_on;
}
// Set the extension if present
if (isset($entity->extension)) {
$item->extension = $entity->extension;
}

if ($entity->isCreatable())
{
// Add the author taxonomy data.
$item->addTaxonomy('Author', $entity->getAuthor()->getName());

// Add the start date
$item->start_date = $entity->created_on;
}
}
else $item = $this->_getFinderItem();

return $item;
}

Expand Down