# Copyright (c) 2008-2010 bivio Software, Inc. All Rights Reserved. # # Visit http://www.bivio.biz for more info. # # This library is free software; you can redistribute it and/or modify # it under the terms of the GNU Lesser General Public License as # published by the Free Software Foundation; either version 2.1 of the # License, or (at your option) any later version. # # This library is distributed in the hope that it will be useful, but # WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # Lesser General Public License for more details. # # You should have received a copy of the GNU Lesser General Public # License along with this library; If not, you may get a copy from: # http://www.opensource.org/licenses/lgpl-license.html # # $Id: RealmFileVersionsList.pm,v 1.12 2010/12/10 23:38:38 nagler Exp $ package Bivio::Biz::Model::RealmFileVersionsList; use strict; use Bivio::Base 'Biz.ListModel'; our($VERSION) = sprintf('%d.%02d', q$Revision: 1.12 $ =~ /\d+/g); my($_FP) = b_use('Type.FilePath'); my($_RFL) = b_use('Model.RealmFileLock'); my($_LOCK) = $_RFL->if_enabled; my($_DEFAULT_LOCATION) = b_use('Model.Email')->DEFAULT_LOCATION; sub internal_initialize { my($self) = @_; return $self->merge_initialize_info($self->SUPER::internal_initialize, { version => 1, primary_key => ['RealmFile.realm_file_id'], auth_id => [qw(RealmFile.realm_id RealmOwner.realm_id)], order_by => [ 'RealmFile.modified_date_time', { name => 'RealmFile.path_lc', sort_order => 0, }, 'Email_2.email', ], other => [ [qw(RealmFile.user_id Email_2.realm_id RealmOwner_2.realm_id)], ['Email_2.location', [$_DEFAULT_LOCATION]], 'Email_2.email', 'RealmOwner.name', 'RealmOwner_2.display_name', !$_LOCK ? () : ( 'RealmFileLock.modified_date_time', 'RealmFileLock.comment', 'RealmOwner_3.display_name', 'Email_3.email', ), 'RealmFile.path', 'RealmFile.folder_id', 'RealmFile.is_folder', { name => 'file_name', type => 'FilePath', constraint => 'NONE', }, { name => 'revision_number', type => 'FilePath', constraint => 'NONE', }, ], }); } sub internal_post_load_row { my($self, $row) = @_; return 0 unless shift->SUPER::internal_post_load_row(@_); $row->{file_name} = $_FP->get_tail($row->{'RealmFile.path'}); $row->{revision_number} = $row->{file_name} =~ /.*\;((\d+)(\.\d+)?).*/ ? $1 : 'current'; return 1; } sub internal_prepare_statement { my($self, $stmt) = @_; $self->prepare_statement_for_realm_file_lock($stmt, 1); my($p) = $self->req('path_info') || ''; my(@parts) = split('/', $p); my($name) = pop(@parts); $stmt->where( $stmt->OR( $stmt->LIKE('RealmFile.path_lc', lc($_FP->VERSIONS_FOLDER . join('/', @parts, $_FP->get_base($name) . '%' . $_FP->get_suffix($name)))), $stmt->EQ('RealmFile.path', [$p]), )); return shift->SUPER::internal_prepare_statement(@_); } sub is_locked { return $_RFL->is_locked(shift, 'RealmFileLock.'); } sub prepare_statement_for_realm_file_lock { my($self, $stmt, $all_locks) = @_; return unless $_LOCK; $stmt->from($stmt->LEFT_JOIN_ON(qw(RealmFile RealmFileLock), [ [qw(RealmFile.realm_file_id RealmFileLock.realm_file_id)], $all_locks ? () : ['RealmFileLock.comment', [undef]], ])); $stmt->from($stmt->LEFT_JOIN_ON(qw(RealmFileLock RealmOwner_3), [ [qw(RealmFileLock.user_id RealmOwner_3.realm_id)], ])); $stmt->from($stmt->LEFT_JOIN_ON(qw(RealmFileLock Email_3), [ [qw(RealmFileLock.user_id Email_3.realm_id)], ['Email_3.location', [$_DEFAULT_LOCATION]], ])); return; } sub _lock { return $_LOCK ? @_ : (); } 1;