Skip to content

Commit

Permalink
Finalize conversion to Joomla Coding Standards
Browse files Browse the repository at this point in the history
  • Loading branch information
jissereitsma committed Sep 7, 2014
1 parent f70904c commit 3826baa
Show file tree
Hide file tree
Showing 8 changed files with 1,044 additions and 525 deletions.
229 changes: 163 additions & 66 deletions chapter09/plg_finder_song/plugins/finder/song/song.php
Expand Up @@ -2,99 +2,161 @@
/**
* Finder Plugin for Joomla! - Song
*
* @author Jisse Reitsma (jisse@yireo.com)
* @copyright Copyright 2014 Jisse Reitsma
* @license GNU Public License version 3 or later
* @link http://www.yireo.com/books/
* @author Jisse Reitsma <jisse@yireo.com>
* @copyright Copyright 2014 Jisse Reitsma
* @license GNU Public License version 3 or later
* @link http://www.yireo.com/books/
*/

defined('_JEXEC') or die;

require_once JPATH_ADMINISTRATOR . '/components/com_finder/helpers/indexer/adapter.php';

/**
* Class PlgFinderSong
*
* @since September 2014
*/
class PlgFinderSong extends FinderIndexerAdapter
{
/**
* @var string
*/
protected $context = 'Song';

/**
* @var string
*/
protected $extension = 'com_music';

/**
* @var string
*/
protected $layout = 'song';

/**
* @var string
*/
protected $type_title = 'Song';

/**
* @var string
*/
protected $table = '#__music_songs';

/**
* @var bool
*/
protected $autoloadLanguage = true;

/**
* Override method to index a certain result
*
* @param FinderIndexerResult $item Finder item
* @param string $format Formatting (html or text)
*
* @return null
*/
protected function index(FinderIndexerResult $item, $format = 'html')
{
//if (JComponentHelper::isEnabled($this->extension) == false)
//{
// return;
//}

// Prepare the item
$item->access = 1;

// Define these items as songs
$item->addTaxonomy('Type', 'Song');

// Add artist information
$item->addInstruction(FinderIndexer::META_CONTEXT, 'artist');
$item->addTaxonomy('Artist', $item->artist);

// Set language
{
/*
if (JComponentHelper::isEnabled($this->extension) == false)
{
return;
}
*/

// Prepare the item
$item->access = 1;

// Define these items as songs
$item->addTaxonomy('Type', 'Song');

// Add artist information
$item->addInstruction(FinderIndexer::META_CONTEXT, 'artist');
$item->addTaxonomy('Artist', $item->artist);

// Set language
//$item->setLanguage();
//$item->addTaxonomy('Language', $item->language);

// Set URLs
$item->route = 'index.php?option=com_music&view=song&id='.$item->id;
// Set URLs
$item->route = 'index.php?option=com_music&view=song&id=' . $item->id;
$item->url = $item->route;
$item->path = FinderIndexerHelper::getContentPath($item->route);

// Allow others to hook into our $item as well
// Allow others to hook into our $item as well
FinderIndexerHelper::getContentExtras($item);

$this->indexer->index($item);
}
$this->indexer->index($item);
}

/**
* Override method to setup the entire plugin process
*
* @return bool
*/
protected function setup()
{
//require_once JPATH_SITE.'/components/com_music/helpers/route.php';
{
//require_once JPATH_SITE.'/components/com_music/helpers/route.php';

return true;
}
return true;
}

/**
* Override method to return the list query
*
* @param mixed $query JDatabaseQuery object or null
*
* @return null
*/
protected function getListQuery($query = null)
{
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query->select('a.*');
$query->select('p.name AS artist');
$query->from($db->quoteName('#__music_songs', 'a'));
$query->innerJoin($db->quoteName('#__music_artists', 'p')
.' ON ('.$db->quoteName('a.artist_id').'='.$db->quoteName('p.id').')'
);

$debugQuery = str_replace('#__', $db->getPrefix(), trim($query));
echo "[SONGS]\n".$debugQuery."\n[/SONGS]\n";
return $query;
}
{
$db = JFactory::getDbo();

$query = $db->getQuery(true);
$query->select('a.*');
$query->select('p.name AS artist');
$query->from($db->quoteName('#__music_songs', 'a'));
$query->innerJoin($db->quoteName('#__music_artists', 'p')
. ' ON (' . $db->quoteName('a.artist_id') . '=' . $db->quoteName('p.id') . ')');

$debugQuery = str_replace('#__', $db->getPrefix(), trim($query));
echo "[SONGS]\n" . $debugQuery . "\n[/SONGS]\n";

return $query;
}

/**
* Override method to return the state query
*
* @return mixed
*/
protected function getStateQuery()
{
$query = $this->db->getQuery(true);
$query->select('a.id');
$query->select('a.'.$this->state_field.' AS state');
$query->select('a.' . $this->state_field . ' AS state');
$query->from($this->table . ' AS a');
jimport('joomla.log.log');
JLog::add($query, JLog::WARNING, 'jerror');

jimport('joomla.log.log');
JLog::add($query, JLog::WARNING, 'jerror');

return $query;
}


/**
* Event method to run when the item state changes
*
* @param text $context String describing the current context
* @param array $pks List of primary keys
* @param mixed $value State value (likely either 0 or 1)
*
* @return null
*/
public function onFinderChangeState($context, $pks, $value)
{
{
if ($context == 'com_music.song')
{
$this->itemStateChange($pks, $value);
Expand All @@ -104,18 +166,35 @@ public function onFinderChangeState($context, $pks, $value)
{
$this->pluginDisable($pks);
}
}
}

/**
* Event method run when the category state changes
*
* @param string $extension String pointing to the component
* @param array $pks Array of primary keys
* @param mixed $value State value
*
* @return null
*/
public function onFinderCategoryChangeState($extension, $pks, $value)
{
{
if ($extension == 'com_music')
{
$this->categoryStateChange($pks, $value);
}
}
}

/**
* Event method run when the item is deleted
*
* @param string $context String describing the current context
* @param JTable $table JTable instance of the content item
*
* @return bool
*/
public function onFinderAfterDelete($context, $table)
{
{
if ($context == 'com_music.song')
{
$id = $table->id;
Expand All @@ -126,39 +205,57 @@ public function onFinderAfterDelete($context, $table)
}

return $this->remove($id);
}
}

public function onFinderAfterSave($context, $row, $isNew)
{
/**
* Event method run after the item is saved
*
* @param string $context String describing the current context
* @param object $item Content item that is being saved
* @param bool $isNew Flag determining whether this item is new or not
*
* @return null
*/
public function onFinderAfterSave($context, $item, $isNew)
{
if ($context == 'com_music.song')
{
if (!$isNew && $this->old_access != $row->access)
if (!$isNew && $this->old_access != $item->access)
{
$this->itemAccessChange($row);
$this->itemAccessChange($item);
}

$this->reindex($row->id);
$this->reindex($item->id);
}

if ($context == 'com_categories.category')
{
if (!$isNew && $this->old_cataccess != $row->access)
if (!$isNew && $this->old_cataccess != $item->access)
{
$this->categoryAccessChange($row);
$this->categoryAccessChange($item);
}
}
}
}

public function onFinderBeforeSave($context, $row, $isNew)
{
/**
* Event method run before the item is saved
*
* @param string $context String describing the current context
* @param object $item Content item that is being saved
* @param bool $isNew Flag determining whether this item is new or not
*
* @return null
*/
public function onFinderBeforeSave($context, $item, $isNew)
{
if ($context == 'com_music.song' && $isNew == false)
{
$this->checkItemAccess($row);
$this->checkItemAccess($item);
}

if ($context == 'com_categories.category' && $isNew == false)
{
$this->checkCategoryAccess($row);
$this->checkCategoryAccess($item);
}
}
}
}

0 comments on commit 3826baa

Please sign in to comment.