package.xml 0000664 0001750 0001750 00000045425 12073544237 011320 0 ustar jan jan
seshapear.horde.orgA simple Inventory App for HordeSesha allows you to define categories with a rich set of attributes to manage your inventory stockJan Schneiderjanjan@horde.orgyesRalf Langrlanglang@b1-systems.deyes2013-01-101.0.0RC31.0.0betabetaGPL-2.0
* [rla] QuickSearch now works by Name or Id (Request #11657).
5.3.01.7.0hordepear.horde.org5.0.06.0.0alpha16.0.0alpha1Horde_Authpear.horde.org2.0.03.0.0alpha13.0.0alpha1Horde_Autoloaderpear.horde.org2.0.03.0.0alpha13.0.0alpha1Horde_Corepear.horde.org2.0.03.0.0alpha13.0.0alpha1Horde_Dbpear.horde.org2.0.03.0.0alpha13.0.0alpha1Horde_Exceptionpear.horde.org2.0.03.0.0alpha13.0.0alpha1Horde_Formpear.horde.org2.0.03.0.0alpha13.0.0alpha1Horde_Permspear.horde.org2.0.03.0.0alpha13.0.0alpha1Horde_Prefspear.horde.org2.0.03.0.0alpha13.0.0alpha1Horde_Rdopear.horde.org2.0.03.0.0alpha13.0.0alpha1hordeRolepear.horde.org1.0.0alpha11.0.0alpha1alphaalpha2012-07-10GPL-2.0
* First alpha release.
* [rla] Use Horde_View in place of Horde_Template.
* [rla] change backend from Sql driver to Rdo driver with enhanced search capabilities.
* [jan] Add Finnish translation (Leena Heino <liinu@uta.fi>).
* [rla] Convert to Horde 5 Framework.
1.0.0beta11.0.0beta1betabeta2012-08-08GPL-2.0
* [rla] Use Horde 5's CSS for sidebar icons.
* [rla] Use Horde 5's New button for the Add Stock menu entry.
1.0.0RC11.0.0beta1betabeta2012-12-10GPL-2.0
* [jan] Update to work with latest Horde 5 code.
1.0.0RC21.0.0betabeta2012-12-10GPL-2.0
* [rla] Improved display of search results (Request #11656).
* [rla] Search now allows to select partial or full value match (Request #11655).
1.0.0RC31.0.0betabeta2013-01-10GPL-2.0
* [rla] QuickSearch now works by Name or Id (Request #11657).
sesha-1.0.0RC3/bin/sesha-add-stock 0000775 0001750 0001750 00000003351 12073544237 014710 0 ustar jan jan #!/usr/bin/env php
*/
if (file_exists(__DIR__ . '/../../sesha/lib/Application.php')) {
$baseDir = __DIR__ . '/../';
} else {
require_once 'PEAR/Config.php';
$baseDir = PEAR_Config::singleton()
->get('horde_dir', null, 'pear.horde.org') . '/sesha/';
}
require_once $baseDir . 'lib/Application.php';
Horde_Registry::appInit('sesha', array('cli' => true));
// Read command line parameters.
if (count($argv) < 4 || count($argv) > 6) {
$cli->message('Too many or too few parameters.', 'cli.error');
usage();
}
list($script, $name, $categories, $description, $attributes) = $argv;
/* Currently we only support one category per item added with this script */
if (!is_array($categories)) {
$categories = array($categories);
}
$driver = $GLOBALS['injector']->getInstance('Sesha_Factory_Driver')->create();
/* Find the categories */
$categoryList = $driver->getCategories(null, $categories);
if ($categoryList->count() == 0) {
$GLOBALS['cli']->message(_('Could not find the requested categories'), 'cli.error');
exit;
}
$properties = array();
foreach ($categoryList as $category) {
foreach ($category->properties as $property) {
$properties[] = $property;
}
print $category->hasRelation('properties', $properties[0]);
}
$cli->message($name, 'cli.success');
function usage()
{
$GLOBALS['cli']->writeln('Usage: sesha-add-stock "name" "category" "description" "prop1:val1,prop2:val2"');
exit;
}
sesha-1.0.0RC3/config/conf.xml 0000664 0001750 0001750 00000003374 12073544237 014161 0 ustar jan jan
Storage System Settingsrdo
Data Typesint, text, boolean, creditcard, cellphone, client, date, dblookup, description, email, enum, file, header, hourminutesecond, html, image, intlist, ipaddress, link, longtext, matrix, mlenum, monthdayyear, monthyear, multienum, number, obrowser, octal, password, radio, set, timeTicketsfalseClientsnameMenu settingstrue
sesha-1.0.0RC3/config/prefs.php 0000664 0001750 0001750 00000004340 12073544237 014334 0 ustar jan jan _("General Options"),
'label' => _("Display Options"),
'desc' => _("Change your inventory sorting and display options."),
'members' => array('sortby', 'sortdir', 'list_properties', 'sesha_default_view')
);
// user preferred sorting column
$_prefs['sortby'] = array(
'value' => Sesha::SORT_STOCKID,
'locked' => false,
'type' => 'enum',
'enum' => array(Sesha::SORT_STOCKID => _("Stock ID"),
Sesha::SORT_NAME => _("Item Name"),
Sesha::SORT_NOTE => _("Note")),
'desc' => _("Default sorting criteria:")
);
// user preferred sorting direction
$_prefs['sortdir'] = array(
'value' => Sesha::SORT_ASCEND,
'locked' => false,
'type' => 'enum',
'enum' => array(Sesha::SORT_ASCEND => _("Ascending"),
Sesha::SORT_DESCEND => _("Descending")),
'desc' => _("Default sorting direction:")
);
// default view
$_prefs['sesha_default_view'] = array(
'value' => 'list',
'locked' => false,
'type' => 'enum',
'enum' => array(
'list' => _("List"),
'search' => _("Search"),
'stock' => _("Stock")
),
'desc' => _("Select the view to display after login:")
);
// properties to show in lists
$_prefs['list_properties'] = array(
'value' => array(),
'locked' => false,
'type' => 'multienum',
'enum' => array(),
'desc' => _("Select properties that you would like to see in the list view. All other properties are only shown on individual item screens:")
);
$sesha_driver = $GLOBALS['injector']->getInstance('Sesha_Factory_Driver')->create();
foreach ($sesha_driver->getProperties() as $property) {
$_prefs['list_properties']['enum'][$property['property_id']] = $property['property'];
}
sesha-1.0.0RC3/docs/CHANGES 0000600 0001750 0001750 00000003533 12073544237 013153 0 ustar jan jan ---------
v1.0.0RC3
---------
[rla] QuickSearch now works by Name or Id (Request #11657).
---------
v1.0.0RC2
---------
[rla] Improved display of search results (Request #11656).
[rla] Search now allows to select partial or full value match (Request #11655).
---------
v1.0.0RC1
---------
[jan] Update to work with latest Horde 5 code.
-----------
v1.0.0beta1
-----------
[rla] Use Horde 5's CSS for sidebar icons.
[rla] Use Horde 5's New button for the Add Stock menu entry.
------------
v1.0.0alpha1
------------
[rla] Use Horde_View in place of Horde_Template.
[rla] Change backend from Sql driver to Rdo driver with enhanced search
capabilities.
[jan] Add Finnish translation (Leena Heino ).
[rla] Convert to Horde 5 Framework.
[jan] Add Latvian translation (Jānis Eisaks).
[cjh] Add sort priorities to categories.
[cjh] Add a preference for showing properties on the Stock List.
[jan] Add Spanish translation (Manuel Perez Ayala ).
[cjh] Separate permission to add stock from general admin permissions
(Manilal K M ).
[jan] Add configuration for address book field used for the client listings.
(Request #3816).
[jan] Remove default categories (vilius@lnk.lt, Request #3430).
[ben] Better support for MS-SQL.
[jan] Add support for dynamic re-sorting of the stock inventory, including
saving the sort preferences on any changes.
[jan] Allow set local administrators through permission interface
(rbreiddal@presinet.com, Request #2523).
[jan] Provide queues (categories) and versions (stock items) for Whups.
[jan] Add interface to set any additional parameters that some data types need.
[mas] Change any output of and tags to and for better
accessibility support.
[jan] Add Lithuanian translation (Vilius Sumskas ).
sesha-1.0.0RC3/docs/CREDITS 0000664 0001750 0001750 00000001360 12073544237 013206 0 ustar jan jan ========================
Sesha Development Team
========================
Core Developers
===============
- Jan Schneider
- Ralf Lang
Localization
============
===================== ===============================================
Finnish Leena Heino
Latvian Jānis Eisaks
Lithuanian Vilius Šumskas
Spanish Manuel Perez Ayala
Juan C. Blanco
===================== ===============================================
Inactive Developers
===================
- Bo Daley
- Andrew Coleman
sesha-1.0.0RC3/docs/INSTALL 0000664 0001750 0001750 00000013335 12073544237 013224 0 ustar jan jan ======================
Installing Sesha 1.0
======================
:Contact: horde@lists.horde.org
.. contents:: Contents
.. section-numbering::
This document contains instructions for installing the Sesha web-based
inventory application on your system.
For information on the capabilities and features of Sesha, see the file
README_ in the top-level directory of the Sesha distribution.
Prerequisites
=============
To function properly, Sesha **requires** the following:
1. A working Horde installation.
Sesha runs within the `Horde Application Framework`_, a set of common
tools for Web applications written in PHP. You must install Horde before
installing Sesha.
.. Important:: Sesha 1.0 requires version 5.0+ of the Horde Framework -
earlier versions of Horde will **not** work.
.. Important:: Be sure to have completed all of the steps in the
`horde/docs/INSTALL`_ file for the Horde Framework before
installing Sesha. Many of Sesha's prerequisites are
also Horde prerequisites. Additionally, many of Sesha's
optional features are configured via the Horde install.
.. _`Horde Application Framework`: http://www.horde.org/apps/horde
2. SQL support in PHP
Sesha stores its data in a backend - currently only SQL database is
supported.
Build PHP with whichever SQL driver you require; see the Horde
`horde/docs/INSTALL`_ file for more details on using databases with Horde.
Installing Sesha
================
The **RECOMMENDED** way to install Sesha is using the PEAR installer.
Alternatively, if you want to run the latest development code or get the
latest not yet released fixes, you can install Sesha from Git.
Installing with PEAR
~~~~~~~~~~~~~~~~~~~~
First follow the instructions in `horde/docs/INSTALL`_ to prepare a PEAR
environment for Horde and install the Horde Framework.
When installing Sesha through PEAR now, the installer will automatically
install any dependencies of Sesha too. If you want to install Sesha
with all optional dependencies, but without the binary PECL packages that need
to be compiled, specify both the ``-a`` and the ``-B`` flag::
pear install -a -B horde/sesha-alpha
By default, only the required dependencies will be installed::
pear install horde/sesha-alpha
If you want to install Sesha even with all binary dependencies, you need to
remove the ``-B`` flag. Please note that this might also try to install PHP
extensions through PECL that might need further configuration or activation in
your PHP configuration::
pear install -a horde/sesha-alpha
Installing from Git
~~~~~~~~~~~~~~~~~~~
See http://www.horde.org/source/git.php
Configuring Sesha
=====================
1. Configuring Horde for Sesha
Sesha requires an SQL backend for the Rdo storage driver. If you didn't
setup an SQL backend yet, go to the configuration interface, select Horde
from the list of applications and select the ``Database`` tab.
2. Configuring Sesha
You must login to Horde as a Horde Administrator to finish the configuration
of Sesha. Use the Horde ``Administration`` menu item to get to the
administration page, and then click on the ``Configuration`` icon to get the
configuration page. Select ``Inventory`` from the selection list of
applications. Fill in or change any configuration values as needed. When
done click on ``Generate Inventory Configuration`` to generate the
``conf.php`` file. If your web server doesn't have write permissions to the
Sesha configuration directory or file, it will not be able to write the
file. In this case, go back to ``Configuration`` and choose one of the
other methods to create the configuration file ``sesha/config/conf.php``.
Documentation on the format and purpose of the other configuration files in
the ``config/`` directory can be found in each file. You may create
``*.local.php`` versions of these files if you wish to customize Sesha's
appearance and behavior. See the header of the configuration files for
details and examples. The defaults will be correct for most sites.
3. Creating the database tables
Once you finished the configuration in the previous step, you can create all
database tables by clicking the ``DB schema is out of date.`` link in the
Sesha row of the configuration screen.
Alternatively creating the Sesha database tables can be accomplished with
Horde's ``horde-db-migrate`` utility. If your database is properly setup in
the Horde configuration, just run the following::
horde/bin/horde-db-migrate sesha
4. Testing Sesha
Use Sesha to create, modify, and delete categories and stock. Test at least
the following:
- Creating a new property
- Creating an inventory category
- Creating an inventory stock item
- Modifying an item
- Deleting an item
Obtaining Support
=================
If you encounter problems with Sesha, help is available!
The Horde Frequently Asked Questions List (FAQ), available on the Web at
http://wiki.horde.org/FAQ
The Horde Project runs a number of mailing lists, for individual applications
and for issues relating to the project as a whole. Information, archives, and
subscription information can be found at
http://www.horde.org/community/mail
Lastly, Horde developers, contributors and users may also be found on IRC,
on the channel #horde on the Freenode Network (irc.freenode.net).
Please keep in mind that Sesha is free software written by volunteers.
For information on reasonable support expectations, please read
http://www.horde.org/community/support
Thanks for using Sesha!
The Horde team
.. _README: README
.. _`horde/docs/INSTALL`: ../../horde/docs/INSTALL
.. _`horde/docs/TRANSLATIONS`: ../../horde/docs/TRANSLATIONS
sesha-1.0.0RC3/docs/RELEASE_NOTES 0000664 0001750 0001750 00000003151 12073544237 014141 0 ustar jan jan notes['fm']['focus'] = array(Horde_Release::FOCUS_MINORFEATURE);
/* Mailing list release notes. */
$this->notes['ml']['changes'] = <<notes['fm']['changes'] = <<notes['name'] = 'Sesha';
$this->notes['list'] = 'horde';
$this->notes['fm']['project'] = 'sesha';
$this->notes['fm']['branch'] = 'Horde 5';
sesha-1.0.0RC3/docs/TODO 0000664 0001750 0001750 00000002361 12073544237 012660 0 ustar jan jan Sesha is mostly complete, especially for just keeping track of inventory.
Here is an incomplete list of features that would be cool to have.
* Remember previous category after editing a stock item
* Search by Property Names, not just values
* Implement API for adding, updating & getting properties for items in inventory
* Add a few new Horde_Form_Types like IP address and Turba contact so that all i
of the previous functionality from Sesha is present in this version.
* More help(?)
* Maybe a better summary that will include a set of user-defined properties to
show (probably will lag too much to implement)
* Add another data field to allow an item to be purchased or not (or another
table all together)
* Add a field allowing user to indicate how many of an item are in stock.
* Consider crossover of this app with Merk (shopping cart)
These are not set in stone, but if Sesha is going to be used to keep up with a
*store's* inventory, these features would be nice to have. If it is nothing
more than to keep track of a few things that are lying around, Sesha is
already set to rock and roll.
Cheers,
Coleman
mercury [at] appisolutions [dot] net
* Horde 5 Ajax view
* Utilisation of the Rdo driver's enhanced search capabilities
Ralf Lang sesha-1.0.0RC3/lib/Driver/Rdo.php 0000664 0001750 0001750 00000052255 12073544237 014505 0 ustar jan jan
* 'db' The Horde_Db adapter
*
* Copyright 2003-2013 Horde LLC (http://www.horde.org/)
* Based on the original Sql driver
* Copyright 2004-2007 Andrew Coleman
*
* See the enclosed file COPYING for license information (GPL). If you
* did not receive this file, see http://www.horde.org/licenses/gpl.
*
* @author Bo Daley
* @author Andrew Coleman
* @author Ralf Lang
* @package Sesha
*/
class Sesha_Driver_Rdo extends Sesha_Driver
{
/**
* Handle for the database connection.
* @var DB
* @access protected
*/
protected $_db;
/**
* The mapper factory
* @var Horde_Rdo_Factory
* @access protected
*/
protected $_mappers;
/**
* This is the basic constructor for the Rdo driver.
*
* @param array $params Hash containing the connection parameters.
*/
public function __construct($params = array())
{
$this->_db = $params['db'];
$this->_mappers = new Horde_Rdo_Factory($this->_db);
}
/**
* This function retrieves a single stock item from the database.
*
* @param integer $stock_id The numeric ID of the stock item to fetch.
*
* @return Sesha_Entity_Stock a stock item
* @throws Sesha_Exception
*/
public function fetch($stock_id)
{
$sm = $this->_mappers->create('Sesha_Entity_StockMapper');
return $sm->findOne($stock_id);
}
/**
* Removes a stock entry from the database. Also removes all related
* category and property information.
*
* @param integer $stock_id The ID of the item to delete.
*
* @return boolean True on success
* @throws Sesha_Exception
*
*/
public function delete($stock_id)
{
$sm = $this->_mappers->create('Sesha_Entity_StockMapper');
return $sm->delete($stock_id);
}
/**
* This will add a new item to the inventory.
*
* @param array $stock A hash of values for the stock item.
*
* @return Sesha_Entity_Stock The newly added item or false.
* @throws Sesha_Exception
*/
public function add($stock)
{
$sm = $this->_mappers->create('Sesha_Entity_StockMapper');
return $sm->create($stock);
}
/**
* This function will modify a pre-existing stock entry with new values.
*
* @param array $stock The hash of values for the inventory item.
*
* @return boolean True on success.
* @throws Sesha_Exception
*/
public function modify($stock_id, $stock)
{
$sm = $this->_mappers->create('Sesha_Entity_StockMapper');
return $sm->update($stock_id, $stock);
}
/**
* This will return the category found matching a specific id.
*
* @param integer|array $category_id The integer ID or key => value hash of the category to find.
*
* @return Sesha_Entity_Category The category on success
*/
public function getCategory($category_id)
{
return $this->_mappers->create('Sesha_Entity_CategoryMapper')->findOne($category_id);
}
/**
* This function returns all the categories matching an id or category list.
*
* @param integer $stock_id The stock ID of categories to fetch.
* Overrides category_ids
* @param integer $category_ids The numeric IDs of the categories to find.
* If both $stock_id and $category_ids are null,
* all categories are returned
* @return array The list of matching categories
*/
public function getCategories($stock_id = null, array $category_ids = null)
{
$cm = $this->_mappers->create('Sesha_Entity_CategoryMapper');
if ((int)$stock_id > 0) {
$sm = $this->_mappers->create('Sesha_Entity_StockMapper');
$stock = $sm->findOne($stock_id);
return $stock->categories;
} elseif (is_int($category_ids)) {
return $cm->find($category_ids);
}
elseif (is_array($category_ids)) {
$query = new Horde_Rdo_Query($cm);
$query->addTest('category_id', 'IN', $category_ids);
return $cm->find($query);
} else {
return iterator_to_array($cm->find(), true);
}
}
/**
* This will find all the available properties matching a specified IDs.
*
* @param array $property_ids The numeric ID of properties to find.
* Matches all properties when null.
*
* @return array matching properties on success
* @throws Sesha_Exception
*/
public function getProperties($property_ids = array())
{
$pm = $this->_mappers->create('Sesha_Entity_PropertyMapper');
if (empty($property_ids)) {
return iterator_to_array($pm->find());
}
$query = new Horde_Rdo_Query($pm);
$query->addTest('property_id', 'IN', $property_ids);
return iterator_to_array($pm->find($query));
}
/**
* Finds the first matching property for a specified property ID.
*
* @param integer $property_id The numeric ID of properties to find.
*
* @return mixed The specified property on success
* @throws Sesha_Exception
*/
public function getProperty($property_id)
{
$result = $this->getProperties(array($property_id));
return array_shift($result);
}
/**
* Updates the attributes stored by a category.
*
* @param array $info Updated category attributes.
*
* @return integer Number of objects updated.
* @throws Sesha_Exception
*/
public function updateCategory($info)
{
$cm = $this->_mappers->create('Sesha_Entity_CategoryMapper');
return $cm->update($info['category_id'], $info);
}
/**
* Adds a new category for classifying inventory.
*
* @param array $info The new category's attributes.
*
* @return Sesha_Entity_Category The category on success
* @throws Sesha_Exception
*/
public function addCategory($info)
{
$cm = $this->_mappers->create('Sesha_Entity_CategoryMapper');
if (array_key_exists('category_id', $info) &&
$info['category_id'] == null)
unset($info['category_id']);
return $cm->create($info);
}
/**
* Deletes a category.
*
* @param integer $category_id The numeric ID of the category to delete. Also accepts Sesha_Entity_Category
*
* @return integer The number of categories deleted
*/
public function deleteCategory($category_id)
{
$cm = $this->_mappers->create('Sesha_Entity_CategoryMapper');
if ($category_id instanceof Sesha_Inventory_Category) {
$category = $category_id;
$category_id = $category->category_id;
} else {
$category = $cm->findOne($category_id);
}
if (empty($category)) throw new Sesha_Exception(sprintf(_('The category %d could not be found', $category_id)));
return $category->delete();
}
/**
* Determines if a category exists in the storage backend.
*
* @param string $category The string representation of the category to
* find.
*
* @return boolean True on success; false otherwise.
*/
public function categoryExists($category)
{
$cm = $this->_mappers->create('Sesha_Entity_CategoryMapper');
if ($category instanceof Sesha_Inventory_Category) {
$category = $category->category;
}
return (boolean) $cm->findOne(array('category' => $category));
}
/**
* Updates a property with new attributes.
*
* @param array $info Array with updated property values.
*
* @return Sesha_Inventory_Property The changed Sesha_Inventory_Property object.
*/
public function updateProperty(array $info)
{
$pm = $this->_mappers->create('Sesha_Entity_PropertyMapper');
$property = $pm->findOne($info['property_id']);
if (empty($property)) throw new Sesha_Exception(sprintf(_('The property %d could not be loaded', $info['property_id'])));
$property->property = $info['property'];
$property->datatype = $info['datatype'];
$property->parameters = $info['parameters'];
$property->unit = $info['unit'];
$property->description = $info['description'];
$property->priority = $info['priority'];
$property->save();
return $property;
}
/**
* Adds a new property to the storage backend.
*
* @param array $info Array with new property values.
*
* @return Sesha_Entity_Property
*/
public function addProperty($info)
{
$pm = $this->_mappers->create('Sesha_Entity_PropertyMapper');
$property = $pm->create($info);
return $property;
}
/**
* Deletes a property from the storage backend.
*
* @param integer $property_id The numeric ID of the property to delete. Also accepts a Sesha_Inventory_Property object
*
* @return integer Number of objects deleted.
*/
public function deleteProperty($property_id)
{
$pm = $this->_mappers->create('Sesha_Entity_PropertyMapper');
if ($property_id instanceof Sesha_Inventory_Property) {
$property = $property_id;
$property_id = $property->property_id;
} else {
$property = $pm->findOne($property_id);
}
if (empty($property)) throw new Sesha_Exception(sprintf(_('The property %d could not be found', $property_id)));
return $property->delete();
}
/**
* This will return a set of properties for a set of specified categories.
*
* @param array $categories The set of categories to fetch properties.
*
* @return mixed An array of properties on success
* @throws Sesha_Exception
*/
public function getPropertiesForCategories($categories = array())
{
$properties = array();
foreach ($categories as $category) {
if (!($category instanceof Sesha_Entity_Category)) {
$cm = $this->_mappers->create('Sesha_Entity_CategoryMapper');
$category = $cm->findOne($category);
}
foreach ($category->properties as $property) {
$properties[$property->property_id] = $property;
}
}
return $properties;
}
/**
* Updates a category with a set of properties.
*
* @param integer $category_id The numeric ID of the category to update.
* @param array $properties An array of property ID's to add.
*
* @throws Sesha_Exception
*/
public function setPropertiesForCategory($category_id, $properties = array())
{
$cm = $this->_mappers->create('Sesha_Entity_CategoryMapper');
if ($category_id instanceof Sesha_Entity_Category) {
$category = $category_id;
} else {
$category = $cm->findOne($category_id);
}
$pm = $this->_mappers->create('Sesha_Entity_PropertyMapper');
$this->clearPropertiesForCategory($category);
foreach ($properties as $property) {
if (!($property instanceof Sesha_Entity_Property)) {
$property = $pm->findOne($property);
$category->addRelation('properties', $property);
}
}
}
/**
* Removes all properties for a specified category.
*
* @param integer $category_id The numeric ID of the category to update.
*
* @return integer The number of deleted properties
* @throws Sesha_Exception
*/
public function clearPropertiesForCategory($category_id)
{
$cm = $this->_mappers->create('Sesha_Entity_CategoryMapper');
if ($category_id instanceof Sesha_Entity_Category) {
$category = $category_id;
} else {
$category = $cm->findOne($category_id);
}
return $category->removeRelation('properties');
}
/**
* Returns a set of properties for a particular stock ID number.
*
* @param integer $stock_id The numeric ID of the stock to find the
* properties for.
*
* @return array of Sesha_Inventory_Property objects
* @throws Sesha_Exception
*/
public function getPropertiesForStock($stock_id)
{
if (($stock_id instanceof Sesha_Entity_Stock)) {
$stock = $stock_id;
$stock_id = $stock->stock_id;
} else {
$sm = $this->_mappers->create('Sesha_Entity_StockMapper');
$stock = $sm->findOne($stock_id);
}
return $this->getPropertiesForCategories($stock->categories);
}
/**
* Returns a set of Value Objects for a particular stock ID number.
*
* @param integer $stock_id The numeric ID of the stock to find the
* properties for.
* You can also pass a Sesha_Entity_Stock item
*
* @return array the list of Sesha_Entity_Value objects
* @throws Sesha_Exception
*/
public function getValuesForStock($stock_id)
{
if (($stock_id instanceof Sesha_Entity_Stock)) {
$stock = $stock_id;
$stock_id = $stock->stock_id;
} else {
$sm = $this->_mappers->create('Sesha_Entity_StockMapper');
$stock = $sm->findOne($stock_id);
}
return iterator_to_array($stock->values);
}
/**
* Removes categories from a particular stock item.
*
* @param integer $stock_id The numeric ID of the stock item to update.
* @param array $categories The array of categories to remove.
*
* @return integer the number of categories removed
* @throws Sesha_Exception
*/
public function clearPropertiesForStock($stock_id, $categories = array())
{
if ($stock_id instanceof Sesha_Entity_Stock) {
$stock_id = $stock_id->stock_id;
}
if (!is_array($categories)) {
$categories = array(0 => array('category_id' => $categories));
}
/* Get list of properties for this set of categories. */
try {
$properties = $this->getPropertiesForCategories($categories);
} catch (Horde_Db_Exception $e) {
throw new Sesha_Exception($e);
}
$vm = $this->_mappers->create('Sesha_Entity_ValueMapper');
$query = Horde_Rdo_Query::create(array('stock_id' => $stock_id), $vm);
$query->addTest(array(
'field' => 'property_id',
'test' => 'IN',
'value' => array_keys($properties)
)
);
$count = 0;
foreach ($vm->find($query) as $value) {
$value->delete();
$count++;
}
return $count;
}
/**
* Updates the set of properties for a particular stock item.
*
* @param integer $stock_id The numeric ID of the stock to update.
* @param array $properties The hash of properties to update.
*
* @throws Sesha_Exception
*/
public function updatePropertiesForStock($stock_id, $properties = array())
{
if ($stock_id instanceof Sesha_Entity_Stock) {
$stock_id = $stock_id->stock_id;
}
$vm = $this->_mappers->create('Sesha_Entity_ValueMapper');
foreach ($properties as $property_id => $property_value) {
$value = $vm->findOne(array('stock_id' => $stock_id, 'property_id' => $property_id));
if (!$value) {
$value = $vm->create(array('stock_id' => $stock_id, 'property_id' => $property_id));
}
$value->setDataValue($property_value);
$value->save();
}
}
/**
* Updates the set of categories for a specified stock item.
*
* @param integer $stock_id The numeric stock ID to update.
* @param array $categories The array of categories to change.
*
*/
public function updateCategoriesForStock($stock_id, $categories = array())
{
$sm = $this->_mappers->create('Sesha_Entity_StockMapper');
$cm = $this->_mappers->create('Sesha_Entity_CategoryMapper');
if (!is_array($categories)) {
$categories = array($categories);
}
if (($stock_id instanceof Sesha_Entity_Stock)) {
$stock = $stock_id;
$stock_id = $stock->stock_id;
} else {
$stock = $sm->findOne($stock_id);
}
/* First clear any categories that might be set for this item. */
$stock->removeRelation('categories');
foreach ($categories as $category) {
if (!($category instanceof Sesha_Entity_Category)) {
$category = $cm->findOne($category);
}
$stock->addRelation('categories', $category);
}
}
/**
* Inventory search
* @param array filters a list of filter hashes, each having keys
* string type ('note', 'stock_name', 'stock_id', 'categories', 'values')
* string test
* boolean exact (only search for full words, default to null)
* mixed value (string for note, stock_name)
* For the 'values' structure, value, value is a map of [values] and optional [property]}
* @return array List of Stock items
*/
public function findStock($filters = array())
{
$sm = $this->_mappers->create('Sesha_Entity_StockMapper');
if (empty($filters)) {
return iterator_to_array($sm->find());
}
$query = new Horde_Rdo_Query($sm);
$query->combineWith('OR');
foreach ($filters as $filter) {
switch ($filter['type']) {
case 'note':
case 'stock_name':
case 'stock_id':
$filter_values = is_array($filter['value']) ? $filter['value'] : array($filter['value']);
$filter_test = $filter['test'] ? $filter['test'] : 'LIKE';
$filter_field = $filter['type'];
foreach ($filter_values as $filter_value) {
if ($filter_test == 'LIKE' and empty($filter['exact'])) {
$filter_value = '%' . $filter_value . '%';
}
$query->addTest($filter_field, $filter_test, $filter_value);
}
break;
case 'categories':
$cm = $this->_mappers->create('Sesha_Entity_CategoryMapper');
$categories = is_array($filter['value']) ? $filter['value'] : array($filter['value']);
$items = array();
foreach ($categories as $category) {
if ($category instanceof Sesha_Entity_Category) {
$category_id = $category->category_id;
} else {
$category_id = $category;
$category = $cm->findOne($category_id);
}
foreach ($category->stock as $item) {
/* prevent duplicates when an item has several categories */
$items[$item->stock_id] = $item;
}
}
if (count($filters == 1)) {
return $items;
}
$query->addTest('stock_id', $filter['test'] ? $filter['test'] : 'IN', array_keys($items));
break;
case 'values':
$vm = $this->_mappers->create('Sesha_Entity_ValueMapper');
$items = array();
foreach ($filter['value'] as $propTest) {
$values = is_array($propTest['values']) ? $propTest['values'] : array($propTest['values']);
// Find all Value objects which match any of the $value[values]
foreach ($values as $filter_value) {
$valueQuery = new Horde_Rdo_Query($vm);
if ($propTest['property']) {
$valueQuery->addTest('property_id', '=', $propTest['property']);
}
if (empty($filter['exact'])) {
$filter_value = '%' . $filter_value . '%';
}
$valueQuery->addTest('txt_datavalue', 'LIKE', $filter_value);
foreach ($vm->find($valueQuery) as $value) {
// prevent doubles
$items[$value->stock_id] = $value->stock;
}
}
}
if (count($filters == 1)) {
return $items;
}
$query->addTest('stock_id',$filter['test'] ? $filter['test'] : 'IN', array_keys($items));
break;
}
}
return iterator_to_array($sm->find($query));
}
}
sesha-1.0.0RC3/lib/Entity/Category.php 0000664 0001750 0001750 00000000076 12073544237 015551 0 ustar jan jan
* @category Horde
* @package Sesha
* @license http://www.horde.org/licenses/gpl GPL
*/
/**
* The Sesha_Entity_CategoryMapper class contains all functions related to handling
* category mapping in Sesha.
*
* Copyright 2012-2013 Horde LLC (http://www.horde.org/)
*
* See the enclosed file COPYING for license information (GPL). If you
* did not receive this file, see http://www.horde.org/licenses/gpl.
*
* @author Ralf Lang
* @category Horde
* @package Sesha
* @license http://www.horde.org/licenses/gpl GPL
*/
class Sesha_Entity_CategoryMapper extends Horde_Rdo_Mapper
{
/**
* Inflector doesn't support Horde-style tables yet
* @var string
* @access protected
*/
protected $_table = 'sesha_categories';
/**
* Relationships loaded on-demand
* @var array
* @access protected
*/
protected $_lazyRelationships = array(
'properties' => array('type' => Horde_Rdo::MANY_TO_MANY,
'mapper' => 'Sesha_Entity_PropertyMapper',
'through' => 'sesha_relations'),
'stock' => array('type' => Horde_Rdo::MANY_TO_MANY,
'mapper' => 'Sesha_Entity_StockMapper',
'through' => 'sesha_inventory_categories')
);
}
sesha-1.0.0RC3/lib/Entity/Property.php 0000664 0001750 0001750 00000001766 12073544237 015627 0 ustar jan jan _fields['parameters']);
}
/**
* Explicit setter for the parameters variable interface.
* Internalizes the (un)serialization of the parameters array for backend storage
* returns mixed
*/
public function setParameters($parameters)
{
return $this->_fields['parameters'] = serialize($parameters);
}
/**
* Save any changes to the backend.
* Overridden because the default save() method passes the external representation to backend, not the serialized representation
* @return boolean Success.
*/
public function save()
{
return $this->getMapper()->update($this->property_id, $this->_fields) == 1;
}
}
sesha-1.0.0RC3/lib/Entity/PropertyMapper.php 0000664 0001750 0001750 00000010106 12073544237 016760 0 ustar jan jan
* @category Horde
* @package Sesha
* @license http://www.horde.org/licenses/gpl GPL
*/
/**
* The Sesha_Entity_PropertyMapper class contains all functions related to handling
* property mapping in Sesha.
*
* Copyright 2012-2013 Horde LLC (http://www.horde.org/)
*
* See the enclosed file COPYING for license information (GPL). If you
* did not receive this file, see http://www.horde.org/licenses/gpl.
*
* @author Ralf Lang
* @category Horde
* @package Sesha
* @license http://www.horde.org/licenses/gpl GPL
*/
class Sesha_Entity_PropertyMapper extends Horde_Rdo_Mapper
{
/**
* Inflector doesn't support Horde-style tables yet
* @var string
* @access protected
*/
protected $_table = 'sesha_properties';
/**
* Relationships loaded on-demand
* @var array
* @access protected
*/
protected $_lazyRelationships = array(
'categories' => array('type' => Horde_Rdo::MANY_TO_MANY,
'mapper' => 'Sesha_Entity_CategoryMapper',
'through' => 'sesha_relations'),
'values' => array('type' => Horde_Rdo::ONE_TO_MANY,
'mapper' => 'Sesha_Entity_ValueMapper',
'foreignKey' => 'property_id',
),
);
/**
* Creates a property definition in the backend.
* This wraps folding of the 'parameters' structure
*
* @param array $property An array with the property definition.
* Keys may be
* property_id Integer (autogenerated)
* property string The property name
* datatype string The property type
* parameters mixed Type definition parameters will be serialized
* unit string The unit to display
* description string
* priority integer
*
* @return Sesha_Entity_Property The property created.
*/
public function create(array $property)
{
if (!is_string($property['parameters'])) {
$property['parameters'] = serialize($property['parameters']);
}
if (array_key_exists('property_id', $property) &&
$property['property_id'] == null)
unset($property['property_id']);
return parent::create($property);
}
/**
* Updates a record in the backend. $object can be either a
* primary key or an Rdo object. If $object is an Rdo instance
* then $fields will be ignored as values will be pulled from the
* object.
*
* @param string|Rdo $object The Rdo instance or unique id to update.
* @param array $fields If passing a unique id, the array of field properties
* to set for $object.
*
* @return integer Number of objects updated.
*/
/**
* Deletes a property definition from the backend. $object can be either a
* primary key, an Rdo_Query object, or a Sesha_Entity_Property object.
* This also cleans up attachment attributes of this property type and category links
*
* @param string|Sesha_Entity_Property|Horde_Rdo_Query $object The Rdo object,
* Horde_Rdo_Query, or unique id to delete.
*
* @return integer Number of objects deleted.
*/
public function delete($object)
{
if (!($object instanceof Sesha_Entity_Property)) {
$object = $this->findOne($object);
}
foreach ($object->values as $value) {
$value->delete();
}
$object->removeRelation('categories');
return parent::delete($object);
}
}
sesha-1.0.0RC3/lib/Entity/Stock.php 0000664 0001750 0001750 00000001165 12073544237 015057 0 ustar jan jan _mapper->factory->create('Sesha_Entity_ValueMapper');
return $am->findOne(array(
'stock_id' => $this->stock_id,
'property_id' => $property instanceof Sesha_Entity_Property ? $property->property_id : $property
)
);
}
}
sesha-1.0.0RC3/lib/Entity/StockMapper.php 0000664 0001750 0001750 00000004610 12073544237 016222 0 ustar jan jan
* @category Horde
* @package Sesha
* @license http://www.horde.org/licenses/gpl GPL
*/
/**
* The Sesha_Entity_StockMapper class contains all functions related to handling
* stock mapping in Sesha.
*
* Copyright 2012-2013 Horde LLC (http://www.horde.org/)
*
* See the enclosed file COPYING for license information (GPL). If you
* did not receive this file, see http://www.horde.org/licenses/gpl.
*
* @author Ralf Lang
* @category Horde
* @package Sesha
* @license http://www.horde.org/licenses/gpl GPL
*/
class Sesha_Entity_StockMapper extends Horde_Rdo_Mapper
{
/**
* Inflector doesn't support Horde-style tables yet
* @var string
* @access protected
*/
protected $_table = 'sesha_inventory';
/**
* Relationships loaded on-demand
* @var array
* @access protected
*/
protected $_lazyRelationships = array(
'categories' => array('type' => Horde_Rdo::MANY_TO_MANY,
'mapper' => 'Sesha_Entity_CategoryMapper',
'through' => 'sesha_inventory_categories'),
'values' => array('type' => Horde_Rdo::ONE_TO_MANY,
'mapper' => 'Sesha_Entity_ValueMapper',
'foreignKey' => 'stock_id',
),
);
/**
* Deletes a stock item from the backend. $object can be either a
* primary key, an Rdo_Query object, or a Sesha_Entity_Stock object.
* This also cleans up attached attributes and categories
*
* @param string|Sesha_Entity_Stock|Horde_Rdo_Query $object The Rdo object,
* Horde_Rdo_Query, or unique id to delete.
*
* @return integer Number of objects deleted.
*/
public function delete($object)
{
if (!($object instanceof Sesha_Entity_Stock)) {
$object = $this->findOne($object);
}
foreach ($object->values as $value) {
$value->delete();
}
$object->removeRelation('categories');
return parent::delete($object);
}
}
sesha-1.0.0RC3/lib/Entity/Value.php 0000664 0001750 0001750 00000004650 12073544237 015052 0 ustar jan jan
* @category Horde
* @package Sesha
*/
class Sesha_Entity_Value extends Horde_Rdo_Base
{
/**
* Retrieves the txt_datavalue or int_datavalue depending on context
*/
public function getDataValue()
{
/* These field-specific handlers should better be delegated to field
* definitions. */
switch ($this->property->datatype) {
case 'date':
case 'datetime':
case 'hourminutesecond':
case 'monthdayyear':
case 'monthyear':
case 'time':
if (is_int($this->txt_datavalue)) {
return new Horde_Date($this->txt_datavalue);
}
$dt = new Horde_Date;
foreach (Horde_Serialize::unserialize($this->txt_datavalue, Horde_Serialize::BASIC) as $marker => $content) {
if (strlen($content)) {
$dt->$marker = $content;
}
}
return $dt;
case 'image';
return array('hash' => $this->txt_datavalue);
default:
return $this->txt_datavalue;
}
}
/**
* Saves the txt_datavalue or int_datavalue depending on context.
*
* Folds special data types into a serializable, preferably search-friendly
* format.
*/
public function setDataValue($value)
{
/* These field-specific handlers should better be delegated to field
* definitions. */
switch ($this->property->datatype) {
case 'date':
case 'datetime':
case 'hourminutesecond':
case 'monthdayyear':
case 'monthyear':
case 'time':
if (is_array($value)) {
// Directly passing the array makes funny breakage :(
$dt = new Horde_Date();
foreach ($value as $marker => $content) {
if (strlen($content)) {
$dt->$marker = $content;
}
}
$value = $dt->datestamp();
}
break;
case 'image':
$value = $value['hash'];
break;
}
return $this->txt_datavalue = $value;
}
}
sesha-1.0.0RC3/lib/Entity/ValueMapper.php 0000664 0001750 0001750 00000003345 12073544237 016217 0 ustar jan jan
* @category Horde
* @package Sesha
* @license http://www.horde.org/licenses/gpl GPL
*/
/**
* The Sesha_Entity_ValueMapper class contains all functions related to handling
* a property's value for a specific stock item in Sesha.
*
* Copyright 2012-2013 Horde LLC (http://www.horde.org/)
*
* See the enclosed file COPYING for license information (GPL). If you
* did not receive this file, see http://www.horde.org/licenses/gpl.
*
* @author Ralf Lang
* @category Horde
* @package Sesha
* @license http://www.horde.org/licenses/gpl GPL
*/
class Sesha_Entity_ValueMapper extends Horde_Rdo_Mapper
{
/**
* Inflector doesn't support Horde-style tables yet
* @var string
* @access protected
*/
protected $_table = 'sesha_inventory_properties';
/**
* Relationships loaded on-demand
* @var array
* @access protected
*/
protected $_lazyRelationships = array(
'stock' => array(
'type' => Horde_Rdo::ONE_TO_ONE,
'foreignKey' => 'stock_id',
'mapper' => 'Sesha_Entity_StockMapper'
),
'property' => array(
'type' => Horde_Rdo::ONE_TO_ONE,
'foreignKey' => 'property_id',
'mapper' => 'Sesha_Entity_PropertyMapper'
),
);
}
sesha-1.0.0RC3/lib/Factory/Driver.php 0000664 0001750 0001750 00000003040 12073544237 015354 0 ustar jan jan _instances[$name])) {
if (!empty($params['driver'])) {
$driver = $params['driver'];
unset($params['driver']);
} else {
$driver = $GLOBALS['conf']['storage']['driver'];
$params = Horde::getDriverConfig('storage', $driver);
}
$class = 'Sesha_Driver_' . ucfirst(basename($driver));
if (!class_exists($class)) {
throw new Sesha_Exception(sprintf('Unable to load the definition of %s.', $class));
}
switch ($class) {
case 'Sesha_Driver_Rdo':
if (empty($params['db'])) {
$params['db'] = $this->_injector->getInstance('Horde_Core_Factory_Db')->create('sesha', $params);
}
break;
}
$this->_instances[$name] = new $class($params);
}
return $this->_instances[$name];
}
}
sesha-1.0.0RC3/lib/Form/Type/Client.php 0000664 0001750 0001750 00000003016 12073544237 015557 0 ustar jan jan
* Copyright 2004-2013 Horde LLC (http://www.horde.org/)
*
* See the enclosed file COPYING for license information (GPL). If you
* did not receive this file, see http://www.horde.org/licenses/gpl.
*
* @author Andrew Coleman
* @since Sesha 1
* @package Sesha
*/
class Sesha_Form_Type_Client extends Horde_Form_Type_enum {
public function init($values = null, $prompt = null)
{
global $conf, $registry;
// Get list of clients, if available.
if ($registry->hasMethod('clients/getClientSource')) {
$source = $registry->call('clients/getClientSource');
if (!empty($source)) {
$results = $registry->call('clients/searchClients', array(array('')));
$clientlist = $results[''];
$clients = array();
foreach ($clientlist as $client) {
$key = isset($client['id']) ? $client['id'] : $client['__key'];
$clients[$key] = isset($client[$conf['client']['field']]) ? $client[$conf['client']['field']] : '';
}
asort($clients);
parent::init($clients);
}
}
}
/**
* Return info about field type.
*/
public function about()
{
$about = array();
$about['name'] = _("Client");
return $about;
}
}
sesha-1.0.0RC3/lib/Form/Category.php 0000664 0001750 0001750 00000005051 12073544237 015176 0 ustar jan jan
* @package Sesha
*/
class Sesha_Form_Category extends Horde_Form
{
public function __construct($vars)
{
parent::__construct($vars);
// This is probably wrong. The library should get the driver
// or the properties passed
$sesha_driver = $GLOBALS['injector']->getInstance('Sesha_Factory_Driver')->create();
$this->appendButtons(_("Save Category"));
$category_id = $vars->get('category_id');
$priorities = array();
for ($i = 0; $i < 100; $i++) {
$priorities[] = $i;
}
try {
$allproperties = $sesha_driver->getProperties();
}
catch (Sesha_Exception $e) {
throw new Sesha_Exception($e);
}
$a = array();
foreach ($allproperties as $p) {
$a[$p['property_id']] = $p['property'];
}
if (!empty($category_id)) {
try {
$properties = $sesha_driver->getPropertiesForCategories($category_id);
} catch (Sesha_Exception $e) {
throw new Sesha_Exception($e);
}
$current = array();
foreach ($properties as $s) {
$current[$s['property_id']] = $s['property'];
}
}
$this->addHidden('', 'actionID', 'text', false, false, null);
$this->addHidden('', 'category_id', 'text', false, false, null);
$this->addHidden('', 'submitbutton', 'text', false, false, null);
$this->addVariable(_("Category Name"), 'category', 'text', true);
$this->addVariable(_("Description"), 'description', 'longtext', false);
$this->addVariable(_("Sort Weight"), 'priority', 'enum', false, false, _("When categories are displayed, they will be shown in weight order from highest to lowest"), array($priorities));
if (!count($a)) {
$fieldtype = 'invalid';
$a = _("No properties are currently configured. Use the \"Manage Properties\" tab above to add some.");
} else {
$fieldtype = 'multienum';
}
$mp = &$this->addVariable(_("Properties"), 'properties', $fieldtype, true, false, null, array($a));
if (!empty($current)) {
$mp->setDefault(array_keys($current));
}
$action = Horde_Form_Action::factory('submit');
}
}
sesha-1.0.0RC3/lib/Form/CategoryDelete.php 0000664 0001750 0001750 00000001557 12073544237 016330 0 ustar jan jan
* @package Sesha
*/
class Sesha_Form_CategoryDelete extends Horde_Form {
public function __construct($vars)
{
parent::__construct($vars);
$this->appendButtons(_("Delete Category"));
$params = array('yes' => _("Yes"),
'no' => _("No"));
$desc = _("Really delete this category?");
$this->addHidden('', 'actionID', 'text', false, false, null, array('delete_category'));
$this->addHidden('', 'category_id', 'text', false, false, null);
$this->addVariable(_("Confirm"), 'confirm', 'enum', true, false, $desc, array($params));
}
}
sesha-1.0.0RC3/lib/Form/CategoryList.php 0000664 0001750 0001750 00000002723 12073544237 016035 0 ustar jan jan
* @package Sesha
*/
class Sesha_Form_CategoryList extends Horde_Form {
public function __construct($vars)
{
parent::__construct($vars);
// This is probably wrong. The library should get the driver
// or the properties passed
$sesha_driver = $GLOBALS['injector']->getInstance('Sesha_Factory_Driver')->create();
$this->setButtons(array(
_("Edit Category"),
array('class' => 'horde-delete', 'value' => _("Delete Category"))));
$categories = $sesha_driver->getCategories();
$params = array();
foreach ($categories as $category) {
$params[$category->category_id] = $category->category;
}
$title = !empty($title) ? $title : _("Edit a category");
$this->setTitle($title);
$this->addHidden('', 'actionID', 'text', false, false, null, array('edit_category'));
if (!count($params)) {
$fieldtype = 'invalid';
$params = _("No categories are currently configured. Use the form below to add one.");
} else {
$fieldtype = 'enum';
}
$this->addVariable(_("Category"), 'category_id', $fieldtype, true, false, null, array($params));
}
}
sesha-1.0.0RC3/lib/Form/Property.php 0000664 0001750 0001750 00000012546 12073544237 015254 0 ustar jan jan
* @package Sesha
*/
class Sesha_Form_Property extends Horde_Form
{
public function __construct($vars)
{
parent::__construct($vars);
$this->appendButtons(_("Save Property"));
$types = array();
$datatypes = $GLOBALS['conf']['datatypes']['types'];
foreach ($datatypes as $d) {
$types[$d] = $d;
}
$priorities = array();
for ($i = 0; $i < 100; $i++) {
$priorities[] = $i;
}
$this->addHidden('', 'actionID', 'text', false, false, null);
$this->addHidden('', 'property_id', 'text', false, false, null);
$this->addVariable(_("Property Name"), 'property', 'text', true);
$action = Horde_Form_Action::factory('submit');
$v = $this->addVariable(_("Data Type"), 'datatype', 'enum', true, false, null, array($types, true));
$v->setAction($action);
$v->setOption('trackchange', true);
$this->addVariable(_("Unit"), 'unit', 'text', false);
$this->addVariable(_("Description"), 'description', 'longtext', false);
$this->addVariable(_("Sort Weight"), 'priority', 'enum', false, false, _("When properties are displayed, they will be shown in weight order from highest to lowest"), array($priorities));
}
/**
* Validates the form, checking if it really has been submitted by calling
* isSubmitted() and if true does any onSubmit() calls for variable types
* in the form. The _submitted variable is then rechecked.
*
* @param Variables $vars A Variables instance, optional since Horde
* 3.2.
* @param boolean $canAutofill Can the form be valid without being
* submitted?
*
* @return boolean True if the form is valid.
*/
public function validate($vars, $canAutoFill = false)
{
$this->_addParameters($vars);
return parent::validate($vars, $canAutoFill);
}
/**
* Renders the form for editing.
*
* @param Horde_Form_Renderer $renderer A renderer instance, optional
* since Horde 3.2.
* @param Variables $vars A Variables instance, optional
* since Horde 3.2.
* @param string $action The form action (url).
* @param string $method The form method, usually either
* 'get' or 'post'.
* @param string $enctype The form encoding type. Determined
* automatically if null.
* @param boolean $focus Focus the first form field?
*/
public function renderActive($renderer, $vars, $action, $method = 'get', $enctype = null, $focus = true)
{
if ($vars->get('old_datatype') === null) {
$this->_addParameters($vars);
}
parent::renderActive($renderer, $vars, $action, $method, $enctype, $focus);
}
protected function _addParameters($vars)
{
$dataType = $vars->get('datatype');
$className = $this->_buildTypeClassname($dataType);
if (empty($dataType)) {
// Noop.
} elseif (!$className) {
$GLOBALS['notification']->push(sprintf(_("The form field type \"%s\" doesn't exist."), $dataType), 'horde.error');
} else {
$params = call_user_func(array($className, 'about'));
if (isset($params['params'])) {
foreach ($params['params'] as $name => $param) {
$field_id = 'parameters[' . $name . ']';
$param['required'] = isset($param['required'])
? $param['required']
: null;
$param['readonly'] = isset($param['readonly'])
? $param['readonly']
: null;
$param['desc'] = isset($param['desc'])
? $param['desc']
: null;
$this->insertVariableBefore('unit', $param['label'],
$field_id, $param['type'],
$param['required'],
$param['readonly'],
$param['desc']);
$vars->set('old_datatype', $dataType);
}
}
}
}
/**
* Helper method to build either h3 style class names as seen in Horde_Form_Type_ccc
* or autoloadable class names used in Sesha
*
* @param string $dataType The type identifier to turn into a class name
*
* @return string A class name or an empty string
*
*/
protected function _buildTypeClassname($dataType)
{
if (class_exists('Horde_Form_Type_' . $dataType)) {
return 'Horde_Form_Type_' . $dataType;
} elseif (class_exists('Sesha_Form_Type_' . ucfirst($dataType))) {
return 'Sesha_Form_Type_' . ucfirst($dataType);
} else {
return '';
}
}
}
sesha-1.0.0RC3/lib/Form/PropertyDelete.php 0000664 0001750 0001750 00000001556 12073544237 016376 0 ustar jan jan
* @package Sesha
*/
class Sesha_Form_PropertyDelete extends Horde_Form
{
public function __construct($vars)
{
parent::__construct($vars);
$this->appendButtons(_("Delete Property"));
$params = array('yes' => _("Yes"),
'no' => _("No"));
$desc = _("Really delete this property?");
$this->addHidden('', 'actionID', 'text', false, false, null, array('delete_property'));
$this->addHidden('', 'property_id', 'text', false, false, null);
$this->addVariable(_("Confirm"), 'confirm', 'enum', true, false, $desc, array($params));
}
}
sesha-1.0.0RC3/lib/Form/PropertyList.php 0000664 0001750 0001750 00000002730 12073544237 016102 0 ustar jan jan
* @package Sesha
*/
class Sesha_Form_PropertyList extends Horde_Form
{
public function __construct($vars)
{
parent::__construct($vars);
// This is probably wrong. The library should get the driver
// or the properties passed
$sesha_driver = $GLOBALS['injector']->getInstance('Sesha_Factory_Driver')->create();
$this->setButtons(array(
_("Edit Property"),
array('class' => 'horde-delete', 'value' => _("Delete Property"))));
$properties = $sesha_driver->getProperties();
$params = array();
foreach ($properties as $property) {
$params[$property['property_id']] = $property['property'];
}
$title = !empty($title) ? $title : _("Edit a property");
$this->setTitle($title);
$this->addHidden('', 'actionID', 'text', false, false, null, array('edit_property'));
if (!count($params)) {
$fieldtype = 'invalid';
$params = _("No properties are currently configured. Use the form below to add one.");
} else {
$fieldtype = 'enum';
}
$this->addVariable(_("Property"), 'property_id', $fieldtype, true, false, null, array($params));
}
}
sesha-1.0.0RC3/lib/Form/Search.php 0000664 0001750 0001750 00000002556 12073544237 014635 0 ustar jan jan
* Copyright 2004-2013 Horde LLC (http://www.horde.org/)
*
* See the enclosed file COPYING for license information (GPL). If you
* did not receive this file, see http://www.horde.org/licenses/gpl.
*
* @author Andrew Coleman
* @package Sesha
*/
class Sesha_Form_Search extends Horde_Form {
/**
* Basic constructor for the SearchForm.
*
* @param Horde_Variables $vars The default variables to use.
*/
public function __construct($vars)
{
parent::__construct($vars, _("Search The Inventory"));
$this->appendButtons(_("Search"));
$this->addHidden('', 'actionId', 'text', true);
$this->addVariable(_("Search these properties"), 'location', 'multienum', true,
false, null, array(array(
Sesha::SEARCH_ID => _("Stock ID"),
Sesha::SEARCH_NAME => _("Item Name"),
Sesha::SEARCH_NOTE => _("Item Note"),
Sesha::SEARCH_PROPERTY => _("Property Value"))));
$this->addVariable(_("For this value"), 'criteria', 'text', true);
$this->addVariable(_("Only exact matches"), 'exact', 'boolean', true, false);
}
}
sesha-1.0.0RC3/lib/Form/Stock.php 0000664 0001750 0001750 00000007751 12073544237 014515 0 ustar jan jan
* Copyright 2004-2013 Horde LLC (http://www.horde.org/)
*
* See the enclosed file COPYING for license information (GPL). If you
* did not receive this file, see http://www.horde.org/licenses/gpl.
*
* @author Andrew Coleman
* @since Sesha 1
* @package Sesha
*/
class Sesha_Form_Stock extends Horde_Form {
/**
* The default constructor for the StockForm class.
*
* @param Horde_Variables $vars The default variables to use.
*/
public function __construct($vars)
{
parent::__construct($vars);
$sesha_driver = $GLOBALS['injector']->getInstance('Sesha_Factory_Driver')->create();
// Buttons and hidden configuration
$this->setButtons(_("Save Item"));
$this->addHidden('', 'actionId', 'text', true);
// Prepare the categories
$cat = array();
$categories = $sesha_driver->getCategories();
foreach ($categories as $c) {
$cat[$c->category_id] = $c->category;
}
// Get the list of selected categories
$categoryIds = array();
$t = $vars->get('category_id');
if (!is_array($t)) {
$t = array($t);
}
$categoryIds = array_merge($categoryIds, $t);
// The stock ID should only be editable if you are adding a new item;
// otherwise let the user know what the stock_id is, and then make a
// read-only required hidden variable
if ($vars->get('actionId') == 'add_stock') {
$this->addVariable(_("Stock ID"), 'stock_id', 'int', false, false);
} else {
$this->addVariable(_("Stock ID"), 'stock_id', 'int', false, true);
$this->addHidden('', 'stock_id', 'int', true, true);
}
// Basic variables for any stock item
$this->addVariable(_("Name"), 'stock_name', 'text', false, false);
if (!count($cat)) {
$fieldtype = 'invalid';
$cat = _("No categories are currently configured. Click \"Administration\" on the left to add some.");
} else {
$fieldtype = 'multienum';
}
$categoryVar = $this->addVariable(_("Category"), 'category_id',
$fieldtype, true, false, null,
array($cat));
// Set the variables already stored in the Driver, if applicable
try {
$properties = $sesha_driver->getPropertiesForCategories($categoryIds);
} catch (Sesha_Exception $e) {
throw new Sesha_Exception($e);
}
foreach ($properties as $property) {
$fieldname = 'property[' . $property->property_id . ']';
$fieldtitle = $property->property;
$fielddesc = $property->description;
if (!empty($property->unit)) {
if (!empty($fielddesc)) {
$fielddesc .= ' -- ';
}
$fielddesc .= _("Unit: ") . $property->unit;
}
$fieldtype = $property->datatype;
$fieldparams = array();
if (is_array($property->parameters)) {
$fieldparams = $property->parameters;
if (in_array($fieldtype, array('link', 'enum', 'multienum', 'mlenum', 'radio', 'set', 'sorter'))) {
$fieldparams->values = Sesha::getStringlistArray($fieldparams->values);
}
}
$this->addVariable($fieldtitle, $fieldname, $fieldtype,
false, false, $fielddesc, $fieldparams);
}
$this->addVariable(_("Note"), 'note', 'longtext', false);
// Default action
$action = Horde_Form_Action::factory('submit');
$categoryVar->setAction($action);
$categoryVar->setOption('trackchange', true);
}
}
sesha-1.0.0RC3/lib/Ui/VarRenderer/Stockedit_Html.php 0000664 0001750 0001750 00000000774 12073544237 020236 0 ustar jan jan
* @package Sesha
*/
class Horde_Core_UI_VarRenderer_Stockedit_Html extends Horde_Core_Ui_VarRenderer_Html {
protected function _renderVarInput_client($form, $var, $vars)
{
return $this->_renderVarInput_enum($form, $var, $vars);
}
}
sesha-1.0.0RC3/lib/View/Base.php 0000664 0001750 0001750 00000001772 12073544237 014310 0 ustar jan jan
* @category Horde
* @package Sesha
* @license http://www.horde.org/licenses/gpl GPL
*/
/**
* The Sesha_View_Base class contains all functions shared among
* views in Sesha.
*
* Copyright 2012-2013 Horde LLC (http://www.horde.org/)
*
* See the enclosed file COPYING for license information (GPL). If you
* did not receive this file, see http://www.horde.org/licenses/gpl.
*
* @author Ralf Lang
* @category Horde
* @package Sesha
* @license http://www.horde.org/licenses/gpl GPL
*/
class Sesha_View_Base extends Horde_View
{
/**
* The page title
* @var string
* @access public
*/
public $title = '';
}
sesha-1.0.0RC3/lib/View/List.php 0000664 0001750 0001750 00000021241 12073544237 014342 0 ustar jan jan
* @category Horde
* @package Sesha
* @license http://www.horde.org/licenses/gpl GPL
*/
class Sesha_View_List extends Sesha_View_Base
{
public function __construct(array $config)
{
if (!empty($config['what']) && !empty($config['loc'])) {
$this->title = _("Search Results");
$this->header = _("Search Results");
$url = new Horde_Url('list.php');
$this->backToList = $url->link() . _('Back to stock list') . '';
} else {
$this->header = $category_id
? sprintf(_("Available Inventory in %s"),
$selectedCategory->category)
: _("Available Inventory");
$this->title = _("Inventory List");
}
$this->selectedCategories = is_array($config['selectedCategories'])
? $config['selectedCategories']
: array($config['selectedCategories']);
if (empty($this->selectedCategories[0])) {
array_shift($this->selectedCategories);
}
$this->shownProperties = $this->properties($config['propertyIds']);
$this->columnHeaders = $this->columnHeaders($config['sortDir'],
$config['sortBy']);
$filters = array();
if (!empty($this->selectedCategories)) {
$filters[] = array('type' => 'categories',
'value' => $this->selectedCategories,
'exact' => $config['exact']);
}
if (in_array(Sesha::SEARCH_ID, $config['loc'])) {
$filters[] = array('type' => 'stock_id',
'exact' => $config['exact'],
'value' => $config['what']);
}
if (in_array(Sesha::SEARCH_NAME, $config['loc'])) {
$filters[] = array('type' => 'stock_name',
'exact' => $config['exact'],
'value' => $config['what']);
}
if (in_array(Sesha::SEARCH_NOTE, $config['loc'])) {
$filters[] = array('type' => 'note',
'exact' => $config['exact'],
'value' => $config['what']);
}
if (in_array(Sesha::SEARCH_PROPERTY, $config['loc'])) {
$filters[] = array(
'type' => 'values',
'exact' => $config['exact'],
'value' => array(array('values' => array($config['what']))));
}
$this->shownStock = $this->stock($filters);
parent::__construct($config);
}
/**
* Retrieves all categories from driver.
*
* @return array List of Sesha_Entity_Category objects.
*/
public function allCategories()
{
return Sesha::listCategories();
}
/**
* Builds column header array out of the list of properties and default
* attributes.
*/
protected function columnHeaders($sortDir, $sortBy)
{
$prefs_url = Horde::url($GLOBALS['registry']->get('webroot', 'horde') . '/services/prefs/', true);
$sortdirclass = $sortDir ? 'sortup' : 'sortdown';
$baseurl = Horde::url('list.php');
$column_headers = array(
array('id' => 's' . Sesha::SORT_STOCKID,
'class' => $sortBy == Sesha::SORT_STOCKID ? ' class="' . $sortdirclass . '"' : '',
'link' => Horde::link($baseurl->copy()->add('sortby', Sesha::SORT_STOCKID), _("Sort by stock ID"), 'sortlink') . _("Stock ID") . '',
'width' => ' width="5%"'),
array('id' => 's' . Sesha::SORT_NAME,
'class' => $sortBy == Sesha::SORT_NAME ? ' class="' . $sortdirclass . '"' : '',
'link' => Horde::link($baseurl->copy()->add('sortby', Sesha::SORT_NAME), _("Sort by item name"), 'sortlink') . _("Item Name") . '',
'width' => '')
);
foreach ($this->shownProperties as $property) {
$column_headers[] = array(
'id' => 'sp' . $property->property_id,
'class' => $sortBy == 'p' . $property->property_id ? ' class="' . $sortdirclass . '"' : '',
'link' => Horde::link($baseurl->copy()->add('sortby', 'p' . $property->property_id), sprintf(_("Sort by %s"), htmlspecialchars($property->property)), 'sortlink') . htmlspecialchars($property->property) . '',
'width' => '',
);
}
$column_headers[] = array(
'id' => 's' . Sesha::SORT_NOTE,
'class' => $sortby == Sesha::SORT_NOTE ? ' class="' . $sortdirclass . '"' : '',
'link' => Horde::link($baseurl->copy()->add('sortby', Sesha::SORT_NOTE), _("Sort by note"), 'sortlink') . _("Note") . '',
'width' => '',
);
return $column_headers;
}
/**
* Returns the list of property objects to display.
*/
protected function properties($propertyIds = array())
{
if (empty($propertyIds)) {
/* The driver understands an empty filter as "all" but if none are
* selected, we want none. */
return array();
}
try {
return $GLOBALS['injector']
->getInstance('Sesha_Factory_Driver')
->create()
->getProperties($propertyIds);
} catch (Sesha_Exception $e) {
return array();
}
}
/**
* Returns the items which match the category or search criteria.
*/
protected function stock($filters = array())
{
$driver = $GLOBALS['injector']
->getInstance('Sesha_Factory_Driver')
->create();
// Get the inventory
$stock = $driver->findStock($filters);
$isAdminEdit = Sesha::isAdmin(Horde_Perms::EDIT);
$itemEditImg = Horde::img('edit.png', _("Edit Item"));
$isAdminDelete = Sesha::isAdmin(Horde_Perms::DELETE);
$adminDeleteImg = Horde::img('delete.png', _("Delete Item"));
$stock_url = Horde::url('stock.php');
foreach ($stock as $item) {
$url = $stock_url->add('stock_id', $item->stock_id);
$columns = array();
// icons
$icons = '';
if ($isAdminEdit) {
$icons .= $url->copy()
->add('actionId', 'update_stock')
->link(array('title' => _("Edit Item")))
. $itemEditImg . '';
}
if ($isAdminDelete) {
$icons .= $url->copy()
->add('actionId', 'remove_stock')
->link(array('title' => _("Delete Item")))
. $adminDeleteImg . '';
}
$columns[] = array('class' => ' class="nowrap"',
'column' => $icons);
// stock_id
$columns[] = array(
'class' => '',
'column' => $url->copy()
->add('actionId', 'view_stock')
->link(array('title' => _("View Item")))
. htmlspecialchars($item->stock_id) . '');
// name
$columns[] = array(
'class' => '',
'column' => $url->copy()
->add('actionId', 'view_stock')
->link(array('title' => _("View Item")))
. htmlspecialchars($item->stock_name) . '');
// properties
foreach ($this->shownProperties as $property) {
$value = $item->getValue($property);
$columns[] = array(
'class' => '',
'column' => $value
? htmlspecialchars($value->getDataValue())
: ' ');
}
// note
$columns[] = array(
'class' => '',
'column' => $item->note
? htmlspecialchars($item->note)
: ' ');
$items[] = array('columns' => $columns);
}
return $items;
}
}
sesha-1.0.0RC3/lib/Api.php 0000664 0001750 0001750 00000006314 12073544237 013232 0 ustar jan jan
* @package Sesha
*/
class Sesha_Api extends Horde_Registry_Api
{
/**
* List categories as ticket queues
* @return array a list of ticket queues with category id as key and category caption as value
*/
public function listQueues()
{
$queues = array();
$categories = $GLOBALS['backend']->getCategories();
foreach ($categories as $category) {
$queues[$category->category_id] = $category->category;
}
asort($queues);
return $queues;
}
/**
* Get a queueDetails hash for a queue (category)
* @param integer $queue_id The Queue for which to build the details hash
* @return array A hash of category id as id, category label as name, category description as description, a link, a list of subjects as configured
*/
public function getQueueDetails($queue_id)
{
global $registry;
$category = $GLOBALS['backend']->getCategory($queue_id);
return array('id' => $queue_id,
'name' => $category->category,
'description' => $category->description,
'link' => Horde::applicationUrl('list.php', true)->add('display_category', $queue_id - 1)->setRaw(true),
'subjectlist' => $GLOBALS['conf']['tickets']['subjects'],
'versioned' => $registry->hasMethod('tickets/listVersions') == $registry->getApp(),
'readonly' => true);
}
/**
* List Stock items as versions for a queue (category)
* @param integer $queue_id The category id (queue) for which we want to fetch versions
* @return array A hash containing stock id as id, stock name as name, stock note as description
*/
public function listVersions($queue_id)
{
$inventory = $GLOBALS['backend']->findStock(array('categories' => $queue_id));
$versions = array();
foreach ($inventory as $item) {
$versions[] = array('id' => $item->stock_id,
'name' => $item->stock_name,
'description' => $item->note,
'readonly' => true);
}
Horde_Array::arraySort($versions, 'name', 0, false);
return $versions;
}
/**
* return a version details hash by version id
* @param integer $version_id The ID of the stock item to display as a version
* @return array The version hash containing stock name as name, stock note as description and a link
*/
public function getVersionDetails($version_id)
{
$item = $GLOBALS['backend']->fetch($version_id);
return array('id' => $version_id,
'name' => $item->stock_name,
'description' => $item->note,
'link' => Horde::applicationUrl('stock.php', true)->add(array('stock_id' => $version_id, 'actionId' => 'view_stock'))->setRaw(true),
'readonly' => true);
}
}
sesha-1.0.0RC3/lib/Application.php 0000664 0001750 0001750 00000005763 12073544237 014773 0 ustar jan jan array(
'title' => _("Administration"),
),
'addStock' => array(
'title' => _("Add Stock")
)
);
return $permissions;
}
/**
* @param Horde_Menu $menu A menu object
*/
public function menu($menu)
{
global $conf, $injector;
if (empty($this->highlight) && basename($_SERVER['PHP_SELF']) == 'index.php') {
$this->highlight = 'sesha-list';
}
$menu->add(Horde::url('list.php'), _("_List Stock"), 'sesha-list', null, null, null, $this->highlight == 'sesha-list' ? 'current' : null);
/* Search. */
$menu->add(Horde::url('search.php'), _("_Search"), 'sesha-search', null, null, null, $this->highlight == 'sesha-search' ? 'current' : null);
if (Sesha::isAdmin(Horde_Perms::READ)|| $perms->hasPermission('sesha:addStock', $GLOBALS['registry']->getAuth(), Horde_Perms::READ)) {
$menu->add(Horde::url('admin.php'), _("Administration"), 'sesha-admin');
}
}
/**
* Add additional items to the sidebar.
*
* @param Horde_View_Sidebar $sidebar The sidebar object.
*/
public function sidebar($sidebar)
{
$perms = $GLOBALS['injector']->getInstance('Horde_Core_Perms');
if (Sesha::isAdmin(Horde_Perms::READ) ||
$perms->hasPermission('sesha:addStock', $GLOBALS['registry']->getAuth(), Horde_Perms::READ)) {
$sidebar->addNewButton(
_("_Add Stock"),
Horde::url('stock.php')->add('actionId', 'add_stock'));
}
}
}
sesha-1.0.0RC3/lib/Driver.php 0000664 0001750 0001750 00000021421 12073544237 013750 0 ustar jan jan
* Copyright 2011-2013 Horde LLC (http://www.horde.org/)
*
* See the enclosed file COPYING for license information (GPL). If you
* did not receive this file, see http://www.horde.org/licenses/gpl.
*
* @author Andrew Coleman
* @author Ralf Lang
* @package Sesha
*/
abstract class Sesha_Driver
{
protected $_params;
/**
* Variable holding the items in the inventory.
*
* @var array
*/
protected $_stock;
public function __construct($params = array())
{
$this->_params = $params;
}
/**
* This function retrieves a single stock item from the backend.
*
* @param integer $stock_id The numeric ID of the stock item to fetch.
*
* @return Sesha_Entity_Stock a stock item
* @throws Sesha_Exception
*/
abstract public function fetch($stock_id);
/**
* Removes a stock entry from the backend. Also removes all related
* category and property information.
*
* @param integer $stock_id The ID of the item to delete.
*
* @return boolean True on success
* @throws Sesha_Exception
*
*/
abstract public function delete($stock_id);
/**
* This will add a new item to the inventory.
*
* @param array $stock A hash of values for the stock item.
*
* @return Sesha_Entity_Stock The newly added item or false.
* @throws Sesha_Exception
*/
abstract public function add($stock);
/**
* This function will modify a pre-existing stock entry with new values.
*
* @param array $stock The hash of values for the inventory item.
*
* @return boolean True on success.
* @throws Sesha_Exception
*/
abstract public function modify($stock_id, $stock);
/**
* This will return the category found matching a specific id.
*
* @param integer|array $category_id The integer ID or key => value hash of the category to find.
*
* @return Sesha_Entity_Category The category on success
*/
abstract public function getCategory($category_id);
/**
* This function returns all the categories matching an id or category list.
*
* @param integer $stock_id The stock ID of categories to fetch.
* Overrides category_ids
* @param integer $category_ids The numeric IDs of the categories to find.
* If both $stock_id and $category_ids are null,
* all categories are returned
* @return array The list of matching categories
*/
abstract public function getCategories($stock_id = null, array $category_ids = null);
/**
* This will find all the available properties matching a specified IDs.
*
* @param array $property_ids The numeric ID of properties to find.
* Matches all properties when null.
*
* @return array matching properties on success
* @throws Sesha_Exception
*/
abstract public function getProperties($property_ids = array());
/**
* Finds the first matching property for a specified property ID.
*
* @param integer $property_id The numeric ID of properties to find.
*
* @return mixed The specified property on success
* @throws Sesha_Exception
*/
abstract public function getProperty($property_id);
/**
* Updates the attributes stored by a category.
*
* @param array $info Updated category attributes.
*
* @return integer Number of objects updated.
* @throws Sesha_Exception
*/
abstract public function updateCategory($info);
/**
* Adds a new category for classifying inventory.
*
* @param array $info The new category's attributes.
*
* @return integer The ID of the new of the category on success
* @throws Sesha_Exception
*/
abstract public function addCategory($info);
/**
* Deletes a category.
*
* @param integer $category_id The numeric ID of the category to delete. Also accepts Sesha_Entity_Category
*
* @return integer The number of categories deleted
*/
abstract public function deleteCategory($category_id);
/**
* Determines if a category exists in the storage backend.
*
* @param string $category The string representation of the category to
* find.
*
* @return boolean True on success; false otherwise.
*/
abstract public function categoryExists($category);
/**
* Updates a property with new attributes.
*
* @param array $info Array with updated property values.
*
* @return Sesha_Inventory_Property The changed Sesha_Inventory_Property object.
*/
abstract public function updateProperty(array $info);
/**
* Adds a new property to the storage backend.
*
* @param array $info Array with new property values.
*
* @return Sesha_Entity_Property
*/
abstract public function addProperty($info);
/**
* Deletes a property from the storage backend.
*
* @param integer $property_id The numeric ID of the property to delete. Also accepts a Sesha_Inventory_Property object
*
* @return integer Number of objects deleted.
*/
abstract public function deleteProperty($property_id);
/**
* This will return a set of properties for a set of specified categories.
*
* @param array $categories The set of categories to fetch properties.
*
* @return mixed An array of properties on success
* @throws Sesha_Exception
*/
abstract public function getPropertiesForCategories($categories = array());
/**
* Updates a category with a set of properties.
*
* @param integer $category_id The numeric ID of the category to update.
* @param array $properties An array of property ID's to add.
*
* @throws Sesha_Exception
*/
abstract public function setPropertiesForCategory($category_id, $properties = array());
/**
* Removes all properties for a specified category.
*
* @param integer $category_id The numeric ID of the category to update.
*
* @return integer The number of deleted properties
* @throws Sesha_Exception
*/
abstract public function clearPropertiesForCategory($category_id);
/**
* Returns a set of properties for a particular stock ID number.
*
* @param integer $stock_id The numeric ID of the stock to find the
* properties for.
*
* @return array of Sesha_Inventory_Property objects
* @throws Sesha_Exception
*/
abstract public function getPropertiesForStock($stock_id);
/**
* Returns a set of Value Objects for a particular stock ID number.
*
* @param integer $stock_id The numeric ID of the stock to find the
* properties for.
* You can also pass a Sesha_Entity_Stock item
*
* @return array the list of Sesha_Entity_Value objects
* @throws Sesha_Exception
*/
abstract public function getValuesForStock($stock_id);
/**
* Removes categories from a particular stock item.
*
* @param integer $stock_id The numeric ID of the stock item to update.
* @param array $categories The array of categories to remove.
*
* @return integer the number of categories removed
* @throws Sesha_Exception
*/
abstract public function clearPropertiesForStock($stock_id, $categories = array());
/**
* Updates the set of properties for a particular stock item.
*
* @param integer $stock_id The numeric ID of the stock to update.
* @param array $properties The hash of properties to update.
*
* @throws Sesha_Exception
*/
abstract public function updatePropertiesForStock($stock_id, $properties = array());
/**
* Updates the set of categories for a specified stock item.
*
* @param integer $stock_id The numeric stock ID to update.
* @param array $categories The array of categories to change.
*
*/
abstract public function updateCategoriesForStock($stock_id, $categories = array());
/**
* Inventory search
* @param array filters a list of filter hashes, each having keys
* string type ('note', 'stock_name', 'stock_id', 'categories', 'properties')
* string test
* mixed value (string fore note, stock_name)
* @return array List of Stock items
*/
abstract public function findStock($filters = array());
}
sesha-1.0.0RC3/lib/Exception.php 0000664 0001750 0001750 00000000513 12073544237 014452 0 ustar jan jan
* Copyright 2007-2013 Horde LLC (http://www.horde.org/)
*
* See the enclosed file COPYING for license information (GPL). If you
* did not receive this file, see http://www.horde.org/licenses/gpl.
*
* @author Andrew Coleman
* @package Sesha
*/
class Sesha
{
/** Sort by stock id. */
const SORT_STOCKID = 100;
/** Sort by stock name. */
const SORT_NAME = 101;
/** Sort by stock note. */
const SORT_NOTE = 102;
/** Sort in ascending order. */
const SORT_ASCEND = 0;
/** Sort in descending order. */
const SORT_DESCEND = 1;
// Search Field Constants
const SEARCH_ID = 1;
const SEARCH_NAME = 2;
const SEARCH_NOTE = 4;
const SEARCH_PROPERTY = 8;
/**
* This function will return the list of available categories.
*
* @return mixed Array of categories on success; PEAR_Error on failure.
*/
public function listCategories()
{
$sesha_driver = $GLOBALS['injector']->getInstance('Sesha_Factory_Driver')->create();
return $sesha_driver->getCategories();
}
/**
* Returns a Hord_Form_Type_stringlist value split to an array.
*
* @param string $string A comma separated string list.
*
* @return array The string list as an array.
*/
public function getStringlistArray($string)
{
$string = str_replace("'", "\'", $string);
$values = explode(',', $string);
foreach ($values as $value) {
$value = trim($value);
$value_array[$value] = $value;
}
return $value_array;
}
/**
* Comparison function for sorting inventory stock by id.
*
* @param array $a Item one.
* @param array $b Item two.
*
* @return integer 1 if item one is greater, -1 if item two is greater;
* 0 if they are equal.
*/
protected function _sortByStockID($a, $b)
{
if ($a['stock_id'] == $b['stock_id']) return 0;
return ($a['stock_id'] > $b['stock_id']) ? 1 : -1;
}
/**
* Comparison function for reverse sorting stock by id.
*
* @param array $a Item one.
* @param array $b Item two.
*
* @return integer -1 if item one is greater, 1 if item two is greater;
* 0 if they are equal.
*/
protected function _rsortByStockID($a, $b)
{
if ($a['stock_id'] == $b['stock_id']) return 0;
return ($a['stock_id'] > $b['stock_id']) ? -1 : 1;
}
/**
* Comparison function for sorting inventory stock by name.
*
* @param array $a Item one.
* @param array $b Item two.
*
* @return integer 1 if item one is greater, -1 if item two is greater;
* 0 if they are equal.
*/
protected function _sortByName($a, $b)
{
if ($a['stock_name'] == $b['stock_name']) return 0;
return ($a['stock_name'] > $b['stock_name']) ? 1 : -1;
}
/**
* Comparison function for reverse sorting stock by name.
*
* @param array $a Item one.
* @param array $b Item two.
*
* @return integer -1 if item one is greater, 1 if item two is greater;
* 0 if they are equal.
*/
protected function _rsortByName($a, $b)
{
if ($a['stock_name'] == $b['stock_name']) return 0;
return ($a['stock_name'] > $b['stock_name']) ? -1 : 1;
}
/**
* Comparison function for sorting inventory stock by a property.
*
* @param array $a Item one.
* @param array $b Item two.
*
* @return integer 1 if item one is greater, -1 if item two is greater;
* 0 if they are equal.
*/
protected function _sortByProperty($a, $b)
{
if ($a[$GLOBALS['_sort_property']] == $b[$GLOBALS['_sort_property']]) return 0;
return ($a[$GLOBALS['_sort_property']] > $b[$GLOBALS['_sort_property']]) ? 1 : -1;
}
/**
* Comparison function for reverse sorting stock by a property.
*
* @param array $a Item one.
* @param array $b Item two.
*
* @return integer -1 if item one is greater, 1 if item two is greater;
* 0 if they are equal.
*/
protected function _rsortByProperty($a, $b)
{
if ($a[$GLOBALS['_sort_property']] == $b[$GLOBALS['_sort_property']]) return 0;
return ($a[$GLOBALS['_sort_property']] > $b[$GLOBALS['_sort_property']]) ? -1 : 1;
}
/**
* Comparison function for sorting inventory stock by note.
*
* @param array $a Item one.
* @param array $b Item two.
*
* @return integer 1 if item one is greater, -1 if item two is greater;
* 0 if they are equal.
*/
protected function _sortByNote($a, $b)
{
if ($a['note'] == $b['note']) return 0;
return ($a['note'] > $b['note']) ? 1 : -1;
}
/**
* Comparison function for reverse sorting stock by note.
*
* @param array $a Item one.
* @param array $b Item two.
*
* @return integer -1 if item one is greater, 1 if item two is greater;
* 0 if they are equal.
*/
protected function _rsortByNote($a, $b)
{
if ($a['note'] == $b['note']) return 0;
return ($a['note'] > $b['note']) ? -1 : 1;
}
public static function isAdmin($permLevel = Horde_Perms::DELETE)
{
return ($GLOBALS['registry']->isAdmin() || $GLOBALS['injector']->getInstance('Horde_Perms')->hasPermission('sesha:admin', $GLOBALS['registry']->getAuth(), $permLevel));
}
}
sesha-1.0.0RC3/locale/de/LC_MESSAGES/sesha.mo 0000664 0001750 0001750 00000220354 12073544237 016320 0 ustar jan jan d : 0N $ 1N ) VN N &