Exemple #1
0
 public function build($runData)
 {
     $users = array();
     $c = new Criteria();
     $c->add('user_id', '1', '>');
     foreach (DB_OzoneUserPeer::instance()->select($c) as $user) {
         $admin = WDPermissionManager::hasPermission('manage_site', $user, 1) ? 1 : 0;
         $mod = WDPermissionManager::hasPermission('moderate_site', $user, 1) ? 1 : 0;
         $users[] = array("nick_name" => $user->getNickName(), "user_id" => $user->getUserId(), "mod" => $mod, "admin" => $admin);
     }
     for ($i = 0; $i < 5; $i++) {
         $users[] = array("user_id" => "new{$i}");
     }
     $runData->contextAdd("users", $users);
 }
Exemple #2
0
 public function saveEvent($runData)
 {
     $params = $runData->getParameterList()->asArray();
     $ids = array();
     foreach ($params as $param_key => $param_val) {
         $m = array();
         if (preg_match(';^nick_name_([new0-9]+)$;', $param_key, $m)) {
             $ids[] = $m[1];
         }
     }
     foreach ($ids as $id) {
         $nick_name = $params["nick_name_{$id}"];
         $password = $params["password_{$id}"];
         $admin = $params["admin_{$id}"] ? true : false;
         $mod = $params["mod_{$id}"] ? true : false;
         $site = $runData->getTemp('site');
         if ($nick_name) {
             if ($id = 1 * $id) {
                 $u = DB_OzoneUserPeer::instance()->selectByPrimaryKey($id);
             } else {
                 $u = null;
             }
             $next = false;
             if (!$u) {
                 $u = new DB_OzoneUser();
                 if (!$password) {
                     $next = true;
                 }
                 $u->save();
                 $m = new DB_Member();
                 $m->setUserId($u->getUserId());
                 $m->setSiteId($site->getSiteId());
                 $m->save();
             }
             if (!$next) {
                 $u->setName($nick_name);
                 $u->setEmail($nick_name);
                 $u->setNickName($nick_name);
                 $u->setUnixName(WDStringUtils::toUnixName($nick_name));
                 if ($password) {
                     $u->setPassword(md5($password));
                 }
                 $u->save();
                 if ($admin) {
                     if (!WDPermissionManager::hasPermission('manage_site', $u, $site)) {
                         $a = new DB_Admin();
                         $a->setUserId($u->getUserId());
                         $a->setSiteId($site->getSiteId());
                         $a->save();
                     }
                 } else {
                     // ! $admin
                     $c = new Criteria();
                     $c->add('site_id', $site->getSiteId());
                     $c->add('user_id', $u->getUserId());
                     DB_AdminPeer::instance()->delete($c);
                 }
                 if ($mod) {
                     if (!WDPermissionManager::hasPermission('moderate_site', $u, $site)) {
                         $m = new DB_Moderator();
                         $m->setUserId($u->getUserId());
                         $m->setSiteId($site->getSiteId());
                         $m->save();
                     }
                 } else {
                     // ! $mod
                     $c = new Criteria();
                     $c->add('site_id', $site->getSiteId());
                     $c->add('user_id', $u->getUserId());
                     DB_ModeratorPeer::instance()->delete($c);
                 }
             }
         }
     }
 }