00001 <?php
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 require_once FASTFRAME_ROOT . 'lib/FastFrame/DataAccess.php';
00026
00027
00028
00029
00040
00041 class FF_DataAccess_Inventory_mysql extends FF_DataAccess {
00042
00043
00048 var $itemsTable;
00049
00054 var $userId;
00055
00056
00057
00058
00065 function FF_DataAccess_Inventory_mysql()
00066 {
00067 FF_DataAccess::FF_DataAccess();
00068 $this->table = $this->o_registry->getConfigParam('data/item_inventory_table');
00069 $this->itemsTable = $this->o_registry->getConfigParam('data/items_table');
00070 $this->userId = FF_Auth::getCredential('userId');
00071 }
00072
00073
00074
00075
00084 function add($in_data)
00085 {
00086 $o_result = new FF_Result();
00087 $s_stmt = $this->o_data->autoPrepare($this->table, array('item_id', 'entered_date', 'user_id'));
00088 $tmp_data[0] = null;
00089 $tmp_data[1] = $this->timestampToISODate(time());
00090 $tmp_data[2] = $this->userId;
00091 foreach ($in_data['items'] as $a_data) {
00092 if (!is_null($a_data['item_id'])) {
00093 $tmp_data[0] = $a_data['item_id'];
00094 if (DB::isError($result = $this->o_data->execute($s_stmt, $tmp_data))) {
00095 $o_result->addMessage($result->getMessage());
00096 $o_result->setSuccess(false);
00097 }
00098 }
00099 }
00100
00101 return $o_result;
00102 }
00103
00104
00105
00106
00113 function &process()
00114 {
00115 require_once dirname(__FILE__) . '/../../Model/Item.php';
00116 $o_result = new FF_Result();
00117 $s_query = "SELECT item_id FROM $this->table";
00118 if (DB::isError($a_items = $this->o_data->getCol($s_query, 0))) {
00119 $o_result->addMessage($a_items->getMessage());
00120 $o_result->setSuccess(false);
00121 return $o_result;
00122 }
00123
00124
00125 $result = $this->o_data->autoExecute($this->itemsTable,
00126 array('status' => ITEM_STATUS_MISSING), DB_AUTOQUERY_UPDATE,
00127 'status=' . $this->o_data->quoteSmart(ITEM_STATUS_AVAILABLE));
00128
00129 if (DB::isError($result)) {
00130 $o_result->addMessage($result->getMessage());
00131 $o_result->setSuccess(false);
00132 return $o_result;
00133 }
00134
00135
00136 $s_where = '';
00137 foreach ($a_items as $s_item) {
00138 $s_where .= 'id = ' . $s_item . " OR \n";
00139 }
00140
00141 $s_where .= '0=1';
00142 $tmp_where = 'status=' . $this->o_data->quoteSmart(ITEM_STATUS_MISSING) . " AND ($s_where)";
00143
00144
00145 $result = $this->o_data->autoExecute($this->itemsTable,
00146 array('status' => ITEM_STATUS_AVAILABLE), DB_AUTOQUERY_UPDATE, $tmp_where);
00147
00148 if (DB::isError($result)) {
00149 $o_result->addMessage($result->getMessage());
00150 $o_result->setSuccess(false);
00151 return $o_result;
00152 }
00153
00154
00155 $s_query = "SELECT id AS itemId FROM $this->itemsTable WHERE status=? AND ($s_where)";
00156 $a_items = $this->o_data->getAll($s_query, array(ITEM_STATUS_ONLOAN));
00157 $o_dao =& FF_DataAccess::factory('Transaction');
00158 $tmp_result =& $o_dao->returnItemsInTransaction($a_items);
00159 if (!$tmp_result->isSuccess()) {
00160 $o_result->setSuccess(false);
00161 $o_result->addMessage($tmp_result->getMessages());
00162 }
00163
00164 return $o_result;
00165 }
00166
00167
00168
00169
00181 function getListData($in_where, $in_orderByField, $in_orderByDir, $in_fields = '*')
00182 {
00183 $s_query = "SELECT t1.item_id, UNIX_TIMESTAMP(t1.entered_date) AS entered_date, t1.user_id,
00184 t2.name, t2.barcode
00185 FROM $this->table AS t1
00186 INNER JOIN $this->itemsTable AS t2 ON t1.item_id=t2.id
00187 WHERE $in_where ORDER BY $in_orderByField " .
00188 $this->_getOrderByDirection($in_orderByDir);
00189
00190 return $this->o_data->query($s_query);
00191 }
00192
00193
00194 }
00195 ?>