示例#1
0
 public function mysql_save()
 {
     $prev = UserShare::from_mysql_id($this->id);
     if ($this->id != 0 && $prev != null) {
         if ($this->UserWorkspace_id != $prev->UserWorkspace_id || $this->invitee_id != $prev->invitee_id) {
             $shares = UserShare::from_property(array("UserWorkspace_id" => $prev->UserWorkspace_id, "invitee_id" => $prev->invitee_id));
             $ws = $prev->get_UserWorkspace();
             if ($ws != null && count($shares) <= 1) {
                 $ws->revoke_privileges_db_user($prev->invitee_id);
             }
         }
     }
     $ws = UserWorkspace::from_mysql_id($this->UserWorkspace_id);
     if ($ws != null) {
         $ws->grant_privileges_db_user($this->invitee_id);
     }
     parent::mysql_save();
 }
示例#2
0
 public function mysql_save_from_post($post)
 {
     $is_new = $this->id == 0;
     if (array_key_exists("superuser", $post)) {
         $logged_user = User::get_logged_user();
         if ($logged_user == null || $logged_user->superuser == 0) {
             $post['superuser'] = 0;
         }
     }
     $post['oid'] = parent::mysql_save_from_post($post);
     $obj = User::from_mysql_id($post['oid']);
     if ($post['modify_password'] == 1) {
         $obj->password = $obj->calculate_password_hash($post['password_hash']);
         $obj->mysql_save();
     }
     if (array_key_exists("deleteShare", $post)) {
         $rows = json_decode($post["deleteShare"]);
         foreach ($rows as $row) {
             $share = UserShare::from_mysql_id($row);
             if ($share != null) {
                 $share->mysql_delete();
             }
         }
     }
     if (array_key_exists("updateShare", $post)) {
         $rows = json_decode($post["updateShare"], true);
         foreach ($rows as $row) {
             if ($row["id"] != 0) {
                 $share = UserShare::from_mysql_id($row['id']);
                 $share->invitee_id = $row['invitee_id'];
                 $share->UserWorkspace_id = $row['workspace_id'];
                 $share->mysql_save();
             } else {
                 $share = new UserShare();
                 $share->invitee_id = $row['invitee_id'];
                 $share->UserWorkspace_id = $row['workspace_id'];
                 $share->mysql_save();
             }
         }
     }
     if ($is_new) {
         $ws = new UserWorkspace();
         $ws->owner_id = $post['oid'];
         $ws->main = 1;
         $ws->name = "main";
         $ws->mysql_save();
     } else {
         if (array_key_exists("deleteWorkspace", $post)) {
             $rows = json_decode($post["deleteWorkspace"]);
             foreach ($rows as $row) {
                 $ws = UserWorkspace::from_mysql_id($row);
                 if ($ws != null) {
                     $ws->mysql_delete();
                 }
             }
         }
         if (array_key_exists("updateWorkspace", $post)) {
             $rows = json_decode($post["updateWorkspace"], true);
             foreach ($rows as $row) {
                 if ($row["id"] != 0) {
                     $ws = UserWorkspace::from_mysql_id($row['id']);
                     $ws->name = $row['name'];
                     $ws->owner_id = $this->id;
                     $ws->mysql_save();
                 } else {
                     $ws = new UserWorkspace();
                     $ws->name = $row['name'];
                     $ws->owner_id = $this->id;
                     $ws->mysql_save();
                 }
             }
         }
     }
     return $post['oid'];
 }