Exemplo n.º 1
0
 public function getAllUpdatedContents($id_usr)
 {
     $followsToFetch = $this->getWhatUserIsFollowing($id_usr);
     //print_r($followsToFetch);die;
     $updatedContents = array();
     if (isset($followsToFetch['own_follows'])) {
         $updatedContents['own'] = $this->_fetchUpdatedContents($id_usr, $followsToFetch['own_follows'], "own");
     }
     if (isset($followsToFetch['fvr_follows'])) {
         $updatedContents['fvr'] = $this->_fetchUpdatedContents($id_usr, $followsToFetch['fvr_follows'], "fvr");
     }
     if ($this->_noNewContents($updatedContents)) {
         return false;
     }
     //print_r($updatedContents);
     $sortedUpdated = array();
     $uniqueUsers = array();
     $actorUsers = array();
     foreach ($updatedContents as $k => $binArray) {
         foreach ($binArray as $bin => $contentArray) {
             if (is_array($contentArray)) {
                 foreach ($contentArray as $info) {
                     $actorUsers[$info['id_cnt']]['users'][] = $info['id_usr'];
                     $actorUsers[$info['id_cnt']]['bin'][] = $bin;
                     $actorUsers[$info['id_cnt']]['time'][] = $info['time'];
                     $uniqueUsers[$info['id_usr']] = 1;
                     //echo $bin . " " . $info['id_cnt'] . ": ". $info['time'] . " \n";
                     if (!isset($sortedUpdated[$k][$info['id_cnt']])) {
                         $sortedUpdated[$k][$info['id_cnt']] = array('time' => $info['time'], 'id_usr' => $info['id_usr']);
                     } elseif (strtotime($sortedUpdated[$k][$info['id_cnt']]['time']) < strtotime($info['time'])) {
                         $sortedUpdated[$k][$info['id_cnt']] = array('time' => $info['time'], 'id_usr' => $info['id_usr']);
                     }
                 }
             }
         }
     }
     //print_r($actorUsers);die;
     foreach ($actorUsers as $id_cnt => $dataArray) {
         array_multisort($dataArray['time'], SORT_DESC, $dataArray['users'], $dataArray['bin']);
         $actorUsers[$id_cnt] = array("time" => $dataArray['time'], "users" => $dataArray['users'], "bin" => $dataArray['bin']);
     }
     //print_r($actorUsers);die;
     $userModel = new Default_Model_User();
     $actorUsersInfo = $userModel->getUserInfo(array_keys($uniqueUsers));
     $actorList = array();
     foreach ($actorUsers as $id_cnt => $dataArray) {
         foreach ($dataArray['users'] as $index => $id_usr) {
             foreach ($actorUsersInfo as $info) {
                 if ($info['id_usr'] == $id_usr) {
                     $actorList[$id_cnt]['info'][$id_usr] = $info;
                     $actorList[$id_cnt]['users'][] = $id_usr;
                     $actorList[$id_cnt]['bin'][] = $dataArray['bin'][$index];
                     $actorList[$id_cnt]['time'][] = $dataArray['time'][$index];
                     continue 2;
                 }
             }
         }
     }
     //print_r($actorUsers);die;
     //print_r($actorUsersInfo);
     //print_r($actorList);die;
     //print_r($sortedUpdated);die;
     foreach ($sortedUpdated as $k => $contentArray) {
         foreach ($contentArray as $id => $info) {
             $sortedUpdated[$k][$id] = $info['time'];
         }
     }
     //print_r($sortedUpdated);die;
     function compare($a, $b)
     {
         if ($a == $b) {
             return 0;
         }
         return strtotime($a) > strtotime($b) ? -1 : 1;
     }
     foreach ($sortedUpdated as $key => $val) {
         uasort($sortedUpdated[$key], "compare");
     }
     $countsContents = array();
     foreach ($updatedContents as $k => $binArray) {
         foreach ($binArray as $l => $timeArray) {
             if (is_array($timeArray)) {
                 foreach ($timeArray as $time => $info) {
                     $countsContents[$k][$l][$time] = $info['id_cnt'];
                 }
             }
         }
     }
     $updatedCounts = $this->_getCounts($countsContents);
     //print_r($updatedCounts);die;
     $updated = $this->_getContentInfo($updatedCounts);
     $followable = $this->getFollows();
     //print_r($updated);die;
     $merge = array();
     foreach ($updated as $k => $contentArray) {
         foreach ($contentArray as $id_cnt => $info) {
             $merge[$k][$id_cnt]['original'] = $info;
             $merge[$k][$id_cnt]['translated'] = null;
             $total = 0;
             foreach ($updatedCounts as $l => $binArray) {
                 foreach ($binArray as $bin => $contentArray) {
                     if (isset($contentArray[$id_cnt])) {
                         $total += $contentArray[$id_cnt];
                         $merge[$l][$id_cnt]['updates']['bins'][$followable[$bin]]['amount'] = $contentArray[$id_cnt];
                     }
                 }
             }
             $merge[$k][$id_cnt]['updates']['total'] = $total;
             foreach ($actorList[$id_cnt]['time'] as $index => $data) {
                 $followBinName = $followable[$actorList[$id_cnt]['bin'][$index]];
                 $userId = $actorList[$id_cnt]['users'][$index];
                 $userInfo = $actorList[$id_cnt]['info'][$userId];
                 $userInfo = array_merge($userInfo, array('time' => $data));
                 $merge[$k][$id_cnt]['updates']['bins'][$followBinName]['values'][] = $userInfo;
             }
         }
     }
     //print_r($followable);die;
     $contents = array();
     //print_r($merge);die;
     //print_r($sortedUpdated);die;
     //print_r($actorList);die; AAARAAAAAAAAAAAAAAAAAAAAAAAAAAAARGGGGGGGGGGGGGGGGGGGG
     foreach ($sortedUpdated as $k => $contentArray) {
         foreach ($contentArray as $id => $time) {
             $contents[$k][$id] = $merge[$k][$id];
             $userId = $actorList[$id]['users'][0];
             $bin = $followable[$actorList[$id]['bin'][0]];
             $contents[$k][$id]['updates']['latest'] = array_merge($actorList[$id]['info'][$userId], array('time' => $time, 'bin' => $bin));
         }
     }
     //print_r($contents);die;
     //print_r($merge);
     //print_r($updatedCounts);print_r($updated);
     //die;
     return $contents;
 }
Exemplo n.º 2
0
 public function getContentViewers($id_cnt, $limit = 10)
 {
     $select = $this->select()->from($this, array('id_usr' => 'id_usr_vws'))->where('id_cnt_vws = ?', $id_cnt)->where('id_usr_vws != 0')->limit($limit);
     $rowset = $this->fetchAll($select);
     //$results = array();
     /*foreach ($rowset as $row) {
      		$results[] = $row->id_usr_vws;
      	}*/
     $usrModel = new Default_Model_User();
     //Zend_Debug::dump($usrModel->getUserInfo($rowset->toArray())); die;
     return $usrModel->getUserInfo($rowset->toArray());
 }