public function actionPostGameNotificationToProfile($content) { $socialItem = new SocialItem(); $socialItem->description = $content; $socialItem->addPermissions(Group::getByName(Group::EVERYONE_GROUP_NAME), Permission::READ_WRITE_CHANGE_PERMISSIONS_CHANGE_OWNER); $saved = $socialItem->save(); if (!$saved) { throw new FailedToSaveModelException(); } }
/** * @param DemoDataHelper $demoDataHelper */ public function makeAll(&$demoDataHelper) { assert('$demoDataHelper instanceof DemoDataHelper'); assert('$demoDataHelper->isSetRange("User")'); assert('$demoDataHelper->isSetRange("Account")'); $socialItems = array(); $data = self::getSocialItemData(); shuffle($data); foreach ($data as $randomSocialItemData) { $postData = array(); $socialItem = new SocialItem(); $socialItem->setScenario('importModel'); $socialItem->owner = $demoDataHelper->getRandomByModelName('User'); $socialItem->createdByUser = $socialItem->owner; //check if we should connect to a note if (isset($randomSocialItemData['noteDescription'])) { $note = new Note(); $account = $demoDataHelper->getRandomByModelName('Account'); $note->description = $randomSocialItemData['noteDescription']; $note->owner = $socialItem->owner; $note->activityItems->add($account); $this->populateModel($note); $saved = $note->save(); assert('$saved'); $socialItem->note = $note; } else { $socialItem->description = $randomSocialItemData['description']; } //Add some comments foreach ($randomSocialItemData['comments'] as $commentDescription) { $comment = new Comment(); $comment->setScenario('importModel'); $comment->createdByUser = $demoDataHelper->getRandomByModelName('User'); $comment->description = $commentDescription; $socialItem->comments->add($comment); } $socialItem->addPermissions(Group::getByName(Group::EVERYONE_GROUP_NAME), Permission::READ_WRITE_CHANGE_PERMISSIONS_CHANGE_OWNER); $saved = $socialItem->save(); assert('$saved'); $socialItems[] = $socialItem->id; } $demoDataHelper->setRangeByModelName('SocialItem', $socialItems[0], $socialItems[count($socialItems) - 1]); }