<commit_before><?php

class ApiNotesController extends BaseController
{
    use SoftDeletingTrait;

    protected $dates = ['deleted_at'];
    public $restful = true;

    private function getNoteTags($noteId)
    {
        $note = Note::with(array('tags' => function($query){
                                                $query->where('visibility','=',1)
                                                ->orWhere('user_id','=',Auth::user()->id);
                                            }
                                )
                           )
                        ->where('notes.id', '=', $noteId)->first();
        $tags = array();
        foreach ($note->tags as $tag) {
            $tags[] = array(
                'id'         => $tag->id,
                'title'      => $tag->title,
                'visibility' => $tag->visibility
            );
        }
        return $tags;
    }

    private function getNoteVersionsBrief($noteId)
    {
        $note           =
            Note::with('version')->where('notes.id', '=', $noteId)->first();
        $versionsObject = $note->version()->first();
        if (is_null($versionsObject)) {
            return null;
        }

        $versionsArray = [];
        $tmp           = $versionsObject;
        $isLatest      = true;

        $versions = array();
        while (!is_null($tmp)) {
            $versionsArray[] = $tmp;
	    $user=$tmp->user()->first();
            $versions[] = array(
                'id'          => $tmp->id,
                'previous_id' => $tmp->previous_id,
                'next_id'     => $tmp->next_id,
                'latest'      => $isLatest,
                'timestamp'   => $tmp->created_at->getTimestamp(),
		'username'    => $user->firstname.' '.$user->lastname
            );
            $isLatest   = false;
            $tmp        = $tmp->previous()->first();
        }

        return $versions;
    }

    public function index($notebookId)
    {
        // $notes = null;

        // // $notes = DB::table('notes')
        // // 	->join('note_user', function($join) {
        // // 		$join->on('notes.id', '=', 'note_user.note_id')<commit_msg>Hide oldest note version from history<commit_after><?php

class ApiNotesController extends BaseController
{
    use SoftDeletingTrait;

    protected $dates = ['deleted_at'];
    public $restful = true;

    private function getNoteTags($noteId)
    {
        $note = Note::with(array('tags' => function($query){
                                                $query->where('visibility','=',1)
                                                ->orWhere('user_id','=',Auth::user()->id);
                                            }
                                )
                           )
                        ->where('notes.id', '=', $noteId)->first();
        $tags = array();
        foreach ($note->tags as $tag) {
            $tags[] = array(
                'id'         => $tag->id,
                'title'      => $tag->title,
                'visibility' => $tag->visibility
            );
        }
        return $tags;
    }

    private function getNoteVersionsBrief($noteId)
    {
        $note = Note::with('version')->where('notes.id', '=', $noteId)->first();
        $versionsObject = $note->version()->first();
        if (is_null($versionsObject)) {
            return null;
        }

        $versionsArray = [];
        $tmp           = $versionsObject;
        $isLatest      = true;

        $versions = array();
        while (!is_null($tmp)) {
            $versionsArray[] = $tmp;
            $user = $tmp->user()->first();
            $versions[] = array(
                'id'          => $tmp->id,
                'previous_id' => $tmp->previous_id,
                'next_id'     => $tmp->next_id,
                'latest'      => $isLatest,
                'timestamp'   => $tmp->created_at->getTimestamp(),
                'username'    => $user->firstname.' '.$user->lastname
            );
            $isLatest   = false;
            $tmp        = $tmp->previous()->first();
        }

        /**
         * If the note has more than one version, remove the oldest version from
         * the returned history since this is the one automatically created when
         * creating the note and thus is blank.
         */
        $versionsCount = count($versions);
        if ($versionsCount > 1) {
            unset($versions[$versionsCount - 1]);
        }

        return $versions;
    }

    public function index($notebookId)
    {
        // $notes = null;

        // // $notes = DB::table('notes')
        // // 	->join('note_user', function($join) {
        // // 		$join->on('notes.id', '=', 'note_user.note_id')
{'fraction_non_alphanumeric': 0.15901882004652146, 'fraction_numerical': 0.0008458447874814971, 'mean_word_length': 1.3231827111984282, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 76, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1457749', 'n_tokens_mistral': 1290, 'n_tokens_neox': 1246, 'n_words': 233}