/**
  * Checks whether a condition (saved search) is fulfilled by the
  * given document.
  *
  * For example, a condition may require a specific value in a
  * metadata field.
  *
  * Returns either true or false (or a PEAR Error object)
  */
 function testConditionOnDocument($oSearch, $oDocument)
 {
     $oSearch =& KTUtil::getObject('KTSavedSearch', $oSearch);
     $iDocumentId = KTUtil::getId($oDocument);
     /*
      * Make a new criteria set, an AND of the existing criteria set
      * and the sql statement requiring that D.id be the document id
      * given to us.
      */
     $aCriteriaSet = array("join" => "AND", "subgroup" => array($oSearch->getSearch(), array("join" => "AND", "values" => array(array("sql" => array("D.id = ?", array($iDocumentId)))))));
     $aOptions = array('select' => 'COUNT(DISTINCT(D.id)) AS cnt');
     $aQuery = KTSearchUtil::criteriaToQuery($aCriteriaSet, null, null, $aOptions);
     if (PEAR::isError($aQuery)) {
         // caused by no permissions being set.
         return false;
     }
     $cnt = DBUtil::getOneResultKey($aQuery, 'cnt');
     if (PEAR::isError($cnt)) {
         return $cnt;
     }
     if (is_null($cnt)) {
         return false;
     }
     if (!is_numeric($cnt)) {
         return PEAR::raiseError(_kt("Non-integer returned when looking for count"));
     }
     return $cnt > 0;
 }
 function getBaseQuery($aOptions)
 {
     $aCriteriaSet = array('join' => 'AND', 'subgroup' => array(0 => array('join' => 'AND', 'values' => array(1 => array('data' => array('ktcore.criteria.tagcloud' => $this->sTag, 'ktcore.criteria.tagcloud_not' => 0), 'type' => 'ktcore.criteria.tagcloud')))));
     $aQuery = KTSearchUtil::criteriaToQuery($aCriteriaSet, $this->oUser, 'ktcore.permissions.read', $aOptions);
     return $aQuery;
 }
 function getQuery($aOptions = null)
 {
     $oUser = User::get($_SESSION['userID']);
     return KTSearchUtil::criteriaToQuery($this->datavars, $oUser, 'ktcore.permissions.read', $aOptions);
 }