Ejemplo n.º 1
0
 public function getPostInfo($post_id)
 {
     $select = $this->getDbTable()->select()->setIntegrityCheck(false);
     $select->from('user_post', array('text' => 'content', 'date' => 'created_at', 'updated_at'));
     $select->join('google_user', 'google_user.id = user_post.user_id', array('author' => 'username', 'user_id' => 'id'));
     $select->where('user_post.id = ?', $post_id);
     $result_set = $this->getDbTable()->fetchAll($select);
     $entries = array();
     foreach ($result_set as $row) {
         $array = $row->toArray();
         remove_null_values($array);
         $entries[] = $array;
     }
     return $entries[0];
 }
Ejemplo n.º 2
0
 public function getComments($post_id, $isLimit = true)
 {
     $select = $this->getDbTable()->select()->setIntegrityCheck(false);
     $select->from('user_comment', array('content', 'created_at', 'user_id'));
     $select->join('google_user', 'google_user.id = user_comment.user_id', array('username'));
     $select->where('user_comment.post_id = ?', $post_id);
     $select->order('user_comment.created_at');
     if ($isLimit) {
         $select->limit(2);
     }
     $result_set = $this->getDbTable()->fetchAll($select);
     $entries = array();
     foreach ($result_set as $row) {
         $array = $row->toArray();
         remove_null_values($array);
         $entries[] = $array;
     }
     return $entries;
 }
Ejemplo n.º 3
0
function remove_null_values(array &$arr, $remove_zero = false)
{
    $to_remove = array();
    foreach ($arr as $key => &$value) {
        if (is_array($value)) {
            remove_null_values($value);
            continue;
        }
        if ($remove_zero) {
            if (empty($value)) {
                $to_remove[] = $key;
            }
        } else {
            if (is_null($value)) {
                $to_remove[] = $key;
            }
        }
    }
    foreach ($to_remove as $key) {
        unset($arr[$key]);
    }
}