Skip to content

Commit

Permalink
*8253* Introduced method to retrieve context objects by settings
Browse files Browse the repository at this point in the history
  • Loading branch information
beghelli committed Jun 10, 2013
1 parent cefdace commit 648deb9
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions classes/context/ContextDAO.inc.php
Expand Up @@ -125,6 +125,30 @@ function getAll($enabledOnly = false, $rangeInfo = null) {
return new DAOResultFactory($result, $this, '_fromRow');
}

/**
* Get journals by setting.
* @param $settingName string
* @param $settingValue mixed
* @param $contextId int
* @return DAOResultFactory
*/
function getBySetting($settingName, $settingValue, $contextId = null) {
$params = array($settingName, $settingValue);
if ($contextId) $params[] = $contextId;

$result = $this->retrieve(
'SELECT * FROM ' . $this->_getTableName() . 'AS c
LEFT JOIN ' . $this->_getSettingsTableName() . 'AS cs
ON c.' . $this->_getPrimaryKeyColumn() . ' = cs.' . $this->_getPrimaryKeyColumn() .
'WHERE cs.setting_name = ? AND cs.setting_value = ?' .
($contextId?' AND c.' . $this->_getPrimaryKeyColumn() . ' = ?':''),
$params
);

return new DAOResultFactory($result, $this, '_fromRow');
}


/**
* Get the ID of the last inserted context.
* @return int
Expand Down

0 comments on commit 648deb9

Please sign in to comment.