Ejemplo n.º 1
0
function doSearch($index, $queryString, $start = 0, $amount = 20)
{
    global $current_user;
    $cachePath = 'cache/modules/AOD_Index/QueryCache/' . md5($queryString);
    if (is_file($cachePath)) {
        $mTime = getCorrectMTime($cachePath);
        if ($mTime > time() - 5 * 60) {
            $hits = unserialize(sugar_file_get_contents($cachePath));
        }
    }
    if (!isset($hits)) {
        $tmphits = $index->find($queryString);
        $hits = array();
        foreach ($tmphits as $hit) {
            $bean = BeanFactory::getBean($hit->record_module, $hit->record_id);
            if (empty($bean)) {
                continue;
            }
            if ($bean->bean_implements('ACL') && !is_admin($current_user)) {
                //Annoyingly can't use the following as it always passes true for is_owner checks on list
                //$bean->ACLAccess('list');
                $in_group = SecurityGroup::groupHasAccess($bean->module_dir, $bean->id, 'list');
                $is_owner = $bean->isOwner($current_user->id);
                $access = ACLController::checkAccess($bean->module_dir, 'list', $is_owner, 'module', $in_group);
                if (!$access) {
                    continue;
                }
            }
            $newHit = new stdClass();
            $newHit->record_module = $hit->record_module;
            $newHit->record_id = $hit->record_id;
            $newHit->score = $hit->score;
            $newHit->label = getModuleLabel($bean->module_name);
            $newHit->name = $bean->get_summary_text();
            $newHit->summary = getRecordSummary($bean);
            $newHit->date_entered = $bean->date_entered;
            $newHit->date_modified = $bean->date_modified;
            $hits[] = $newHit;
        }
        //Cache results so pagination is nice and snappy.
        cacheQuery($queryString, $hits);
    }
    $total = count($hits);
    $hits = array_slice($hits, $start, $amount);
    $res = array('total' => $total, 'hits' => $hits);
    return $res;
}
Ejemplo n.º 2
0
?>
            </div>
        </th>
        <th scope='col' width='10%' >
            <div style='white-space: nowrap;'width='100%' align='left'>
                <?php 
echo translate("LBL_SEARCH_RESULT_SCORE", "AOD_Index");
?>
            </div>
        </th>
    </tr>
    <?php 
if ($hits) {
    foreach ($hits as $hit) {
        $bean = BeanFactory::getBean($hit->record_module, $hit->record_id);
        echo "<tr>" . "<td>" . getModuleLabel($bean->module_name) . "</td>" . "<td><a href='index.php?module=" . $hit->record_module . "&action=DetailView&record=" . $hit->record_id . "'>" . $bean->get_summary_text() . "</a></td>" . "<td>" . getRecordSummary($bean) . "</td>" . "<td>" . $bean->date_entered . "</td>" . "<td>" . $bean->date_modified . "</td>" . "<td>" . getScoreDisplay($hit) . "</td>" . "</tr>";
    }
} else {
    echo "<tr><td>" . translate("LBL_SEARCH_RESULT_EMPTY", "AOD_Index") . "</td></td>";
}
?>
</table>

<?php 
function getRecordSummary(SugarBean $bean)
{
    global $listViewDefs;
    if (!isset($listViewDefs) || !isset($listViewDefs[$bean->module_dir])) {
        if (file_exists('custom/modules/' . $bean->module_dir . '/metadata/listviewdefs.php')) {
            require 'custom/modules/' . $bean->module_dir . '/metadata/listviewdefs.php';
        } else {