private function clearForbiddenLyricsData(Lyric $lyric) { $forbiddenArtist = $lyric->getForbidden(); if ($forbiddenArtist) { $lyric->setText("Artist {$forbiddenArtist->getName()} is forbidden"); } }
/** * Anonymous user try to edit existing lyric */ public function testGetAllowedFields() { $user = new User(); $lyric = new Lyric(); $lyric->setId(5); $allowedFields = $user->getAllowedLyricFields($lyric); $this->assertEmpty($allowedFields); }
public function testGetAllowedFieldsDownload() { $userMockBuilder = $this->getMockBuilder(User::class); $userMockBuilder->setMethods(['getPermissions']); $user = $userMockBuilder->getMock(); $user->expects($this->once())->method('getPermissions')->will($this->returnValue([Permission::LYRIC_EDIT_DOWNLOAD => Permission::LYRIC_EDIT_DOWNLOAD])); $lyric = new \Tekstove\ApiBundle\Model\Lyric(); $lyric->setId(5); $allowedFields = $user->getAllowedLyricFields($lyric); $this->assertCount(1, $allowedFields); $this->assertSame('download', $allowedFields[0]); }
public function updateUpdateuserId(Lyric $lyric) { // update only on new lyric if ($lyric->getId()) { return false; } // @TODO fix $user = $this->securityContext->getToken()->getUser(); if (!$user instanceof \Tekstove\ApiBundle\Model\User) { return false; } $lyric->setUser($user); }
/** * @param string $attribute * @param Lyric $lyric * @param TokenInterface $token * @return bool|null */ protected function voteOnAttribute($attribute, $lyric, TokenInterface $token) { $user = $token->getUser(); if (!$user instanceof User) { return null; } switch ($attribute) { case 'edit': if ($user->getId() == $lyric->getsendBy()) { return true; } } }
public function updateCache(Lyric $lyric) { $cacheTitleShort = ''; $artists = $lyric->getOrderedArtists(); array_slice($artists, 0, 2); if (isset($artists[0])) { $cacheTitleShort .= $artists[0]['name']; } if (isset($artists[1])) { // @TODO translate! $cacheTitleShort .= ' и ' . $artists[1]['name']; } if ($cacheTitleShort) { $cacheTitleShort .= ' - '; } $cacheTitleShort .= $lyric->getTitle(); $lyric->setcacheTitleShort($cacheTitleShort); }
/** * @param Lyric $lyric * @return array */ public function getAllowedLyricFields(Lyric $lyric) { $allowedFields = []; $owner = false; // $this->getId is check if user is guest if ($this->getId() && $lyric->getsendBy() === $this->getId()) { $owner = true; } if (!$lyric->getId()) { $owner = true; } if ($owner) { $allowedFields[] = 'title'; $allowedFields[] = 'artists'; $allowedFields[] = 'text'; $allowedFields[] = 'textBg'; $allowedFields[] = 'languages'; $allowedFields[] = 'extraInfo'; $allowedFields[] = 'videoYoutube'; $allowedFields[] = 'videoVbox7'; $allowedFields[] = 'videoMetacafe'; // do not allow delete on new lyric if ($lyric->getId()) { $allowedFields[] = 'delete'; } } $permissions = $this->getPermissions(); if (array_key_exists(Permission::LYRIC_EDIT_DOWNLOAD, $permissions)) { $allowedFields[] = 'download'; } if ($lyric->isForbidden()) { $hasTextField = array_search('text', $allowedFields); if (false !== $hasTextField) { unset($allowedFields[$hasTextField]); } } return $allowedFields; }
/** * Clears the current object, sets all attributes to their default values and removes * outgoing references as well as back-references (from other objects to this one. Results probably in a database * change of those foreign objects when you call `save` there). */ public function clear() { if (null !== $this->aLyric) { $this->aLyric->removeLyricLanguage($this); } if (null !== $this->aLanguage) { $this->aLanguage->removeLyricLanguage($this); } $this->lyric_id = null; $this->language_id = null; $this->alreadyInSave = false; $this->clearAllReferences(); $this->resetModified(); $this->setNew(true); $this->setDeleted(false); }
/** * Clears the current object, sets all attributes to their default values and removes * outgoing references as well as back-references (from other objects to this one. Results probably in a database * change of those foreign objects when you call `save` there). */ public function clear() { if (null !== $this->aLyric) { $this->aLyric->removeArtistLyric($this); } if (null !== $this->aArtist) { $this->aArtist->removeArtistLyric($this); } $this->lyric_id = null; $this->artist_id = null; $this->order = null; $this->alreadyInSave = false; $this->clearAllReferences(); $this->resetModified(); $this->setNew(true); $this->setDeleted(false); }
/** * Clears the current object, sets all attributes to their default values and removes * outgoing references as well as back-references (from other objects to this one. Results probably in a database * change of those foreign objects when you call `save` there). */ public function clear() { if (null !== $this->aLyric) { $this->aLyric->removeLyricTranslation($this); } if (null !== $this->aUser) { $this->aUser->removeLyricTranslation($this); } $this->id = null; $this->lyric_id = null; $this->user_id = null; $this->text = null; $this->alreadyInSave = false; $this->clearAllReferences(); $this->resetModified(); $this->setNew(true); $this->setDeleted(false); }
/** * Filter the query by a related \Tekstove\ApiBundle\Model\Lyric object * * @param \Tekstove\ApiBundle\Model\Lyric|ObjectCollection $lyric The related object(s) to use as filter * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL * * @throws \Propel\Runtime\Exception\PropelException * * @return ChildLyricVoteQuery The current query, for fluid interface */ public function filterByLyric($lyric, $comparison = null) { if ($lyric instanceof \Tekstove\ApiBundle\Model\Lyric) { return $this->addUsingAlias(LyricVoteTableMap::COL_LYRIC_ID, $lyric->getId(), $comparison); } elseif ($lyric instanceof ObjectCollection) { if (null === $comparison) { $comparison = Criteria::IN; } return $this->addUsingAlias(LyricVoteTableMap::COL_LYRIC_ID, $lyric->toKeyValue('PrimaryKey', 'Id'), $comparison); } else { throw new PropelException('filterByLyric() only accepts arguments of type \\Tekstove\\ApiBundle\\Model\\Lyric or Collection'); } }
public function save(Lyric $lyric) { $lyric->setEventDispacher($this->eventDispacher); $lyric->setValidator($this->validator); $lyric->save(); }
/** * @param ChildLyric $lyric The ChildLyric object to add. */ protected function doAddLyric(ChildLyric $lyric) { $this->collLyrics[] = $lyric; $lyric->setUser($this); }
/** * Filter the query by a related \Tekstove\ApiBundle\Model\Lyric object * * @param \Tekstove\ApiBundle\Model\Lyric|ObjectCollection $lyric the related object to use as filter * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL * * @return ChildUserQuery The current query, for fluid interface */ public function filterByLyric($lyric, $comparison = null) { if ($lyric instanceof \Tekstove\ApiBundle\Model\Lyric) { return $this->addUsingAlias(UserTableMap::COL_ID, $lyric->getsendBy(), $comparison); } elseif ($lyric instanceof ObjectCollection) { return $this->useLyricQuery()->filterByPrimaryKeys($lyric->getPrimaryKeys())->endUse(); } else { throw new PropelException('filterByLyric() only accepts arguments of type \\Tekstove\\ApiBundle\\Model\\Lyric or Collection'); } }
/** * Exclude object from result * * @param ChildLyric $lyric Object to remove from the list of results * * @return $this|ChildLyricQuery The current query, for fluid interface */ public function prune($lyric = null) { if ($lyric) { $this->addUsingAlias(LyricTableMap::COL_ID, $lyric->getId(), Criteria::NOT_EQUAL); } return $this; }