/** * Run the database seeds. * * @return void */ public function run() { $destinationFile = File::first(); $file = new VideoFile(array("width" => 1920, "height" => 1080)); $file->qualityDefinition()->associate(QualityDefinition::find(1)); $file->file()->associate($destinationFile); $file->save(); $file = new VideoFile(array("width" => 1280, "height" => 720)); $file->qualityDefinition()->associate(QualityDefinition::find(2)); $file->file()->associate($destinationFile); $file->save(); $file = new VideoFile(array("width" => 640, "height" => 480)); $file->qualityDefinition()->associate(QualityDefinition::find(3)); $file->file()->associate($destinationFile); $file->save(); $file = new VideoFile(array("width" => 640, "height" => 360)); $file->qualityDefinition()->associate(QualityDefinition::find(4)); $file->file()->associate($destinationFile); $file->save(); $file = new VideoFile(array("width" => 426, "height" => 240)); $file->qualityDefinition()->associate(QualityDefinition::find(5)); $file->file()->associate($destinationFile); $file->save(); $this->command->info('Video files records created!'); }
public function anyEdit($id = null) { Auth::getUser()->hasPermissionOr401(Config::get("permissions.liveStreams"), 1); $liveStream = null; $editing = false; if (!is_null($id)) { $liveStream = LiveStream::find($id); if (is_null($liveStream)) { App::abort(404); return; } $editing = true; } $formSubmitted = isset($_POST['form-submitted']) && $_POST['form-submitted'] === "1"; // has id 1 // populate $formData with default values or received values $formData = FormHelpers::getFormData(array(array("enabled", ObjectHelpers::getProp(false, $liveStream, "enabled") ? "y" : ""), array("shownAsLivestream", ObjectHelpers::getProp(false, $liveStream, "shown_as_livestream") ? "y" : ""), array("name", ObjectHelpers::getProp("", $liveStream, "name")), array("description", ObjectHelpers::getProp("", $liveStream, "description")), array("cover-art-id", ObjectHelpers::getProp("", $liveStream, "coverArtFile", "id")), array("urls", json_encode(array()))), !$formSubmitted); // this will contain any additional data which does not get saved anywhere $additionalFormData = array("coverArtFile" => FormHelpers::getFileInfo($formData['cover-art-id']), "urlsInput" => null, "urlsInitialData" => null); if (!$formSubmitted) { $additionalFormData['urlsInput'] = ObjectHelpers::getProp(json_encode(array()), $liveStream, "urls_for_input"); $additionalFormData['urlsInitialData'] = ObjectHelpers::getProp(json_encode(array()), $liveStream, "urls_for_orderable_list"); } else { $additionalFormData['urlsInput'] = LiveStream::generateInputValueForUrlsOrderableList(JsonHelpers::jsonDecodeOrNull($formData['urls'], true)); $additionalFormData['urlsInitialData'] = LiveStream::generateInitialDataForUrlsOrderableList(JsonHelpers::jsonDecodeOrNull($formData["urls"], true)); } $errors = null; if ($formSubmitted) { $modelCreated = DB::transaction(function () use(&$formData, &$liveStream, &$errors) { Validator::extend('valid_file_id', FormHelpers::getValidFileValidatorFunction()); Validator::extend('valid_urls', function ($attribute, $value, $parameters) { return LiveStream::isValidDataFromUrlsOrderableList(JsonHelpers::jsonDecodeOrNull($value, true)); }); $validator = Validator::make($formData, array('name' => array('required', 'max:50'), 'description' => array('max:500'), 'cover-art-id' => array('valid_file_id'), 'urls' => array('required', 'valid_urls')), array('name.required' => FormHelpers::getRequiredMsg(), 'name.max' => FormHelpers::getLessThanCharactersMsg(50), 'description.max' => FormHelpers::getLessThanCharactersMsg(500), 'cover-art-id.valid_file_id' => FormHelpers::getInvalidFileMsg(), 'urls.required' => FormHelpers::getGenericInvalidMsg(), 'urls.valid_urls' => FormHelpers::getGenericInvalidMsg())); if (!$validator->fails()) { // everything is good. save/create model if (is_null($liveStream)) { $liveStream = new LiveStream(); } $liveStream->name = $formData['name']; $liveStream->description = FormHelpers::nullIfEmpty($formData['description']); $liveStream->enabled = FormHelpers::toBoolean($formData['enabled']); $liveStream->shown_as_livestream = FormHelpers::toBoolean($formData['shownAsLivestream']); $coverArtFileId = FormHelpers::nullIfEmpty($formData['cover-art-id']); $file = Upload::register(Config::get("uploadPoints.coverArt"), $coverArtFileId, $liveStream->coverArtFile); EloquentHelpers::associateOrNull($liveStream->coverArtFile(), $file); if ($liveStream->save() === false) { throw new Exception("Error saving LiveStream."); } $liveStream->liveStreamUris()->delete(); // detaches all. this causes any corresponding dvrBridgeServiceUrl's to be deleted as well which must happen on any change $urlsData = json_decode($formData['urls'], true); foreach ($urlsData as $a) { $qualityDefinition = QualityDefinition::find(intval($a['qualityState']['id'])); $url = $a['url']; $dvrBridgeServiceUri = $a['dvrBridgeServiceUrl']; $nativeDvr = $a['nativeDvr']; $type = $a['type']; $support = $a['support']; $supportedDevices = null; if ($support === "pc") { $supportedDevices = "desktop"; } else { if ($support === "mobile") { $supportedDevices = "mobile"; } } $liveStreamUri = new LiveStreamUri(array("uri" => $url, "dvr_bridge_service_uri" => $dvrBridgeServiceUri, "has_dvr" => $nativeDvr, "type" => $type, "supported_devices" => $supportedDevices, "enabled" => $support !== "none")); $liveStreamUri->qualityDefinition()->associate($qualityDefinition); $liveStream->liveStreamUris()->save($liveStreamUri); } // the transaction callback result is returned out of the transaction function return true; } else { $errors = $validator->messages(); return false; } }); if ($modelCreated) { return Redirect::to(Config::get("custom.admin_base_url") . "/livestreams"); } // if not valid then return form again with errors } $view = View::make('home.admin.livestreams.edit'); $view->editing = $editing; $view->form = $formData; $view->additionalForm = $additionalFormData; $view->coverArtUploadPointId = Config::get("uploadPoints.coverArt"); $view->formErrors = $errors; $view->cancelUri = Config::get("custom.admin_base_url") . "/livestreams"; $this->setContent($view, "livestreams", "livestreams-edit"); }
public function __construct($data) { if (!is_array($data)) { $this->valid = false; $this->initialDataString = json_encode(array()); $this->stringForInput = json_encode(array()); return; } $this->valid = true; $output = array(); foreach ($data as $a) { $currentItemOutput = array(); if (!isset($a['qualityState']) || !isset($a['qualityState']['id']) || !is_numeric($a['qualityState']['id'])) { $this->valid = false; $currentItemOutput["qualityState"] = array("id" => null, "text" => ""); } else { // lookup the quality definition and replace the name $qualityDefinitionId = intval($a['qualityState']['id']); if ($qualityDefinitionId === 0) { $qualityDefinitionId = null; } $qualityDefinition = null; if (!is_null($qualityDefinitionId)) { $qualityDefinition = QualityDefinition::find($qualityDefinitionId); } $currentItemOutput['qualityState'] = array("id" => null, "text" => ""); if (!is_null($qualityDefinition)) { $currentItemOutput['qualityState'] = array("id" => intval($qualityDefinition->id), "text" => $qualityDefinition->name); } else { $this->valid = false; } } if (!isset($a['url']) || !is_string($a['url'])) { $this->valid = false; $currentItemOutput["url"] = ""; } else { $a['url'] = trim($a['url']); if (filter_var($a['url'], FILTER_VALIDATE_URL) === false) { $this->valid = false; } $currentItemOutput["url"] = $a['url']; } if (!isset($a["type"]) || !is_string($a["type"])) { $this->valid = false; $currentItemOutput["type"] = ""; } else { $a['type'] = trim($a['type']); if ($a['type'] === "" || preg_match('/\\s/', $a['type'])) { // empty or contains whitespace // this could check a lot more but not really fussed $this->valid = false; } $currentItemOutput["type"] = $a['type']; } if (!isset($a['dvrBridgeServiceUrl']) || !is_bool($a['dvrBridgeServiceUrl'])) { $this->valid = false; $currentItemOutput["dvrBridgeServiceUrl"] = false; } else { $currentItemOutput["dvrBridgeServiceUrl"] = $a['dvrBridgeServiceUrl']; } // type must be this if using dvr bridge service as this is the type the dvr bridge service uses if ($currentItemOutput["dvrBridgeServiceUrl"] && $currentItemOutput["type"] !== "application/x-mpegURL") { $this->valid = false; } $currentItemOutput["dvrBridgeServiceUrl"] = isset($a['dvrBridgeServiceUrl']) && $a['dvrBridgeServiceUrl'] === true; if ($currentItemOutput["dvrBridgeServiceUrl"]) { if (!array_key_exists('nativeDvr', $a) || !is_null($a['nativeDvr'])) { $this->valid = false; } $currentItemOutput["nativeDvr"] = null; } else { if (!array_key_exists('nativeDvr', $a) || !is_bool($a['nativeDvr'])) { $this->valid = false; $currentItemOutput["nativeDvr"] = false; } else { $currentItemOutput["nativeDvr"] = $a['nativeDvr']; } } if (!isset($a["support"]) || $a["support"] !== "all" && $a["support"] !== "pc" && $a["support"] !== "mobile" && $a["support"] !== "none") { $this->valid = false; $currentItemOutput["support"] = "all"; } else { $currentItemOutput["support"] = $a['support']; } $output[] = $currentItemOutput; } // the string for the input and the initial data string are the same for the chapters reordable list $this->initialDataString = json_encode($output); $this->stringForInput = json_encode($output); }