Skip to content

Commit

Permalink
Part two - child table
Browse files Browse the repository at this point in the history
  • Loading branch information
qzminski committed Jul 20, 2013
1 parent e2832fe commit 7755629
Show file tree
Hide file tree
Showing 13 changed files with 372 additions and 17 deletions.
6 changes: 4 additions & 2 deletions config/autoload.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
*/
ClassLoader::addClasses(array
(
'Contao\ModuleCdList' => 'system/modules/cd_collection/modules/ModuleCdList.php'
'Contao\ModuleCdList' => 'system/modules/cd_collection/modules/ModuleCdList.php',
'Contao\ModuleCdReader' => 'system/modules/cd_collection/modules/ModuleCdReader.php'
));


Expand All @@ -14,5 +15,6 @@
*/
TemplateLoader::addFiles(array
(
'mod_cdlist' => 'system/modules/cd_collection/templates/modules'
'mod_cdlist' => 'system/modules/cd_collection/templates/modules',
'mod_cdreader' => 'system/modules/cd_collection/templates/modules'
));
5 changes: 3 additions & 2 deletions config/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
(
'cd_collection' => array
(
'tables' => array('tl_cds'),
'tables' => array('tl_cds', 'tl_cds_song'),
'icon' => 'system/modules/cd_collection/assets/icon.png'
)
));
Expand All @@ -16,4 +16,5 @@
/**
* Front end modules
*/
$GLOBALS['FE_MOD']['miscellaneous']['cd_list'] = 'ModuleCdList';
$GLOBALS['FE_MOD']['miscellaneous']['cd_list'] = 'ModuleCdList';
$GLOBALS['FE_MOD']['miscellaneous']['cd_reader'] = 'ModuleCdReader';
9 changes: 8 additions & 1 deletion dca/tl_cds.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
'config' => array
(
'dataContainer' => 'Table',
'ctable' => array('tl_cds_song'),
'enableVersioning' => true,
'sql' => array
(
Expand Down Expand Up @@ -50,9 +51,15 @@
'edit' => array
(
'label' => &$GLOBALS['TL_LANG']['tl_cds']['edit'],
'href' => 'act=edit',
'href' => 'table=tl_cds_song',
'icon' => 'edit.gif'
),
'editheader' => array
(
'label' => &$GLOBALS['TL_LANG']['tl_cds']['editheader'],
'href' => 'act=edit',
'icon' => 'header.gif'
),
'copy' => array
(
'label' => &$GLOBALS['TL_LANG']['tl_cds']['copy'],
Expand Down
143 changes: 143 additions & 0 deletions dca/tl_cds_song.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
<?php

/**
* Table tl_cds_song
*/
$GLOBALS['TL_DCA']['tl_cds_song'] = array
(

// Config
'config' => array
(
'dataContainer' => 'Table',
'ptable' => 'tl_cds',
'enableVersioning' => true,
'sql' => array
(
'keys' => array
(
'id' => 'primary',
'pid' => 'index'
)
)
),

// List
'list' => array
(
'sorting' => array
(
'mode' => 4,
'fields' => array('sorting'),
'headerFields' => array('title', 'artist', 'year', 'genre'),
'panelLayout' => 'search,limit',
'child_record_callback' => array('tl_cds_song', 'generateSongRow')
),
'global_operations' => array
(
'all' => array
(
'label' => &$GLOBALS['TL_LANG']['MSC']['all'],
'href' => 'act=select',
'class' => 'header_edit_all',
'attributes' => 'onclick="Backend.getScrollOffset()" accesskey="e"'
)
),
'operations' => array
(
'edit' => array
(
'label' => &$GLOBALS['TL_LANG']['tl_cds_song']['edit'],
'href' => 'act=edit',
'icon' => 'edit.gif'
),
'copy' => array
(
'label' => &$GLOBALS['TL_LANG']['tl_cds_song']['copy'],
'href' => 'act=paste&amp;mode=copy',
'icon' => 'copy.gif'
),
'cut' => array
(
'label' => &$GLOBALS['TL_LANG']['tl_cds_song']['cut'],
'href' => 'act=paste&amp;mode=cut',
'icon' => 'cut.gif'
),
'delete' => array
(
'label' => &$GLOBALS['TL_LANG']['tl_cds_song']['delete'],
'href' => 'act=delete',
'icon' => 'delete.gif',
'attributes' => 'onclick="if(!confirm(\'' . $GLOBALS['TL_LANG']['MSC']['deleteConfirm'] . '\'))return false;Backend.getScrollOffset()"'
),
'show' => array
(
'label' => &$GLOBALS['TL_LANG']['tl_cds_song']['show'],
'href' => 'act=show',
'icon' => 'show.gif'
)
)
),

// Palettes
'palettes' => array
(
'default' => '{title_legend},title,duration'
),

// Fields
'fields' => array
(
'id' => array
(
'sql' => "int(10) unsigned NOT NULL auto_increment"
),
'pid' => array
(
'sql' => "int(10) unsigned NOT NULL default '0'"
),
'sorting' => array
(
'sql' => "int(10) unsigned NOT NULL default '0'"
),
'tstamp' => array
(
'sql' => "int(10) unsigned NOT NULL default '0'"
),
'title' => array
(
'label' => &$GLOBALS['TL_LANG']['tl_cds_song']['title'],
'exclude' => true,
'search' => true,
'inputType' => 'text',
'eval' => array('mandatory'=>true, 'maxlength'=>128, 'tl_class'=>'w50'),
'sql' => "varchar(128) NOT NULL default ''"
),
'duration' => array
(
'label' => &$GLOBALS['TL_LANG']['tl_cds_song']['duration'],
'exclude' => true,
'inputType' => 'text',
'eval' => array('mandatory'=>true, 'maxlength'=>8, 'tl_class'=>'w50'),
'sql' => "varchar(8) NOT NULL default ''"
)
)
);


/**
* Provide miscellaneous methods that are used by the data configuration array
*/
class tl_cds_song extends Backend
{

/**
* Generate a song row and return it as HTML string
* @param array
* @return string
*/
public function generateSongRow($arrRow)
{
return '<div>' . $arrRow['title'] . ' <span style="padding-left:3px;color:#b3b3b3;">[' . $arrRow['duration'] . ']</span></div>';
}
}
5 changes: 3 additions & 2 deletions dca/tl_module.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php

/**
* Add a palette to tl_module
* Add palettes to tl_module
*/
$GLOBALS['TL_DCA']['tl_module']['palettes']['cd_list'] = '{title_legend},name,headline,type;{protected_legend:hide},protected;{expert_legend:hide},guests,cssID,space';
$GLOBALS['TL_DCA']['tl_module']['palettes']['cd_list'] = '{title_legend},name,headline,type;{redirect_legend},jumpTo;{protected_legend:hide},protected;{expert_legend:hide},guests,cssID,space';
$GLOBALS['TL_DCA']['tl_module']['palettes']['cd_reader'] = '{title_legend},name,headline,type;{protected_legend:hide},protected;{expert_legend:hide},guests,cssID,space';
8 changes: 8 additions & 0 deletions languages/en/default.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

/**
* Miscellaneous
*/
$GLOBALS['TL_LANG']['MSC']['song_number'] = 'No.';
$GLOBALS['TL_LANG']['MSC']['song_title'] = 'Title';
$GLOBALS['TL_LANG']['MSC']['song_duration'] = 'Duration';
3 changes: 2 additions & 1 deletion languages/en/modules.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@
/**
* Front end modules
*/
$GLOBALS['TL_LANG']['FMD']['cd_list'] = array('CD List', 'Adds a list of CDs to the website.');
$GLOBALS['TL_LANG']['FMD']['cd_list'] = array('CD List', 'Adds a list of CDs to the website.');
$GLOBALS['TL_LANG']['FMD']['cd_reader'] = array('CD Reader', 'Adds a CD reader to the website.');
11 changes: 6 additions & 5 deletions languages/en/tl_cds.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@
/**
* Buttons
*/
$GLOBALS['TL_LANG']['tl_cds']['new'] = array('New album', 'Add a new album');
$GLOBALS['TL_LANG']['tl_cds']['show'] = array('Album details', 'Show the details of album ID %s');
$GLOBALS['TL_LANG']['tl_cds']['edit'] = array('Edit album', 'Edit album ID %s');
$GLOBALS['TL_LANG']['tl_cds']['copy'] = array('Copy album', 'Copy album ID %s');
$GLOBALS['TL_LANG']['tl_cds']['delete'] = array('Delete album', 'Delete album ID %s');
$GLOBALS['TL_LANG']['tl_cds']['new'] = array('New album', 'Add a new album');
$GLOBALS['TL_LANG']['tl_cds']['show'] = array('Album details', 'Show the details of album ID %s');
$GLOBALS['TL_LANG']['tl_cds']['edit'] = array('Edit album', 'Edit album ID %s');
$GLOBALS['TL_LANG']['tl_cds']['editheader'] = array('Edit album settings', 'Edit album settings ID %s');
$GLOBALS['TL_LANG']['tl_cds']['copy'] = array('Copy album', 'Copy album ID %s');
$GLOBALS['TL_LANG']['tl_cds']['delete'] = array('Delete album', 'Delete album ID %s');
26 changes: 26 additions & 0 deletions languages/en/tl_cds_song.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

/**
* Fields
*/
$GLOBALS['TL_LANG']['tl_cds_song']['title'] = array('Title', 'Please enter the song title.');
$GLOBALS['TL_LANG']['tl_cds_song']['duration'] = array('Song duration', 'Please enter the song duration.');


/**
* Legends
*/
$GLOBALS['TL_LANG']['tl_cds_song']['title_legend'] = 'Title and duration';


/**
* Buttons
*/
$GLOBALS['TL_LANG']['tl_cds_song']['new'] = array('New song', 'Add a new song');
$GLOBALS['TL_LANG']['tl_cds_song']['show'] = array('Song details', 'Show the details of song ID %s');
$GLOBALS['TL_LANG']['tl_cds_song']['edit'] = array('Edit song', 'Edit song ID %s');
$GLOBALS['TL_LANG']['tl_cds_song']['copy'] = array('Copy song', 'Copy song ID %s');
$GLOBALS['TL_LANG']['tl_cds_song']['cut'] = array('Move song', 'Move song ID %s');
$GLOBALS['TL_LANG']['tl_cds_song']['delete'] = array('Delete song', 'Delete song ID %s');
$GLOBALS['TL_LANG']['tl_cds_song']['pasteafter'] = array('Paste into this album', 'Paste after song ID %s');
$GLOBALS['TL_LANG']['tl_cds_song']['pastenew'] = array('Add new at the top', 'Add new after question ID %s');
16 changes: 15 additions & 1 deletion modules/ModuleCdList.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,19 @@ protected function compile()
return;
}

$strLink = '';

// Generate a jumpTo link
if ($this->jumpTo > 0)
{
$objJump = \PageModel::findByPk($this->jumpTo);

if ($objJump !== null)
{
$strLink = $this->generateFrontendUrl($objJump->row(), '/items/%s');
}
}

$arrCds = array();

// Generate CDs
Expand All @@ -74,7 +87,8 @@ protected function compile()
'genre' => $objCds->genre,
'year' => $objCds->year,
'cover' => $strCover,
'description' => $objCds->description
'description' => $objCds->description,
'link' => strlen($strLink) ? sprintf($strLink, $objCds->id) : ''
);
}

Expand Down
Loading

0 comments on commit 7755629

Please sign in to comment.