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


PHP Posts::reassign方法代码示例

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


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

示例1: update_users

 /**
  * Update an array of POSTed users.
  */
 public function update_users($handler_vars)
 {
     if (isset($handler_vars['delete'])) {
         $currentuser = User::identify();
         $wsse = Utils::WSSE($handler_vars['nonce'], $handler_vars['timestamp']);
         if (isset($handler_vars['digest']) && $handler_vars['digest'] != $wsse['digest']) {
             Session::error(_t('WSSE authentication failed.'));
             return Session::messages_get(true, 'array');
         }
         foreach ($_POST as $id => $delete) {
             // skip POST elements which are not user ids
             if (preg_match('/^p\\d+$/', $id) && $delete) {
                 $id = (int) substr($id, 1);
                 $ids[] = array('id' => $id);
             }
         }
         if (isset($handler_vars['checkbox_ids'])) {
             $checkbox_ids = $handler_vars['checkbox_ids'];
             foreach ($checkbox_ids as $id => $delete) {
                 if ($delete) {
                     $ids[] = array('id' => $id);
                 }
             }
         }
         $count = 0;
         if (!isset($ids)) {
             Session::notice(_t('No users deleted.'));
             return Session::messages_get(true, 'array');
         }
         foreach ($ids as $id) {
             $id = $id['id'];
             $user = User::get_by_id($id);
             if ($currentuser != $user) {
                 $assign = intval($handler_vars['reassign']);
                 if ($user->id == $assign) {
                     return;
                 }
                 $posts = Posts::get(array('user_id' => $user->id, 'nolimit' => 1));
                 if (isset($posts[0])) {
                     if (0 == $assign) {
                         foreach ($posts as $post) {
                             $post->delete();
                         }
                     } else {
                         Posts::reassign($assign, $posts);
                     }
                 }
                 $user->delete();
             } else {
                 $msg_status = _t('You cannot delete yourself.');
             }
             $count++;
         }
         if (!isset($msg_status)) {
             $msg_status = sprintf(_t('Deleted %d users.'), $count);
         }
         Session::notice($msg_status);
     }
 }
开发者ID:psaintlaurent,项目名称:Habari,代码行数:62,代码来源:adminhandler.php

示例2: do_delete_users

 /**
  * Success method for the delete_users form
  * @param FormUI $form The delete_users form
  */
 public function do_delete_users(FormUI $form)
 {
     $success = true;
     // Get the user to assign deleted users' posts to
     $assign = intval($form->reassign->value);
     if (in_array($assign, $form->deletion_queue->value)) {
         Session::error(_t('You may not assign posts from deleted users to a user that is being deleted'));
         return false;
     }
     $count = 0;
     if (count($form->deletion_queue->value) == 0) {
         Session::notice(_t('No users deleted.'));
         return false;
     }
     foreach ($form->deletion_queue->value as $id) {
         $user = User::get_by_id($id);
         $posts = Posts::get(array('user_id' => $user->id, 'nolimit' => 1));
         $one_success = $user->delete();
         if ($one_success && count($posts)) {
             if (0 == $assign) {
                 /** @var Post $post */
                 foreach ($posts as $post) {
                     $post->delete();
                 }
             } else {
                 Posts::reassign($assign, $posts);
             }
         }
         $success = $success && $one_success;
         $count++;
     }
     if ($success) {
         $msg_status = sprintf(_n('Deleted one user.', 'Deleted %s users.', $count), $count);
         Session::notice($msg_status);
         return true;
     } else {
         $msg_status = _t('There was a problem deleting users.');
         Session::error($msg_status);
         return false;
     }
 }
开发者ID:habari,项目名称:system,代码行数:45,代码来源:adminusershandler.php


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