-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
352 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,6 @@ | ||
blog-cd_collection | ||
================== | ||
cd_collection | ||
============= | ||
|
||
This extension is a part of the "Create a custom module" tutorial at [qzminski Blog](http://blog.qzminski.com). | ||
|
||
The icon used in the project is made by [FamFamFam](http://famfamfam.com). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<IfModule !mod_authz_core.c> | ||
Order allow,deny | ||
Allow from all | ||
</IfModule> | ||
<IfModule mod_authz_core.c> | ||
Require all granted | ||
</IfModule> |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?php | ||
|
||
/** | ||
* Register the classes | ||
*/ | ||
ClassLoader::addClasses(array | ||
( | ||
'Contao\ModuleCdList' => 'system/modules/cd_collection/modules/ModuleCdList.php' | ||
)); | ||
|
||
|
||
/** | ||
* Register the templates | ||
*/ | ||
TemplateLoader::addFiles(array | ||
( | ||
'mod_cdlist' => 'system/modules/cd_collection/templates/modules' | ||
)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?php | ||
|
||
/** | ||
* Back end modules | ||
*/ | ||
array_insert($GLOBALS['BE_MOD']['content'], 1, array | ||
( | ||
'cd_collection' => array | ||
( | ||
'tables' => array('tl_cds'), | ||
'icon' => 'system/modules/cd_collection/assets/icon.png' | ||
) | ||
)); | ||
|
||
|
||
/** | ||
* Front end modules | ||
*/ | ||
$GLOBALS['FE_MOD']['miscellaneous']['cd_list'] = 'ModuleCdList'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,149 @@ | ||
<?php | ||
|
||
/** | ||
* Table tl_cds | ||
*/ | ||
$GLOBALS['TL_DCA']['tl_cds'] = array | ||
( | ||
|
||
// Config | ||
'config' => array | ||
( | ||
'dataContainer' => 'Table', | ||
'enableVersioning' => true, | ||
'sql' => array | ||
( | ||
'keys' => array | ||
( | ||
'id' => 'primary' | ||
) | ||
) | ||
), | ||
|
||
// List | ||
'list' => array | ||
( | ||
'sorting' => array | ||
( | ||
'mode' => 1, | ||
'fields' => array('title'), | ||
'flag' => 1, | ||
'panelLayout' => 'filter;search,limit' | ||
), | ||
'label' => array | ||
( | ||
'fields' => array('title', 'artist'), | ||
'format' => '%s <span style="color:#b3b3b3;padding-left:3px;">[%s]</span>' | ||
), | ||
'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']['edit'], | ||
'href' => 'act=edit', | ||
'icon' => 'edit.gif' | ||
), | ||
'copy' => array | ||
( | ||
'label' => &$GLOBALS['TL_LANG']['tl_cds']['copy'], | ||
'href' => 'act=copy', | ||
'icon' => 'copy.gif' | ||
), | ||
'delete' => array | ||
( | ||
'label' => &$GLOBALS['TL_LANG']['tl_cds']['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']['show'], | ||
'href' => 'act=show', | ||
'icon' => 'show.gif' | ||
) | ||
) | ||
), | ||
|
||
// Palettes | ||
'palettes' => array | ||
( | ||
'default' => '{title_legend},title,artist,genre,year;{cover_legend},cover,description' | ||
), | ||
|
||
// Fields | ||
'fields' => array | ||
( | ||
'id' => array | ||
( | ||
'sql' => "int(10) unsigned NOT NULL auto_increment" | ||
), | ||
'tstamp' => array | ||
( | ||
'sql' => "int(10) unsigned NOT NULL default '0'" | ||
), | ||
'title' => array | ||
( | ||
'label' => &$GLOBALS['TL_LANG']['tl_cds']['title'], | ||
'exclude' => true, | ||
'search' => true, | ||
'inputType' => 'text', | ||
'eval' => array('mandatory'=>true, 'maxlength'=>128, 'tl_class'=>'w50'), | ||
'sql' => "varchar(128) NOT NULL default ''" | ||
), | ||
'artist' => array | ||
( | ||
'label' => &$GLOBALS['TL_LANG']['tl_cds']['artist'], | ||
'exclude' => true, | ||
'filter' => true, | ||
'inputType' => 'text', | ||
'eval' => array('mandatory'=>true, 'maxlength'=>128, 'tl_class'=>'w50'), | ||
'sql' => "varchar(128) NOT NULL default ''" | ||
), | ||
'genre' => array | ||
( | ||
'label' => &$GLOBALS['TL_LANG']['tl_cds']['genre'], | ||
'exclude' => true, | ||
'filter' => true, | ||
'inputType' => 'text', | ||
'eval' => array('mandatory'=>true, 'maxlength'=>32, 'tl_class'=>'w50'), | ||
'sql' => "varchar(32) NOT NULL default ''" | ||
), | ||
'year' => array | ||
( | ||
'label' => &$GLOBALS['TL_LANG']['tl_cds']['year'], | ||
'exclude' => true, | ||
'filter' => true, | ||
'inputType' => 'text', | ||
'eval' => array('mandatory'=>true, 'rgxp'=>'digit', 'maxlength'=>4, 'tl_class'=>'w50'), | ||
'sql' => "varchar(4) NOT NULL default ''" | ||
), | ||
'cover' => array | ||
( | ||
'label' => &$GLOBALS['TL_LANG']['tl_cds']['cover'], | ||
'exclude' => true, | ||
'inputType' => 'fileTree', | ||
'eval' => array('fieldType'=>'radio', 'files'=>true, 'filesOnly'=>true, 'extensions'=>$GLOBALS['TL_CONFIG']['validImageTypes']), | ||
'sql' => "int(10) unsigned NOT NULL default '0'" | ||
), | ||
'description' => array | ||
( | ||
'label' => &$GLOBALS['TL_LANG']['tl_cds']['description'], | ||
'exclude' => true, | ||
'search' => true, | ||
'inputType' => 'textarea', | ||
'eval' => array('rte'=>'tinyMCE'), | ||
'sql' => "text NULL" | ||
) | ||
) | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<?php | ||
|
||
/** | ||
* Add a palette 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'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?php | ||
|
||
/** | ||
* Back end modules | ||
*/ | ||
$GLOBALS['TL_LANG']['MOD']['cd_collection'] = array('CD Collection', 'Add and manage your favourite CDs.'); | ||
|
||
|
||
/** | ||
* Front end modules | ||
*/ | ||
$GLOBALS['TL_LANG']['FMD']['cd_list'] = array('CD List', 'Adds a list of CDs to the website.'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
|
||
/** | ||
* Fields | ||
*/ | ||
$GLOBALS['TL_LANG']['tl_cds']['title'] = array('Title', 'Please enter the album title.'); | ||
$GLOBALS['TL_LANG']['tl_cds']['artist'] = array('Artist name', 'Please enter the artist name.'); | ||
$GLOBALS['TL_LANG']['tl_cds']['genre'] = array('Genre', 'Here you can enter the album genre.'); | ||
$GLOBALS['TL_LANG']['tl_cds']['year'] = array('Year released', 'Here you can enter the year album was released.'); | ||
$GLOBALS['TL_LANG']['tl_cds']['cover'] = array('Cover image', 'Here you can choose an image of the cover.'); | ||
$GLOBALS['TL_LANG']['tl_cds']['description'] = array('Description', 'Here you can enter the album description.'); | ||
|
||
|
||
/** | ||
* Legends | ||
*/ | ||
$GLOBALS['TL_LANG']['tl_cds']['title_legend'] = 'Title and artist'; | ||
$GLOBALS['TL_LANG']['tl_cds']['cover_legend'] = 'Cover and description'; | ||
|
||
|
||
/** | ||
* 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'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
<?php | ||
|
||
namespace Contao; | ||
|
||
/** | ||
* Class ModuleCdList | ||
* | ||
* Front end module "cd list". | ||
*/ | ||
class ModuleCdList extends \Module | ||
{ | ||
|
||
/** | ||
* Template | ||
* @var string | ||
*/ | ||
protected $strTemplate = 'mod_cdlist'; | ||
|
||
|
||
/** | ||
* Display a wildcard in the back end | ||
* @return string | ||
*/ | ||
public function generate() | ||
{ | ||
if (TL_MODE == 'BE') | ||
{ | ||
$objTemplate = new \BackendTemplate('be_wildcard'); | ||
|
||
$objTemplate->wildcard = '### ' . utf8_strtoupper($GLOBALS['TL_LANG']['FMD']['cd_list'][0]) . ' ###'; | ||
$objTemplate->title = $this->headline; | ||
$objTemplate->id = $this->id; | ||
$objTemplate->link = $this->name; | ||
$objTemplate->href = 'contao/main.php?do=themes&table=tl_module&act=edit&id=' . $this->id; | ||
|
||
return $objTemplate->parse(); | ||
} | ||
|
||
return parent::generate(); | ||
} | ||
|
||
|
||
/** | ||
* Generate the module | ||
*/ | ||
protected function compile() | ||
{ | ||
$objCds = $this->Database->execute("SELECT * FROM tl_cds"); | ||
|
||
// Return if no CDs were found | ||
if (!$objCds->numRows) | ||
{ | ||
return; | ||
} | ||
|
||
$arrCds = array(); | ||
|
||
// Generate CDs | ||
while ($objCds->next()) | ||
{ | ||
$strCover = ''; | ||
$objCover = \FilesModel::findByPk($objCds->cover); | ||
|
||
// Add cover image | ||
if ($objCover !== null) | ||
{ | ||
$strCover = \Image::getHtml(\Image::get($objCover->path, '100', '100', 'center_center')); | ||
} | ||
|
||
$arrCds[] = array | ||
( | ||
'title' => $objCds->title, | ||
'artist' => $objCds->artist, | ||
'genre' => $objCds->genre, | ||
'year' => $objCds->year, | ||
'cover' => $strCover, | ||
'description' => $objCds->description | ||
); | ||
} | ||
|
||
$this->Template->cds = $arrCds; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
|
||
<div class="<?php echo $this->class; ?> block"<?php echo $this->cssID; ?><?php if ($this->style): ?> style="<?php echo $this->style; ?>"<?php endif; ?>> | ||
|
||
<?php if ($this->headline): ?> | ||
<<?php echo $this->hl; ?>><?php echo $this->headline; ?></<?php echo $this->hl; ?>> | ||
<?php endif; ?> | ||
|
||
<?php if ($this->cds): foreach ($this->cds as $cd): ?> | ||
<div class="cd"> | ||
<?php if ($cd['cover']): ?><figure class="cover"><?php echo $cd['cover']; ?></figure><?php endif; ?> | ||
|
||
<h3><?php echo $cd['title']; ?></h3> | ||
|
||
<p class="info"><?php echo $cd['artist']; ?> (<?php echo $cd['year']; ?>), <?php echo $cd['genre']; ?></p> | ||
|
||
<?php if ($cd['description']): ?> | ||
<div class="description"> | ||
<?php echo $cd['description']; ?> | ||
</div> | ||
<?php endif; ?> | ||
</div> | ||
<?php endforeach; endif; ?> | ||
|
||
</div> |