Ejemplo n.º 1
0
 /**
  *   getDataForView
  *
  *   Get content by id.
  *   Is this function used anywhere?
  *   If not, this function should probably be removed.
  *
  *   @param ineteger $id
  *   @return array
  */
 public function getDataForView($id = 0)
 {
     // Array for content data
     $data = array();
     // Find content row by id
     //$rowset = $this->find((int)$id)->current();
     $select = $this->_db->select()->from(array('contents_cnt' => 'contents_cnt'), array('*'))->where('id_cnt = ?', $id);
     $result = $this->_db->fetchAll($select);
     // If content was found
     if (count($result) == 1) {
         $data['Content']['Data'] = $result[0];
         // Find Ratings
         //$select_ratings = $this->select()->from('content_ratings_crt', array('SUM(rating_crt) AS rate_crt'));
         //$ratings = $rowset->findDependentRowset('Default_Model_ContentRatings', 'RatingsContent', $select_ratings)->toArray();
         $ratings = new Default_Model_ContentRatings();
         $rating = $ratings->getById($id);
         // Find content owners
         //$content_owner = $rowset->findManyToManyRowset('Default_Model_User', 'Default_Model_ContentHasUser');
         $cntHasUser = new Default_Model_ContentHasUser();
         $owners = $cntHasUser->getContentOwners($id);
         // Find owners
         $userModel = new Default_Model_User();
         $i = 0;
         foreach ($owners as $owner) {
             $data['Content']['Data']['Owners'][$i] = $userModel->getSimpleUserDataById($owner);
             $i++;
         }
         // Find content comments
         //$select_comment = $this->select()->order('created_cmt ASC');
         //$comments = $rowset->findDependentRowset('Default_Model_Comments', 'CommentContent', $select_comment);
         $commentModel = new Default_Model_Comments();
         $comments = $commentModel->getAllByContentId($id);
         /*  comment owner username is fetched in the previous query, no need for this anymore
             			 // Array for comment owners
             			 $comment_owners = array();
             
             			 // Go through all comments
             			 foreach($comments as $cmt)
             			 {
             			 // Find comment owner
             			 $usr = $cmt->findDependentRowset('Default_Model_User', 'CommentUser')->toArray();
             
             			 // If owner found
             			 if(!empty($usr))
             			 {
             			 // Specify comment owner
             			 $comment_owners[$usr[0]['id_usr']] = $usr[0];
             			 } // end if
             			 } // end foreach
             			 */
         // Find content keywords
         //$tags = $rowset->findManyToManyRowset('Default_Model_Tags', 'Default_Model_ContentHasTag')->toArray();
         $cntHasTag = new Default_Model_ContentHasTag();
         $tags = $cntHasTag->getContentTags($id);
         // Find content links - needs updating to this version
         $links = array();
         //$rowset->findDependentRowset('Default_Model_Links')->toArray();
         // Find related content
         //$$related_content = $rowset->findManyToManyRowset('Default_Model_Content', 'Default_Model_ContentHasContent', 'ParentContent', 'ChildContent')->toArray();
         $contentHasContent = new Default_Model_ContentHasContent();
         $familyTree = $contentHasContent->getContentFamilyTree($id);
         // echo"<pre>"; print_r($tagArray); echo"</pre>"; die;
         // Gather and format content data a bit
         $data['Content']['Data']['rating'] = $rating;
         //$data['Content']['Data']['owner'] = $owner;
         $data['Content']['Tags'] = $tags;
         $data['Content']['Links'] = $links;
         $data['Content']['FamilyTree'] = $familyTree;
         $data['Comments']['Data'] = $comments;
         //echo"<pre>"; print_r($comments); echo"</pre>"; die;
         //$data['Comments']['Posters']        = $comment_owners;
     }
     return $data;
 }