Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remember the order of new widgets #3

Open
wants to merge 2 commits into
base: gui
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions includes/controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@ public function save_profile_data() {
}

// Now edit and add
$order_iterator = 0;
foreach ( $widget_order as $key ) {
$title = isset( $_POST[ $key ]['title'] ) ? $_POST[ $key ]['title'] : '';
$content = isset( $_POST[ $key ]['content'] ) ? $_POST[ $key ]['content'] : '';
Expand All @@ -253,15 +254,18 @@ public function save_profile_data() {
'widget_type' => $widget_type,
'title' => $title,
'content' => $content,
'position' => $order_iterator,
) );
} else {
$user->save_widget_instance( array(
'key' => $key,
'widget_type' => $widget_type,
'title' => $title,
'content' => $content,
'position' => $order_iterator,
) );
}
$order_iterator = $order_iterator + 1;
}
}
}
Expand Down
4 changes: 4 additions & 0 deletions includes/user.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ public function create_widget_instance( $args = array() ) {
'widget_type' => '',
'title' => '',
'content' => '',
'position' => '',
) );

$r['user_id'] = $this->user_id;
Expand All @@ -131,6 +132,7 @@ public function save_widget_instance( $args = array() ) {
'widget_type' => '',
'title' => '',
'content' => '',
'position' => '',
) );

$r['user_id'] = $this->user_id;
Expand All @@ -139,6 +141,7 @@ public function save_widget_instance( $args = array() ) {
'key' => $r['key'],
'widget_type' => $r['widget_type'],
'user_id' => $r['user_id'],
'position' => $r['position'],
) );

// todo - what if it's new
Expand All @@ -147,6 +150,7 @@ public function save_widget_instance( $args = array() ) {
'user_id' => $widget_instance->user_id,
'title' => $r['title'],
'content' => $r['content'],
'position' => $r['position'],
) );
}

Expand Down
2 changes: 2 additions & 0 deletions includes/widget.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ public function save_instance_for_user( $args = array() ) {
'user_id' => 0,
'title' => $this->name,
'content' => '',
'position' => '',
) );

if ( ! $r['user_id'] ) {
Expand Down Expand Up @@ -99,6 +100,7 @@ public function save_instance_for_user( $args = array() ) {
'key' => $r['title'],
'value' => $r['content'],
'widget_type' => $this->slug,
'position' => $r['position'],
) );
} else {
// phooey
Expand Down
3 changes: 2 additions & 1 deletion includes/widget_instance.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ public function create( $args = array() ) {
'widget_type' => '',
'title' => '',
'content' => '',
'position' => '',
) );

$types = cacap_widget_types();
Expand Down Expand Up @@ -207,7 +208,7 @@ public static function format_instance( $args = array() ) {
'user_id' => 0,
'key' => '',
'widget_type' => '',
'position' => 50,
'position' => '',
) );

$retval = array(
Expand Down
10 changes: 6 additions & 4 deletions includes/widgets/text.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,11 @@ public function __construct() {
*/
public function save_instance_for_user( $args = array() ) {
$r = wp_parse_args( $args, array(
'key' => '',
'user_id' => 0,
'title' => '',
'content' => '',
'key' => '',
'user_id' => 0,
'title' => '',
'content' => '',
'position' => '',
) );

// @todo better error reporting
Expand All @@ -50,6 +51,7 @@ public function save_instance_for_user( $args = array() ) {
'key' => $meta_key,
'value' => $meta_value,
'widget_type' => $this->slug,
'position' => $r['position'],
) );
} else {
// do something bad
Expand Down