/** * onPopulateUserProperty * * @param Event $e e * * @return bool|Result */ public function onPopulateUserProperty($e) { $propertyNameSpace = $e->getParam('propertyNameSpace'); $data = $e->getParam('data'); $thisPropertyNameSpace = $this->getUserPropertyKey(); if ($propertyNameSpace !== $thisPropertyNameSpace) { return false; } $property = new UserRoleProperty(); try { $property->populate($data); } catch (\Exception $e) { return new \RcmUser\Result($property, Result::CODE_FAIL, 'Property failed to populate with error: ' . $e->getMessage()); } return new Result($property); }
</table> <?php } } else { if ($action == 'view') { $event = new Event(param('id')); ?> <h3>Error #<?php echo $event->getID(); ?> </h3> <table> <tr> <th>Message: </th> <td><?php echo $event->getMessage(); ?> </td> </tr> <tr> <th>User:</th> <td><?php echo $event->getUser()->getName(); ?> </td> </tr> <tr> <th>Time:</th> <td><?php echo $event->getDate(); ?>
/** * Install a consumable to a printer */ public function installTo($printer) { global $db; #printf('Installing consumable %s to printer %s.', $this->getName(), $printer->getName()); #fCore::dump($printer); // Validation checks // 1. Check printer model is compatible $models = $this->getModels(); if (!in_array($printer->getModelId(), $models)) { $this->err = sprintf('Consumable %s not compatible with printer %s.', $this->getName(), $printer->getName()); return FALSE; } // 2. Check quantity if ($this->getQty() < 1) { $this->err = sprintf('No stock of the consumable %s.', $this->getName()); return FALSE; } // Finished validation // Add 'event' try { $e = new Event(); $e->setPrinterId($printer->getId()); $e->setConsumableId($this->getId()); $e->setDate(date('Y-m-d H:i:s')); $e->setCost($this->getCost()); $e->store(); } catch (fExpectedException $e) { #fMessaging::create('error', fURL::get(), $e->getMessage()); $this->err = $e->getMessage(); return FALSE; } catch (fSQLException $e) { #fMessaging::create('error', fURL::get(), 'Database error: ' . $e->getMessage()); $this->err = $e->getMessage(); return FALSE; } // Decrease stock try { $sql = 'UPDATE consumables SET qty = qty - 1 WHERE id = %i LIMIT 1'; $query = $db->execute($sql, $this->getId()); } catch (fSQLException $e) { $this->err = $e->getMessage(); return FALSE; } // Return true #echo 'Done!'; return TRUE; }