Example #1
0
 static function fetch($nodeID, $asObject = true)
 {
     return eZPersistentObject::fetchObject(eZTipafriendCounter::definition(), null, array('node_id' => $nodeID), $asObject);
 }
 public static function fetchTipafriendTopList($offset, $limit, $start_time, $end_time, $duration, $ascending, $extended)
 {
     $currentTime = time();
     $conds = array();
     if (is_numeric($start_time) and is_numeric($end_time)) {
         $conds = array('requested' => array(false, array($start_time, $end_time)));
     } else {
         if (is_numeric($start_time) and is_numeric($duration)) {
             $conds = array('requested' => array(false, array($start_time, $start_time + $duration)));
         } else {
             if (is_numeric($end_time) and is_numeric($duration)) {
                 $conds = array('requested' => array(false, array($end_time - $duration, $end_time)));
             } else {
                 if (is_numeric($start_time)) {
                     $conds = array('requested' => array('>', $start_time));
                 } else {
                     if (is_numeric($end_time)) {
                         $conds = array('requested' => array('<', $end_time));
                     } else {
                         if (is_numeric($duration)) {
                             // substract passed duration from current time timestamp to get start_time stamp
                             // end_timestamp is equal to current time in this case
                             $conds = array('requested' => array('>', $currentTime - $duration));
                         }
                     }
                 }
             }
         }
     }
     $topList = eZPersistentObject::fetchObjectList(eZTipafriendCounter::definition(), array('node_id'), $conds, array('count' => $ascending ? 'asc' : 'desc'), array('length' => $limit, 'offset' => $offset), false, array('node_id'), array(array('operation' => 'count( * )', 'name' => 'count')));
     if ($extended) {
         foreach (array_keys($topList) as $key) {
             $contentNode = eZContentObjectTreeNode::fetch($topList[$key]['node_id']);
             if (!is_object($contentNode)) {
                 return array('error' => array('error_type' => 'kernel', 'error_code' => eZError::KERNEL_NOT_FOUND));
             }
             $topList[$key]['node'] = $contentNode;
         }
         return array('result' => $topList);
     } else {
         $retList = array();
         foreach ($topList as $entry) {
             $contentNode = eZContentObjectTreeNode::fetch($entry['node_id']);
             if (!is_object($contentNode)) {
                 return array('error' => array('error_type' => 'kernel', 'error_code' => eZError::KERNEL_NOT_FOUND));
             }
             $retList[] = $contentNode;
         }
         return array('result' => $retList);
     }
 }