&ModBranch
&CheckBranchCategorycode
&GetBranchInfo
+ &GetCategoryTypes
+ &GetBranchCategories
+ &GetBranchesInCategory
&ModBranchCategoryInfo
&DelBranch
&DelBranchCategory
returns informations about ALL branches.
Create a branch selector with the following code
IndependantBranches Insensitive...
+ GetBranchInfo() returns the same information without the problems of this function
+ (namespace collision, mainly). You should probably use that, and replace GetBranches()
+ with GetBranchInfo() where you see it in the code.
=head3 in PERL SCRIPT
# you to list the categories that a branch belongs to:
# you'd have to list keys %$branch, and remove those keys
# that aren't fields in the "branches" table.
- $branch->{$cat} = 1;
+ # $branch->{$cat} = 1;
+ $branch->{category}{$cat} = 1;
}
$branches{ $branch->{'branchcode'} } = $branch;
}
return \@results;
}
+=head2 GetCategoryTypes
+
+$categorytypes = GetCategoryTypes;
+returns a list of category types.
+Currently these types are HARDCODED.
+type: 'searchdomain' defines a group of agencies that the calling library may search in.
+Other usage of agency categories falls under type: 'properties'.
+ to allow for other uses of categories.
+The searchdomain bit may be better implemented as a separate module, but
+the categories were already here, and minimally used.
+=cut
+
+ #TODO manage category types. rename possibly to 'agency domains' ? as borrowergroups are called categories.
+sub GetCategoryTypes() {
+ return ( 'searchdomain','properties');
+}
+
=head2 GetBranch
$branch = GetBranch( $query, $branches );
return $branchname;
}
-
=head2 get_branchinfos_of
my $branchinfos_of = get_branchinfos_of(@branchcodes);
return C4::Koha::get_infos_of( $query, 'branchcode' );
}
+=head2 GetBranchCategories
+
+ my $categories = GetBranchCategories($branchcode,$categorytype);
+
+Returns a list ref of anon hashrefs with keys eq columns of branchcategories table,
+i.e. categorycode, categorydescription, categorytype, categoryname.
+if $branchcode and/or $categorytype are passed, limit set to categories that
+$branchcode is a member of , and to $categorytype.
+
+=cut
+
+sub GetBranchCategories($$) {
+ my ($branchcode,$categorytype) = @_;
+ my $dbh = C4::Context->dbh();
+ my $select = "SELECT c.* FROM branchcategories c";
+ my (@where, @bind);
+ if($branchcode) {
+ $select .= ",branchrelations r, branches b ";
+ push @where, "c.categorycode=r.categorycode and r.branchcode=? ";
+ push @bind , $branchcode;
+ }
+ if ($categorytype) {
+ push @where, " c.categorytype=? ";
+ push @bind, $categorytype;
+ }
+ my $sth=$dbh->prepare( $select . " where " . join(" and ", @where) );
+ $sth->execute(@bind);
+
+ my $branchcats = $sth->fetchall_arrayref({});
+ $sth->finish();
+ return( $branchcats );
+}
+
+
+=head2 GetBranchesInCategory
+
+ my $branches = GetBranchesInCategory($categorycode);
+
+Returns a href: keys %$branches eq (branchcode,branchname) .
+
+=cut
+
+sub GetBranchesInCategory($) {
+ my ($categorycode) = @_;
+ my $dbh = C4::context->dbh();
+ my $sth=$dbh->prepare( "SELECT branchcode, branchname FROM branchrelations r, branches b
+ where r.branchcode=b.branchcode and r.categorycode=?");
+ $sth->execute($categorycode);
+ my $branches = $sth->fetchall_hashref;
+ $sth->finish();
+ return( $branches );
+}
+
=head2 GetBranchInfo
$results = GetBranchInfo($branchcode);
returns C<$results>, a reference to an array of hashes containing branches.
-
+if $branchcode, just this branch, with associated categories.
+if ! $branchcode && $categorytype, all branches in the category.
=cut
sub GetBranchInfo {
- my ($branchcode) = @_;
+ my ($branchcode,$categorytype) = @_;
my $dbh = C4::Context->dbh;
my $sth;
- if ($branchcode) {
+
+
+ if ($branchcode) {
$sth =
$dbh->prepare(
"Select * from branches where branchcode = ? order by branchcode");
}
my @results;
while ( my $data = $sth->fetchrow_hashref ) {
- my $nsth =
- $dbh->prepare(
- "select categorycode from branchrelations where branchcode = ?");
- $nsth->execute( $data->{'branchcode'} );
+ my @bind = ($data->{'branchcode'});
+ my $query= "select r.categorycode from branchrelations r";
+ $query .= ", branchcategories c " if($categorytype);
+ $query .= " where branchcode=? ";
+ if($categorytype) {
+ $query .= " and c.categorytype=? and r.categorycode=c.categorycode";
+ push @bind, $categorytype;
+ }
+ my $nsth=$dbh->prepare($query);
+ $nsth->execute( @bind );
my @cats = ();
while ( my ($cat) = $nsth->fetchrow_array ) {
push( @cats, $cat );
my ($data) = @_;
my $dbh = C4::Context->dbh;
- my $sth = $dbh->prepare("replace branchcategories (categorycode,categoryname,codedescription) values (?,?,?)");
- $sth->execute(uc( $data->{'categorycode'} ),$data->{'categoryname'}, $data->{'codedescription'} );
+ my $sth = $dbh->prepare("replace branchcategories (categorycode,categoryname,codedescription,categorytype) values (?,?,?,?)");
+ $sth->execute(uc( $data->{'categorycode'} ),$data->{'categoryname'}, $data->{'codedescription'},$data->{'categorytype'} );
$sth->finish;
}
{
categoryname => $cat->{'categoryname'},
categorycode => $cat->{'categorycode'},
+ categorytype => $cat->{'categorytype'},
codedescription => $cat->{'codedescription'},
checked => $checked,
};
my ($categorycode,$innertemplate) = @_;
warn "cat : $categorycode";
my $data;
- if ($categorycode) {
+ my @cats;
+ $innertemplate->param( categorytype => \@cats);
+ if ($categorycode) {
$data = GetBranchCategory($categorycode);
$data = $data->[0];
- $innertemplate->param( categorycode => $data->{'categorycode'} );
- $innertemplate->param( categoryname => $data->{'categoryname'} );
- $innertemplate->param( codedescription => $data->{'codedescription'} );
+ $innertemplate->param( categorycode => $data->{'categorycode'} ,
+ categoryname => $data->{'categoryname'},
+ codedescription => $data->{'codedescription'} ,
+ );
}
+ for my $ctype (GetCategoryTypes()) {
+ push @cats , { type => $ctype , selected => ($data->{'categorytype'} eq $ctype) };
+ }
}
sub deleteconfirm {
$branchinfo = GetBranchInfo($branchcode);
}
else {
- $branchinfo = GetBranchInfo();
+ $branchinfo = GetBranchInfo(undef,'properties');
}
my $toggle;
my $i;
$i++;
}
my @branchcategories = ();
- my $catinfo = GetBranchCategory();
- $i = 0;
- foreach my $cat (@$catinfo) {
- ( $i % 2 ) ? ( $toggle = 1 ) : ( $toggle = 0 );
- push @branchcategories,
- {
- toggle => $toggle,
- categoryname => $cat->{'categoryname'},
- categorycode => $cat->{'categorycode'},
- codedescription => $cat->{'codedescription'},
- };
- $i++;
- }
-
+ for my $ctype ( GetCategoryTypes() ) {
+ my $catinfo = GetBranchCategories(undef,$ctype);
+ my @categories;
+ foreach my $cat (@$catinfo) {
+ push @categories,
+ {
+ categoryname => $cat->{'categoryname'},
+ categorycode => $cat->{'categorycode'},
+ codedescription => $cat->{'codedescription'},
+ categorytype => $cat->{'categorytype'},
+ };
+ }
+ push @branchcategories, { categorytype => $ctype , $ctype => 1 , catloop => \@categories};
+ }
$innertemplate->param(
branches => \@loop_data,
branchcategories => \@branchcategories
}
-# FIXME logic seems wrong
+# FIXME logic seems wrong ## sub is not used.
sub branchcategoriestable {
my $innertemplate = shift;
#Needs to be implemented...
DROP TABLE IF EXISTS `branchcategories`;
CREATE TABLE `branchcategories` (
- `categorycode` varchar(4) NOT NULL default '',
- `categoryname` mediumtext,
+ `categorycode` char(10) NOT NULL default '',
+ `categoryname` varchar(32),
`codedescription` mediumtext,
+ `categorytype` varchar(16),
PRIMARY KEY (`categorycode`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
DROP TABLE IF EXISTS `branchrelations`;
CREATE TABLE `branchrelations` (
`branchcode` char(10) NOT NULL default '',
- `categorycode` varchar(4) NOT NULL default '',
+ `categorycode` char(10) NOT NULL default '',
+ `relation` char(10) default NULL,
PRIMARY KEY (`branchcode`,`categorycode`),
KEY `branchcode` (`branchcode`),
KEY `categorycode` (`categorycode`),
<th>Name</th>
<th>Code</th>
<th>Address</th>
- <th>Category</th>
- <th>Library IP</th>
- <th>Library Printer</th>
+ <th>Properties</th>
+ <th>IP</th>
+ <th>Printer</th>
<th colspan="2"> </th>
</tr>
<!-- TMPL_LOOP name="branches" -->
</td>
<td>
<!-- TMPL_IF name="no-categories-p" -->
- (no categories set)
<!-- TMPL_ELSE -->
<!-- TMPL_LOOP name="category_list" -->
<!-- TMPL_VAR name="categoryname" --><br />
</form>
<!-- TMPL_IF NAME="branchcategories" -->
- <table>
- <caption>Agency Categories</caption>
+
+ <!-- TMPL_LOOP NAME="branchcategories" -->
+ <table>
+ <caption>Agency Categories: <!-- TMPL_IF NAME="properties" -->Properties<!-- TMPL_ELSE --><!-- TMPL_IF NAME="searchdomain" -->Search Domain<!-- /TMPL_IF --><!-- /TMPL_IF --></caption>
<tr>
<th>Name</th>
<th>Code</th>
<th> </th>
<th> </th>
</tr>
- <!-- TMPL_LOOP name="branchcategories" -->
+ <!-- TMPL_LOOP name="catloop" -->
<tr>
<td><!-- TMPL_VAR name="categoryname" --></td>
<td><!-- TMPL_VAR name="categorycode" --></td>
</tr>
<!-- /TMPL_LOOP -->
</table>
+ <!-- /TMPL_LOOP -->
+
<!-- TMPL_ELSE -->
<p>
No Agency Categories defined.
<!-- TMPL_VAR name="categorycode" -->
<!-- TMPL_ELSE -->
<label for="categorycode">Category code:</label>
- <input type="text" name="categorycode" id="categorycode" size="5" maxlength="5" value="<!-- TMPL_VAR name="categorycode" escape="HTML" -->" />
+ <input type="text" name="categorycode" id="categorycode" size="11" maxlength="10" value="<!-- TMPL_VAR name="categorycode" escape="HTML" -->" />
<!-- /TMPL_IF -->
</li>
<li>
<li>
<label for="codedescription">Description: </label>
<input type="text" name="codedescription" id="codedescription" size="70" maxlength="80" value="<!-- TMPL_VAR name="codedescription" escape="HTML" -->" />
- </li></ol>
+ </li>
+ <li>
+ <label for="categorytype">Category Type</label>
+ <select id="categorytype" name="categorytype">
+ <!-- TMPL_LOOP NAME="categorytype" -->
+ <option value="<!-- TMPL_VAR NAME="type" -->" <!-- TMPL_IF NAME="selected" -->selected="selected"<!-- /TMPL_IF -->><!-- TMPL_VAR NAME="type" --></option>
+ <!-- /TMPL_LOOP -->
+ </select>
+ </li>
+ </ol>
</fieldset><input type="submit" value="Update" />
</form>
<!-- /TMPL_IF -->