Overview

Packages

  • None
  • Yaga

Functions

  • ActionRow
  • AgeArray
  • RenderPerkConfigurationForm
  • RenderPerkPermissionForm
  • RenderReactionList
  • RenderReactionRecord
  • WriteModuleDiscussion
  • WritePromotedContent
  • Overview
  • Package
  • Function
  • Tree
  • Todo
  • Download
  1: <?php if(!defined('APPLICATION')) exit();
  2: /**
  3:  * Contains render functions that can be used cross controller
  4:  * 
  5:  * @package Yaga
  6:  * @since 1.0
  7:  * @copyright (c) 2013-2014, Zachary Doll
  8:  */
  9: if(!function_exists('RenderReactions')) {
 10: 
 11:   /**
 12:    * Renders a list of available actions that also contains the current count of
 13:    * reactions an item has received if allowed
 14:    *
 15:    * @param int $ID
 16:    * @param string $Type 'discussion', 'activity', or 'comment'
 17:    * @param bool $Echo Should it be echoed?
 18:    * @return mixed String if $Echo is false, TRUE otherwise
 19:    */
 20:   function RenderReactionList($ID, $Type, $Echo = TRUE) {
 21:     $Reactions = Yaga::ReactionModel()->GetList($ID, $Type);
 22:     $ShowCount = Gdn::Session()->CheckPermission('Yaga.Reactions.View');
 23:     $ActionsString = '';
 24:     foreach($Reactions as $Action) {
 25:       if(CheckPermission($Action->Permission)) {
 26:         $CountString = ($ShowCount && $Action->Count) ? $Action->Count : '';
 27:         $ActionsString .= Anchor(
 28:                 Wrap('&nbsp;', 'span', array('class' => 'ReactSprite React-' . $Action->ActionID . ' ' . $Action->CssClass)) .
 29:                 WrapIf($CountString, 'span', array('class' => 'Count')) .
 30:                 Wrap($Action->Name, 'span', array('class' => 'ReactLabel')), 'react/' . $Type . '/' . $ID . '/' . $Action->ActionID,
 31:                 array(
 32:                   'class' => 'Hijack ReactButton',
 33:                   'title' => $Action->Tooltip)
 34:         );
 35:       }
 36:     }
 37: 
 38:     $AllActionsString = Wrap($ActionsString, 'span', array('class' => 'ReactMenu'));
 39: 
 40:     if($Echo) {
 41:       echo $AllActionsString;
 42:       return true;
 43:     }
 44:     else {
 45:       return $AllActionsString;
 46:     }
 47:   }
 48: 
 49: }
 50: 
 51: if(!function_exists('RenderReactionRecord')) {
 52: 
 53:   /**
 54:    * Renders the reaction record for a specific item
 55:    * 
 56:    * @param int $ID
 57:    * @param string $Type 'discussion', 'activity', or 'comment'
 58:    */
 59:   function RenderReactionRecord($ID, $Type) {
 60:     $Reactions = Yaga::ReactionModel()->GetRecord($ID, $Type);
 61:     $Limit = C('Yaga.Reactions.RecordLimit');
 62:     $ReactionCount = count($Reactions);
 63:     $i = 0;
 64:     foreach($Reactions as $Reaction) {
 65:       $i++;
 66:       
 67:       // Limit the record if there are a lot of reactions
 68:       if($i <= $Limit || $Limit <= 0) {
 69:         $User = Gdn::UserModel()->GetID($Reaction->UserID);
 70:         $DateTitle = sprintf(
 71:                 T('Yaga.Reactions.RecordFormat'),
 72:                 $User->Name,
 73:                 $Reaction->Name,
 74:                 Gdn_Format::Date($Reaction->DateInserted, '%B %e, %Y')
 75:               );
 76:         $String = UserPhoto($User, array('Size' => 'Small', 'title' => $DateTitle));
 77:         $String .= '<span class="ReactSprite Reaction-' . $Reaction->ActionID . ' ' . $Reaction->CssClass . '"></span>';
 78:         $Wrapttributes = array(
 79:             'class' => 'UserReactionWrap',
 80:             'data-userid' => $User->UserID,
 81:             'title' => $DateTitle
 82:         );
 83:         echo Wrap($String, 'span', $Wrapttributes);
 84:       }
 85:       
 86:       if($Limit > 0 && $i >= $ReactionCount && $ReactionCount > $Limit) {
 87:         echo Plural($ReactionCount - $Limit, 'Yaga.Reactions.RecordLimit.Single', 'Yaga.Reactions.RecordLimit.Plural');
 88:       }
 89:     }
 90:   }
 91: 
 92: }
 93: 
 94: if(!function_exists('ActionRow')) {
 95:   
 96:   /**
 97:    * Renders an action row used to construct the action admin screen
 98:    * 
 99:    * @param stdClass $Action
100:    * @return string
101:    */
102:   function ActionRow($Action) {
103:     return Wrap(
104:             Wrap(
105:                     Anchor(T('Edit'), 'action/edit/' . $Action->ActionID, array('class' => 'Popup SmallButton')) . Anchor(T('Delete'), 'action/delete/' . $Action->ActionID, array('class' => 'Popup SmallButton')), 'div', array('class' => 'Tools')) .
106:             Wrap(
107:                     Wrap($Action->Name, 'h4') .
108:                     Wrap(
109:                             Wrap($Action->Description, 'span') . ' ' .
110:                             Wrap(Plural($Action->AwardValue, '%s Point', '%s Points'), 'span'), 'div', array('class' => 'Meta')) .
111:                     Wrap(
112:                             Wrap('&nbsp;', 'span', array('class' => 'ReactSprite React-' . $Action->ActionID . ' ' . $Action->CssClass)) .
113:                             WrapIf(rand(0, 18), 'span', array('class' => 'Count')) .
114:                             Wrap($Action->Name, 'span', array('class' => 'ReactLabel')), 'div', array('class' => 'Preview Reactions')), 'div', array('class' => 'Action')), 'li', array('id' => 'ActionID_' . $Action->ActionID));
115:   }
116: }
117: 
118: if(!function_exists('RenderPerkPermissionForm')) {
119:   
120:   /**
121:    * Render a simple permission perk form
122:    * 
123:    * @param string $Perm The permission you want to grant/revoke
124:    * @param string $Label Translation code used on the form
125:    */
126:   function RenderPerkPermissionForm($Perm, $Label) {
127:     $Form = Gdn::Controller()->Form;
128:     $Fieldname = 'Perm' . $Perm;
129:     echo '<li>';
130:     echo $Form->Label($Label, $Fieldname);
131:     echo $Form->Dropdown($Fieldname, array(
132:         '' => T('Default'),
133:         'grant' => T('Grant'),
134:         'revoke' => T('Revoke')
135:     ));
136:     echo '</li>';
137:   }
138: }
139: 
140: if(!function_exists('RenderPerkConfigurationForm')) {
141:   
142:   /**
143:    * Render a perk form for the specified configuration
144:    * 
145:    * @param string $Config The configuration you want to override (i.e. 'Vanilla.EditTimeout')
146:    * @param string $Label Translation code used on the form
147:    * @param array $Options The options you want shown instead of default/enable/disable.
148:    */
149:   function RenderPerkConfigurationForm($Config, $Label, $Options = NULL) {
150:     if(is_null($Options)) {
151:       // Default to a true/false/default array
152:       $Options = array(
153:           '' => T('Default'),
154:           1 => T('Enabled'),
155:           0 => T('Disabled')
156:       );
157:     }
158:     // Add a default option
159:     $Options = $Options + array('' => T('Default'));
160:     $Form = Gdn::Controller()->Form;
161:     $Fieldname = 'Conf' . $Config;
162:     echo '<li>';
163:     echo $Form->Label($Label, $Fieldname);
164:     echo $Form->Dropdown($Fieldname, $Options);
165:     echo '</li>';
166:   }
167: }
168: 
169: 
Yaga API documentation generated by ApiGen 2.8.0