Esempio n. 1
0
 public function init()
 {
     if (!$this->model instanceof VoteModel && $this->parentType == null || $this->parentId == null) {
         $this->model = new VoteModel(['parent_id' => $this->parentId, 'parent_type' => $this->parentType]);
     } else {
         $this->model = $this->model instanceof VoteModel ? $this->model : VoteModel::findModel([$this->parentId, $this->parentType]);
     }
     $this->uniqid = uniqid();
     $this->iconOptions = !isset($this->iconOptions) ? $this->_defaultIconOptions : $this->iconOptions;
     parent::init();
     Asset::register($this->getView());
 }
 /**
  * Get the query that orders items by their activity
  */
 protected function getOrderByQuery()
 {
     $localOrderBy = ["(" . new Expression("SELECT COUNT(*) FROM " . \nitm\widgets\models\Vote::tableName() . " WHERE \n\t\t\t\tparent_id=id AND \n\t\t\t\tparent_type='" . $this->model->isWhat()) . "'\n\t\t\t)" => SORT_DESC, "(CASE status \n\t\t\t\tWHEN 'normal' THEN 0\n\t\t\t\tWHEN 'important' THEN 1 \n\t\t\t\tWHEN 'critical' THEN 2\n\t\t\tEND)" => SORT_DESC];
     return array_merge(parent::getOrderByQuery(), $localOrderBy);
 }
Esempio n. 3
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getVoteModel()
 {
     return $this->getWidgetRelationModelQuery(\nitm\widgets\models\Vote::className());
 }
Esempio n. 4
0
 /**
  * Place an upvote
  * @param string $type the type of object
  * @param int $id the id
  * @return boolean should we allow more upvoting?
  */
 public function actionReset($type, $id)
 {
     $ret_val = ['success' => false, 'value' => null, 'id' => $id];
     switch (\Yii::$app->user->identity->isAdmin()) {
         case true:
             $deleted = Vote::deleteAll(['parent_id' => $id, 'parent_type' => $type]);
             $ret_val['success'] = $deleted;
             break;
     }
     $this->setResponseFormat('json');
     return $this->renderResponse($ret_val);
 }