Example #1
0
 protected function setUp()
 {
     if (defined('SKIPPING')) {
         return;
     }
     $db = new fDatabase(DB_TYPE, DB, DB_USERNAME, DB_PASSWORD, DB_HOST, DB_PORT);
     $db->execute(file_get_contents(DB_SETUP_FILE));
     $this->sharedFixture = array('db' => $db, 'schema' => fJSON::decode(file_get_contents(DB_SCHEMA_FILE), TRUE));
 }
 public static function setUpBeforeClass()
 {
     if (defined('SKIPPING')) {
         return;
     }
     $db = new fDatabase(DB_TYPE, DB, DB_USERNAME, DB_PASSWORD, DB_HOST, DB_PORT);
     $db->execute(file_get_contents(DB_SETUP_FILE));
     self::$db = $db;
     self::$json_schema = fJSON::decode(file_get_contents(DB_SCHEMA_FILE), TRUE);
 }
 /**
  * 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);
 }
     Good_receipt_note_detail::deleteDetail($_POST['key']);
 } else {
     if ($_POST['type'] == "json") {
         $grn_details = Good_receipt_note_detail::findDetail($_POST['key']);
         echo $grn_details->toJSON();
     } else {
         if ($_POST['type'] == "save") {
             try {
                 $grn = new Good_receipt_note($_POST['doc_number']);
                 $grn->populate();
                 if (!$error) {
                     $grn->store();
                 }
                 if ($_POST['jsonForm'] != "") {
                     $json_form = fRequest::get('jsonForm');
                     $jsonForm = fJSON::decode($json_form);
                     foreach ($jsonForm as $row) {
                         try {
                             $grn_detail = new Good_receipt_note_detail();
                             $grn_detail->setDocNumber($_POST['doc_number']);
                             $grn_detail->setItemId($row->{'itemCode'});
                             $grn_detail->setDescription($row->{'itemDesc'});
                             $grn_detail->setQuantity($row->{'itemQuan'});
                             $grn_detail->setAssessment($row->{'assess'});
                             $grn_detail->setRemark($row->{'remarks'});
                             if (!$error) {
                                 $grn_detail->store();
                             }
                         } catch (fExpectedException $e) {
                             echo $e->printMessage();
                             $error = true;
Example #5
0
 *      events: [
 *          {
 *
 *          },
 *          ...
 *      ]
 *  }
 *
 * If there is a problem the error code will be 400 with a json response of the form:
 *  {
 *      "error": {
 *          "message": "Error message"
 *      }
 *  }
 */
if (isset($_GET['startdate']) && ($parseddate = strtotime($_GET['startdate']))) {
    $startdate = $parseddate;
} else {
    $startdate = time();
}
if (isset($_GET['enddate']) && ($parseddate = strtotime($_GET['enddate']))) {
    $enddate = $parseddate;
} else {
    $enddate = time();
}
$json = array('events' => array());
foreach (EventTime::getRangeVisible($startdate, $enddate) as $eventTime) {
    $json['events'][] = $eventTime->toEventSummaryArray();
}
fJSON::output($json);
Example #6
0
 *  JSON:
 *  {
 *
 *  }
 *
 * If there is a problem the error code will be 400 with a json response of the form:
 *  {
 *      "error": {
 *          "message": "Error message"
 *      }
 *  }
 */
$response = array();
if (isset($_GET['id'])) {
    $event_id = $_GET['id'];
    try {
        // get event by id
        $event = new Event($event_id);
        $secret_valid = isset($_GET['secret']) && $event->secretValid($_GET['secret']);
        if ($secret_valid) {
            $event->unhide();
        }
        $response = $event->toDetailArray($secret_valid);
    } catch (fExpectedException $e) {
        $response['error'] = array('message' => $e->getMessage());
    }
} else {
    $response['error'] = array('message' => "Request incomplete, please pass an id in the url");
}
fJSON::output($response);
Example #7
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>
Example #8
0
 /**
  * Loads a fixture and makes the fixture data accessible through $this->fixture_data.
  *
  * @param string $fixture_name
  *   Name of the fixture to load.
  * @return Returns the loaded fixture data or NULL in the case that there was no source for the requested fixture. Note that if fill mode is off exceptions are thrown in stead of returning NULL.
  */
 private function loadFixture($fixture_name)
 {
     if (isset($this->fixture_data[$fixture_name])) {
         return $this->fixture_data[$fixture_name];
     }
     if (isset($this->fixture_sources[$fixture_name]) === FALSE) {
         //if ($this->fill_mode === FALSE) {
         throw new fValidationException("There exists no fixtures for, %s", $fixture_name);
         //}
         return NULL;
     }
     $fixture_source = $this->fixture_sources[$fixture_name];
     // Helper vars
     $fixture = $this;
     $now = date('Y-m-d H:i:s');
     $a_moment_ago = date('Y-m-d H:i:s', strtotime('-5 minutes'));
     $in_a_moment_ago = date('Y-m-d H:i:s', strtotime('+5 minutes'));
     // Source is a JSON fixture file
     if ($fixture_source instanceof fFile) {
         // Grab the content from buffer
         ob_start();
         require $fixture_source->getPath();
         $json_data = ob_get_clean();
         // Decode
         $fixture_data = fJSON::decode($json_data);
         if (empty($fixture_data)) {
             throw new fValidationException("Invalid fixture file, %s", $fixture_source->getPath());
         }
         $this->fixture_data[$fixture_name] = $fixture_data;
     } else {
         if ($fixture_source instanceof fFixtureSeed) {
             // Source is a fFixtureSeed
         }
     }
 }
    public function testDecodeObjectToAssoc()
    {
        $output = fJSON::decode('{
				 "level1_key1": {
					 "level2_key1": {
						 "level3_key1": true,
						 "level3_key2": false
					 },
					 "level2_key2": {
						 "level3_key3": true,
						 "level3_key4": false,
						 "level3_key5": null
					 }
				 }
			 }', TRUE);
        $expected = array('level1_key1' => array('level2_key1' => array('level3_key1' => TRUE, 'level3_key2' => FALSE), 'level2_key2' => array('level3_key3' => TRUE, 'level3_key4' => FALSE, 'level3_key5' => NULL)));
        $this->assertEquals($expected, $output);
    }