Skip to content

Commit

Permalink
Merge pull request #1 from contao-estatemanager/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
doishub authored Nov 29, 2021
2 parents ae3f6ea + 7ba818f commit d4616a9
Show file tree
Hide file tree
Showing 10 changed files with 91 additions and 47 deletions.
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
"license":"MIT",
"authors":[
{
"name":"Oveleon",
"homepage":"https://oveleon.de/",
"name":"Daniele Sciannimanica",
"homepage":"https://github.com/doishub",
"role":"Developer"
}
],
Expand Down
3 changes: 1 addition & 2 deletions src/ContaoManager/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ public function getBundles(ParserInterface $parser): array
{
return [
BundleConfig::create(ObjectTypeEntity::class)
->setLoadAfter([ContaoCoreBundle::class])
->setReplace(['object-type-entity']),
->setLoadAfter([ContaoCoreBundle::class])
];
}
}
12 changes: 8 additions & 4 deletions src/Resources/contao/classes/ObjectType.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,24 @@

namespace ContaoEstateManager\ObjectTypeEntity;

class ObjectType extends \Backend
use Contao\Backend;
use Contao\DataContainer;
use Contao\StringUtil;

class ObjectType extends Backend
{

/**
* Save connection from save callback
*
* @param $varValue
* @param \DataContainer $dc
* @param DataContainer $dc
*
* @return string
*/
public function objectTypeConnectionSaveCallback($varValue, \DataContainer $dc)
public function objectTypeConnectionSaveCallback($varValue, DataContainer $dc)
{
$arrObjectTypes = \StringUtil::deserialize($varValue);
$arrObjectTypes = StringUtil::deserialize($varValue);

// delete previous connections
ObjectTypeConnectionModel::deleteByPidAndPtable($dc->activeRecord->id, $dc->table);
Expand Down
12 changes: 6 additions & 6 deletions src/Resources/contao/config/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
*/

// Back end modules
$GLOBALS['BE_MOD']['system']['objectTypes'] = array('tables' => array('tl_object_type', 'tl_object_type_connection'));
$GLOBALS['BE_MOD']['content']['objectTypes'] = array
(
'tables' => array('tl_object_type', 'tl_object_type_connection')
);

// Models
$GLOBALS['TL_MODELS']['tl_object_type'] = '\\ContaoEstateManager\\ObjectTypeEntity\\ObjectTypeModel';
$GLOBALS['TL_MODELS']['tl_object_type_connection'] = '\\ContaoEstateManager\\ObjectTypeEntity\\ObjectTypeConnectionModel';

// Add permissions
$GLOBALS['TL_PERMISSIONS'][] = 'objectTypes';
$GLOBALS['TL_MODELS']['tl_object_type'] = 'ContaoEstateManager\ObjectTypeEntity\ObjectTypeModel';
$GLOBALS['TL_MODELS']['tl_object_type_connection'] = 'ContaoEstateManager\ObjectTypeEntity\ObjectTypeConnectionModel';
44 changes: 24 additions & 20 deletions src/Resources/contao/dca/tl_object_type.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
'mode' => 2,
'fields' => array('title'),
'flag' => 1,
'panelLayout' => 'sort,search,limit'
'panelLayout' => 'filter;sort,search,limit'
),
'label' => array
(
Expand Down Expand Up @@ -93,13 +93,18 @@
(
'sql' => "int(10) unsigned NOT NULL auto_increment"
),
'vid' => array
(
'sql' => "varchar(255) NOT NULL default ''"
),
'tstamp' => array
(
'sql' => "int(10) unsigned NOT NULL default '0'",
'sorting' => true
'sorting' => true,
'sql' => "int(10) unsigned NOT NULL default '0'"
),
'title' => array
(
'label' => &$GLOBALS['TL_LANG']['tl_object_type']['title'],
'exclude' => true,
'search' => true,
'sorting' => true,
Expand All @@ -110,6 +115,7 @@
),
'published' => array
(
'label' => &$GLOBALS['TL_LANG']['tl_object_type']['published'],
'exclude' => true,
'filter' => true,
'inputType' => 'checkbox',
Expand All @@ -119,23 +125,21 @@
)
);


/**
* Provide miscellaneous methods that are used by the data configuration array.
*
* @author Daniele Sciannimanica <https://github.com/doishub>
*/

use ContaoEstateManager\ObjectTypeEntity\ObjectTypeModel;

class tl_object_type extends \Backend
class tl_object_type extends Contao\Backend
{
/**
* Import the back end user object
*/
public function __construct()
{
parent::__construct();
$this->import('BackendUser', 'User');
$this->import('Contao\BackendUser', 'User');
}


Expand All @@ -151,11 +155,11 @@ public function __construct()
*
* @return string
*/
public function toggleIcon($row, $href, $label, $title, $icon, $attributes)
public function toggleIcon(array $row, ?string $href, string $label, string $title, string $icon, string $attributes): string
{
if (\Input::get('tid'))
if (Contao\Input::get('tid'))
{
$this->toggleVisibility(\Input::get('tid'), (\Input::get('state') == 1), (@func_get_arg(12) ?: null));
$this->toggleVisibility(Contao\Input::get('tid'), (Contao\Input::get('state') == 1), (@func_get_arg(12) ?: null));
$this->redirect($this->getReferer());
}

Expand All @@ -172,28 +176,28 @@ public function toggleIcon($row, $href, $label, $title, $icon, $attributes)
$icon = 'invisible.svg';
}

if (!$this->User->hasAccess('objectTypes', 'alpty') || ($objObjectType = ObjectTypeModel::findById($row['id'])) === null)
if (!$this->User->hasAccess('objectTypes', 'alpty') || ($objObjectType = ContaoEstateManager\ObjectTypeEntity\ObjectTypeModel::findById($row['id'])) === null)
{
return \Image::getHtml($icon) . ' ';
return Contao\Image::getHtml($icon) . ' ';
}

return '<a href="' . $this->addToUrl($href) . '" title="' . \StringUtil::specialchars($title) . '"' . $attributes . '>' . \Image::getHtml($icon, $label, 'data-state="' . ($row['published'] ? 1 : 0) . '"') . '</a> ';
return '<a href="' . $this->addToUrl($href) . '" title="' . Contao\StringUtil::specialchars($title) . '"' . $attributes . '>' . Contao\Image::getHtml($icon, $label, 'data-state="' . ($row['published'] ? 1 : 0) . '"') . '</a> ';
}

/**
* Disable/enable a user group
*
* @param integer $intId
* @param boolean $blnVisible
* @param \DataContainer $dc
* @param Contao\DataContainer $dc
*
* @throws \CoreBundle\Exception\AccessDeniedException
* @throws Contao\CoreBundle\Exception\AccessDeniedException
*/
public function toggleVisibility($intId, $blnVisible, \DataContainer $dc=null)
public function toggleVisibility(int $intId, bool $blnVisible, Contao\DataContainer $dc=null): void
{
// Set the ID and action
\Input::setGet('id', $intId);
\Input::setGet('act', 'toggle');
Contao\Input::setGet('id', $intId);
Contao\Input::setGet('act', 'toggle');

if ($dc)
{
Expand All @@ -220,7 +224,7 @@ public function toggleVisibility($intId, $blnVisible, \DataContainer $dc=null)
// Check the field access
if (!$this->User->hasAccess('tl_object_type::published', 'alexf'))
{
throw new \CoreBundle\Exception\AccessDeniedException('Not enough permissions to publish/unpublish object type ID ' . $intId . '.');
throw new Contao\CoreBundle\Exception\AccessDeniedException('Not enough permissions to publish/unpublish object type ID ' . $intId . '.');
}

// Set the current record
Expand Down
2 changes: 1 addition & 1 deletion src/Resources/contao/dca/tl_object_type_connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
),
'oid' => array
(
'label' => array('Object type ID'),
'search' => true,
'sql' => "int(10) unsigned NOT NULL default 0"
),
Expand All @@ -87,7 +88,6 @@
),
'ptable' => array
(
'exclude' => true,
'search' => true,
'sorting' => true,
'flag' => 1,
Expand Down
17 changes: 17 additions & 0 deletions src/Resources/contao/languages/de/tl_object_type.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,23 @@
<source>Publishing</source>
<target>Veröffentlichung</target>
</trans-unit>

<trans-unit id="tl_object_type.title.0">
<source>Title</source>
<target>Titel</target>
</trans-unit>
<trans-unit id="tl_object_type.title.1">
<source>Enter the title of the object type here</source>
<target>Geben Sie hier den Titel des Objekttypen an</target>
</trans-unit>
<trans-unit id="tl_object_type.published.0">
<source>publish</source>
<target>veröffentlicht</target>
</trans-unit>
<trans-unit id="tl_object_type.published.1">
<source>Specify here whether the object type is published</source>
<target>Geben Sie hier an, ob der Objekttyp veröffentlicht ist</target>
</trans-unit>
</body>
</file>
</xliff>
13 changes: 13 additions & 0 deletions src/Resources/contao/languages/en/tl_object_type.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,19 @@
<trans-unit id="tl_object_type.publish_legend">
<source>Publishing</source>
</trans-unit>

<trans-unit id="tl_object_type.title.0">
<source>Title</source>
</trans-unit>
<trans-unit id="tl_object_type.title.1">
<source>Enter the title of the object type here</source>
</trans-unit>
<trans-unit id="tl_object_type.published.0">
<source>publish</source>
</trans-unit>
<trans-unit id="tl_object_type.published.1">
<source>Specify here whether the object type is published</source>
</trans-unit>
</body>
</file>
</xliff>
13 changes: 8 additions & 5 deletions src/Resources/contao/models/ObjectTypeConnectionModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

namespace ContaoEstateManager\ObjectTypeEntity;

use Contao\Database;
use Contao\Model;

/**
* Reads and writes object type connections
*
Expand All @@ -13,17 +16,17 @@
* @method static ObjectTypeConnectionModel|null findOneByPid($id, array $opt=array())
* @method static ObjectTypeConnectionModel|null findOneByPtable($id, array $opt=array())
*
* @method static \Model\Collection|ObjectTypeConnectionModel[]|ObjectTypeConnectionModel|null findByOid($val, array $opt=array())
* @method static \Model\Collection|ObjectTypeConnectionModel[]|ObjectTypeConnectionModel|null findByPid($val, array $opt=array())
* @method static \Model\Collection|ObjectTypeConnectionModel[]|ObjectTypeConnectionModel|null findByPtable($val, array $opt=array())
* @method static Model\Collection|ObjectTypeConnectionModel[]|ObjectTypeConnectionModel|null findByOid($val, array $opt=array())
* @method static Model\Collection|ObjectTypeConnectionModel[]|ObjectTypeConnectionModel|null findByPid($val, array $opt=array())
* @method static Model\Collection|ObjectTypeConnectionModel[]|ObjectTypeConnectionModel|null findByPtable($val, array $opt=array())
*
* @method static integer countByOid($id, array $opt=array())
* @method static integer countByPid($val, array $opt=array())
* @method static integer countByPtable($val, array $opt=array())
*
* @author Daniele Sciannimanica <https://github.com/doishub>
*/
class ObjectTypeConnectionModel extends \Model
class ObjectTypeConnectionModel extends Model
{

/**
Expand All @@ -42,7 +45,7 @@ public static function deleteByPidAndPtable($pid, $ptable)
{
$strTable = static::$strTable;

$objDatabase = \Database::getInstance();
$objDatabase = Database::getInstance();
$objDatabase->prepare('DELETE FROM ' . $strTable . ' WHERE pid=' . $pid . ' AND ptable="' . $ptable . '"')->execute();
}
}
18 changes: 11 additions & 7 deletions src/Resources/contao/models/ObjectTypeModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@

namespace ContaoEstateManager\ObjectTypeEntity;

use Contao\Model;

/**
* Reads and writes object types
*
* @property integer $id
* @property string $vid
* @property integer $tstamp
* @property string $title
* @property boolean $published
Expand All @@ -17,12 +20,13 @@
* @method static ObjectTypeModel|null findOneByTitle($val, array $opt=array())
* @method static ObjectTypeModel|null findOneByPublished($val, array $opt=array())
*
* @method static \Model\Collection|ObjectTypeModel[]|ObjectTypeModel|null findByTstamp($val, array $opt=array())
* @method static \Model\Collection|ObjectTypeModel[]|ObjectTypeModel|null findByTitle($val, array $opt=array())
* @method static \Model\Collection|ObjectTypeModel[]|ObjectTypeModel|null findByPublished($val, array $opt=array())
* @method static \Model\Collection|ObjectTypeModel[]|ObjectTypeModel|null findMultipleByIds($var, array $opt=array())
* @method static \Model\Collection|ObjectTypeModel[]|ObjectTypeModel|null findBy($col, $val, array $opt=array())
* @method static \Model\Collection|ObjectTypeModel[]|ObjectTypeModel|null findAll(array $opt=array())
* @method static Model\Collection|ObjectTypeModel[]|ObjectTypeModel|null findByVid($val, array $opt=array())
* @method static Model\Collection|ObjectTypeModel[]|ObjectTypeModel|null findByTstamp($val, array $opt=array())
* @method static Model\Collection|ObjectTypeModel[]|ObjectTypeModel|null findByTitle($val, array $opt=array())
* @method static Model\Collection|ObjectTypeModel[]|ObjectTypeModel|null findByPublished($val, array $opt=array())
* @method static Model\Collection|ObjectTypeModel[]|ObjectTypeModel|null findMultipleByIds($var, array $opt=array())
* @method static Model\Collection|ObjectTypeModel[]|ObjectTypeModel|null findBy($col, $val, array $opt=array())
* @method static Model\Collection|ObjectTypeModel[]|ObjectTypeModel|null findAll(array $opt=array())
*
* @method static integer countById($id, array $opt=array())
* @method static integer countByTitle($val, array $opt=array())
Expand All @@ -31,7 +35,7 @@
*
* @author Daniele Sciannimanica <https://github.com/doishub>
*/
class ObjectTypeModel extends \Model
class ObjectTypeModel extends Model
{

/**
Expand Down

0 comments on commit d4616a9

Please sign in to comment.