Skip to content

Commit

Permalink
Merge branch 'master' of github.com:vanillaforums/Garden
Browse files Browse the repository at this point in the history
  • Loading branch information
tburry committed Sep 15, 2011
2 parents 502af1d + 5b7a0dd commit bb2d269
Show file tree
Hide file tree
Showing 5 changed files with 91 additions and 38 deletions.
12 changes: 6 additions & 6 deletions applications/dashboard/models/class.usermodel.php
Original file line number Diff line number Diff line change
Expand Up @@ -1594,7 +1594,7 @@ public function Approve($UserID, $Email) {
$this->SaveRoles($UserID, $RoleIDs, FALSE);

// Send out a notification to the user
$User = $this->Get($UserID);
$User = $this->GetID($UserID);
if ($User) {
$Email->Subject(sprintf(T('[%1$s] Membership Approved'), C('Garden.Title')));
$Email->Message(sprintf(T('EmailMembershipApproved'), $User->Name, ExternalUrl(SignInUrl())));
Expand Down Expand Up @@ -2063,8 +2063,8 @@ public function SendEmailConfirmationEmail($User = NULL) {

public function SendWelcomeEmail($UserID, $Password, $RegisterType = 'Add', $AdditionalData = NULL) {
$Session = Gdn::Session();
$Sender = $this->Get($Session->UserID);
$User = $this->Get($UserID);
$Sender = $this->GetID($Session->UserID);
$User = $this->GetID($UserID);

if (!ValidateEmail($User->Email))
return;
Expand Down Expand Up @@ -2111,8 +2111,8 @@ public function SendWelcomeEmail($UserID, $Password, $RegisterType = 'Add', $Add

public function SendPasswordEmail($UserID, $Password) {
$Session = Gdn::Session();
$Sender = $this->Get($Session->UserID);
$User = $this->Get($UserID);
$Sender = $this->GetID($Session->UserID);
$User = $this->GetID($UserID);
$AppTitle = Gdn::Config('Garden.Title');
$Email = new Gdn_Email();
$Email->Subject(sprintf(T('[%s] Password Reset'), $AppTitle));
Expand Down Expand Up @@ -2278,7 +2278,7 @@ public function PasswordReset($UserID, $Password) {
$this->EventArguments['UserID'] = $UserID;
$this->FireEvent('AfterPasswordReset');

return $this->Get($UserID);
return $this->GetID($UserID);
}

public function SetField($RowID, $Property, $Value = FALSE) {
Expand Down
1 change: 1 addition & 0 deletions applications/dashboard/views/empty.master.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@
<body id="{$BodyID}" class="{$BodyClass}">
<div id="Content">{asset name='Content'}</div>
{asset name='Foot'}
{event name='AfterBody'}
</body>
</html>
17 changes: 13 additions & 4 deletions applications/vanilla/models/class.discussionmodel.php
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,9 @@ public function Get($Offset = '0', $Limit = '', $Wheres = '', $AdditionalFields

$this->AddArchiveWhere($this->SQL);


$this->SQL->Limit($Limit, $Offset);

$this->EventArguments['SortField'] = C('Vanilla.Discussions.SortField', 'd.DateLastComment');
$this->EventArguments['SortDirection'] = C('Vanilla.Discussions.SortDirection', 'desc');
$this->EventArguments['Wheres'] = &$Wheres;
Expand All @@ -165,7 +168,7 @@ public function Get($Offset = '0', $Limit = '', $Wheres = '', $AdditionalFields

// Get sorting options from config
$SortField = $this->EventArguments['SortField'];
if (!in_array($SortField, array('d.DateLastComment', 'd.DateInserted')))
if (!in_array($SortField, array('d.DiscussionID', 'd.DateLastComment', 'd.DateInserted')))
$SortField = 'd.DateLastComment';

$SortDirection = $this->EventArguments['SortDirection'];
Expand All @@ -175,9 +178,7 @@ public function Get($Offset = '0', $Limit = '', $Wheres = '', $AdditionalFields
$this->SQL->OrderBy($SortField, $SortDirection);

// Set range and fetch
$Data = $this->SQL
->Limit($Limit, $Offset)
->Get();
$Data = $this->SQL->Get();

// If not looking at discussions filtered by bookmarks or user, filter announcements out.
if (!isset($Wheres['w.Bookmarked']) && !isset($Wheres['d.InsertUserID']))
Expand Down Expand Up @@ -784,6 +785,14 @@ public function Save($FormPostValues) {

// Get the DiscussionID from the form so we know if we are inserting or updating.
$DiscussionID = ArrayValue('DiscussionID', $FormPostValues, '');

// See if there is a source ID.
if (array_key_exists('SourceID', $FormPostValues)) {
$DiscussionID = $this->SQL->GetWhere('Discussion', ArrayTranslate($FormPostValues, array('Source', 'SourceID')))->Value('DiscussionID');
if ($DiscussionID)
$FormPostValues['DiscussionID'] = $DiscussionID;
}

$Insert = $DiscussionID == '' ? TRUE : FALSE;
$this->EventArguments['Insert'] = $Insert;

Expand Down
2 changes: 1 addition & 1 deletion library/core/class.form.php
Original file line number Diff line number Diff line change
Expand Up @@ -779,7 +779,7 @@ public function DropDown($FieldName, $DataSet, $Attributes = FALSE) {
// Get value from attributes and ensure it's an array
$Value = ArrayValueI('Value', $Attributes);
if ($Value === FALSE)
$Value = $this->GetValue($FieldName);
$Value = $this->GetValue($FieldName, GetValue('Default', $Attributes));
if (!is_array($Value))
$Value = array($Value);

Expand Down
97 changes: 70 additions & 27 deletions plugins/Tagging/class.tagging.plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,7 @@ public function DiscussionsController_Tagged_Create($Sender) {
}

$Tag = StringEndsWith($Tag, '.rss', TRUE, TRUE);
$Foo = OffsetLimit($Page, Gdn::Config('Vanilla.Discussions.PerPage', 30));
list($Offset, $Limit) = OffsetLimit($Page, Gdn::Config('Vanilla.Discussions.PerPage', 30));

// var_dump($Offset);
// var_dump($Limit);
// die(print_r($Foo, TRUE));

$Sender->SetData('Tag', $Tag, TRUE);
$Sender->Title(T('Tagged with ').htmlspecialchars($Tag));
Expand Down Expand Up @@ -101,21 +96,14 @@ public function DiscussionsController_Tagged_Create($Sender) {
$Sender->AddModule($BookmarkedModule);

$Sender->SetData('Category', FALSE, TRUE);
$DiscussionModel = new DiscussionModel();
$Tag = $DiscussionModel->SQL->Select()->From('Tag')->Where('Name', $Sender->Tag)->Get()->FirstRow();
$TagID = $Tag ? $Tag->TagID : 0;

$CountDiscussions = $Tag ? $Tag->CountDiscussions : FALSE;
if ($Sender->Request->Get('DateFrom'))
$CountDiscussions = FALSE;
$Sender->SetData('CountDiscussions', $CountDiscussions);


$Sender->SetData('CountDiscussions', FALSE);

$Sender->AnnounceData = FALSE;
$Sender->SetData('Announcements', array(), TRUE);
$DiscussionModel->FilterToTagID = $TagID;
$Sender->DiscussionData = $DiscussionModel->Get($Offset, $Limit);

$DiscussionModel = new DiscussionModel();
$this->_SetTagSql($DiscussionModel->SQL, $Tag, $Limit, $Offset, $Sender->Request->Get('op', 'or'));
$Sender->DiscussionData = $DiscussionModel->Get(FALSE);

$Sender->SetData('Discussions', $Sender->DiscussionData, TRUE);
$Sender->SetJson('Loading', $Offset . ' to ' . $Limit);
Expand All @@ -133,7 +121,7 @@ public function DiscussionsController_Tagged_Create($Sender) {
$Sender->Pager->Configure(
$Offset,
$Limit,
$CountDiscussions,
FALSE,
$PageUrlFormat
);

Expand Down Expand Up @@ -237,15 +225,12 @@ public function DiscussionModel_AfterSaveDiscussion_Handler($Sender) {
* Should we limit the discussion query to a specific tagid?
* @param DiscussionModel $Sender
*/
public function DiscussionModel_BeforeGet_Handler($Sender) {
if (C('Plugins.Tagging.Enabled') && property_exists($Sender, 'FilterToTagID')) {
$Sender->SQL->Join('TagDiscussion td', 'd.DiscussionID = td.DiscussionID and td.TagID = '.$Sender->FilterToTagID);

if ($DateFrom = Gdn::Request()->Get('DateFrom')) {
$Sender->SQL->Where('d.DateInserted >= ', $DateFrom);
}
}
}
// public function DiscussionModel_BeforeGet_Handler($Sender) {
// if (C('Plugins.Tagging.Enabled') && property_exists($Sender, 'FilterToDiscussionIDs')) {
// $Sender->SQL->WhereIn('d.DiscussionID', $Sender->FilterToDiscussionIDs)
// ->Limit(FALSE);
// }
// }

/**
* Validate tags when saving a discussion.
Expand Down Expand Up @@ -318,6 +303,64 @@ public function PluginController_TagSearch_Create($Sender) {
exit();
}

/**
*
* @param Gdn_SQLDriver $Sql
*/
protected function _SetTagSql($Sql, $Tag, $Limit, $Offset = 0, $Op = 'or') {
$SortField = 'd.DateLastComment';
$SortDirection = 'desc';

$TagSql = clone Gdn::Sql();

if ($DateFrom = Gdn::Request()->Get('DateFrom')) {
// Find the discussion ID of the first discussion created on or after the date from.
$DiscussionIDFrom = $TagSql->GetWhere('Discussion', array('DateInserted >= ' => $DateFrom), 'DiscussionID', 'asc', 1)->Value('DiscussionID');
$SortField = 'd.DiscussionID';
}

$Tags = array_map('trim', explode(',', $Tag));
$TagIDs = $TagSql
->Select('TagID')
->From('Tag')
->WhereIn('Name', $Tags)
->Get()->ResultArray();

$TagIDs = ConsolidateArrayValuesByKey($TagIDs, 'TagID');

if ($Op == 'and' && count($Tags) > 1) {
$DiscussionIDs = $TagSql
->Select('DiscussionID')
->Select('TagID', 'count', 'CountTags')
->From('TagDiscussion')
->WhereIn('TagID', $TagIDs)
->GroupBy('DiscussionID')
->Having('CountTags >=', count($Tags))
->Limit($Limit, $Offset)
->OrderBy('DiscussionID', 'desc')
->Get()->ResultArray();

$DiscussionIDs = ConsolidateArrayValuesByKey($DiscussionIDs, 'DiscussionID');

$Sql->WhereIn('d.DiscussionID', $DiscussionIDs);
$SortField = 'd.DiscussionID';
} else {
$Sql
->Join('TagDiscussion td', 'd.DiscussionID = td.DiscussionID')
->Limit($Limit, $Offset)
->WhereIn('td.TagID', $TagIDs);

if ($Op == 'and')
$SortField = 'd.DiscussionID';
}

// Set up the sort field and direction.
SaveToConfig(array(
'Vanilla.Discussions.SortField' => $SortField,
'Vanilla.Discussions.SortDirection' => $SortDirection),
FALSE);
}

/**
* Add the tag input to the discussion form.
* @param Gdn_Controller $Sender
Expand Down

0 comments on commit bb2d269

Please sign in to comment.