Ejemplo n.º 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;
 }
Ejemplo n.º 2
0
 private function getViewRows($id_usr)
 {
     $viewsModel = new Default_Model_ContentViews();
     $contentHasTagModel = new Default_Model_ContentHasTag();
     // Get recent post data
     $recentposts_raw = $viewsModel->getUserViewedContents($id_usr);
     $recentposts = array();
     // Gather data for recent posts
     $i = 0;
     foreach ($recentposts_raw as $post) {
         $tags = $contentHasTagModel->getContentTags($post['id_cnt']);
         // Action helper for define is tag running number divisible by two
         $tags = $this->_helper->tagsizes->isTagDivisibleByTwo($tags);
         $this->gtranslate->setLangFrom($post['language_cnt']);
         $translang = $this->gtranslate->getLangPair();
         $recentposts[$i]['class'] = 'views';
         $recentposts[$i]['original'] = $post;
         $recentposts[$i]['translated'] = $this->gtranslate->translateContent($post);
         $recentposts[$i]['original']['tags'] = $tags;
         $recentposts[$i]['translated']['tags'] = $tags;
         $recentposts[$i]['original']['translang'] = $translang;
         $recentposts[$i]['translated']['translang'] = $translang;
         $i++;
     }
     return $recentposts;
 }