num_rows == 1){ $action = $res->fetch_assoc(); return $action['id']; } } return false; } function activityObj($id){ if($res = query("SELECT UNIX_TIMESTAMP(a.date) as timestamp, a.id, ac.name AS action, CASE WHEN a.u_id IS NOT NULL THEN 'u' WHEN a.p_id IS NOT NULL THEN 'p' WHEN a.i_id IS NOT NULL THEN 'i' WHEN a.m_id IS NOT NULL THEN 'm' ELSE 'other' END AS type, a.u_id, a.p_id, a.i_id, a.m_id FROM `activity` AS a JOIN `actions` AS ac ON ac.id = a.a_id WHERE a.id = %d ",array($id))){ if($res->num_rows == 1){ $activity = $res->fetch_assoc(); $ret = array( 'id'=>$activity['id'], 'timestamp'=>$activity['timestamp'], 'action'=>$activity['action'], 'type'=>$activity['type'] ); switch($activity['type']){ case 'u': $ret['rel'] = userObj($activity['u_id']); $ret['url'] = '#~'.$ret['rel']['name']; break; case 'p': $ret['rel'] = projectObj($activity['p_id']); $ret['url'] = '#project-'.$ret['rel']['id']; $ret['rel']['title'] = 'Project - '.$ret['rel']['title']; break; case 'i': $ret['rel'] = issueObj($activity['i_id']); $ret['url'] = '#!'.$ret['rel']['id']; $ret['rel']['title'] = 'Issue - '.$ret['rel']['title']; break; case 'm': $ret['rel'] = messageObj($activity['i_id']); $ret['url'] = '#message-'.$ret['rel']['id']; break; default: $ret['rel'] = array(); } return $ret; } } return false; } ?>