/** * Put all your PMs into auto-folders. * @return string */ private function onAutoFolder() { $user = GWF_Session::getUser(); $userid = GWF_Session::getUserID(); if (false === ($pmo = GWF_PMOptions::getPMOptions($user))) { return GWF_HTML::err('ERR_DATABASE', array(__FILE__, __LINE__)); } if (0 >= ($peak = $pmo->getAutoFolderValue())) { return $this->module->message('msg_auto_folder_off'); } $del = GWF_PM::OWNER_DELETED; # count pm from and to user. $conditions = "(pm_owner={$userid} AND pm_options&{$del}=0)"; $db = gdo_db(); $pms = GDO::table('GWF_PM'); $sorted = array(); if (false === ($result = $pms->select('*', $conditions))) { return GWF_HTML::err('ERR_DATABASE', array(__FILE__, __LINE__)); } # Sort By UID while (false !== ($row = $db->fetchAssoc($result))) { $pm = new GWF_PM($row); $other_user = $pm->getOtherUser($user); $other_uid = $other_user->getID(); if (!isset($sorted[$other_uid])) { $sorted[$other_uid] = array(); } $sorted[$other_uid][] = $pm; } $db->free($result); $back = ''; foreach ($sorted as $uid => $pms) { if (count($pms) < $peak) { continue; } $other_user = $pms[0]->getOtherUser($user); $foldername = $other_user->getVar('user_name'); # Create the folder if not exists. if (false === ($folder = GWF_PMFolder::getByName($foldername, $user))) { $folder = GWF_PMFolder::fakeFolder($user->getID(), $foldername); if (false === $folder->insert()) { return GWF_HTML::err('ERR_DATABASE', array(__FILE__, __LINE__)); } $back .= $this->module->message('msg_auto_folder_created', array($other_user->displayUsername())); } $moved = 0; foreach ($pms as $pm) { if (false !== $pm->move($user, $folder)) { $moved++; } } if ($moved > 0) { $back .= $this->module->message('msg_auto_folder_moved', array($moved, $other_user->displayUsername())); } } return $back . $this->module->message('msg_auto_folder_done'); }