FluentBoardsApi('boards') to get the class instance * * @package FluentBoards\App\Api\Classes * @namespace FluentBoards\App\Api\Classes * * @version 1.0.0 */ class Boards { private $instance = null; private $allowedInstanceMethods = [ 'all', 'get', 'find', 'first', 'paginate' ]; public function __construct(Board $instance) { $this->instance = $instance; } /** * Get Boards * * Use: * FluentBoardsApi('boards')->getBoards(); * * @param array $with * @return array|Board Model */ public function getBoards($with = []) { $userId = get_current_user_id(); $query = Board::where('type', 'to-do')->byAccessUser($userId); if ($with) { $query->with($with); } $boards = $query->get(); return $boards; } /** * Get stages by board * * Use: * FluentBoardsApi('boards')->getStagesByBoard($board_id); * * @param int|string $board_id * @return array Model */ public function getStagesByBoard($board_id) { if (empty($board_id)) { return []; } return Board::with('stages')->where('id', $board_id)->get(); } public function create($data) { if (empty($data['title'])) { return false; } $boardData = $this->boardSanitizeAndValidate($data); $boardService = new BoardService(); $labelService = new LabelService(); $stageService = new StageService(); $board = $boardService->createBoard($boardData); if (!$board) { return false; } $labelService->createDefaultLabel($board->id); $stageService->createDefaultStages($board); // if board is created from crm contact if (isset($boardData['crm_contact_id'])) { $boardService->updateAssociateMember($boardData['crm_contact_id'], $board->id); } do_action('fluent_boards/board_created', $board); return $board; } private function boardSanitizeAndValidate($data) { return Helper::sanitizeBoard($data); } }