[pLog-svn] r1807 - plog/branches/plog-1.0.1/class/action

Mark Wu markplace at gmail.com
Mon Apr 11 09:13:29 GMT 2005


Hi Oscar:

I see.

So, let me clarify something.

1. There could be multiple $users belong to one blog
2. There is only one $owner of one blog
3. $owner is blogin to one of $user

So, 

1. I will try to modify to code as you suggest to populate the $ower instead
of $userto template. 
2. But, do you think we need to populate "$users" to templates (all template
pages). Or just let template editor get them from $post->getUserInfo() (only
work on post.templaye and postandcomment.template)

Regards, Mark


-----Original Message-----
From: plog-svn-bounces at devel.plogworld.net
[mailto:plog-svn-bounces at devel.plogworld.net] On Behalf Of Oscar Renalias
Sent: Monday, April 11, 2005 4:55 PM
To: plog-svn at devel.plogworld.net
Subject: Re: [pLog-svn] r1807 - plog/branches/plog-1.0.1/class/action

Mark, I am afraid that this commit doesn't make too much sense to me:

- there can be situations where $user and $blogInfo->getOwner() are not the
same. For example I can visit the following url:
"index.php?op=Default&userId=4&blogId=3" while the id of the owner is '5'.
This means that I want to see only the posts made by user with id '4' in the
blog '3' (let's assume that the user belongs to this blog).
Or in other words, what you said about $user and blogInfo->getOwner() is not
correct.

- Also, if you look at the logic of your changes... it doesn't work.
Look at how many times we load the same User object:

-->         // load the user if we got a "userId" parameter (correct)
            if( $this->_userId > 0) {
                $user = $users->getUserInfoFromId( $this->_userName );
                if( !$user ) {
                   ...
                }
            }

-->        // load the user if we got a "userName" parameter (correct)
            if( $this->_userName ) {
                $user = $users->getUserInfoFromUsername( $this->_userName );
                if( !$user ) {
                   ....
                }
               
                // if everything went fine...
                $this->_userId = $user->getId();
            }

-->        // and now, are we populating the $user variable once
again??? (incorrect)
            $ownerId = $this->_blogInfo->getOwner();
                        $user = $users->getUserInfoFromId( $ownerId );
            if( !$user ) {
                $this->_view = new ErrorView( $this->_blogInfo );
                $this->_view->setValue( 'message',
'error_incorrect_owner_id' );
                $this->setCommonData();
                return false;
            }                  

            // export the user
            if( isset($user) )
                $this->_view->setValue( "user", $user );

I suggest we remove the last bit because it's wrong and unnecessary, and
replace it:

$this->_view->setValue( "owner", $this->_blogInfo->getOwnerInfo());

- You can use $blogInfo->getOwnerInfo() to get a UserInfo right away, there
is no need to get the user id and then use the class Users to load that
info. Whenever in doubt, check the API :) I will upload it as soon as I have
the time but in the meantime, download Doxygen (http://www.doxygen.org), go
to your class/ folder and execute Doxygen. Once done, go back to the root
plog folder and load the following file in your browser:
docs-devel/html/index.html. The API is all yours now too :-)

Hope it's clear... And hope you don't mind my comments! But it's just that I
saw your changes and it was clear that it wouldn't work so I had to comment
on it :-)

Oscar

On Apr 11, 2005 11:33 AM, Mark Wu <markplace at gmail.com> wrote:
> Hi Oscar:
>
> I fix the issue that $user object does not exist in template pages
> when use userid instead of username in custom url ...
>
> And, I assume the $user (actually) should be blogowner,  therefore I
> get it from blogInfo->getOwner() instead get it from username and userid.
>
> And, each post author can get through $post->getUserInfo(), ... So, I
> think this should be enough those template editor who want to put
> onwer or user information in template pages.
>
> Mark
>
> -----Original Message-----
> From: plog-svn-bounces at devel.plogworld.net
> [mailto:plog-svn-bounces at devel.plogworld.net] On Behalf Of
> mark at devel.plogworld.net
> Sent: Monday, April 11, 2005 4:10 PM
> To: plog-svn at devel.plogworld.net
> Subject: [pLog-svn] r1807 - plog/branches/plog-1.0.1/class/action
>
> Author: mark
> Date: 2005-04-11 08:09:52 +0000 (Mon, 11 Apr 2005) New Revision: 1807
>
> Modified:
>    plog/branches/plog-1.0.1/class/action/defaultaction.class.php
> Log:
> Solve the bug reported by Jas in Chinese Forum
> http://forum.plogworld.org.tw/viewtopic.php?t=396 , get the user
> object from blogInfo instead of username and userid.
>
> Modified:
> plog/branches/plog-1.0.1/class/action/defaultaction.class.php
> ===================================================================
> --- plog/branches/plog-1.0.1/class/action/defaultaction.class.php
> 2005-04-11 07:05:16 UTC (rev 1806)
> +++ plog/branches/plog-1.0.1/class/action/defaultaction.class.php
> 2005-04-11 08:09:52 UTC (rev 1807)
> @@ -108,11 +108,25 @@
>              if( isset($category) )
>                  $this->_view->setValue( "category", $category );
>
> +
> +            $users = new Users();
> +
> +            // if we got a user user id, then we should first look up
> + this
> id
> +            // user in the database and see if it exists
> +            if( $this->_userId > 0) {
> +                $user = $users->getUserInfoFromId( $this->_userName );
> +                if( !$user ) {
> +                    $this->_view = new ErrorView( $this->_blogInfo );
> +                    $this->_view->setValue( 'message',
> 'error_incorrect_user_id' );
> +                    $this->setCommonData();
> +                    return false;
> +                }
> +            }
> +
>              // if we got a user name instead of a user id, then we
>              // should first look up this user in the database and see if
>              // it exists
>              if( $this->_userName ) {
> -                               $users = new Users();
>                  $user = $users->getUserInfoFromUsername(
> $this->_userName );
>                  if( !$user ) {
>                      $this->_view = new ErrorView( $this->_blogInfo );
> @@
> -125,6 +139,17 @@
>                  $this->_userId = $user->getId();
>              }
>
> +            // The user object should not get from user_name or
> + user_id, it
> should
> +            // get from blogInfo
> +            $ownerId = $this->_blogInfo->getOwner();
> +                       $user = $users->getUserInfoFromId( $ownerId );
> +            if( !$user ) {
> +                $this->_view = new ErrorView( $this->_blogInfo );
> +                $this->_view->setValue( 'message',
> 'error_incorrect_owner_id' );
> +                $this->setCommonData();
> +                return false;
> +            }
> +
>              // export the user
>              if( isset($user) )
>                  $this->_view->setValue( "user", $user );
>
> _______________________________________________
> pLog-svn mailing list
> pLog-svn at devel.plogworld.net
> http://devel.plogworld.net/mailman/listinfo/plog-svn
>
> _______________________________________________
> pLog-svn mailing list
> pLog-svn at devel.plogworld.net
> http://devel.plogworld.net/mailman/listinfo/plog-svn
>
_______________________________________________
pLog-svn mailing list
pLog-svn at devel.plogworld.net
http://devel.plogworld.net/mailman/listinfo/plog-svn 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.plogworld.net/pipermail/plog-svn/attachments/20050411/b7526d0a/attachment.html


More information about the pLog-svn mailing list