Skip to content
This repository has been archived by the owner on Mar 30, 2019. It is now read-only.

Commit

Permalink
Full integration of 3.1 Tags API
Browse files Browse the repository at this point in the history
  • Loading branch information
mbabker committed Apr 27, 2013
1 parent 262e32f commit f1caea9
Show file tree
Hide file tree
Showing 18 changed files with 410 additions and 212 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG
@@ -1,3 +1,6 @@
26-April-2013 Michael Babker
+ Full integration of 3.1 Tags API

10-March-2013 Michael Babker
+ Initial support of 3.1 Tags component
~ Update MediaElement.JS to 2.10.3
Expand Down
43 changes: 0 additions & 43 deletions com_podcastmanager/admin/controllers/feed.php
Expand Up @@ -83,47 +83,4 @@ protected function allowEdit($data = array(), $key = 'id')

return false;
}


/**
* Function that allows child controller access to model data after the data has been saved.
*
* @param JModelLegacy $model The data model object.
* @param array $validData The validated data.
*
* @return void
*
* @since 2.1
*/
protected function postSaveHook(JModelLegacy $model, $validData = array())
{
// Only supports CMS 3.1+ for now
if (version_compare(JVERSION, '3.1', 'ge'))
{
$item = $model->getItem();

$id = $item->id;

if (empty($validData['tags']) && !empty($item->tags))
{
$oldTags = new JHelperTags;
$oldTags->unTagItem($id, 'com_podcastmanager.feed');

return;
}

$tags = $validData['tags'];

// Store the tag data if the feed was saved.
if ($tags[0] != '')
{
$isNew = $item->id == 0 ? true : false;

$tagsHelper = new JHelperTags;
$tagsHelper->tagItem($id, 'com_podcastmanager.feed', $isNew, $item, $tags, null);
}
}

return;
}
}
33 changes: 33 additions & 0 deletions com_podcastmanager/admin/models/feed.php
Expand Up @@ -147,6 +147,39 @@ public function getForm($data = array(), $loadData = true)
return $form;
}

/**
* Method to get a single record.
*
* @param integer $pk The id of the primary key.
*
* @return mixed Object on success, false on failure.
*
* @since 2.1
*/
public function getItem($pk = null)
{
if ($item = parent::getItem($pk))
{
// Convert the metadata field to an array.
$registry = new JRegistry;
$registry->loadString($item->metadata);
$item->metadata = $registry->toArray();

// Tags support in CMS 3.1+
if (version_compare(JVERSION, '3.1', 'ge'))
{
if (!empty($item->id))
{
$item->tags = new JHelperTags;
$item->tags->getTagIds($item->id, 'com_podcastmanager.feed');
$item->metadata['tags'] = $item->tags;
}
}
}

return $item;
}

/**
* Returns a JTable object, always creating it
*
Expand Down
51 changes: 51 additions & 0 deletions com_podcastmanager/admin/models/podcast.php
Expand Up @@ -107,6 +107,16 @@ public function batch($commands, $pks, $contexts)
$done = true;
}

if (!empty($commands['tag']))
{
if (!$this->batchTag($commands['tag'], $pks, $contexts))
{
return false;
}

$done = true;
}

if (!$done)
{
$this->setError(JText::_('JLIB_APPLICATION_ERROR_INSUFFICIENT_BATCH_INFORMATION'));
Expand Down Expand Up @@ -476,9 +486,50 @@ public function getForm($data = array(), $loadData = true)
$form->setFieldAttribute('published', 'filter', 'unset');
}

// Add tags for CMS 3.1 and later
if (version_compare(JVERSION, '3.1', 'ge'))
{
$form->setField(
new SimpleXMLElement('<field name="tags" type="tag" label="JTAG" description="JTAG_DESC" class="inputbox" multiple="true" />')
);
}

return $form;
}

/**
* Method to get a single record.
*
* @param integer $pk The id of the primary key.
*
* @return mixed Object on success, false on failure.
*
* @since 2.1
*/
public function getItem($pk = null)
{
if ($item = parent::getItem($pk))
{
// Convert the metadata field to an array.
$registry = new JRegistry;
$registry->loadString($item->metadata);
$item->metadata = $registry->toArray();

// Tags support in CMS 3.1+
if (version_compare(JVERSION, '3.1', 'ge'))
{
if (!empty($item->id))
{
$item->tags = new JHelperTags;
$item->tags->getTagIds($item->id, 'com_podcastmanager.podcast');
$item->metadata['tags'] = $item->tags;
}
}
}

return $item;
}

/**
* Returns a JTable object, always creating it
*
Expand Down
2 changes: 2 additions & 0 deletions com_podcastmanager/admin/sql/install.mysql.sql
Expand Up @@ -23,6 +23,7 @@ CREATE TABLE IF NOT EXISTS `#__podcastmanager` (
`itSummary` varchar(5120) NOT NULL default '',
`mime` varchar(20) NOT NULL default '',
`language` char(7) NOT NULL,
`metadata` text NOT NULL,
PRIMARY KEY (`id`)
) DEFAULT CHARSET=utf8;

Expand Down Expand Up @@ -55,5 +56,6 @@ CREATE TABLE IF NOT EXISTS `#__podcastmanager_feeds` (
`checked_out` integer unsigned NOT NULL default '0',
`checked_out_time` datetime NOT NULL default '0000-00-00 00:00:00',
`language` char(7) NOT NULL,
`metadata` text NOT NULL,
PRIMARY KEY (`id`)
) DEFAULT CHARSET=utf8;
2 changes: 2 additions & 0 deletions com_podcastmanager/admin/sql/install.postgresql.sql
Expand Up @@ -23,6 +23,7 @@ CREATE TABLE "#__podcastmanager" (
"itSummary" character varying(5120) DEFAULT '' NOT NULL,
"mime" character varying(20) DEFAULT '' NOT NULL,
"language" character varying(7) NOT NULL,
"metadata" text NOT NULL,
PRIMARY KEY ("id")
);

Expand Down Expand Up @@ -55,5 +56,6 @@ CREATE TABLE "#__podcastmanager_feeds" (
"checked_out" bigint DEFAULT 0 NOT NULL,
"checked_out_time" timestamp without time zone DEFAULT '1970-01-01 00:00:00' NOT NULL,
"language" character varying(7) NOT NULL,
"metadata" text NOT NULL,
PRIMARY KEY ("id")
);
2 changes: 2 additions & 0 deletions com_podcastmanager/admin/sql/install.sqlsrv.sql
Expand Up @@ -25,6 +25,7 @@ CREATE TABLE [#__podcastmanager](
[itSummary] [nvarchar](max) NOT NULL,
[mime] [nvarchar](20) NOT NULL,
[language] [nvarchar](7) NOT NULL,
[metadata] [nvarchar](max) NOT NULL,
CONSTRAINT [PK_#__podcastmanager] PRIMARY KEY CLUSTERED
(
[id] ASC
Expand Down Expand Up @@ -102,6 +103,7 @@ CREATE TABLE [#__podcastmanager_feeds](
[checked_out] [int] NOT NULL,
[checked_out_time] [datetime] NOT NULL,
[language] [nvarchar](7) NOT NULL,
[metadata] [nvarchar](max) NOT NULL,
CONSTRAINT [PK_#__podcastmanager_feeds] PRIMARY KEY CLUSTERED
(
[id] ASC
Expand Down
2 changes: 2 additions & 0 deletions com_podcastmanager/admin/sql/updates/mysql/2.1.0.sql
@@ -1,3 +1,5 @@
ALTER TABLE `#__podcastmanager` ADD `alias` varchar(255) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL DEFAULT '' AFTER `title`;
ALTER TABLE `#__podcastmanager` ADD `metadata` text NOT NULL AFTER `language`;

ALTER TABLE `#__podcastmanager_feeds` ADD `alias` varchar(255) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL DEFAULT '' AFTER `name`;
ALTER TABLE `#__podcastmanager_feeds` ADD `metadata` text NOT NULL AFTER `language`;
2 changes: 2 additions & 0 deletions com_podcastmanager/admin/sql/updates/postgresql/2.1.0.sql
Expand Up @@ -23,6 +23,7 @@ CREATE TABLE "#__podcastmanager_new" (
"itSummary" character varying(5120) DEFAULT '' NOT NULL,
"mime" character varying(20) DEFAULT '' NOT NULL,
"language" character varying(7) NOT NULL,
"metadata" text NOT NULL,
PRIMARY KEY ("id")
);

Expand Down Expand Up @@ -59,6 +60,7 @@ CREATE TABLE "#__podcastmanager_feeds_new" (
"checked_out" bigint DEFAULT 0 NOT NULL,
"checked_out_time" timestamp without time zone DEFAULT '1970-01-01 00:00:00' NOT NULL,
"language" character varying(7) NOT NULL,
"metadata" text NOT NULL,
PRIMARY KEY ("id")
);

Expand Down
2 changes: 2 additions & 0 deletions com_podcastmanager/admin/sql/updates/sqlsrv/2.1.0.sql
@@ -1,3 +1,5 @@
ALTER TABLE [#__podcastmanager] ADD [alias] [nvarchar](255) CONSTRAINT [DF_#__podcastmanager_alias] DEFAULT '' NOT NULL;
ALTER TABLE [#__podcastmanager] ADD [metadata] [nvarchar](max) NOT NULL;

ALTER TABLE [#__podcastmanager_feeds] ADD [alias] [nvarchar](255) CONSTRAINT [DF_#__podcastmanager_feeds_alias] DEFAULT '' NOT NULL;
ALTER TABLE [#__podcastmanager_feeds] ADD [metadata] [nvarchar](max) NOT NULL;
61 changes: 60 additions & 1 deletion com_podcastmanager/admin/tables/feed.php
Expand Up @@ -23,6 +23,14 @@
*/
class PodcastManagerTableFeed extends JTable
{
/**
* Helper object for storing and deleting tag information.
*
* @var JHelperTags
* @since 2.1
*/
protected $tagsHelper;

/**
* The class constructor.
*
Expand All @@ -33,6 +41,13 @@ class PodcastManagerTableFeed extends JTable
public function __construct(&$db)
{
parent::__construct('#__podcastmanager_feeds', 'id', $db);

// Tags support in CMS 3.1+
if (version_compare(JVERSION, '3.1', 'ge'))
{
$this->tagsHelper = new JHelperTags;
$this->tagsHelper->typeAlias = 'com_podcastmanager.feed';
}
}

/**
Expand Down Expand Up @@ -160,6 +175,32 @@ public function check()
return true;
}

/**
* Override parent delete method to delete tags information.
*
* @param integer $pk Primary key to delete.
*
* @return boolean True on success.
*
* @since 2.1
*/
public function delete($pk = null)
{
$result = parent::delete($pk);

// Tags support in CMS 3.1+
if (version_compare(JVERSION, '3.1', 'ge'))
{
$tagResult = $this->tagsHelper->deleteTagData($this, $pk);
}
else
{
$tagResult = true;
}

return $result && $tagResult;
}

/**
* Overriden JTable::store to set modified data and user id.
*
Expand Down Expand Up @@ -194,6 +235,24 @@ public function store($updateNulls = false)
}
}

return parent::store($updateNulls);
// Tags support in CMS 3.1+
if (version_compare(JVERSION, '3.1', 'ge'))
{
$this->tagsHelper->preStoreProcess($this);
}

$result = parent::store($updateNulls);

// Tags support in CMS 3.1+
if (version_compare(JVERSION, '3.1', 'ge'))
{
$tagResult = $this->tagsHelper->postStoreProcess($this);
}
else
{
$tagResult = true;
}

return $result && $tagResult;
}
}

0 comments on commit f1caea9

Please sign in to comment.