*/ class RealEstateAssetsModel extends Model { /** * Table name * @var string */ protected static $strTable = 'tl_vr_real_estate_assets'; /** * Find a published assets from one or more categories * * @param mixed $varId The numeric id or alias name * @param array $arrOptions An optional options array * * @return RealEstateAssetsModel|null A model or null if there is no asset */ public static function findPublishedByIdOrAlias($varId, array $arrOptions = array()) { $t = static::$strTable; $arrColumns = !preg_match('/^[1-9]\d*$/', $varId) ? array("BINARY $t.alias=?") : array("$t.id=?"); if (!static::isPreviewMode($arrOptions)) { $time = Date::floorToMinute(); $arrColumns[] = "$t.published='1' AND ($t.start='' OR $t.start<='$time') AND ($t.stop='' OR $t.stop>'$time')"; } return static::findOneBy($arrColumns, $varId, $arrOptions); } /** * Find a published assets from one or more categories * * @param array $arrPids An array of parent IDs * @param integer $intLimit An optional limit * @param integer $intOffset An optional offset * @param array $arrOptions An optional options array * * @return Collection|RealEstateAssetsModel[]|RealEstateAssetsModel|null A collection of models or null if there are no assets */ public static function findPublishedByParent($arrPids, $intLimit = 0, $intOffset = 0, array $arrOptions = array()) { if (empty($arrPids) || !\is_array($arrPids)) { return null; } $t = static::$strTable; $arrColumns = ["$t.pid IN(" . implode(',', array_map('\intval', $arrPids)) . ")"]; $arrValues = []; if (!static::isPreviewMode($arrOptions)) { $time = Date::floorToMinute(); $arrColumns[] = "$t.published='1' AND ($t.start='' OR $t.start<='$time') AND ($t.stop='' OR $t.stop>'$time')"; } if (!isset($arrOptions['order'])) { $arrOptions['order'] = "FIELD($t.pid," . implode(',', $arrPids) . "), $t.title ASC, $t.livingSpace ASC"; } $arrOptions['limit'] = $intLimit; $arrOptions['offset'] = $intOffset; if (isset($arrOptions['column'])) { $arrColumns = array_merge($arrColumns,$arrOptions['column']); } if (isset($arrOptions['value'])) { $arrValues = array_merge($arrValues,$arrOptions['value']); } return static::findBy($arrColumns, $arrValues, $arrOptions); } /** * Find a published assets from one or more categories * * @param array $arrPids An array of parent IDs * @param array $arrOptions An optional options array * * @return integer The number of matching rows */ public static function countPublishedByParent($arrPids, array $arrOptions = array()) { if (empty($arrPids) || !\is_array($arrPids)) { return 0; } $t = static::$strTable; $arrColumns = ["$t.pid IN(" . implode(',', array_map('\intval', $arrPids)) . ")"]; $arrValues = []; if (!static::isPreviewMode($arrOptions)) { $time = Date::floorToMinute(); $arrColumns[] = "$t.published='1' AND ($t.start='' OR $t.start<='$time') AND ($t.stop='' OR $t.stop>'$time')"; } if (isset($arrOptions['column'])) { $arrColumns = array_merge($arrColumns,$arrOptions['column']); } if (isset($arrOptions['value'])) { $arrValues = array_merge($arrValues,$arrOptions['value']); } return static::countBy($arrColumns, $arrValues, $arrOptions); } }