Пример #1
0
 public function viewAction()
 {
     if (Zend_Controller_Action_HelperBroker::hasHelper('redirector')) {
         $redirector = Zend_Controller_Action_HelperBroker::getExistingHelper('redirector');
     }
     $hometargeturl = $this->_urlHelper->url(array('controller' => 'index', 'action' => 'index', 'language' => $this->view->language), 'lang_default', true);
     // Get user identity
     $auth = Zend_Auth::getInstance();
     // Disable edit profile by default
     $userEdit = false;
     // Get params
     $params = $this->getRequest()->getParams();
     if (isset($params['user'])) {
         // Get username from params
         $username = $params['user'];
     } else {
         $redirector->gotoUrl($hometargeturl);
     }
     // Get content types
     $contentTypes = new Default_Model_ContentTypes();
     $this->view->content_types = $contentTypes->getAllNamesAndIds();
     // Get user data from User Model
     $user = new Default_Model_User();
     $data = $user->getUserByName($username);
     if ($data == null) {
         $redirector->gotoUrl($hometargeturl);
     }
     $this->view->user = $data;
     $id = $data['id_usr'];
     // Get public user data from UserProfiles Model
     $userProfile = new Default_Model_UserProfiles();
     $dataa = $userProfile->getPublicData($id);
     // $dataa is an array with key=>val like firstname => "Joel Peeloten"
     // This was replaced with get public data and the foreach above
     // Kept here just in case for the future
     /*
     $dataa['gender'] 		= $userprofile->getUserProfileValue($id, 'gender');
     		$dataa['surname'] 		= $userprofile->getUserProfileValue($id, 'surname');
     		$dataa['firstname'] 	= $userprofile->getUserProfileValue($id, 'firstname');
     		$dataa['category'] 		= $userprofile->getUserProfileValue($id, 'user category');
     		$dataa['profession']	= $userprofile->getUserProfileValue($id, 'profession');
     		$dataa['company'] 		= $userprofile->getUserProfileValue($id, 'company');
     		$dataa['biography'] 	= $userprofile->getUserProfileValue($id, 'biography');
     		$dataa['city'] 			= $userprofile->getUserProfileValue($id, 'city');
     		$dataa['phone'] 		= $userprofile->getUserProfileValue($id, 'phone');
     		$dataa['birthday'] 		= $userprofile->getUserProfileValue($id, 'birthday');
     */
     // No countries in countries_ctr and not very good table at all?
     // This would be better: http://snipplr.com/view/6636/mysql-table--iso-country-list-with-abbreviations/
     /*
     		$dataa['country'] = $userProfile->getUserProfileValue($id, 'country');
     
     $userCountry = new Default_Model_UserCountry();
     		$dataa['country'] = $userCountry->getCountryNameById(
         $dataa['country']['profile_value_usp']
     );
     */
     // Get content user has released
     $type = isset($params['type']) ? $params['type'] : 0;
     $contentList = $user->getUserContent($data['id_usr']);
     $temp = array();
     // Initialize content counts
     $dataa['contentCounts']['all'] = 0;
     $dataa['contentCounts']['user_edit'] = 0;
     $dataa['contentCounts']['problem'] = 0;
     $dataa['contentCounts']['finfo'] = 0;
     $dataa['contentCounts']['idea'] = 0;
     // Count amount of content user has published
     // and check unpublished so only owner can see it.
     foreach ($contentList as $k => $c) {
         // If user not logged in and content not published,
         // remove content from list
         if (!$auth->hasIdentity() && $c['published_cnt'] == 0) {
             unset($contentList[$k]);
             // Else if user logged in and not owner of unpublished content,
             // remove content from list
         } else {
             if ($auth->hasIdentity() && $c['id_usr'] != $auth->getIdentity()->user_id && $c['published_cnt'] == 0) {
                 unset($contentList[$k]);
                 // Else increase content counts and sort content by content type
             } else {
                 if (isset($c['key_cty'])) {
                     // Set content to array by its content type
                     //$temp[$c['key_cty']][] = $c;
                     //$temp[] = $c;
                     // Increase total count
                     $dataa['contentCounts']['all']++;
                     // Set content type count to 0 if count is not set
                     if (!isset($dataa['contentCounts'][$c['key_cty']])) {
                         $dataa['contentCounts'][$c['key_cty']] = 0;
                     }
                     // Increase content type count
                     $dataa['contentCounts'][$c['key_cty']]++;
                 }
             }
         }
         if ($c['published_cnt'] == 0) {
             $dataa['contentCounts']['user_edit']++;
         }
     }
     // end foreach
     // If user is logged in, and viewing self; allow edit
     if ($auth->hasIdentity()) {
         $identity = $auth->getIdentity();
         if ($data['id_usr'] == $identity->user_id) {
             $userEdit = true;
         }
     }
     if ($auth->hasIdentity() && $data['id_usr'] == $auth->getIdentity()->user_id) {
         $favouriteModel = new Default_Model_UserHasFavourites();
         $favouriteType = isset($params['favourite']) ? $params['favourite'] : 0;
         $favouriteList = $user->getUserFavouriteContent($data['id_usr']);
         // Initialize Favourite counts
         $dataa['favouriteCounts']['totalCount'] = 0;
         $dataa['favouriteCounts']['problem'] = 0;
         $dataa['favouriteCounts']['finfo'] = 0;
         $dataa['favouriteCounts']['idea'] = 0;
         foreach ($favouriteList as $k => $favourite) {
             /*
              * If content Id doesn't exist anymore:
              * unset from Favouritelist and remove all lines from user_has_favourites table that
              * refers to this content id
              */
             if ($favourite['id_cnt'] == '') {
                 unset($favouriteList[$k]);
                 $favouriteModel->removeAllContentFromFavouritesByContentId($favourite['id_cnt_fvr']);
             }
             if (isset($favourite['key_cty'])) {
                 // Increase total count
                 $dataa['favouriteCounts']['totalCount']++;
                 // Set content type count to 0 if count is not set
                 if (!isset($dataa['favouriteCounts'][$favourite['key_cty']])) {
                     $dataa['favouriteCounts'][$favourite['key_cty']] = 0;
                 }
                 // Increase content type count
                 $dataa['favouriteCounts'][$favourite['key_cty']]++;
             }
         }
         //print_r($dataa);print_r($favouriteList);die;
     }
     //Zend_Debug::dump("" === null);
     //Zend_Debug::dump($dataa['contentCounts']['idea']);
     //Zend_Debug::dump($dataa['contentCounts']['idea'] == "");
     //die;
     //	My Posts box data
     $box = new Oibs_Controller_Plugin_AccountViewBox();
     $box->setHeader("My Posts")->setClass("right")->setName("my-posts")->addTab("All", "all", "all selected", $dataa['contentCounts']['all'])->addTab("Challenges", "problem", "challenges", $dataa['contentCounts']['problem'])->addTab("Ideas", "idea", "ideas", $dataa['contentCounts']['idea'])->addTab("Visions", "finfo", "visions", $dataa['contentCounts']['finfo']);
     if ($dataa['contentCounts']['user_edit'] && $userEdit) {
         $box->addTab("Saved", "user_edit", "saved", $dataa['contentCounts']['user_edit']);
     }
     $boxes[] = $box;
     $views = new Default_Model_ContentViews();
     $myViews = $views->getUserViewedContents($data['id_usr']);
     $box = new Oibs_Controller_Plugin_AccountViewBox();
     $box->setHeader("My Views")->setName("my-views")->setClass("right")->addTab("Views", "views", "all selected");
     //$boxes[] = $box;
     $myReaders = $user->getUsersViewers($data['id_usr']);
     $box = new Oibs_Controller_Plugin_AccountViewBox();
     $box->setHeader("My Reads")->setClass("right")->setName("my-reads")->addTab("Readers", "readers", "all selected");
     //$boxes[] = $box;
     // Set to view
     $this->view->user_has_image = $user->userHasProfileImage($data['id_usr']);
     $this->view->userprofile = $dataa;
     $this->view->authorContents = $contentList;
     /*$temp*/
     $this->view->boxes = $boxes;
     $this->view->myViews = $myViews;
     $this->view->myReaders = $myReaders;
     //$this->view->authorFavourites = $favouriteList;
     $this->view->user_edit = $userEdit;
     $this->view->type = $type;
     /* Waiting for layout that is maybe coming 
        // MyViews
        $viewsModel = new Default_Model_ContentViews();
        Zend_Debug::dump($viewsModel->getUserViewedContents($data['id_usr']));
        
        // MyReaders
        Zend_Debug::dump($user->getUsersViewers($data['id_usr']));
        die;*/
     $group_model = new Default_Model_UserHasGroup();
     $usergroups = $group_model->getGroupsByUserId($id);
     $this->view->usergroups = $usergroups;
 }
Пример #2
0
 public function viewAction()
 {
     if (Zend_Controller_Action_HelperBroker::hasHelper('redirector')) {
         $redirector = Zend_Controller_Action_HelperBroker::getExistingHelper('redirector');
     }
     $hometargeturl = $this->_urlHelper->url(array('controller' => 'index', 'action' => 'index', 'language' => $this->view->language), 'lang_default', true);
     // Get user identity
     $auth = Zend_Auth::getInstance();
     // Disable edit profile by default
     $userEdit = false;
     // Get params
     $params = $this->getRequest()->getParams();
     if (isset($params['user'])) {
         // Get username from params
         $username = $params['user'];
     } else {
         $redirector->gotoUrl($hometargeturl);
     }
     // Get content types
     $contentTypes = new Default_Model_ContentTypes();
     $this->view->content_types = $contentTypes->getAllNamesAndIds();
     // Get user data from User Model
     $user = new Default_Model_User();
     $data = $user->getUserByName($username);
     if ($data == null) {
         $redirector->gotoUrl($hometargeturl);
     }
     $this->view->user = $data;
     $id = $data['id_usr'];
     $topListClasses = $user->getUserTopList();
     $topListUsers = $topListClasses['Users'];
     if ($id != 0) {
         $topListUsers->addUser($id);
     }
     $topList = $topListUsers->getTopList();
     // Get public user data from UserProfiles Model
     $userProfile = new Default_Model_UserProfiles();
     $dataa = $userProfile->getPublicData($id);
     if (isset($dataa['biography'])) {
         $dataa['biography'] = str_replace("\n", '<br>', $dataa['biography']);
     }
     // User weblinks
     $userWeblinksModel = new Default_Model_UserWeblinks();
     $dataa['userWeblinks'] = $userWeblinksModel->getUserWeblinks($id);
     $i = 0;
     foreach ($dataa['userWeblinks'] as $weblink) {
         if (strlen($weblink['name_uwl']) == 0 || strlen($weblink['url_uwl']) == 0) {
             unset($dataa['userWeblinks'][$i]);
         }
         $i++;
     }
     // $dataa is an array with key=>val like firstname => "Joel Peeloten"
     // This was replaced with get public data and the foreach above
     // Kept here just in case for the future
     /*
     $dataa['gender'] 		= $userprofile->getUserProfileValue($id, 'gender');
     		$dataa['surname'] 		= $userprofile->getUserProfileValue($id, 'surname');
     		$dataa['firstname'] 	= $userprofile->getUserProfileValue($id, 'firstname');
     		$dataa['category'] 		= $userprofile->getUserProfileValue($id, 'user category');
     		$dataa['profession']	= $userprofile->getUserProfileValue($id, 'profession');
     		$dataa['company'] 		= $userprofile->getUserProfileValue($id, 'company');
     		$dataa['biography'] 	= $userprofile->getUserProfileValue($id, 'biography');
     		$dataa['city'] 			= $userprofile->getUserProfileValue($id, 'city');
     		$dataa['phone'] 		= $userprofile->getUserProfileValue($id, 'phone');
     		$dataa['birthday'] 		= $userprofile->getUserProfileValue($id, 'birthday');
     */
     // No countries in countries_ctr and not very good table at all?
     // This would be better: http://snipplr.com/view/6636/mysql-table--iso-country-list-with-abbreviations/
     /*
     		$dataa['country'] = $userProfile->getUserProfileValue($id, 'country');
     
     $userCountry = new Default_Model_UserCountry();
     		$dataa['country'] = $userCountry->getCountryNameById(
         $dataa['country']['profile_value_usp']
     );
     */
     // Get content user has released
     $type = isset($params['type']) ? $params['type'] : 0;
     $temp = array();
     // Initialize content counts
     $dataa['contentCounts']['all'] = 0;
     $dataa['contentCounts']['user_edit'] = 0;
     $dataa['contentCounts']['problem'] = 0;
     $dataa['contentCounts']['finfo'] = 0;
     $dataa['contentCounts']['idea'] = 0;
     // Count amount of content user has published
     // and check unpublished so only owner can see it.
     $cntModel = new Default_Model_Content();
     $contentList = array();
     foreach ($user->getUserContent($data['id_usr'], array('order' => 'DESC')) as $k => $c) {
         // If user not logged in and content not published,
         // remove content from list
         if (!$auth->hasIdentity() && $c['published_cnt'] == 0) {
             //unset($contentList[$k]);
             // Else if user logged in and not owner of unpublished content,
             // remove content from list
         } else {
             if (isset($c['id_usr']) && $auth->hasIdentity() && $c['id_usr'] != $auth->getIdentity()->user_id && $c['published_cnt'] == 0) {
                 //unset($contentList[$k]);
                 // Else increase content counts and sort content by content type
             } else {
                 if (isset($c['key_cty'])) {
                     // Set content to array by its content type
                     //$temp[$c['key_cty']][] = $c;
                     //$temp[] = $c;
                     // Increase total count
                     $dataa['contentCounts']['all']++;
                     // Set content type count to 0 if count is not set
                     if (!isset($dataa['contentCounts'][$c['key_cty']])) {
                         $dataa['contentCounts'][$c['key_cty']] = 0;
                     }
                     // Increase content type count
                     $dataa['contentCounts'][$c['key_cty']]++;
                 }
                 if ($c['published_cnt'] == 0) {
                     $dataa['contentCounts']['user_edit']++;
                 }
                 $c['hasCntLinks'] = $cntModel->hasCntLinks($c['id_cnt']);
                 $c['hasCmpLinks'] = $cntModel->hasCmpLinks($c['id_cnt']);
                 $contentList[] = $c;
             }
         }
     }
     // end foreach
     // If user is logged in, and viewing self; allow edit
     if ($auth->hasIdentity()) {
         $identity = $auth->getIdentity();
         if ($data['id_usr'] == $identity->user_id) {
             $userEdit = true;
         }
     }
     // if ($auth->hasIdentity() && $data['id_usr'] == $auth->getIdentity()->user_id) {
     $myFavourites = $this->getFavouriteRows($data['id_usr']);
     //print_r($dataa);print_r($favouriteList);die;
     //}
     //Zend_Debug::dump("" === null);
     //Zend_Debug::dump($dataa['contentCounts']['idea']);
     //Zend_Debug::dump($dataa['contentCounts']['idea'] == "");
     //die;
     //	My Posts box data
     $box = new Oibs_Controller_Plugin_AccountViewBox();
     $box->setHeader("My Posts")->setClass("right")->setName("my-posts")->addTab("All", "all", "all selected", $dataa['contentCounts']['all'])->addTab("Challenges", "problem", "challenges", $dataa['contentCounts']['problem'])->addTab("Ideas", "idea", "ideas", $dataa['contentCounts']['idea'])->addTab("Visions", "finfo", "visions", $dataa['contentCounts']['finfo']);
     //Zend_Debug::dump($dataa); die;
     if ($dataa['contentCounts']['user_edit'] && $userEdit) {
         $box->addTab("Saved", "user_edit", "saved", $dataa['contentCounts']['user_edit']);
     }
     $boxes[] = $box;
     $box = new Oibs_Controller_Plugin_AccountViewBox();
     $box->setHeader("My Groups")->setClass("left")->setName("my_groups")->addTab("All", "all", "all selected");
     $boxes[] = $box;
     $views = new Default_Model_ContentViews();
     $myViews = $this->getViewRows($data['id_usr']);
     $myViews = array_merge($myViews, $myFavourites['contents']);
     //print_r($myViews);die;
     $box = new Oibs_Controller_Plugin_AccountViewBox();
     $box->setHeader("My Views & Favourites")->setName("my-views")->setClass("right")->addTab("Views", "views", "views selected")->addTab("Updated", "updated", "fvr_updated", $myFavourites['counts']['updated'])->addTab("Challenges", "problem", "fvr_problem", $myFavourites['counts']['problem'])->addTab("Ideas", "idea", "fvr_idea", $myFavourites['counts']['idea'])->addTab("Visions", "finfo", "fvr_finfo", $myFavourites['counts']['finfo']);
     //$boxes[] = $box;
     $myReaders = $user->getUsersViewers($data['id_usr']);
     $box = new Oibs_Controller_Plugin_AccountViewBox();
     $box->setHeader("My Readers")->setClass("left")->setName("my-reads")->addTab("Readers", "readers", "all selected");
     //$boxes[] = $box;
     /*Box for user profile custom layout settings*/
     $box = new Oibs_Controller_Plugin_AccountViewBox();
     $box->setHeader("Custom Layout")->setClass("wide")->setName("my-custom-layout")->addTab("Customize", "fonts", "all selected");
     //$boxes[] = $box;
     $customLayoutForm = new Default_Form_AccountCustomLayoutSettingsForm();
     // Set to view
     // Comment module
     $comments = new Oibs_Controller_Plugin_Comments("account", $id);
     $this->view->jsmetabox->append('commentUrls', $comments->getUrls());
     // enable comment form
     if ($auth->hasIdentity()) {
         $comments->allowComments(true);
     }
     $comments->loadComments();
     $this->view->user_has_image = $user->userHasProfileImage($data['id_usr']);
     $this->view->userprofile = $dataa;
     $this->view->comments = $comments;
     $this->view->authorContents = $contentList;
     /*$temp*/
     $this->view->boxes = $boxes;
     $this->view->myViews = $myViews;
     $this->view->myReaders = $myReaders;
     $this->view->user_edit = $userEdit;
     $this->view->topList = $topList;
     $this->view->type = $type;
     $this->view->customLayoutSettingsForm = $customLayoutForm;
     $group_model = new Default_Model_UserHasGroup();
     $usergroups = $group_model->getGroupsByUserId($id);
     $this->view->usergroups = $usergroups;
 }