Skip to content

Commit

Permalink
Adding database (single record)
Browse files Browse the repository at this point in the history
  • Loading branch information
alve89 committed Sep 6, 2021
1 parent bd1e048 commit ec3a1be
Show file tree
Hide file tree
Showing 9 changed files with 40 additions and 46 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
/**
* @package Joomla.Administrator
* @subpackage com_helloworld
* @subpackage com_tvo
*
* @copyright Copyright (C) 2005 - 2018 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
Expand All @@ -13,18 +13,18 @@
JFormHelper::loadFieldClass('list');

/**
* TvoTeams Form Field class for the HelloWorld component
* HelloWorld Form Field class for the HelloWorld component
*
* @since 0.0.1
*/
class JFormFieldTvoTeams extends JFormFieldList
class JFormFieldTvoTeam extends JFormFieldList
{
/**
* The field type.
*
* @var string
*/
protected $type = 'TvoTeams';
protected $type = 'TvoTeam';

/**
* Method to get a list of options for a list input.
Expand All @@ -35,16 +35,17 @@ protected function getOptions()
{
$db = JFactory::getDBO();
$query = $db->getQuery(true);
$query->select('id,teamId,title,published');
$query->from('#__tvo_teams');
$query->select('id,greeting');
$query->from('#__helloworld');
$db->setQuery((string) $query);
$teams = $db->loadObjectList();
$messages = $db->loadObjectList();
$options = array();

if ($teams) {
foreach ($teams as $team)
if ($messages)
{
foreach ($messages as $message)
{
$options[] = JHtml::_('select.option', $team->teamId, $team->title, $team->published);
$options[] = JHtml::_('select.option', $message->id, $message->greeting);
}
}

Expand Down
19 changes: 8 additions & 11 deletions admin/sql/install.mysql.utf8mb4.sql
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
DROP TABLE IF EXISTS `#__tvo_teams`;
DROP TABLE IF EXISTS `#__helloworld`;

CREATE TABLE `#__tvo_teams` (
CREATE TABLE `#__helloworld` (
`id` INT(11) NOT NULL AUTO_INCREMENT,
`title` VARCHAR(20) NOT NULL DEFAULT 'NoNameSet',
`teamId` INT(8) NOT NULL,
`published` BOOLEAN DEFAULT FALSE,
`greeting` VARCHAR(25) NOT NULL,
`published` tinyint(4) NOT NULL DEFAULT '1',
PRIMARY KEY (`id`)
)
ENGINE=InnoDB
DEFAULT CHARSET=utf8mb4
DEFAULT COLLATE=utf8mb4_unicode_ci;
ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 DEFAULT COLLATE=utf8mb4_unicode_ci;

INSERT INTO `#__tvo_teams` (`teamId`, `title`) VALUES
('123456', 'Testteam01'),
('234567', 'Testteam02');
INSERT INTO `#__helloworld` (`greeting`) VALUES
('Hello beautiful World!'),
('Good bye awful World!');
2 changes: 1 addition & 1 deletion admin/sql/uninstall.mysql.utf8mb4.sql
Original file line number Diff line number Diff line change
@@ -1 +1 @@
DROP TABLE IF EXISTS `#__tvo_teams`;
DROP TABLE IF EXISTS `#__helloworld`;
19 changes: 8 additions & 11 deletions admin/sql/updates/mysql/0.0.8.sql
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
DROP TABLE IF EXISTS `#__tvo_teams`;
DROP TABLE IF EXISTS `#__helloworld`;

CREATE TABLE `#__tvo_teams` (
CREATE TABLE `#__helloworld` (
`id` INT(11) NOT NULL AUTO_INCREMENT,
`title` VARCHAR(20) NOT NULL DEFAULT 'NoNameSet',
`teamId` INT(8) NOT NULL,
`published` BOOLEAN DEFAULT FALSE,
`greeting` VARCHAR(25) NOT NULL,
`published` tinyint(4) NOT NULL DEFAULT '1',
PRIMARY KEY (`id`)
)
ENGINE=InnoDB
DEFAULT CHARSET=utf8mb4
DEFAULT COLLATE=utf8mb4_unicode_ci;
ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 DEFAULT COLLATE=utf8mb4_unicode_ci;

INSERT INTO `#__tvo_teams` (`teamId`, `title`) VALUES
('123456', 'Testteam01'),
('234567', 'Testteam02');
INSERT INTO `#__helloworld` (`greeting`) VALUES
('Hello beautiful World!'),
('Good bye awful World!');
4 changes: 2 additions & 2 deletions admin/tables/tvoTable.php → admin/tables/tvoteam.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
*
* @since 0.0.1
*/
class TvoTableTvoTeams extends JTable
class TvoTableTvoTeam extends JTable
{
/**
* Constructor
Expand All @@ -23,6 +23,6 @@ class TvoTableTvoTeams extends JTable
*/
function __construct(&$db)
{
parent::__construct('#__tvo_teams', 'id', $db);
parent::__construct('#__helloworld', 'id', $db);
}
}
11 changes: 5 additions & 6 deletions site/models/tvo.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@
defined('_JEXEC') or die('Restricted access');

/**
* Tvo Model
* HelloWorld Model
*
* @since 0.0.1
*/
class TvoModelTvo extends JModelItem {
class TvoModelTvo extends JModelItem
{
/**
* @var array messages
*/
Expand All @@ -32,7 +33,7 @@ class TvoModelTvo extends JModelItem {
*
* @since 1.6
*/
public function getTable($type = 'tvoTeam', $prefix = 'TvoTable', $config = array())
public function getTable($type = 'TvoTeam', $prefix = 'TvoTable', $config = array())
{
return JTable::getInstance($type, $prefix, $config);
}
Expand Down Expand Up @@ -64,11 +65,9 @@ public function getMsg($id = 1)
$table->load($id);

// Assign the message
$this->messages[$id] = $table->title;
$this->messages[$id] = $table->greeting;
}

return $this->messages[$id];
}


}
4 changes: 2 additions & 2 deletions site/views/tvo/tmpl/default.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
</layout>
<fields
name="request"
addfieldpath="/administrator/components/com_helloworld/models/fields"
addfieldpath="/administrator/components/com_tvo/models/fields"
>
<fieldset name="request">
<field
name="id"
type="tvoTeams"
type="TvoTeam"
label="COM_HELLOWORLD_HELLOWORLD_FIELD_GREETING_LABEL"
description="COM_HELLOWORLD_HELLOWORLD_FIELD_GREETING_DESC"
/>
Expand Down
4 changes: 2 additions & 2 deletions tvo.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@

<install> <!-- Runs on install -->
<sql>
<file driver="mysql" charset="utf8mb4">sql/install.mysql.utf8mb4.sql</file>
<file driver="mysql" charset="utf8">sql/install.mysql.utf8mb4.sql</file>
</sql>
</install>
<uninstall> <!-- Runs on uninstall -->
<sql>
<file driver="mysql" charset="utf8mb4">sql/uninstall.mysql.utf8mb4.sql</file>
<file driver="mysql" charset="utf8">sql/uninstall.mysql.utf8mb4.sql</file>
</sql>
</uninstall>

Expand Down
2 changes: 1 addition & 1 deletion updates.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<element>com_tvo</element>
<type>component</type>
<version>0.0.9</version>
<client>administrator</client>
<client>0</client>
<infourl title="com_tvp Update Server" />
<downloads>
<downloadurl
Expand Down

0 comments on commit ec3a1be

Please sign in to comment.