Code Monkey home page Code Monkey logo

humhub-modules-star's Introduction

Star

This module adds the ability to Star/Favourite objects. Please note, this is not a standalone module, it requires integration.

Installation

  • Clone the star module into your modules directory
cd protected/modules
git clone https://github.com/ConnectedCommunities/humhub-modules-star.git star
  • Go to Admin > Modules. You should now see the Star module in your list of installed modules

  • Click "Enable". This will install the Star module for you

Usage

This is the first implementation of the Star module. It is not a standalone module, it needs to be used with modules/code that have integrated it.

Add a Star

You can Star an object like so:

use humhub\modules\star\models\Star;
// ...
$star = new Star();
$star->object_model = 'humhub\modules\questionanswer\models\Question';
$star->object_id = 1;
$like->save();

The Star Widget

To help reduce your development time, the module comes with a widget that lets you star and unstar an object.

$question = \humhub\modules\questionanswer\models\Question::findOne(['id' => 1]);
echo humhub\modules\star\widgets\StarLink::widget(array('object' => $question))

Getting Stars

You can get the Stars on an object:

use humhub\modules\star\models\Star;
// ...
$stars = Star::GetStars('humhub\modules\questionanswer\models\Question', 1);

Showing a Star

Each object that can be starred can also have a widget that defines how that the starred object should be displayed (e.g. in the Star list at star/views/list)

Simply create a new widget with two parameters star and object

class StarredItem extends \yii\base\Widget
{

    public $object;

    public $star;
    
    public function run()
    {
        return $this->render('starredItem', array(
            'star' => $this->star,
            'object' => $this->object
        ));
    }

}

Then set the following property on your object's model. It might look similar to this.

class Answer extends ContentActiveRecord implements Searchable
{

    // ...
    
    /**
     * Class of widget to use to show starred item
     *
     * @var string StarredItem widget class
     */
    public $starredItemClass = "humhub\modules\questionanswer\widgets\StarredItem";
    
    // ...
    
}

humhub-modules-star's People

Contributors

benmag avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.