예제 #1
0
 /**
  * @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;
             }
     }
 }
예제 #2
0
 /**
  * @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;
 }
예제 #3
0
 /**
  * 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');
     }
 }