public function testUpdateOnlyTouched() { $post = new BlogPost(); $post->userId = 2; $post->title = "Hello World!"; $post->message = "This is a blog post!"; $this->assertEqual($post->save(), true); $id = $post->id; $post1 = BlogPost::load($id); $post1->title = "Not this World"; $post->message = "This is an another blog post!"; $post->save(); $post1->save(); $post2 = BlogPost::load($id); $this->assertEqual($post2->title, "Not this World"); $this->assertEqual($post2->message, "This is an another blog post!"); }
function render() { $login_uid = @PA::$login_user->user_id; $this->gid = @$this->params['blog_id']; $this->blog_name = @$this->params['blog_name']; $this->note = ''; if ($this->blog_name) { $this->find_or_create_blog(); } if ($this->gid) { $this->type == 'group'; $group = new Group(); $group->collection_id = $this->gid; $group->load($this->gid); $this->group_member = Group::member_exists($group->collection_id, $login_uid) ? TRUE : FALSE; switch ($this->view) { case "recent_post": // load content $this->contents = $group->get_contents_for_collection($type = 'all', $cnt = FALSE, 1, 1, 'created', 'DESC'); $this->inner_template = 'recent_post.tpl'; break; case 'user': // load content if (@$this->params['cid']) { // permalink, load only this one $bp = new BlogPost(); try { $bp->load((int) $this->params['cid']); $this->count = 1; $content = array(); foreach ($bp as $k => $v) { $content[$k] = $v; } $this->contents[] = $content; } catch (PAException $e) { $this->err = __("Couldn't load BlogPost. ") . $e->getMessage(); } } else { $this->count = $group->get_contents_for_collection($type = 'all', $cnt = TRUE, 'all', 0, $sort_by = 'created', $direction = 'DESC'); $this->contents = $group->get_contents_for_collection($type = 'all', $cnt = FALSE, $this->show, $this->page, 'created', 'DESC'); } break; case "admin": $this->title = "Managing authors for " . $this->blog_name; $this->inner_template = 'manageauthors.tpl'; // find members $this->members = $group->get_members(); $this->member_count = count($this->members); break; } // load Items for all BlogPosts -> for Comments to work foreach ($this->contents as $i => $post) { $item_params = array("type" => 'blogpost', "id" => $post['content_id'], "name" => $post['content_id'], "thumbnail" => "", "thumbnail_w" => "0", "thumbnail_h" => "0", "genres" => "blog", "url" => $this->blog_url . "?b_cid=" . $post['content_id']); Item::sync($item_params); // create or update row in 'items' database table $item = Item::find_by_subject('blogpost', $post['content_id']); $this->contents[$i]['comment_count'] = $item->comment_count; } } else { $this->err = __("No Blog found."); } $tmp_file = dirname(__FILE__) . "/" . $this->skin . "_" . $this->inner_template; $inner_html_gen =& new Template($tmp_file, $this); $this->inner_HTML = $inner_html_gen->fetch(); $content = parent::render(); return $content; }