/** * Run the database seeds. * * @return void */ public function run() { $users = array(array("first_name" => "Joe", "last_name" => "Bloggs", "name" => "Joe Bloggs"), array("first_name" => "Tom", "last_name" => "Jenkinson", "name" => "Tom Jenkison"), array("first_name" => "Chrisopher", "last_name" => "Osborn", "name" => "Chris Osborn"), array("first_name" => "Luke", "last_name" => "Moscrop", "name" => "Luke Moscrop"), array("first_name" => "Ben", "last_name" => "Freke", "name" => "Ben Freke")); foreach ($users as $b => $a) { SiteUser::create(array_merge($a, array("fb_uid" => $b, "fb_access_token" => str_random(40)))); } $this->command->info('Site users created!'); }
private function addComments($mediaItem) { $noUsers = SiteUser::count(); if ($noUsers <= 0) { $this->command->info("Can't add comments. No users!"); return; } $comments = array("This is a random comment.", "Another completley different random commment.", "Blah blah blah blah blah blah blah blah blah blah something interesting.", "<script>alert('xss');</script> some <strong>xss</strong>"); $noToCreate = rand(0, 20); if ($noToCreate > 0) { $users = SiteUser::take($noToCreate)->get(); for ($i = 0; $i < $noToCreate; $i++) { $comment = new MediaItemComment(array("msg" => $comments[rand(0, count($comments) - 1)])); $user = $users[rand(0, count($users) - 1)]; $comment->siteUser()->associate($user); $comment->mediaItem()->associate($mediaItem); $comment->save(); } } }
/** * Run the database seeds. * * @return void */ public function run() { DB::statement('SET FOREIGN_KEY_CHECKS=0;'); LiveStream::truncate(); MediaItem::truncate(); MediaItemComment::truncate(); MediaItemLike::truncate(); MediaItemLiveStream::truncate(); MediaItemVideo::truncate(); Permission::truncate(); PermissionGroup::truncate(); QualityDefinition::truncate(); LiveStreamUri::truncate(); Playlist::truncate(); Show::truncate(); SiteUser::truncate(); User::truncate(); VideoFile::truncate(); DB::table("media_item_to_playlist")->truncate(); DB::table("permission_to_group")->truncate(); DB::table("user_to_group")->truncate(); DB::statement('SET FOREIGN_KEY_CHECKS=1;'); $this->command->info('Tables truncated!'); }
public static function sendMediaItemEmail($mediaItem, $subject, $heading, $msg) { if (!$mediaItem->email_notifications_enabled) { throw new Exception("This method should not have been called as this media item has email notifications disabled."); } $data = self::getMediaItemEmailData($mediaItem, $subject, $heading, $msg); // get all users that have emails enabled $users = SiteUser::whereNotNull("fb_email")->where("email_notifications_enabled", true)->get(); foreach ($users as $user) { // attempt to update the users facebook info Facebook::updateUserOpenGraph($user); $email = $user->fb_email; // check the email hasn't become null after the facebook update and that we have permission from facebook to use the email // also check the last time the users details were updated successfully and if it is longer than a month ago then presume it's stale and the facebook token has expired and the user hasn't renewed it by logging back in for a long time $cutOffTime = Carbon::now()->subMonths(1); if ($user->hasFacebookPermission("email") && !is_null($email) && $user->fb_last_update_time->timestamp > $cutOffTime->timestamp) { Log::info("Sending media item email to user with id " . $user->id . " and email \"" . $email . "\"."); // send the email Mail::send(array("html" => 'emails.mediaItem'), $data, function ($message) use(&$email, &$data) { $message->to($email)->subject($data['subject']); }); } } }
public function anyEdit($id = null) { Auth::getUser()->hasPermissionOr401(Config::get("permissions.mediaItems"), 1); $mediaItem = null; $editing = false; if (!is_null($id)) { $mediaItem = MediaItem::with("coverFile", "sideBannerFile", "videoItem", "liveStreamItem", "liveStreamItem.liveStream", "liveStreamItem.stateDefinition", "relatedItems")->find($id); if (is_null($mediaItem)) { 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(true, $mediaItem, "enabled") ? "y" : ""), array("promoted", ObjectHelpers::getProp(false, $mediaItem, "promoted") ? "y" : ""), array("name", ObjectHelpers::getProp("", $mediaItem, "name")), array("description", ObjectHelpers::getProp("", $mediaItem, "description")), array("email-notifications-enabled", ObjectHelpers::getProp(true, $mediaItem, "email_notifications_enabled") ? "y" : ""), array("likes-enabled", ObjectHelpers::getProp(true, $mediaItem, "likes_enabled") ? "y" : ""), array("comments-enabled", ObjectHelpers::getProp(true, $mediaItem, "comments_enabled") ? "y" : ""), array("cover-image-id", ObjectHelpers::getProp("", $mediaItem, "coverFile", "id")), array("cover-art-id", ObjectHelpers::getProp("", $mediaItem, "coverArtFile", "id")), array("side-banners-image-id", ObjectHelpers::getProp("", $mediaItem, "sideBannerFile", "id")), array("side-banners-fill-image-id", ObjectHelpers::getProp("", $mediaItem, "sideBannerFillFile", "id")), array("publish-time", ObjectHelpers::getProp("", $mediaItem, "scheduled_publish_time_for_input")), array("vod-added", !is_null(ObjectHelpers::getProp(null, $mediaItem, "videoItem")) ? "1" : "0"), array("vod-enabled", ObjectHelpers::getProp(true, $mediaItem, "videoItem", "enabled") ? "y" : ""), array("vod-video-id", ObjectHelpers::getProp("", $mediaItem, "videoItem", "sourceFile", "id")), array("vod-time-recorded", ObjectHelpers::getProp("", $mediaItem, "videoItem", "time_recorded_for_input")), array("vod-chapters", json_encode(array())), array("stream-added", !is_null(ObjectHelpers::getProp(null, $mediaItem, "liveStreamItem")) ? "1" : "0"), array("stream-enabled", ObjectHelpers::getProp(true, $mediaItem, "liveStreamItem", "enabled") ? "y" : ""), array("stream-state", ObjectHelpers::getProp(LiveStreamStateDefinition::first()->id, $mediaItem, "liveStreamItem", "stateDefinition", "id")), array("stream-being-recorded", ObjectHelpers::getProp(false, $mediaItem, "liveStreamItem", "being_recorded") ? "y" : ""), array("stream-info-msg", ObjectHelpers::getProp("", $mediaItem, "liveStreamItem", "information_msg")), array("stream-stream-id", ObjectHelpers::getProp("", $mediaItem, "liveStreamItem", "liveStream", "id")), array("stream-external-stream-url", ObjectHelpers::getProp("", $mediaItem, "liveStreamItem", "external_stream_url")), array("credits", json_encode(array())), array("related-items", json_encode(array()))), !$formSubmitted); // this will contain any additional data which does not get saved anywhere $additionalFormData = array("coverImageFile" => FormHelpers::getFileInfo($formData['cover-image-id']), "sideBannersImageFile" => FormHelpers::getFileInfo($formData['side-banners-image-id']), "sideBannersFillImageFile" => FormHelpers::getFileInfo($formData['side-banners-fill-image-id']), "coverArtFile" => FormHelpers::getFileInfo($formData['cover-art-id']), "vodVideoFile" => FormHelpers::getFileInfo($formData['vod-video-id']), "vodChaptersInput" => null, "vodChaptersInitialData" => null, "creditsInput" => null, "creditsInputInitialData" => null, "relatedItemsInput" => null, "relatedItemsInitialData" => null); if (!$formSubmitted) { $additionalFormData['creditsInput'] = ObjectHelpers::getProp(json_encode(array()), $mediaItem, "credits_for_input"); $additionalFormData['creditsInitialData'] = ObjectHelpers::getProp(json_encode(array()), $mediaItem, "credits_for_reorderable_list"); $additionalFormData['relatedItemsInput'] = ObjectHelpers::getProp(json_encode(array()), $mediaItem, "related_items_for_input"); $additionalFormData['relatedItemsInitialData'] = ObjectHelpers::getProp(json_encode(array()), $mediaItem, "related_items_for_reorderable_list"); } else { $additionalFormData['creditsInput'] = MediaItem::generateInputValueForMediaItemCreditsReorderableList(JsonHelpers::jsonDecodeOrNull($formData['credits'], true)); $additionalFormData['creditsInitialData'] = MediaItem::generateInitialDataForMediaItemCreditsReorderableList(JsonHelpers::jsonDecodeOrNull($formData['credits'], true)); $additionalFormData['relatedItemsInput'] = MediaItem::generateInputValueForAjaxSelectReorderableList(JsonHelpers::jsonDecodeOrNull($formData['related-items'], true)); $additionalFormData['relatedItemsInitialData'] = MediaItem::generateInitialDataForAjaxSelectReorderableList(JsonHelpers::jsonDecodeOrNull($formData['related-items'], true)); } if (!$formSubmitted && !is_null($mediaItem) && !is_null($mediaItem->videoItem)) { $additionalFormData['vodChaptersInput'] = ObjectHelpers::getProp(json_encode(array()), $mediaItem, "videoItem", "chapters_for_input"); $additionalFormData['vodChaptersInitialData'] = ObjectHelpers::getProp(json_encode(array()), $mediaItem, "videoItem", "chapters_for_reorderable_list"); } else { $additionalFormData['vodChaptersInput'] = MediaItemVideo::generateInputValueForChaptersReorderableList(JsonHelpers::jsonDecodeOrNull($formData['vod-chapters'], true)); $additionalFormData['vodChaptersInitialData'] = MediaItemVideo::generateInitialDataForChaptersReorderableList(JsonHelpers::jsonDecodeOrNull($formData['vod-chapters'], true)); } $liveStreamStateDefinitions = LiveStreamStateDefinition::orderBy("id", "asc")->get(); $additionalFormData['streamStateButtonsData'] = array(); foreach ($liveStreamStateDefinitions as $a) { $additionalFormData['streamStateButtonsData'][] = array("id" => intval($a->id), "text" => $a->name); } $errors = null; if ($formSubmitted) { // validate input Validator::extend('valid_file_id', FormHelpers::getValidFileValidatorFunction()); Validator::extend('valid_stream_id', FormHelpers::getValidStreamValidatorFunction()); Validator::extend('my_date', FormHelpers::getValidDateValidatorFunction()); Validator::extend('valid_credits', function ($attribute, $value, $parameters) { return MediaItem::isValidDataFromMediaItemCreditsReorderableList(JsonHelpers::jsonDecodeOrNull($value, true)); }); Validator::extend('valid_related_items', function ($attribute, $value, $parameters) { return MediaItem::isValidIdsFromAjaxSelectReorderableList(JsonHelpers::jsonDecodeOrNull($value, true)); }); Validator::extend('valid_vod_chapters', function ($attribute, $value, $parameters) { return MediaItemVideo::isValidDataFromChaptersReorderableList(JsonHelpers::jsonDecodeOrNull($value, true)); }); Validator::extend('valid_stream_state_id', function ($attribute, $value, $parameters) { return !is_null(LiveStreamStateDefinition::find(intval($value))); }); Validator::extend('not_specified', function ($attribute, $value, $parameters) { return false; }); $modelCreated = DB::transaction(function () use(&$formData, &$mediaItem, &$errors) { $validator = Validator::make($formData, array('name' => array('required', 'max:50'), 'description' => array('max:500'), 'cover-image-id' => array('valid_file_id'), 'side-banners-image-id' => array('valid_file_id'), 'side-banners-fill-image-id' => array('valid_file_id'), 'cover-art-id' => array('valid_file_id'), 'publish-time' => array('my_date'), 'vod-video-id' => array('required_if:vod-added,1', 'valid_file_id'), 'vod-time-recorded' => array('my_date'), 'vod-chapters' => array('required', 'valid_vod_chapters'), 'stream-state' => array('required', 'valid_stream_state_id'), 'stream-info-msg' => array('max:500'), 'stream-stream-id' => array('valid_stream_id'), 'stream-external-stream-url' => array('url'), 'credits' => array('required', 'valid_credits'), 'related-items' => array('required', 'valid_related_items')), array('name.required' => FormHelpers::getRequiredMsg(), 'name.max' => FormHelpers::getLessThanCharactersMsg(50), 'description.max' => FormHelpers::getLessThanCharactersMsg(500), 'cover-image-id.valid_file_id' => FormHelpers::getInvalidFileMsg(), 'side-banners-image-id.valid_file_id' => FormHelpers::getInvalidFileMsg(), 'side-banners-fill-image-id.valid_file_id' => FormHelpers::getInvalidFileMsg(), 'cover-art-id.valid_file_id' => FormHelpers::getInvalidFileMsg(), 'publish-time.my_date' => FormHelpers::getInvalidTimeMsg(), 'vod-video-id.required_if' => FormHelpers::getRequiredMsg(), 'vod-video-id.valid_file_id' => FormHelpers::getInvalidFileMsg(), 'vod-time-recorded.my_date' => FormHelpers::getInvalidTimeMsg(), 'vod-time-recorded.not_specified' => "This cannot be set if this is a recording of a live stream. The time will be inferred from the scheduled live time.", 'vod-chapters.required' => FormHelpers::getGenericInvalidMsg(), 'vod-chapters.valid_vod_chapters' => FormHelpers::getGenericInvalidMsg(), 'stream-state.required' => FormHelpers::getRequiredMsg(), 'stream-state.valid_stream_state_id' => FormHelpers::getGenericInvalidMsg(), 'stream-info-msg.max' => FormHelpers::getLessThanCharactersMsg(500), 'stream-stream-id.valid_stream_id' => FormHelpers::getInvalidStreamMsg(), 'stream-external-stream-url.url' => "This is not a valid url.", 'credits.required' => FormHelpers::getGenericInvalidMsg(), 'credits.valid_credits' => FormHelpers::getGenericInvalidMsg(), 'related-items.required' => FormHelpers::getGenericInvalidMsg(), 'related-items.valid_related_items' => FormHelpers::getGenericInvalidMsg())); $validator->sometimes("vod-time-recorded", "not_specified", function ($input) use(&$formData) { return $formData['stream-added'] === "1" && $formData['vod-added'] === "1"; }); if (!$validator->fails()) { // everything is good. save/create model if (is_null($mediaItem)) { $mediaItem = new MediaItem(); } $mediaItem->name = $formData['name']; $mediaItem->description = FormHelpers::nullIfEmpty($formData['description']); $mediaItem->enabled = FormHelpers::toBoolean($formData['enabled']); $mediaItem->promoted = FormHelpers::toBoolean($formData['promoted']); // if the scheduled publish time is empty and this item is enabled, set it to the current time. // an enabled media item should always have a published time. $scheduledPublishTime = FormHelpers::nullIfEmpty(strtotime($formData['publish-time'])); $mediaItem->scheduled_publish_time = !is_null($scheduledPublishTime) ? $scheduledPublishTime : Carbon::now(); $mediaItem->email_notifications_enabled = FormHelpers::toBoolean($formData['email-notifications-enabled']); $mediaItem->likes_enabled = FormHelpers::toBoolean($formData['likes-enabled']); // if comments are being disabled then remove any existing comments. $commentsEnabled = FormHelpers::toBoolean($formData['comments-enabled']); $currentCommentsEnabled = (bool) $mediaItem->comments_enabled; $mediaItem->comments_enabled = $commentsEnabled; if ($currentCommentsEnabled !== $commentsEnabled) { // remove when changing from enabled to disabled and vice versa // I think it might be possible for someone to make a comment during this transaction when going from enabled to disable. // deleting when going from disabled to enabled should always catch any that this happens to $mediaItem->comments()->delete(); } $coverImageId = FormHelpers::nullIfEmpty($formData['cover-image-id']); $file = Upload::register(Config::get("uploadPoints.coverImage"), $coverImageId, $mediaItem->coverFile); EloquentHelpers::associateOrNull($mediaItem->coverFile(), $file); $sideBannerFileId = FormHelpers::nullIfEmpty($formData['side-banners-image-id']); $file = Upload::register(Config::get("uploadPoints.sideBannersImage"), $sideBannerFileId, $mediaItem->sideBannerFile); EloquentHelpers::associateOrNull($mediaItem->sideBannerFile(), $file); $sideBannerFillFileId = FormHelpers::nullIfEmpty($formData['side-banners-fill-image-id']); $file = Upload::register(Config::get("uploadPoints.sideBannersFillImage"), $sideBannerFillFileId, $mediaItem->sideBannerFillFile); EloquentHelpers::associateOrNull($mediaItem->sideBannerFillFile(), $file); $coverArtId = FormHelpers::nullIfEmpty($formData['cover-art-id']); $file = Upload::register(Config::get("uploadPoints.coverArt"), $coverArtId, $mediaItem->coverArtFile); EloquentHelpers::associateOrNull($mediaItem->coverArtFile(), $file); // vod $mediaItemVideo = null; if ($formData['vod-added'] === "1") { // create MediaItemVideo if doesn't exist, otherwise retrieve it if (!is_null($mediaItem->videoItem)) { $mediaItemVideo = $mediaItem->videoItem; } else { $mediaItemVideo = new MediaItemVideo(); } $mediaItemVideo->time_recorded = FormHelpers::nullIfEmpty(strtotime($formData['vod-time-recorded'])); $mediaItemVideo->enabled = FormHelpers::toBoolean($formData['vod-enabled']); $vodVideoId = FormHelpers::nullIfEmpty($formData['vod-video-id']); $file = Upload::register(Config::get("uploadPoints.vodVideo"), $vodVideoId, $mediaItemVideo->sourceFile); EloquentHelpers::associateOrNull($mediaItemVideo->sourceFile(), $file); if ($mediaItemVideo->chapters()->count() > 0) { if (!$mediaItemVideo->chapters()->delete()) { // remove all chapters throw new Exception("Error deleting MediaItemVideo chapters."); } } // now add the chapters again $chapterData = json_decode($formData['vod-chapters'], true); foreach ($chapterData as $chapter) { $chapterModel = new MediaItemVideoChapter(array("title" => trim($chapter['title']), "time" => $chapter['time'])); $mediaItemVideo->chapters()->save($chapterModel); } } else { // remove video model if there is one if (!is_null($mediaItem->videoItem)) { // remove source file and cover art file (if there is one) Upload::delete($mediaItem->videoItem->sourceFile); Upload::delete($mediaItem->videoItem->coverArtFile); if ($mediaItem->videoItem->delete() === false) { throw new Exception("Error deleting MediaItemVideo."); } } } // stream $mediaItemLiveStream = null; if ($formData['stream-added'] === "1") { // create MediaItemLiveStream if doesn't exist, otherwise retrieve it if (!is_null($mediaItem->liveStreamItem)) { $mediaItemLiveStream = $mediaItem->liveStreamItem; } else { $mediaItemLiveStream = new MediaItemLiveStream(); } $mediaItemLiveStream->information_msg = FormHelpers::nullIfEmpty($formData['stream-info-msg']); $mediaItemLiveStream->being_recorded = FormHelpers::toBoolean($formData['stream-being-recorded']); $mediaItemLiveStream->enabled = FormHelpers::toBoolean($formData['stream-enabled']); $mediaItemLiveStream->stateDefinition()->associate(LiveStreamStateDefinition::find($formData['stream-state'])); if (!is_null(FormHelpers::nullIfEmpty($formData['stream-stream-id']))) { $liveStream = LiveStream::find(intval($formData['stream-stream-id'], 10)); if (is_null($liveStream)) { throw new Exception("Live stream no longer exists in transaction."); } $mediaItemLiveStream->liveStream()->associate($liveStream); } else { EloquentHelpers::setForeignKeyNull($mediaItemLiveStream->liveStream()); } $mediaItemLiveStream->external_stream_url = FormHelpers::nullIfEmpty($formData['stream-external-stream-url']); } else { // remove livestream model if there is one if (!is_null($mediaItem->liveStreamItem)) { if ($mediaItem->liveStreamItem->delete() === false) { throw new Exception("Error deleting MediaItemLiveStream."); } } } if ($mediaItem->save() === false) { throw new Exception("Error saving MediaItem."); } if (!is_null($mediaItemVideo)) { if ($mediaItem->videoItem()->save($mediaItemVideo) === false) { throw new Exception("Error creating MediaItemVideo."); } } if (!is_null($mediaItemLiveStream)) { if ($mediaItem->liveStreamItem()->save($mediaItemLiveStream) === false) { throw new Exception("Error creating MediaItemLiveStream."); } } // update credits if ($mediaItem->credits()->count() > 0) { if (!$mediaItem->credits()->delete()) { // remove all chapters throw new Exception("Error deleting MediaItem credits."); } } $creditsData = json_decode($formData['credits'], true); foreach ($creditsData as $credit) { $creditModel = new Credit(array("name_override" => $credit["nameOverride"])); $productionRole = ProductionRoleMediaItem::find($credit["productionRoleId"]); $creditModel->productionRole()->associate($productionRole); if (!is_null($credit["siteUserId"])) { $siteUser = SiteUser::find($credit["siteUserId"]); if (is_null($siteUser)) { // given the credits data has been validated earlier, it shouldn't have passed if the SiteUser didn't exist throw new Exception("Was expecting the SiteUser to exist."); } $creditModel->siteUser()->associate($siteUser); } $mediaItem->credits()->save($creditModel); } $mediaItem->relatedItems()->detach(); // detaches all $ids = json_decode($formData['related-items'], true); if (count($ids) > 0) { $mediaItems = MediaItem::whereIn("id", $ids)->get(); foreach ($mediaItems as $a) { $mediaItem->relatedItems()->attach($a, array("position" => array_search(intval($a->id), $ids, true))); } } // 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") . "/media"); } // if not valid then return form again with errors } $liveStreams = LiveStream::orderBy("name", "asc")->orderBy("description", "asc")->get(); $streamOptions = array(); $streamOptions[] = array("id" => "", "name" => "[None]"); foreach ($liveStreams as $a) { $name = $a->name; if (!$a->enabled) { $name .= " [Disabled]"; } $streamOptions[] = array("id" => $a->id, "name" => $name); } $hasDvrRecording = false; $liveStreamItem = !is_null($mediaItem) ? $mediaItem->liveStreamItem : null; if (!is_null($liveStreamItem)) { $hasDvrRecording = $liveStreamItem->dvrLiveStreamUris()->count() > 0; } $view = View::make('home.admin.media.edit'); $view->editing = $editing; $view->streamOptions = $streamOptions; $view->form = $formData; $view->additionalForm = $additionalFormData; $view->hasDvrRecording = $hasDvrRecording; if ($hasDvrRecording) { $view->dvrRecordingRemoveUri = Config::get("custom.admin_base_url") . "/media/remove-dvr-recording/" . $liveStreamItem->id; } $view->formErrors = $errors; // used to uniquely identify these file upload points on the site. Must not be duplicated for different upload points. $view->coverImageUploadPointId = Config::get("uploadPoints.coverImage"); $view->sideBannersImageUploadPointId = Config::get("uploadPoints.sideBannersImage"); $view->sideBannersFillImageUploadPointId = Config::get("uploadPoints.sideBannersFillImage"); $view->coverArtUploadPointId = Config::get("uploadPoints.coverArt"); $view->vodVideoUploadPointId = Config::get("uploadPoints.vodVideo"); $view->cancelUri = Config::get("custom.admin_base_url") . "/media"; $this->setContent($view, "media", "media-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['productionRoleId']) || !is_numeric($a['productionRoleId'])) { $this->valid = false; $currentItemOutput["productionRoleState"] = array("id" => null, "text" => null); } else { // lookup the production role and replace the name $productionRoleId = intval($a['productionRoleId']); if ($productionRoleId === 0) { $productionRoleId = null; } $productionRole = null; if (!is_null($productionRoleId)) { $productionRole = $this->getProductionRoleModel()->find($productionRoleId); } $currentItemOutput['productionRoleState'] = array("id" => null, "text" => null); if (!is_null($productionRole)) { $currentItemOutput['productionRoleState'] = array("id" => intval($productionRole->id), "text" => $productionRole->getName()); } else { $this->valid = false; } } if (!array_key_exists('siteUserId', $a)) { $this->valid = false; $currentItemOutput["siteUserState"] = array("id" => null, "text" => null); } else { if (is_null($a['siteUserId']) || !is_numeric($a['siteUserId'])) { // a check will be made later to ensure that the nameOverride is provided $currentItemOutput["siteUserState"] = array("id" => null, "text" => null); } else { // lookup the user and set name $siteUserId = intval($a['siteUserId']); if ($siteUserId === 0) { $siteUserId = null; } $siteUser = null; if (!is_null($siteUserId)) { $siteUser = SiteUser::find($siteUserId); } $currentItemOutput['siteUserState'] = array("id" => null, "text" => null); if (!is_null($siteUser)) { $userId = intval($siteUser->id); $currentItemOutput['siteUserState'] = array("id" => $userId, "text" => $siteUser->name); if ($this->valid) { // check to make sure there isn't a duplicate entry // ie same person to same role foreach ($output as $a) { $loopUserId = $a["siteUserState"]["id"]; if (!is_null($loopUserId) && $loopUserId === $userId && $a["productionRoleState"]["id"] === $currentItemOutput['productionRoleState']['id']) { $this->valid = false; break; } } } } else { $this->valid = false; } } } if (!array_key_exists('nameOverride', $a) || !is_null($a['nameOverride']) && !is_string($a['nameOverride'])) { $this->valid = false; $currentItemOutput["nameOverride"] = null; $currentItemOutput['siteUserState'] = array("id" => null, "text" => null); } else { if (!is_null($a["nameOverride"])) { if (trim($a['nameOverride']) === "") { $this->valid = false; $currentItemOutput["nameOverride"] = ""; } else { if (strlen(trim($a['nameOverride'])) > 50) { $this->valid = false; $currentItemOutput["nameOverride"] = trim($a['nameOverride']); } else { $a['nameOverride'] = trim($a['nameOverride']); $currentItemOutput["nameOverride"] = $a['nameOverride']; $currentItemOutput["siteUserState"] = null; } } } else { $currentItemOutput["nameOverride"] = null; } } if (is_null($currentItemOutput['siteUserState']['id']) === is_null($currentItemOutput["nameOverride"])) { // either a site user must be provided or a name $this->valid = false; $currentItemOutput["nameOverride"] = null; $currentItemOutput['siteUserState'] = array("id" => null, "text" => null); } $output[] = $currentItemOutput; } $stringForInputData = []; foreach ($output as $a) { $stringForInputData[] = array("productionRoleId" => $a["productionRoleState"]["id"], "siteUserId" => !is_null($a["nameOverride"]) ? null : $a["siteUserState"]["id"], "nameOverride" => $a["nameOverride"]); } // 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($stringForInputData); }
private function getUserWithStoredSecret($secret) { // if there's a cached version use that if ($this->siteUserCached) { // use cached version return $this->siteUser; } $siteUser = SiteUser::where("secret", $secret)->first(); if (!is_null($siteUser)) { $this->siteUser = $siteUser; $this->siteUserCached = true; // update last_seen time $siteUser->last_seen = Carbon::now(); $siteUser->save(); } return $siteUser; }
public function postAjaxselect() { // used on media items page for credits Auth::getUser()->hasPermissionOr401(Config::get("permissions.mediaItems"), 0); $resp = array("success" => false, "payload" => null); $searchTerm = FormHelpers::getValue("term", ""); $qualities = null; if (!empty($searchTerm)) { $siteUsers = SiteUser::search($searchTerm)->orderBy("last_name", "asc")->orderBy("first_name", "asc")->orderBy("name", "asc")->take(100)->get(); } else { $siteUsers = SiteUser::orderBy("last_name", "asc")->orderBy("first_name", "asc")->orderBy("name", "asc")->take(100)->get(); } $results = array(); foreach ($siteUsers as $a) { $results[] = array("id" => intval($a->id), "text" => $a->name); } $resp['payload'] = array("results" => $results, "term" => $searchTerm); $resp['success'] = true; return Response::json($resp); }