public function getById($id, $exclude_fields = null) { if (!$exclude_fields) { return parent::getById($id); } foreach ((array) $exclude_fields as $name) { if (isset($this->fields[$name])) { unset($this->fields[$name]); } } $fields = array_keys($this->fields); $sql = "SELECT " . implode(',', $fields) . " FROM " . $this->table; if ($where = $this->getWhereByField('id', $id)) { $sql .= " WHERE " . $where; } return $this->query($sql)->fetchAssoc(); }
/** * Delete records from table by primary key * * @param array|string $field * @param $value * @return bool */ public function deleteByField($field, $value = null) { $items = $this->getByField($field, $value, $this->id); $blog_ids = array_keys($items); /** * @event blog_predelete * @param array[] int $blog_ids array of blog's ID * @return void */ wa()->event('blog_predelete', $blog_ids); $res = parent::deleteByField($field, $value); if ($res) { $post_model = new blogPostModel(); $post_model->deleteByField('blog_id', $blog_ids); /** * @event blog_delete * @param array[] int $blog_ids array of blog's ID * @return void */ wa()->event('blog_delete', $blog_ids); } return $res; }