2013-10-24 13:14:52 -05:00
< ? php if ( ! defined ( 'APPLICATION' )) exit ();
2013-10-24 15:19:32 -05:00
/* Copyright 2013 Zachary Doll */
2013-10-24 13:14:52 -05:00
2013-10-24 15:19:32 -05:00
if ( ! isset ( $Drop )) {
2013-10-24 13:14:52 -05:00
$Drop = FALSE ; // Safe default - Set to TRUE to drop the table if it already exists.
2013-10-24 15:19:32 -05:00
}
2013-10-24 13:14:52 -05:00
2013-10-24 15:19:32 -05:00
if ( ! isset ( $Explicit )) {
2013-10-24 13:14:52 -05:00
$Explicit = FALSE ; // Safe default - Set to TRUE to remove all other columns from table.
2013-10-24 15:19:32 -05:00
}
2013-10-24 13:14:52 -05:00
$Database = Gdn :: Database ();
2013-11-06 12:23:20 -06:00
$SQL = $Database -> SQL (); // To run queries.
2013-10-24 13:14:52 -05:00
$Construct = $Database -> Structure (); // To modify and add database tables.
2013-11-12 09:16:30 -06:00
// Tracks the data associated with reacting to content
2013-10-24 15:19:32 -05:00
$Construct -> Table ( 'Reaction' )
-> PrimaryKey ( 'ReactionID' )
-> Column ( 'InsertUserID' , 'int' , FALSE , 'index.1' )
-> Column ( 'ActionID' , 'int' , FALSE , 'index' )
-> Column ( 'ParentID' , 'int' , TRUE )
-> Column ( 'ParentType' , array ( 'discussion' , 'comment' , 'activity' ), TRUE )
2013-10-25 17:05:01 -05:00
-> Column ( 'ParentAuthorID' , 'int' , FALSE )
2013-10-24 15:19:32 -05:00
-> Column ( 'DateInserted' , 'datetime' )
-> Set ( $Explicit , $Drop );
2013-10-24 13:14:52 -05:00
2013-11-12 09:16:30 -06:00
// Describes actions that can be taken on a comment, discussion or activity
2013-10-24 15:19:32 -05:00
$Construct -> Table ( 'Action' )
-> PrimaryKey ( 'ActionID' )
-> Column ( 'Name' , 'varchar(140)' )
-> Column ( 'Description' , 'varchar(255)' )
-> Column ( 'Tooltip' , 'varchar(255)' )
2013-10-28 15:03:05 -05:00
-> Column ( 'CssClass' , 'varchar(255)' )
2013-10-24 15:19:32 -05:00
-> Column ( 'AwardValue' , 'int' , 1 )
2013-11-15 14:48:39 -06:00
-> Column ( 'Permission' , 'varchar(255)' , 'Yaga.Reactions.Add' )
2013-11-15 10:51:18 -06:00
-> Column ( 'Sort' , 'int' , TRUE )
2013-10-24 15:19:32 -05:00
-> Set ( $Explicit , $Drop );
2013-11-12 09:16:30 -06:00
// Describes a badge and the associated rule criteria
2013-10-24 15:19:32 -05:00
$Construct -> Table ( 'Badge' )
-> PrimaryKey ( 'BadgeID' )
-> Column ( 'Name' , 'varchar(140)' )
2013-11-01 16:14:14 -05:00
-> Column ( 'Description' , 'varchar(255)' , NULL )
-> Column ( 'Photo' , 'varchar(255)' , NULL )
-> Column ( 'RuleClass' , 'varchar(255)' )
-> Column ( 'RuleCriteria' , 'text' , TRUE )
-> Column ( 'AwardValue' , 'int' , 0 )
-> Column ( 'Enabled' , 'tinyint(1)' , '1' )
2013-10-24 15:19:32 -05:00
-> Set ( $Explicit , $Drop );
2013-11-04 17:32:04 -06:00
2013-11-12 09:16:30 -06:00
// Tracks the actual awarding of badges
2013-11-04 17:32:04 -06:00
$Construct -> Table ( 'BadgeAward' )
-> PrimaryKey ( 'BadgeAwardID' )
-> Column ( 'BadgeID' , 'int' )
-> Column ( 'UserID' , 'int' )
2013-11-11 17:34:57 -06:00
-> Column ( 'InsertUserID' , 'int' , NULL )
-> Column ( 'Reason' , 'text' , NULL )
2013-11-04 17:32:04 -06:00
-> Column ( 'DateInserted' , 'datetime' )
-> Set ( $Explicit , $Drop );
2013-11-06 12:23:20 -06:00
2013-11-22 16:08:30 -06:00
// Describes a rank and associated values
2013-11-19 11:41:46 -06:00
$Construct -> Table ( 'Rank' )
-> PrimaryKey ( 'RankID' )
-> Column ( 'Name' , 'varchar(140)' )
-> Column ( 'Description' , 'varchar(255)' , NULL )
-> Column ( 'Photo' , 'varchar(255)' , NULL )
2013-11-20 16:37:31 -06:00
-> Column ( 'PointsRequired' , 'int' , 0 )
2013-11-22 16:08:30 -06:00
-> Column ( 'Permission' , 'text' , NULL )
2013-11-19 11:41:46 -06:00
-> Column ( 'Enabled' , 'tinyint(1)' , '1' )
-> Set ( $Explicit , $Drop );
2013-11-22 16:08:30 -06:00
// Tracks the current rank a user has
$Construct -> Table ( 'User' )
-> Column ( 'CountBadges' , 'int' , 0 )
-> Column ( 'RankID' , 'int' , 0 )
-> Set ();
2013-11-12 09:16:30 -06:00
// Add activity types for Badge and Rank awards
2013-11-06 12:23:20 -06:00
if ( $SQL -> GetWhere ( 'ActivityType' , array ( 'Name' => 'BadgeAward' )) -> NumRows () == 0 )
2013-11-07 15:52:35 -06:00
$SQL -> Insert ( 'ActivityType' , array ( 'AllowComments' => '1' , 'Name' => 'BadgeAward' , 'FullHeadline' => '%1$s earned a badge.' , 'ProfileHeadline' => '%1$s earned a badge.' , 'Notify' => 1 ));
2013-11-06 12:23:20 -06:00
if ( $SQL -> GetWhere ( 'ActivityType' , array ( 'Name' => 'RankPromotion' )) -> NumRows () == 0 )
2013-11-07 15:52:35 -06:00
$SQL -> Insert ( 'ActivityType' , array ( 'AllowComments' => '1' , 'Name' => 'RankPromotion' , 'FullHeadline' => '%1$s was promoted.' , 'ProfileHeadline' => '%1$s was promoted.' , 'Notify' => 1 ));