Search code examples
yiifullcalendar-scheduler

Yii changing functionality of fullcalendar-scheduler


I'am using fullcalendarscheduler widget posted on github by Edofre im my yii2 project. Is there any way i could change predefined rooms displayed in the table into a data from the database.

How it looks now:

'resources'         => [
        ['id' => 'a', 'title' => 'Auditorium A'],
        ['id' => 'b', 'title' => 'Auditorium B', 'eventColor' => 'green'],
        ['id' => 'c', 'title' => 'Auditorium C', 'eventColor' => 'orange'],
        [
            'id'       => 'd', 'title' => 'Auditorium D',
            'children' => [
                ['id' => 'd1', 'title' => 'Room D1'],
                ['id' => 'd2', 'title' => 'Room D2'],
            ],
        ],
        ['id' => 'e', 'title' => 'Auditorium E'],

    ],

How i could imagine this would work:

'resources' => [
    foreach ($rooms as $key) {
        ['id' => $rooms[$key]->id, 'title' => $rooms[$key]->room],
    }
],

Edit: I have learned that i can return data using function:

$model = Workers::findAll(['user_id' => 16]);
         $table=[];
         foreach ($model as $key) {
             $work = new Resource(["id" => "a", "title" => $key->imie]);
             $table = $work;
         }

        return [
                $table,
            ];
        }

But its only displaying the last record from the table. What should i do to display entire table with $table variable?


Solution

  • $model = Workers::findAll(['user_id' => 16]);
             $table=[];
             foreach ($model as $key) {
                 $table[] = ["id" => "a", "title" => $key->imie];
             }
    
            return $table;
            //return [$table];
    

    try these returns