ultimix

- Main Page
- Data Structures
- Files
- Examples

- File List
- Globals

gallery_algorithms.php
Go to the documentation of this file.
1 <?php
2
3 /*
4 * This source code is a part of the Ultimix Project.
5 * It is distributed under BSD license. All other third side source code (like tinyMCE) is distributed under
6 * it's own license wich could be found from the corresponding files or sources.
7 * This source code is provided "as is" without any warranties or garanties.
8 *
9 * Have a nice day!
10 *
11 * @url http://ultimix.sorceforge.net
12 *
13 * @author Alexey "gdever" Dodonov
14 */
15
26 class gallery_algorithms_1_0_0{
27
38 var $FileInputAccess = false;
39 var $GalleryAccess = false;
40 var $Link = false;
41 var $Security = false;
42
53 function __construct()
54 {
55 try
56 {
57 $this->FileInputAccess = get_package( 'file_input::file_input_access' , 'last' , __FILE__ );
58 $this->GalleryAccess = get_package( 'gallery::gallery_access' , 'last' , __FILE__ );
59 $this->Link = get_package( 'link' , 'last' , __FILE__ );
60 $this->Security = get_package( 'security' , 'last' , __FILE__ );
61 }
62 catch( Exception $e )
63 {
64 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
65 }
66 }
67
90 function object_exists( $id )
91 {
92 try
93 {
94 $id = $this->Security->get( $id , 'integer' );
95
96 $Records = $this->GalleryAccess->unsafe_select( $this->GalleryAccess->NativeTable.".id = $id" );
97
98 return( count( $Records ) === 1 );
99 }
100 catch( Exception $e )
101 {
102 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
103 }
104 }
105
128 function get_by_id( $id )
129 {
130 try
131 {
132 $id = $this->Security->get( $id , 'integer' );
133
134 $Records = $this->GalleryAccess->unsafe_select( $this->GalleryAccess->NativeTable.".id = $id" );
135
136 if( count( $Records ) == 0 )
137 {
138 throw( new Exception( 'Record was not found' ) );
139 }
140
141 return( $Records[ 0 ] );
142 }
143 catch( Exception $e )
144 {
145 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
146 }
147 }
148
171 function get_gallery_files( $gid )
172 {
173 try
174 {
175 $gid = $this->Security->get( $gid , 'integer' );
176
177 $Links = $this->Link->get_links( $gid , false , 'gallery' , 'file' );
178
179 $Ids = get_field_ex( $Links , 'object2_id' );
180
181 if( isset( $Ids[ 0 ] ) )
182 {
183 return( $this->FileInputAccess->unsafe_select( 'id IN ( '.implode( ',' , $Ids ).' )' ) );
184 }
185 else
186 {
187 return( array() );
188 }
189 }
190 catch( Exception $e )
191 {
192 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
193 }
194 }
195
218 function attach_file( $gid , $fid )
219 {
220 try
221 {
222 $gid = $this->Security->get( $gid , 'integer' );
223 $fid = $this->Security->get( $fid , 'integer' );
224
225 $this->Link->create_link( $gid, $fid , 'gallery' , 'file' );
226 }
227 catch( Exception $e )
228 {
229 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
230 }
231 }
232
255 function detach_file( $gid , $fid )
256 {
257 try
258 {
259 $gid = $this->Security->get( $gid , 'integer' );
260 $fid = $this->Security->get( $fid , 'integer' );
261
262 $this->Link->delete_link( $gid, $fid , 'gallery' , 'file' );
263
264 $FileInputAccess = get_package( 'file_input::file_input_access' , 'last' , __FILE__ );
265 $FileInputAccess->delete( $fid );
266 }
267 catch( Exception $e )
268 {
269 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
270 }
271 }
272 }
273
274 ?>