diff --git a/protected/components/HActiveRecordContent.php b/protected/components/HActiveRecordContent.php index 4753d6bf39..45cbec8620 100644 --- a/protected/components/HActiveRecordContent.php +++ b/protected/components/HActiveRecordContent.php @@ -74,7 +74,6 @@ class HActiveRecordContent extends HActiveRecord { return $objectModel . " (" . $this->id . ")"; } - /** * If the content should also displayed on a wall, overwrite this * method and produce a wall output. @@ -168,6 +167,27 @@ class HActiveRecordContent extends HActiveRecord { return parent::hasErrors() || $this->content->hasErrors(); } + /** + * Scope to limit for a given content container + * + * @param HActiveRecordContentContainer $container + */ + public function contentContainer($container) { + + $criteria = new CDbCriteria(); + $criteria->join = "LEFT JOIN content ON content.object_model='" . get_class($this) . "' AND content.object_id=t." . $this->tableSchema->primaryKey; + + $containerClass = get_class($container); + if ($containerClass == 'Space') { + $criteria->condition = 'content.space_id=' . $container->id; + } elseif ($containerClass == 'User') { + $criteria->condition = 'content.user_id=' . $container->id; + } + $this->getDbCriteria()->mergeWith($criteria); + + return $this; + } + } ?>