Files
contao-leaflet-maps/src/Model/AbstractActiveModel.php

67 lines
1.7 KiB
PHP
Raw Normal View History

2015-01-09 11:53:58 +01:00
<?php
/**
2017-10-05 15:45:43 +02:00
* Leaflet maps for Contao CMS.
*
2016-10-11 10:40:15 +02:00
* @package contao-leaflet-maps
2015-01-09 11:53:58 +01:00
* @author David Molineus <david.molineus@netzmacht.de>
2017-10-05 15:45:43 +02:00
* @copyright 2016-2017 netzmacht David Molineus. All rights reserved.
* @license LGPL-3.0 https://github.com/netzmacht/contao-leaflet-maps/blob/master/LICENSE
2015-01-09 11:53:58 +01:00
* @filesource
*/
namespace Netzmacht\Contao\Leaflet\Model;
2015-01-12 19:03:29 +01:00
/**
* Class AbstractActiveModel is the base model for models with an active field.
*
* @package Netzmacht\Contao\Leaflet\Model
*/
2015-01-09 15:24:34 +01:00
abstract class AbstractActiveModel extends \Model
2015-01-09 11:53:58 +01:00
{
/**
2015-01-12 19:03:29 +01:00
* Find an active model by its model id.
2015-01-09 11:53:58 +01:00
*
2015-01-12 19:03:29 +01:00
* @param int $modelId The model id.
* @param array $options The query options.
2015-01-09 11:53:58 +01:00
*
* @return \Model|null
*/
public static function findActiveByPK($modelId, $options = array())
{
return static::findOneBy('active=1 AND id', $modelId, $options);
}
/**
2015-01-12 19:03:29 +01:00
* Find active models by a defined column.
2015-01-09 11:53:58 +01:00
*
2015-01-12 19:03:29 +01:00
* @param string|array $column The query columns.
* @param mixed $value The column value.
* @param array $options The options.
2015-01-09 11:53:58 +01:00
*
* @return \Model|null
*/
2015-01-09 15:24:34 +01:00
public static function findActiveBy($column, $value, $options = array())
2015-01-09 11:53:58 +01:00
{
2015-01-12 19:03:29 +01:00
if (is_array($column)) {
$column[] = 'active=1';
} else {
$column = 'active=1 AND ' . $column;
}
return static::findBy($column, $value, $options);
2015-01-09 11:53:58 +01:00
}
2015-01-12 19:03:29 +01:00
/**
* Find collection activated models.
*
* @param array $options The query options.
*
* @return \Model\Collection|null
*/
public static function findActives($options = array())
2015-01-09 11:53:58 +01:00
{
return static::findBy('active', '1', $options);
}
}