Location: PHPKode > projects > Web2.0 community/group web site > web20groups_pre-alpha-2/include/Controllers/ProfileController.php
<?php
	
class ProfileController extends CommonCustomControllerAction
{
	public function init()
	{
		parent::init();

		$this->profilespath= rtrim(Zend_Registry::get('config')->paths->profiles, '/');
		
        $this->view->extra_styles= array(
                                                '/css/main.css',
                                                '/css/windowstyle.css',
                                                '/css/formstyle.css',
                                                '/css/userprofile.css'
                                            );
        $this->view->extra_scripts= array(
                                                '/js/main.js',
                                                '/js/mylib.inlineframe.class.js',
                                                '/js/mylib.menu.class.js'
                                            );
	}
			
    public function indexAction()
    {
		$this->_redirect($this->getUrl('view'));
    }

	public function viewAction()
	{
        $this->preprocessParams();

	/*	if (strlen($this->param_username) == 0) {
			//$this->param_username= //get latest modified profile;
			//show the latest created/modified profile
			//select based on the timestamp of the file
		}*/

		if (!file_exists($this->param_profpath)) {
            if ($this->param_my == '') {
                if (DatabaseObject_User::isExists($this->db,
                                        $this->param_username)) {
                    $this->view->noprofile= true;
                }
                else {
                    $this->view->usernotfound= true;
                }
            }
            else {
    			$this->_redirect($this->getUrl('edit') );
            }
		}
        else {
            //this is a dirty hack, need to remove in later versions
            $fp =new FormProcessor_UserProfile($this->db, $this->param_username, $this->param_profpath);
            $fp->encodeforRendering();
            $this->view->fp= $fp;

            //dirty hack ends here

		    $this->selected_submenu1_item= ucwords($this->param_username);
        }

		$this->createSubMenu();
		$this->addUserMenu();

        $this->fillViewVariables();
	}

	public function editAction()
	{
        $request= $this->getRequest();
        $this->preprocessParams();

        $fp= new FormProcessor_UserProfile($this->db, $this->param_username, $this->param_profpath);
        $validate = $request->isXmlHttpRequest();

        if ($request->isPost()) {
            if ($validate) {
                $fp->validateOnly(true);
                $fp->process($request);
            }
            else if ($fp->process($request)) {
                $this->view->url = $this->getUrl('view');
                $this->_redirect($this->getUrl('view'));
            }
        }

        if ($validate) {
            $json = array('errors' => $fp->getErrors());
            $this->sendJson($json);
        }
        else {
            $this->view->fp= $fp;
        }

		$this->createSubMenu();
		$this->addUserMenu();

        $this->fillViewVariables();
    }

    protected function preprocessParams()
    {
        $this->view->usernotfound= false;;

        $request = $this->getRequest();
        $this->param_username = strtolower(trim($request->getUserParam('username')));
		$this->param_my= $request->getParam('my');

        if ($this->param_username == '') {
            //todo: need to get the latest modified user profile
            $this->param_my= 'yes';
            $this->param_username= strtolower($this->username);
        }

        if ($this->param_my != '') {
            $this->param_username= strtolower($this->username);
        }

        if ($this->param_username == strtolower($this->username)) {
            $this->param_my= 'yes';
        }

        if ($this->param_my != '') {
			$this->selected_usermenu_item= 'My Profile';
        }
        else {
			$this->selected_commonmenu_item= 'Profiles';
        }

		$this->param_profpath= $this->profilespath .'/'. $this->param_username;
    }

	protected function fillViewVariables()
	{
		parent::fillViewVariables();

        $this->view->requestedUsername = ucwords($this->param_username);
	}

	protected function createSubMenu()
	{
		//Load a list of users
		$count= 0;

        $usernames= DatabaseObject_User::getAllUserNames($this->db);
        foreach ($usernames as $name) {
			$this->submenu1[$count]->name= ucwords($name);
			$this->submenu1[$count]->title= "view profile of" . $name;
			$this->submenu1[$count]->url= $this->getUrl('view') . '/user/' . $name;
            $count++;
        }
	}

	protected function addUserMenu()
	{
		$usermenu_index= count($this->usermenu);
		$this->usermenu[$usermenu_index]->controller='profile';
        $this->usermenu[$usermenu_index]->name= 'Edit Profile';
        $this->usermenu[$usermenu_index]->action= 'edit';
        $this->usermenu[$usermenu_index]->title= 'Edit Ur Profile';
        $this->usermenu[$usermenu_index]->url= $this->getUrl('edit') . '/my' ;
		$usermenu_index += 1;

		$this->usermenu[$usermenu_index]->controller='profile';
        $this->usermenu[$usermenu_index]->name= 'My Profile';
        $this->usermenu[$usermenu_index]->action= 'view';
        $this->usermenu[$usermenu_index]->title= 'View Ur Profile';
        $this->usermenu[$usermenu_index]->url= $this->getUrl('view') . '/my' ;

		parent::addUserMenu();
	}	
}

?>
Return current item: Web2.0 community/group web site