function getByAttributes($criteria, $parent = DATATREE_ROOT, $allLevels = true, $restrict = 'name', $from = 0, $count = 0, $sortby_name = null, $sortby_key = null, $direction = 0) { if (!count($criteria)) { return PEAR::raiseError('no criteria'); } // Use Criteria one by one until we find results ikoutsil 21/8/06 foreach ($criteria as $key => $vals) { if ($key == 'OR' ) { $num_or_statements=count($criteria[$key]); for ($i=0; $i<$num_or_statements; $i++) { $criteria_or=$criteria['OR'][$i]; list($query, $values) = $this->buildAttributeQuery( $criteria_or, $parent, $allLevels, $restrict, DATATREE_BUILD_SELECT, $sortby_name, $sortby_key, $direction); if ($count) { $query = $this->_db->modifyLimitQuery($query, $from, $count); if (is_a($query, 'PEAR_Error')) { return $query; } } // Horde::logMessage('SQL Query by DataTree_sql::getByAttributes(): ' . $query, __FILE__, __LINE__, PEAR_LOG_NOTICE); $result = $this->_db->query($query, $values); if (is_a($result, 'PEAR_Error')) { Horde::logMessage($result, __FILE__, __LINE__, PEAR_LOG_ERR); return $result; } $rows = array(); while ($row = &$result->fetchRow()) { $rows[$row[0]] = String::convertCharset($row[1], $this->_params['charset']); } if ( count($rows)>0 || $i==$num_or_statements-1 ) return $rows; } } } //Default Horde Code Goes Here list($query, $values) = $this->buildAttributeQuery($criteria, $parent, $allLevels, $restrict, DATATREE_BUILD_SELECT, $sortby_name, $sortby_key, $direction); if ($count) { $query = $this->_db->modifyLimitQuery($query, $from, $count); if (is_a($query, 'PEAR_Error')) { return $query; } } Horde::logMessage('SQL Query by DataTree_sql::getByAttributes(): ' . $query, __FILE__, __LINE__, PEAR_LOG_DEBUG); $result = $this->_db->query($query, $values); if (is_a($result, 'PEAR_Error')) { Horde::logMessage($result, __FILE__, __LINE__, PEAR_LOG_ERR); return $result; } $rows = array(); while ($row = &$result->fetchRow()) { $rows[$row[0]] = String::convertCharset($row[1], $this->_params['charset']); } return $rows; }