当前位置: 首页>>代码示例>>PHP>>正文


PHP CategoryModel::RebuildTree方法代码示例

本文整理汇总了PHP中CategoryModel::RebuildTree方法的典型用法代码示例。如果您正苦于以下问题:PHP CategoryModel::RebuildTree方法的具体用法?PHP CategoryModel::RebuildTree怎么用?PHP CategoryModel::RebuildTree使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在CategoryModel的用法示例。


在下文中一共展示了CategoryModel::RebuildTree方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: array

   $RootCategoryInserted = TRUE;
}

if ($Drop) {
   $SQL->Insert('Category', array('ParentCategoryID' => -1, 'TreeLeft' => 2, 'TreeRight' => 3, 'InsertUserID' => 1, 'UpdateUserID' => 1, 'DateInserted' => Gdn_Format::ToDateTime(), 'DateUpdated' => Gdn_Format::ToDateTime(), 'Name' => 'General', 'UrlCode' => 'general', 'Description' => 'General discussions', 'PermissionCategoryID' => -1));
} elseif ($CategoryExists && !$PermissionCategoryIDExists) {
   if (!C('Garden.Permissions.Disabled.Category')) {
      // Existing installations need to be set up with per/category permissions.
      $SQL->Update('Category')->Set('PermissionCategoryID', 'CategoryID', FALSE)->Put();
      $SQL->Update('Permission')->Set('JunctionColumn', 'PermissionCategoryID')->Where('JunctionColumn', 'CategoryID')->Put();
   }
}

if ($CategoryExists) {
   $CategoryModel = new CategoryModel();
   $CategoryModel->RebuildTree();
   unset($CategoryModel);
}

// Construct the discussion table.
$Construct->Table('Discussion');

$FirstCommentIDExists = $Construct->ColumnExists('FirstCommentID');
$BodyExists = $Construct->ColumnExists('Body');
$LastCommentIDExists = $Construct->ColumnExists('LastCommentID');
$LastCommentUserIDExists = $Construct->ColumnExists('LastCommentUserID');
$CountBookmarksExists = $Construct->ColumnExists('CountBookmarks');

$Construct
   ->PrimaryKey('DiscussionID')
   ->Column('Type', 'varchar(10)', NULL, 'index')
开发者ID:nerdgirl,项目名称:Forums-ILoveBadTV,代码行数:31,代码来源:structure.php

示例2: UpdateCounts


//.........这里部分代码省略.........
                     set uc.CountReadMessages = c.CountMessages,
                       uc.LastMessageID = c.LastMessageID";
               }
            } elseif(!$this->ImportExists('UserConversation', 'DateLastViewed')) {
               // We have the last message so grab the date from that.
               $Sqls['UserConversation.DateLastViewed'] =
                     "update :_UserConversation uc
                     join :_ConversationMessage m
                       on m.ConversationID = uc.ConversationID
                         and m.MessageID = uc.LastMessageID
                     set uc.DateLastViewed = m.DateInserted";
            }
         }
      }

      // User counts.
      if (!$this->ImportExists('User', 'CountDiscussions')) {
         $Sqls['User.CountDiscussions'] = $this->GetCountSQL('count', 'User', 'Discussion', 'CountDiscussions', 'DiscussionID', 'UserID', 'InsertUserID');
      }
      if (!$this->ImportExists('User', 'CountComments')) {
         $Sqls['User.CountComments'] = $this->GetCountSQL('count', 'User', 'Comment', 'CountComments', 'CommentID', 'UserID', 'InsertUserID');
      }
      if (!$this->ImportExists('User', 'CountBookmarks')) {
         $Sqls['User.CountBookmarks'] = "update :_User u
            set CountBookmarks = (
               select count(ud.DiscussionID)
               from :_UserDiscussion ud
               where ud.Bookmarked = 1
                  and ud.UserID = u.UserID
            )";
      }
//      if (!$this->ImportExists('User', 'CountUnreadConversations')) {
//         $Sqls['User.CountUnreadConversations'] =
//            'update :_User u
//            set u.CountUnreadConversations = (
//              select count(c.ConversationID)
//              from :_Conversation c
//              inner join :_UserConversation uc
//                on c.ConversationID = uc.ConversationID
//              where uc.UserID = u.UserID
//                and uc.CountReadMessages < c.CountMessages
//            )';
//      }

      // The updates start here.
		$CurrentSubstep = GetValue('CurrentSubstep', $this->Data, 0);

      if($CurrentSubstep == 0) {
         // Add the FirstCommentID to the discussion table.
         Gdn::Structure()->Table('Discussion')->Column('FirstCommentID', 'int', NULL, 'index')->Set(FALSE, FALSE);
      }

//      $Sqls2 = array();
//      $i = 1;
//      foreach ($Sqls as $Name => $Sql) {
//         $Sqls2[] = "/* $i. $Name */\n"
//            .str_replace(':_', $this->Database->DatabasePrefix, $Sql)
//            .";\n";
//         $i++;
//      }
//      throw new Exception(implode("\n", $Sqls2));

		// Execute the SQL.
      $Keys = array_keys($Sqls);
      for($i = $CurrentSubstep; $i < count($Keys); $i++) {
         $this->Data['CurrentStepMessage'] = sprintf(T('%s of %s'), $CurrentSubstep + 1, count($Keys));
			$Sql = $Sqls[$Keys[$i]];
			$this->Query($Sql);
			if($this->Timer->ElapsedTime() > $this->MaxStepTime) {
				$this->Data['CurrentSubstep'] = $i + 1;
				return FALSE;
			}
		}
		if(isset($this->Data['CurrentSubstep']))
			unset($this->Data['CurrentSubstep']);

		// Remove the FirstCommentID from the discussion table.
		Gdn::Structure()->Table('Discussion')->DropColumn('FirstCommentID');
		$this->Data['CurrentStepMessage'] = '';

      // Update the url codes of categories.
      if (!$this->ImportExists('Category', 'UrlCode')) {
         $Categories = Gdn::SQL()->Get('Category')->ResultArray();
         foreach ($Categories as $Category) {
            $UrlCode = Gdn_Format::Url($Category['Name']);
            if (strlen($UrlCode) > 50)
               $UrlCode = $Category['CategoryID'];

            Gdn::SQL()->Put(
               'Category',
               array('UrlCode' => $UrlCode),
               array('CategoryID' => $Category['CategoryID']));
         }
      }
      // Rebuild the category tree.
      $CategoryModel = new CategoryModel();
      $CategoryModel->RebuildTree();

      return TRUE;
	}
开发者ID:nerdgirl,项目名称:Forums-ILoveBadTV,代码行数:101,代码来源:class.importmodel.php

示例3: UpdateCounts


//.........这里部分代码省略.........
             $Sqls['Conversation.LastMessageID'] = $this->GetCountSQL('max', 'Conversation', 'ConversationMessage', 'LastMessageID', 'MessageID');
         }
         if (!$this->ImportExists('Conversation', 'DateUpdated')) {
             $Sqls['Converstation.DateUpdated'] = "update :_Conversation c join :_ConversationMessage m on c.LastMessageID = m.MessageID set c.DateUpdated = m.DateInserted";
         }
         if ($this->ImportExists('UserConversation')) {
             if (!$this->ImportExists('UserConversation', 'LastMessageID')) {
                 if ($this->ImportExists('UserConversation', 'DateLastViewed')) {
                     // Get the value from the DateLastViewed.
                     $Sqls['UserConversation.LastMessageID'] = "update :_UserConversation uc\r\n                     set LastMessageID = (\r\n                       select max(MessageID)\r\n                       from :_ConversationMessage m\r\n                       where m.ConversationID = uc.ConversationID\r\n                         and m.DateInserted >= uc.DateLastViewed)";
                 } else {
                     // Get the value from the conversation.
                     // In this case just mark all of the messages read.
                     $Sqls['UserConversation.LastMessageID'] = "update :_UserConversation uc\r\n                     join :_Conversation c\r\n                       on c.ConversationID = uc.ConversationID\r\n                     set uc.CountReadMessages = c.CountMessages,\r\n                       uc.LastMessageID = c.LastMessageID";
                 }
             } elseif (!$this->ImportExists('UserConversation', 'DateLastViewed')) {
                 // We have the last message so grab the date from that.
                 $Sqls['UserConversation.DateLastViewed'] = "update :_UserConversation uc\r\n                     join :_ConversationMessage m\r\n                       on m.ConversationID = uc.ConversationID\r\n                         and m.MessageID = uc.LastMessageID\r\n                     set uc.DateLastViewed = m.DateInserted";
             }
         }
     }
     // User counts.
     if (!$this->ImportExists('User', 'DateFirstVisit')) {
         $Sqls['User.DateFirstVisit'] = 'update :_User set DateFirstVisit = DateInserted';
     }
     if (!$this->ImportExists('User', 'CountDiscussions')) {
         $Sqls['User.CountDiscussions'] = $this->GetCountSQL('count', 'User', 'Discussion', 'CountDiscussions', 'DiscussionID', 'UserID', 'InsertUserID');
     }
     if (!$this->ImportExists('User', 'CountComments')) {
         $Sqls['User.CountComments'] = $this->GetCountSQL('count', 'User', 'Comment', 'CountComments', 'CommentID', 'UserID', 'InsertUserID');
     }
     if (!$this->ImportExists('User', 'CountBookmarks')) {
         $Sqls['User.CountBookmarks'] = "update :_User u\r\n            set CountBookmarks = (\r\n               select count(ud.DiscussionID)\r\n               from :_UserDiscussion ud\r\n               where ud.Bookmarked = 1\r\n                  and ud.UserID = u.UserID\r\n            )";
     }
     //      if (!$this->ImportExists('User', 'CountUnreadConversations')) {
     //         $Sqls['User.CountUnreadConversations'] =
     //            'update :_User u
     //            set u.CountUnreadConversations = (
     //              select count(c.ConversationID)
     //              from :_Conversation c
     //              inner join :_UserConversation uc
     //                on c.ConversationID = uc.ConversationID
     //              where uc.UserID = u.UserID
     //                and uc.CountReadMessages < c.CountMessages
     //            )';
     //      }
     // The updates start here.
     $CurrentSubstep = GetValue('CurrentSubstep', $this->Data, 0);
     //      $Sqls2 = array();
     //      $i = 1;
     //      foreach ($Sqls as $Name => $Sql) {
     //         $Sqls2[] = "/* $i. $Name */\n"
     //            .str_replace(':_', $this->Database->DatabasePrefix, $Sql)
     //            .";\n";
     //         $i++;
     //      }
     //      throw new Exception(implode("\n", $Sqls2));
     // Execute the SQL.
     $Keys = array_keys($Sqls);
     for ($i = $CurrentSubstep; $i < count($Keys); $i++) {
         $this->Data['CurrentStepMessage'] = sprintf(T('%s of %s'), $CurrentSubstep + 1, count($Keys));
         $Sql = $Sqls[$Keys[$i]];
         $this->Query($Sql);
         if ($this->Timer->ElapsedTime() > $this->MaxStepTime) {
             $this->Data['CurrentSubstep'] = $i + 1;
             return FALSE;
         }
     }
     if (isset($this->Data['CurrentSubstep'])) {
         unset($this->Data['CurrentSubstep']);
     }
     $this->Data['CurrentStepMessage'] = '';
     // Update the url codes of categories.
     if (!$this->ImportExists('Category', 'UrlCode')) {
         $Categories = CategoryModel::Categories();
         $TakenCodes = array();
         foreach ($Categories as $Category) {
             $UrlCode = urldecode(Gdn_Format::Url($Category['Name']));
             if (strlen($UrlCode) > 50) {
                 $UrlCode = $Category['CategoryID'];
             }
             if (in_array($UrlCode, $TakenCodes)) {
                 $ParentCategory = CategoryModel::Categories($Category['ParentCategoryID']);
                 if ($ParentCategory && $ParentCategory['CategoryID'] != -1) {
                     $UrlCode = Gdn_Format::Url($ParentCategory['Name']) . '-' . $UrlCode;
                 }
                 if (in_array($UrlCode, $TakenCodes)) {
                     $UrlCode = $Category['CategoryID'];
                 }
             }
             $TakenCodes[] = $UrlCode;
             Gdn::SQL()->Put('Category', array('UrlCode' => $UrlCode), array('CategoryID' => $Category['CategoryID']));
         }
     }
     // Rebuild the category tree.
     $CategoryModel = new CategoryModel();
     $CategoryModel->RebuildTree();
     $this->SetCategoryPermissionIDs();
     return TRUE;
 }
开发者ID:elpum,项目名称:TgaForumBundle,代码行数:101,代码来源:class.importmodel.php

示例4: MergeForums

 /**
  * Grab second forum's data and merge with current forum.
  *
  * Merge Users on email address. Keeps this forum's username/password.
  * Merge Roles, Tags, and Categories on precise name matches.
  *
  * @todo Compare column names between forums and use intersection
  */
 public function MergeForums($OldDatabase, $OldPrefix, $LegacySlug)
 {
     $NewPrefix = C('Database.DatabasePrefix');
     $this->OldDatabase = $OldDatabase;
     $this->OldPrefix = $OldPrefix;
     $DoLegacy = !empty($LegacySlug);
     // USERS //
     if ($this->OldTableExists('User')) {
         $UserColumns = $this->GetColumns('User', $OldDatabase, $OldPrefix);
         // Merge IDs of duplicate users
         Gdn::SQL()->Query('update ' . $NewPrefix . 'User u set u.OldID =
         (select u2.UserID from `' . $OldDatabase . '`.' . $OldPrefix . 'User u2 where u2.Email = u.Email limit 1)');
         // Copy non-duplicate users
         Gdn::SQL()->Query('insert into ' . $NewPrefix . 'User (' . $UserColumns . ', OldID)
         select ' . $UserColumns . ', UserID
         from `' . $OldDatabase . '`.' . $OldPrefix . 'User
         where Email not in (select Email from ' . $NewPrefix . 'User)');
         // UserMeta
         if ($this->OldTableExists('UserMeta')) {
             Gdn::SQL()->Query('insert ignore into ' . $NewPrefix . 'UserMeta (UserID, Name, Value)
            select u.UserID, um.Name, um.Value
            from ' . $NewPrefix . 'User u, `' . $OldDatabase . '`.' . $OldPrefix . 'UserMeta um
            where u.OldID = um.UserID');
         }
     }
     // ROLES //
     if ($this->OldTableExists('Role')) {
         $RoleColumns = $this->GetColumns('Role', $OldDatabase, $OldPrefix);
         // Merge IDs of duplicate roles
         Gdn::SQL()->Query('update ' . $NewPrefix . 'Role r set r.OldID =
         (select r2.RoleID from `' . $OldDatabase . '`.' . $OldPrefix . 'Role r2 where r2.Name = r.Name)');
         // Copy non-duplicate roles
         Gdn::SQL()->Query('insert into ' . $NewPrefix . 'Role (' . $RoleColumns . ', OldID)
         select ' . $RoleColumns . ', RoleID
         from `' . $OldDatabase . '`.' . $OldPrefix . 'Role
         where Name not in (select Name from ' . $NewPrefix . 'Role)');
         // UserRole
         if ($this->OldTableExists('UserRole')) {
             Gdn::SQL()->Query('insert ignore into ' . $NewPrefix . 'UserRole (RoleID, UserID)
            select r.RoleID, u.UserID
            from ' . $NewPrefix . 'User u, ' . $NewPrefix . 'Role r, `' . $OldDatabase . '`.' . $OldPrefix . 'UserRole ur
            where u.OldID = (ur.UserID) and r.OldID = (ur.RoleID)');
         }
     }
     // CATEGORIES //
     if ($this->OldTableExists('Category')) {
         $CategoryColumnOptions = array('Legacy' => $DoLegacy);
         $CategoryColumns = $this->GetColumns('Category', $OldDatabase, $OldPrefix, $CategoryColumnOptions);
         /*if ($this->MergeCategories) {
                     // Merge IDs of duplicate category names
                     Gdn::SQL()->Query('update '.$NewPrefix.'Category c set c.OldID =
                        (select c2.CategoryID from `'.$OldDatabase.'`.'.$OldPrefix.'Category c2 where c2.Name = c.Name)');
         
                     // Copy non-duplicate categories
                     Gdn::SQL()->Query('insert into '.$NewPrefix.'Category ('.$CategoryColumns.', OldID)
                        select '.$CategoryColumns.', CategoryID
                        from `'.$OldDatabase.'`.'.$OldPrefix.'Category
                        where Name not in (select Name from '.$NewPrefix.'Category)');
                  }
                  else {*/
         // Import categories
         if ($DoLegacy) {
             Gdn::SQL()->Query('insert into ' . $NewPrefix . 'Category (' . $CategoryColumns . ', OldID, ForeignID)
            select ' . $CategoryColumns . ', CategoryID, concat(\'' . $LegacySlug . '-\', CategoryID)
            from `' . $OldDatabase . '`.' . $OldPrefix . 'Category
            where Name <> "Root"');
         } else {
             Gdn::SQL()->Query('insert into ' . $NewPrefix . 'Category (' . $CategoryColumns . ', OldID)
            select ' . $CategoryColumns . ', CategoryID
            from `' . $OldDatabase . '`.' . $OldPrefix . 'Category
            where Name <> "Root"');
         }
         // Remap hierarchy in the ugliest way possible
         $CategoryMap = array();
         $Categories = Gdn::SQL()->Select('CategoryID')->Select('ParentCategoryID')->Select('OldID')->From('Category')->Where(array('OldID >' => 0))->Get()->Result(DATASET_TYPE_ARRAY);
         foreach ($Categories as $Category) {
             $CategoryMap[$Category['OldID']] = $Category['CategoryID'];
         }
         foreach ($Categories as $Category) {
             if ($Category['ParentCategoryID'] > 0 && !empty($CategoryMap[$Category['ParentCategoryID']])) {
                 $ParentID = $CategoryMap[$Category['ParentCategoryID']];
                 Gdn::SQL()->Update('Category')->Set(array('ParentCategoryID' => $ParentID))->Where(array('CategoryID' => $Category['CategoryID']))->Put();
             }
         }
         $CategoryModel = new CategoryModel();
         $CategoryModel->RebuildTree();
         //}
         // UserCategory
     }
     // DISCUSSIONS //
     if ($this->OldTableExists('Discussion')) {
         $DiscussionColumnOptions = array('Legacy' => $DoLegacy);
//.........这里部分代码省略.........
开发者ID:SatiricMan,项目名称:addons,代码行数:101,代码来源:class.forummerge.plugin.php


注:本文中的CategoryModel::RebuildTree方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。