Untitled

mail@pastecode.io avatar
unknown
plain_text
7 months ago
3.0 kB
6
Indexable
Never
if (!empty($old_background_img)) {
                $deleted_library = $this->library->remove_library_usage($this->library->library_reference['media_room']['reference'], $media_room->id, $this->library->library_reference['media_room']['media_type']);

                if ($deleted_library['return'] != true) {
                    return API::response()->array(
                        [
                        'return' => false,
                        'output' => $deleted_library,
                        'extra' => [
                            'message' => 'There was an error deleteing old media reference. Please try again.'
                        ]
                        ]
                    )->statusCode(401);
                }
                $media_room_category = \EventType::find($media_room->type_id);
                if (isset($library_id)) {
                    /**
                     * Update library usage
                     */
                    $usage = LibraryUsage::where('type', $this->library->library_reference['media_room']['reference'])->where('type_id', $media_room->id)->update([
                        'library_id' => $library_id
                    ]);
                } else {
                    /**
                     * Store media to library
                     */
                    $library_item = $this->library->store_media(
                    $media_room->user_id,
                    $media_room->name,
                    $media_room->description,
                    $this->library->library_reference['media_room']['reference'],
                    $this->library->library_reference['media_room']['media_type'],
                    $media_room->background_image,
                    $media_room->background_image,
                    '',
                    '',
                    $media_room_category->name
                    );
                    /**
                     * Store media to library usage
                     */
                    if ($library_item['return'] !== true) {
                    return API::response()->array(
                        [
                        'return' => false,
                        'extra' => [
                            'message' => 'Error while creating library item!'
                        ]
                        ]
                    )->statusCode(500);
                    }
                    $library_usage = $this->library->add_media_to_usage($library_item['output'],$this->library->library_reference['media_room']['reference'],$media_room->id);
                    if ($library_usage['return'] !== true) {
                    return API::response()->array(
                        [
                        'return' => false,
                        'extra' => [
                            'message' => 'Error while creating library usage!'
                        ]
                        ]
                    )->statusCode(500);
                    }
                 }
            }