Exemplo n.º 1
0
 /**
  * Returns a JSON object representation of the record
  *
  * @internal
  *
  * @param  fActiveRecord $object            The fActiveRecord instance
  * @param  array         &$values           The current values
  * @param  array         &$old_values       The old values
  * @param  array         &$related_records  Any records related to this record
  * @param  array         &$cache            The cache array for the record
  * @param  string        $method_name       The method that was called
  * @param  array         $parameters        The parameters passed to the method
  * @return string  The JSON object that represents the values of this record
  */
 public static function toJSON($object, &$values, &$old_values, &$related_records, &$cache, $method_name, $parameters)
 {
     $output = array();
     foreach ($values as $column => $value) {
         if (is_object($value) && is_callable(array($value, '__toString'))) {
             $value = $value->__toString();
         } elseif (is_object($value)) {
             $value = (string) $value;
         }
         $output[$column] = $value;
     }
     return fJSON::encode($output);
 }
Exemplo n.º 2
0
 */
// Get consumables
$sql = "SELECT\n\t\tconsumables.*,\n\t\t( round( ( (consumables.qty) / (SELECT MAX(qty) FROM consumables) ) * 100 ) ) AS qty_percent,\n\t\tGROUP_CONCAT(CAST(CONCAT(manufacturers.name, ' ', models.name) AS CHAR) SEPARATOR ', ') AS model\n\t\tFROM consumables\n\t\tLEFT JOIN consumables_models ON consumables.id = consumables_models.consumable_id\n\t\tLEFT JOIN models ON consumables_models.model_id = models.id\n\t\tLEFT JOIN manufacturers ON models.manufacturer_id = manufacturers.id\n\t\tGROUP BY consumables.id\n\t\tORDER BY models.name ASC, consumables.name ASC";
$consumables = $db->query($sql)->asObjects();
// Get the most consumables in stock
$sql = 'SELECT MAX(qty) AS max FROM consumables';
$max_consumables = $db->query($sql)->fetchRow();
$max_consumables = $max_consumables['max'];
/**
 * Quick add
 */
// List of printers
$printers = Printer::getSimple($db);
// List of models and which consumables are available
$models_consumables = Consumable::getForModels($db);
$models_consumables_json = fJSON::encode($models_consumables);
?>

	<br />

	<div class="grid_5 suffix_1">
		<?php 
include 'views/home/quickadd.php';
?>
	</div>

	<div class="grid_6">
		<?php 
include 'views/home/stock.php';
?>
	</div>
Exemplo n.º 3
0
 /**
  * @dataProvider encode2Provider
  */
 public function testEncode2($input, $output)
 {
     $this->assertEquals($output, fJSON::encode($input));
 }