Overview

Packages

  • None
  • Yaga

Classes

  • ActedModel
  • ActionController
  • ActionModel
  • AwardCombo
  • BadgeAwardModel
  • BadgeController
  • BadgeModel
  • BadgesController
  • BadgesModule
  • BestController
  • BestFilterModule
  • CakeDayPost
  • CommentCount
  • CommentMarathon
  • DiscussionBodyLength
  • DiscussionCategory
  • DiscussionCount
  • DiscussionPageCount
  • HasMentioned
  • HolidayVisit
  • LeaderBoardModule
  • LengthOfService
  • ManualAward
  • NecroPost
  • NewbieComment
  • PhotoExists
  • PostCount
  • PostReactions
  • QnAAnserCount
  • RankController
  • RankModel
  • ReactController
  • ReactionCount
  • ReactionModel
  • ReflexComment
  • RulesController
  • SocialConnection
  • Yaga
  • YagaController
  • YagaHooks

Interfaces

  • YagaRule
  • Overview
  • Package
  • Class
  • Tree
  • Todo
  • Download
  1: <?php if(!defined('APPLICATION')) exit();
  2: /* Copyright 2013 Zachary Doll */
  3: 
  4: /**
  5:  * Manages the building of a rules cache and is provides admin functions for
  6:  * managing badges in the dashboard.
  7:  *
  8:  * @since 1.0
  9:  * @package Yaga
 10:  */
 11: class RulesController extends Gdn_Controller {
 12: 
 13:   /**
 14:    * May be used in the future.
 15:    *
 16:    * @since 1.0
 17:    * @access public
 18:    */
 19:   public function Initialize() {
 20:     parent::Initialize();
 21:     $this->Application = 'Yaga';
 22:   }
 23: 
 24:   /**
 25:    * This checks the cache for current rule set and expires once a day.
 26:    * It loads all php files in the rules folder and selects only those that
 27:    * implement the 'YagaRule' interface.
 28:    *
 29:    * @return array Rules that are currently available to use. The class names
 30:    * are keys and the friendly names are values.
 31:    */
 32:   public static function GetRules() {
 33:     $Rules = Gdn::Cache()->Get('Yaga.Badges.Rules');
 34:     if($Rules === Gdn_Cache::CACHEOP_FAILURE) {
 35:       foreach(glob(PATH_APPLICATIONS . DS . 'yaga' . DS . 'library' . DS . 'rules' . DS . '*.php') as $filename) {
 36:         include_once $filename;
 37:       }
 38: 
 39:       $TempRules = array();
 40:       foreach(get_declared_classes() as $className) {
 41:         if(in_array('YagaRule', class_implements($className))) {
 42:           $Rule = new $className();
 43:           $TempRules[$className] = $Rule->Name();
 44:         }
 45:       }
 46:       if(empty($TempRules)) {
 47:         $Rules = serialize(FALSE);
 48:       }
 49:       else{
 50:         $Rules = serialize($TempRules);
 51:       }
 52:       Gdn::Cache()->Store('Yaga.Badges.Rules', $Rules, array(Gdn_Cache::FEATURE_EXPIRY => C('Yaga.Rules.CacheExpire', 86400)));
 53:     }
 54: 
 55:     return unserialize($Rules);
 56:   }
 57:   
 58:   /**
 59:    * This checks the cache for current rule set that can be triggered for a user
 60:    * by another user. It loads all rules and selects only those that return true
 61:    * on its `Interacts()` method.
 62:    *
 63:    * @return array Rules that are currently available to use that are interactive.
 64:    */
 65:   public static function GetInteractionRules() {
 66:     $Rules = Gdn::Cache()->Get('Yaga.Badges.InteractionRules');
 67:     if($Rules === Gdn_Cache::CACHEOP_FAILURE) {
 68:       $AllRules = RulesController::GetRules();
 69: 
 70:       $TempRules = array();
 71:       foreach($AllRules as $ClassName => $Name) {
 72:         $Rule = new $ClassName();
 73:         if($Rule->Interacts()) {
 74:           $TempRules[$ClassName] = $Name;
 75:         }
 76:       }
 77:       if(empty($TempRules)) {
 78:         $Rules = serialize(FALSE);
 79:       }
 80:       else{
 81:         $Rules = serialize($TempRules);
 82:       }
 83:       
 84:       Gdn::Cache()->Store('Yaga.Badges.InteractionRules', $Rules, array(Gdn_Cache::FEATURE_EXPIRY => C('Yaga.Rules.CacheExpire', 86400)));
 85:     }
 86: 
 87:     return unserialize($Rules);
 88:   }
 89: 
 90:   /**
 91:    * This creates a new rule object in a safe way and renders its criteria form.
 92:    *
 93:    * @param string $RuleClass
 94:    */
 95:   public function GetCriteriaForm($RuleClass) {
 96:     if(class_exists($RuleClass) && in_array('YagaRule', class_implements($RuleClass))) {
 97:       $Rule = new $RuleClass();
 98:       $Form = Gdn::Factory('Form');
 99:       $Form->InputPrefix = '_Rules';
100:       $FormString = $Rule->Form($Form);
101:       $Description = $Rule->Description();
102:       $Name = $Rule->Name();
103: 
104:       $Data = array('CriteriaForm' => $FormString, 'RuleClass' => $RuleClass, 'Name' => $Name, 'Description' => $Description);
105:       $this->RenderData($Data);
106:     }
107:     else {
108:       $this->RenderException(new Gdn_UserException(T('Yaga.Error.Rule404')));
109:     }
110:   }
111: }
112: 
Yaga API documentation generated by ApiGen 2.8.0