承接 onexhovia/rating-bundle 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

onexhovia/rating-bundle

Composer 安装命令:

composer require onexhovia/rating-bundle

包简介

This Bundle provides functionality for a rating system for Symfony2 applications

README 文档

README

The DCSRatingBundle adds support for a rating system in Symfony2. Features include:

  • You can add your vote to any page with a single line of code.
  • You can integrate it with any user management system (eg FOSUserBundle)
  • You can set different roles for access to the vote
  • The bundle using one stylesheet file without javascript file

1) Installation

A) Download and install DCSRatingBundle

To install DCSRatingBundle run the following command

bash $ php composer.phar require damianociarla/rating-bundle

B) Enable the bundle

Enable the required bundles in the kernel:

<?php
// app/AppKernel.php

public function registerBundles()
{
    $bundles = array(
    	// ...
    	new DCS\RatingBundle\DCSRatingBundle(),
	);
}

2) Create your Vote and Rating classes

In this first release DCSRatingBundle supports only Doctrine ORM. However, you must provide a concrete Vote and Rating class. You must extend the abstract entities provided by the bundle and creating the appropriate mappings.

Rating

<?php
// src/MyProject/MyBundle/Entity/Rating.php

namespace MyProject\MyBundle\Entity;

use DCS\RatingBundle\Entity\Rating as BaseRating;
use Doctrine\ORM\Mapping as ORM;

/**
 * @ORM\Entity
 * @ORM\ChangeTrackingPolicy("DEFERRED_EXPLICIT")
 */
class Rating extends BaseRating
{
    /**
     * @ORM\Id
     * @ORM\Column(type="string")
     */
    protected $id;

    /**
     * @ORM\OneToMany(targetEntity="MyProject\MyBundle\Entity\Vote", mappedBy="rating")
     */
    protected $votes;
}

Vote

<?php
// src/MyProject/MyBundle/Entity/Vote.php

namespace MyProject\MyBundle\Entity;

use DCS\RatingBundle\Entity\Vote as BaseVote;
use Doctrine\ORM\Mapping as ORM;

/**
 * @ORM\Entity
 * @ORM\ChangeTrackingPolicy("DEFERRED_EXPLICIT")
 */
class Vote extends BaseVote
{
    /**
     * @ORM\Id
     * @ORM\Column(type="integer")
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    protected $id;

    /**
     * @ORM\ManyToOne(targetEntity="MyProject\MyBundle\Entity\Rating", inversedBy="votes")
     * @ORM\JoinColumn(name="rating_id", referencedColumnName="id")
     */
    protected $rating;

    /**
     * @ORM\ManyToOne(targetEntity="MyProject\UserBundle\Entity\User")
     */
    protected $voter;
}

3) Configure your application

# app/config/config.yml

dcs_rating:
    db_driver: orm
    base_path_to_redirect: / # when the permalink is not configured
    max_value: 5 # maximum value for the vote (stars displayed)
    model:
        rating: MyProject\MyBundle\Entity\Rating
        vote: MyProject\MyBundle\Entity\Vote

4) Import DCSRatingBundle routing

Import the bundle routing:

dcs_rating:
    resource: "@DCSRatingBundle/Resources/config/routing.xml"
	prefix:   /

5) Import stylesheet in your template

To import the stylesheet run the following command:

bash $ php app/console assets:install

and include the stylesheet in your template:

<link rel="stylesheet" href="{{ asset('bundles/dcsrating/css/rating.css') }}" />

5.1) Enable vote via ajax

To vote via ajax you have to include the script below after loading the jQuery library:

<script src="{{ asset('bundles/dcsrating/js/rating.js') }}"></script>

6) Showing rating and enabling vote

You can only vote the page you are in. You can not vote a page while you are on a different one. But you can show the rating of a page (read-only mode) in any page

Showing rating

You can show rating using stars without enabling voting:

{% include 'DCSRatingBundle:Rating:rating.html.twig' with {'id' : 'YOUR_UNIQUE_ID'} %}

This is useful if you have a list of items and want to show the rating of each item.

Enabling vote

To enable voting on a page use the following twig code:

{% include 'DCSRatingBundle:Rating:control.html.twig' with {'id' : 'YOUR_UNIQUE_ID'} %}

If you need to change the default user role for a specific page, add the role parameter:

{% include 'DCSRatingBundle:Rating:control.html.twig' with {'id' : 'YOUR_UNIQUE_ID', 'role' : 'ROLE_USER'} %}

If you need to change the permalink, add the permalink parameter, otherwise it will be stored the current route:

{% include 'DCSRatingBundle:Rating:control.html.twig' with {'id' : 'YOUR_UNIQUE_ID', 'permalink' : url('YOUR_ROUTE_ID')} %}

onexhovia/rating-bundle 适用场景与选型建议

onexhovia/rating-bundle 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 393 次下载、GitHub Stars 达 0, 最近一次更新时间为 2016 年 10 月 22 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「twig」 「Symfony2」 「fos」 「Rating」 「FOSUserBundle」 「star」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 onexhovia/rating-bundle 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 onexhovia/rating-bundle 我们能提供哪些服务?
定制开发 / 二次开发

基于 onexhovia/rating-bundle 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 393
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 6
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 19
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2016-10-22