Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 59 additions & 4 deletions models/Table/ItemRelationsRelation.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,12 @@ public function getSelect()
*
* @param integer $subjectItemId
* @param boolean $onlyExistingObjectItems
* @param integer|array $propertyId
* @return array
*/
public function findBySubjectItemId($subjectItemId, $onlyExistingObjectItems = true)
public function findBySubjectItemId($subjectItemId, $onlyExistingObjectItems = true, $propertyId = null)
{
$db = $this->getDb();
$db = $this->_db;
$select = $this->getSelect()
->where('item_relations_relations.subject_item_id = ?', (int) $subjectItemId);
if ($onlyExistingObjectItems) {
Expand All @@ -58,6 +59,17 @@ public function findBySubjectItemId($subjectItemId, $onlyExistingObjectItems = t
array()
);
}
if ($propertyId) {
if (is_array($propertyId)) {
$select
->where('item_relations_relations.property_id IN (?)', array_map('intval', $propertyId));
}
// Single property.
else{
$select
->where('item_relations_relations.property_id = ?', (int) $propertyId);
}
}
return $this->fetchObjects($select);
}

Expand All @@ -66,11 +78,12 @@ public function findBySubjectItemId($subjectItemId, $onlyExistingObjectItems = t
*
* @param integer $objectItemId
* @param boolean $onlyExistingSubjectItems
* @param integer|array $propertyId
* @return array
*/
public function findByObjectItemId($objectItemId, $onlyExistingSubjectItems = true)
public function findByObjectItemId($objectItemId, $onlyExistingSubjectItems = true, $propertyId = null)
{
$db = $this->getDb();
$db = $this->_db;
$select = $this->getSelect()
->where('item_relations_relations.object_item_id = ?', (int) $objectItemId);
if ($onlyExistingSubjectItems) {
Expand All @@ -80,6 +93,48 @@ public function findByObjectItemId($objectItemId, $onlyExistingSubjectItems = tr
array()
);
}
if ($propertyId) {
if (is_array($propertyId)) {
$select
->where('item_relations_relations.property_id IN (?)', array_map('intval', $propertyId));
}
// Single property.
else{
$select
->where('item_relations_relations.property_id = ?', (int) $propertyId);
}
}
return $this->fetchObjects($select);
}

/**
* Find all specified relations.
*
* @internal This is a short for findBy().
*
* @param integer|array $objectItemId
* @param integer|array $propertyId
* @param integer|array $subjectItemId
* @return array
*/
public function findRelations($subjectItemId = null, $propertyId = null, $objectItemId = null)
{
$params = array();
if (!is_null($subjectItemId)) {
$params['subject_item_id'] = is_array($subjectItemId)
? array_map('intval', $subjectItemId)
: (integer) $subjectItemId;
}
if (!is_null($propertyId)) {
$params['property_id'] = is_array($propertyId)
? array_map('intval', $propertyId)
: (integer) $propertyId;
}
if (!is_null($objectItemId)) {
$params['object_item_id'] = is_array($objectItemId)
? array_map('intval', $objectItemId)
: (integer) $objectItemId;
}
return $this->findBy($params);
}
}