/** * affiliated to another registered * * @param Permission $item permission instance * @param string $to parent name * * @return void */ public function affiliate(Permission $item, $to) { if ($to !== null) { $this->conn->table($this->table)->where('siteKey', $item->siteKey)->where(function ($query) use($item) { $query->where('name', $item->name)->orWhere('name', 'like', $item->name . '.%'); })->update(['name' => $this->conn->raw("concat('{$to}', '.', `name`)")]); } }
/** * countByInstanceId * * @param string $instanceId instance Id * @param callable $filter filter * * @return int */ public function countByInstanceId($instanceId, callable $filter = null) { $query = $this->conn->table($this->table)->where('instanceId', '=', $instanceId); if ($filter !== null) { $query->where($filter); } return $query->count(); }
/** * document 의 덧글 리스트 반환 * * @param DocumentEntity $doc document entity * @return array */ public function getReplies(DocumentEntity $doc) { $query = $this->connection->table($this->table)->where('head', $doc->head); if ($doc->reply != null) { $query = $query->where('reply', 'like', $doc->reply . '%'); } return $query->get(); }
/** * affiliated to another config * * @param ConfigEntity $config config object * @param string|null $to parent name * * @return void */ public function affiliate(ConfigEntity $config, $to = null) { if ($to !== null) { $this->conn->table($this->table)->where('siteKey', $config->siteKey)->where(function ($query) use($config) { $query->where('name', $config->name)->orWhere('name', 'like', $config->name . '.%'); })->update(['name' => $this->conn->raw("concat('{$to}', '.', `name`)")]); } }
/** * fetch slugs * * @param string|array $ids ids * @param string|array $instanceIds instance ids * @return SlugEntity[] */ public function fetchByIdsInstanceIds($ids, $instanceIds) { $slugs = $this->connection->table($this->table)->whereIn('id', $ids)->whereIn('instanceId', $instanceIds)->get(); foreach ($slugs as $key => $row) { $slugs[$key] = new SlugEntity($row); $this->putCache($slugs[$key]); } return $slugs; }
/** * Retrieve the "count" result of the query by groupBy * * @param string $groupBy groupBy column * @param array $wheres where clause * @return array groupBy => count format */ public function countGroupBy($groupBy, array $wheres = []) { $rows = $this->buildWhere($this->conn->table($this->table), $wheres)->selectRaw("`{$groupBy}`, count(*) as cnt")->groupBy($groupBy)->get(); $array = []; foreach ($rows as $row) { $row = (array) $row; $array[$row[$groupBy]] = $row['cnt']; } return $array; }
/** * userId 리스트 반환 * 최근 counter log에 insert 된 userId 를 보기 위해 * * @param array $wheres make where query list * @param array $orders make order query list * @param int $limit number of list * @return mixed */ public function fetchByUserIds(array $wheres, array $orders, $limit = null) { $query = $this->conn->table($this->table); $query = $this->wheres($query, $wheres); $query = $this->orders($query, $orders); if ($limit !== null) { $query = $query->take($limit); } return $query->lists('userId'); }
/** * Specific word used target information * * return sample * ['freeboard' => ['xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx', 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx']] * * @param string $word specific word * @param string $instanceId instance id * @return array */ public function getUsed($word, $instanceId) { $query = $this->conn->table($this->usedTable . ' as used')->leftJoin($this->itemTable . ' as item', 'used.itemId', '=', 'item.id')->select(['item.instanceId', 'used.targetId'])->where('item.word', $word); if ($instanceId !== null) { $query->where('item.instanceId', $instanceId); } $rows = $query->get(); $data = []; foreach ($rows as $row) { $row = (array) $row; if (isset($data[$row['instanceId']]) !== true) { $data[$row['instanceId']] = []; } $data[$row['instanceId']][] = $row['targetId']; } return empty($data) ? $data : ($instanceId === null ? $data : array_pop($data)); }
/** * fetch node list tree type * * @param NodeInterface $top node instance * @param int $depth want get depth * * @return TreeCollection */ public function fetchTree(NodeInterface $top, $depth = 0) { $prefix = $this->conn->getTablePrefix(); $query = $this->conn->table($this->nodeTable . " as t")->selectRaw("{$prefix}t.*, {$prefix}h.`depth`, GROUP_CONCAT({$prefix}crumbs.`ancestor` " . "order by {$prefix}crumbs.`depth` desc) AS breadcrumbs")->join($this->hierarchyTable . ' as h', 't.id', '=', 'h.descendant')->join($this->hierarchyTable . ' as crumbs', 'crumbs.descendant', '=', 'h.descendant')->where('h.ancestor', $top->id); if ($depth > 0) { $query->where('h.depth', '<', $depth); } $rows = $query->groupBy('t.id')->orderBy('breadcrumbs')->orderBy('t.ordering')->get(); $nodes = []; foreach ($rows as $row) { $row = (array) $row; $node = $this->createNodeModel(array_diff_key($row, array_flip(['depth', 'breadcrumbs']))); $node->setdepth($row['depth']); $node->setTreeNodePath($row['breadcrumbs']); $nodes[$node->id] = $node; } return new TreeCollection($nodes); }
/** * Delete * * @param Meta $meta meta instance * @return int */ public function delete(Meta $meta) { return $this->conn->table($this->table)->where('id', $meta->id)->delete(); }
/** * 임시저장 데이터 삭제 * * @param TemporaryEntity $temporary 임시저장 객체 * @return int 삭제된 레코드 수(정상적인 경우 '1') */ public function delete(TemporaryEntity $temporary) { return $this->conn->table($this->table)->where('id', $temporary->id)->delete(); }
/** * delete revision by document id * * @param string $id document id * @return void */ public function deleteByDocumentId($id) { $this->connection->table($this->table)->where('id', $id)->delete(); }
/** * 임시저장 데이터 삭제 * * @param DraftEntity $draft 임시저장 객체 * @return int 삭제된 레코드 수(정상적인 경우 '1') */ public function delete(DraftEntity $draft) { return $this->conn->table($this->table)->where('id', $draft->id)->delete(); }
/** * Delete by origin * * @param string $originId origin id * @return int */ public function deleteByOriginId($originId) { return $this->conn->table($this->table)->where('originId', $originId)->delete(); }
/** * instance 내 모든 데이터 삭제 * * @param string $instanceId instance identifier * @return void */ public function dropInstance($instanceId) { $this->conn->table($this->table)->where('instanceId', $instanceId)->delete(); }
/** * get last table record * * @return array|null */ private function lastRecord() { $row = $this->conn->table($this->table)->orderBy('createdAt', 'desc')->first(); return $row ? (array) $row : null; }
/** * 같은 depth 에 가장 마지막 자식노드의 reply 코드 값 * * @param CommentEntity $comment comment object * @return string */ public function getLastChildReply(CommentEntity $comment) { $reply = $this->conn->table($this->table)->where('head', $comment->head)->where('reply', 'like', $comment->reply . str_repeat('_', CommentEntity::getReplyCharlen()))->max('reply'); return $reply; }
/** * count * * @param string $host site unique host * * @return int */ public function count($host) { return $this->conn->table($this->table)->where('host', $host)->count(); }