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(); } }
/** * Override to process the note as a social item when needed. * (non-PHPdoc) * @see ZurmoBaseController::actionAfterSuccessfulModelSave() */ protected function actionAfterSuccessfulModelSave($model, $modelToStringValue, $redirectUrlParams = null) { assert('$model instanceof Note'); if (ArrayUtil::getArrayValue(PostUtil::getData(), 'postToProfile')) { $explicitReadWriteModelPermissions = ExplicitReadWriteModelPermissionsUtil::makeBySecurableItem($model); $socialItem = new SocialItem(); $socialItem->note = $model; $saved = $socialItem->save(); if (!$saved) { throw new FailedToSaveModelException(); } ExplicitReadWriteModelPermissionsUtil::resolveExplicitReadWriteModelPermissions($socialItem, $explicitReadWriteModelPermissions); } parent::actionAfterSuccessfulModelSave($model, $modelToStringValue, $redirectUrlParams); }
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]); }
public function testAddingNoteAndDeletingNoteAndThenTheSocialItemsAreRemoved() { $super = User::getByUsername('super'); $this->assertEquals(0, SocialItem::getCount()); $accounts = Account::getByName('anAccount'); $note = NoteTestHelper::createNoteWithOwnerAndRelatedAccount('aNote', $super, $accounts[0]); $socialItem = new SocialItem(); $socialItem->description = 'My test description'; $socialItem->note = $note; $saved = $socialItem->save(); $this->assertTrue($saved); $socialItemId = $socialItem->id; $noteId = $note->id; $note->forget(); $this->assertEquals(1, SocialItem::getCount()); $note = Note::getById($noteId); $deleted = $note->delete(); $this->assertTrue($deleted); $this->assertEquals(0, SocialItem::getCount()); }