added the beginning of a date component using selects, and also added the email valid...
[clinton/lisp-on-lines.git] / src / lisp-on-lines.lisp
CommitLineData
da26d003
DC
1(in-package :lisp-on-lines)
2
3;;;; *LoL Entry points
4;;;;
5
6;;;; This file contains the high level functions and macros
7;;;; that are part of LoL proper, that is to say, not Mewa
8;;;; or Meta-Model.
9
10;;;; ** Initialisation
11;;;; The following macros are used to initialise a set of database tables as LoL objects.
12(eval-when (:compile-toplevel :load-toplevel :execute)
d5e996b3 13 (defun generate-define-view-for-table (table)
da26d003
DC
14 "
15Generates a form that, when evaluated, initialises the given table as an lol object.
16This involves creating a meta-model, a clsql view-class, and the setting up the default attributes for a mewa presentation"
17
18 `(progn
5a4eea11 19 (def-view-class-from-table ,table)
da26d003
DC
20 (set-default-attributes (quote ,(meta-model::sql->sym table))))))
21
d5e996b3 22(defmacro define-view-for-table (&rest tables)
da26d003
DC
23 " expand to a form which initialises TABLES for use with LOL"
24 `(progn
d5e996b3 25 ,@(loop for tbl in tables collect (generate-define-view-for-table tbl))
da26d003
DC
26 (values)))
27
d5e996b3 28(defmacro define-views-for-database ()
da26d003 29 "expands to init-i-f-t using the listing of tables provided by meta-model"
d5e996b3
DC
30 `(define-view-for-table ,@(meta-model::list-tables)))
31
32(eval-when (:compile-toplevel :load-toplevel :execute)
b890d449
DC
33 (defun %make-view (object type attributes args)
34
35 (when attributes
36 (setf args
37 (cons `(:attributes ,attributes) args)))
d5e996b3
DC
38 `(mewa:make-presentation
39 ,object
40 :type ,type
b890d449
DC
41 ,@(when args
42 `(:initargs
43 '(,@ (mapcan #'identity args)))))))
d5e996b3 44
598f1fa8 45(defmethod make-view (object &rest args &key (type :viewer)
d5e996b3 46 &allow-other-keys )
598f1fa8
DC
47 (remf args :type)
48 ;(warn "~A ~A" args `(:type ,type :initargs ,@args))
49 (apply #'make-presentation object `(:type ,type ,@ (when args
50 `(:initargs ,args)))))
d5e996b3 51
b890d449 52(defmacro present-view ((object &optional (type :viewer) (parent 'self))
d5e996b3 53 &body attributes-and-args)
b890d449
DC
54 (arnesi:with-unique-names (view)
55 `(let ((,view (lol:make-view ,object
56 :type ,type
598f1fa8
DC
57 ,@(when (car attributes-and-args)
58 `(:attributes ',(car attributes-and-args)))
b890d449
DC
59 ,@ (cdr attributes-and-args))))
60 (setf (ucw::parent ,view) ,parent)
61 (lol:present ,view))))
d5e996b3
DC
62
63
64(defmacro call-view ((object &optional (type :viewer) (component 'self component-supplied-p))
b890d449 65 &body attributes-and-args)
d5e996b3
DC
66 `(ucw:call-component
67 ,component
b890d449 68 ,(%make-view object type (car attributes-and-args) (cdr attributes-and-args))))
d5e996b3
DC
69
70(defmethod slot-view ((self mewa) slot-name)
71 (mewa::find-attribute-slot self slot-name))
72
73(defmethod present-slot-view ((self mewa) slot-name &optional (instance (instance self)))
74 (present-slot (slot-view self slot-name) instance))
75
38a016c7 76
38a016c7
DC
77(defmethod find-slots-of-type (model &key (type 'string)
78 (types '((string)) types-supplied-p))
79 "returns a list of slots matching TYPE, or matching any of TYPES"
80 (let (ty)
81 (if types-supplied-p
82 (setf ty types)
83 (setf ty (list type)))
84 (remove nil (mapcar #'(lambda (st) (when (member (second st) ty)
85 (first st)))
86 (lisp-on-lines::list-slot-types model)))))
87
88
b890d449 89
b890d449 90
e8f6e086 91
b890d449 92
38a016c7
DC
93(defmethod word-search (class-name slots search-terms
94 &key (limit 10) (where (sql-and t)))
95 (select class-name
96 :where (sql-and
97 where
98 (word-search-where class-name slots search-terms :format-string "~a%"))
99 :flatp t
100 :limit limit))
101
102
103(defmethod word-search (class-name slots (s string) &rest args)
487243db 104 (apply #'word-search class-name slots (list s) args))
38a016c7
DC
105
106(defmethod word-search-where (class-name slots search-terms &key (format-string "%~a%"))
107 (sql-or
108 (mapcar #'(lambda (term)
109 (apply #'sql-or
110 (mapcar #'(lambda (slot)
111 (sql-uplike
112 (sql-slot-value class-name slot)
113 (format nil format-string term)))
114 slots)))
115 search-terms)))
116
b890d449
DC
117
118