Evernote\Client::findNotes_processResultsWithContext PHP Method

findNotes_processResultsWithContext() protected method

protected findNotes_processResultsWithContext ( $context )
    protected function findNotes_processResultsWithContext($context)
    {
        // OK, now we have a complete list of note refs objects. If we need to do a local sort, then do so.
        if ($context->requiresLocalMerge) {
            if ($this->isFlagSet($context->sortOrder, self::SORT_ORDER_RECENTLY_CREATED)) {
                return usort($context->findMetadataResults, array($this, 'compareByCreated'));
            } elseif ($this->isFlagSet($context->sortOrder, self::SORT_ORDER_RECENTLY_UPDATED)) {
                return usort($context->findMetadataResults, array($this, 'compareByUpdated'));
            } else {
                return usort($context->findMetadataResults, array($this, 'compareByTitle'));
            }
        }
        // Prepare a dictionary of all notebooks by GUID so lookup below is fast.
        $notebooksByGuid = array();
        if (!$context->scopeNotebook) {
            foreach ($context->allNotebooks as $notebook) {
                $notebooksByGuid[$notebook->guid] = $notebook;
            }
        }
        $findNotesResults = array();
        // Turn the metadata list into a list of note refs.
        foreach ($context->findMetadataResults as $metadata) {
            $result = new SearchResult();
            $result->guid = $metadata->guid;
            // Figure out which notebook this note belongs to. (If there's a scope notebook, it always belongs to that one.)
            $notebook = $context->scopeNotebook ?: $notebooksByGuid[$metadata->notebookGuid];
            if (!$notebook) {
                // This is probably a business notebook that we haven't explicitly joined, so we don't have it in our list.
                if (!array_key_exists($metadata->guid, $context->resultGuidsFromBusiness)) {
                    //TODO
                    // Oh, it's not from the business. We really can't find it. This is an error.
                    //ENSDKLogError(@"Found note metadata but can't determine owning notebook by guid. Metadata = %@", metadata);
                }
                continue;
            }
            if ($notebook->isBusinessNotebook()) {
                $result->type = self::BUSINESS_NOTE;
            } elseif ($notebook->isLinkedNotebook()) {
                $result->type = self::SHARED_NOTE;
            } else {
                $result->type = self::PERSONAL_NOTE;
            }
            //$result->notebook          = $notebook;
            $result->title = $metadata->title;
            $result->created = $metadata->created;
            $result->updated = $metadata->updated;
            $result->updateSequenceNum = $metadata->updateSequenceNum;
            $findNotesResults[] = $result;
            // If the caller specified a max result count, and we've reached it, then stop fixing up
            // results here.
            if ($context->maxResults > 0 && count($findNotesResults) >= $context->maxResults) {
                break;
            }
        }
        return $findNotesResults;
    }