public function comment($title, $content, User $user) { $c = parent::comment($title, $content, $user); // generate activity $info = array('user' => $user, 'action' => 'comment', 'object' => $this, 'link' => $c); $act = Activity::create($info); // inform all stack holders $users = Sdb::fetch('user', Comment::table(), array('teacher=?' => array($this->id))); $info = array('activity' => $act); foreach ($users as $u) { $info['user'] = $u; Timeline::create($info); } }
public function addContent($content) { $info = compact('content'); $info['comment'] = $this; Addition::create($info); // generate activity $info = array('user' => $this->user, 'action' => 'add', 'object' => $this, 'link' => $this); $act = Activity::create($info); // inform all stack holders $conds = array('comment=?' => array($this->id)); $users = Sdb::fetch('DISTINCT(user)', Discuss::table(), $conds); $info = array('activity' => $act); foreach ($users as $u) { if ($u == $this->user) { break; // 不需要通知本人 } $info['user'] = $u; Timeline::create($info); } }
public function count() { $field = count($this->tables) > 1 ? "{$this->table}.id" : '*'; if ($this->distinct) { $field = "DISTINCT({$field})"; } $field = "count({$field})"; if ($this->conds) { $condStr = implode(' AND ', array_keys($this->conds)); $a = array_filter(array_values($this->conds), function ($v) { return $v !== false && $v !== null; }); $values = array(); foreach ($a as $v) { if (is_array($v)) { $values += $v; } else { $values[] = $v; } } $conds = array($condStr => $values); } else { $conds = ''; } $arr = Sdb::fetch($field, $this->tables, $conds); return $arr[0]; }