Skip to content

Instantly share code, notes, and snippets.

View kylejohnson's full-sized avatar

Kyle Johnson kylejohnson

View GitHub Profile
@kylejohnson
kylejohnson / gist:5506759
Created May 3, 2013 02:05
Attempting to apply $conditions to the $hasMany['Event'] array only
<?php
class Monitor extends AppModel {
public $useTable = 'Monitors';
public $hasMany = array(
'Event' => array(
'className' => 'Event',
'foreignKey' => 'MonitorId'
),
<?php
class Monitor extends AppModel {
public $useTable = 'Monitors';
public $hasMany = array(
'Event' => array(
'className' => 'Event',
'foreignKey' => 'MonitorId'
),
@kylejohnson
kylejohnson / Event.php
Created May 4, 2013 19:17
Attempting to return the event count on a per-monitor basis (lines 8-10 of the first file), instead its doing a count() on all monitors. The last file shows the query that is being run - why isn't WHERE `Event`.`MonitorId` IN ('1', '2') being appended to the query such as is for the find on line 6?
<?php
class Event extends AppModel {
public $useTable = 'Events';
public $belongsTo = array(
'Monitor' => array(
'className' => 'Monitor',
'foreignKey' => 'MonitorId'
)
);
}
@kylejohnson
kylejohnson / gist:5519480
Created May 5, 2013 02:46
What I want to return from monitors is... an array!
$monitor['Events']['Hour']
$monitor['Events']['Day']
$monitor['Events']['Week']
$monitor['Events']['Month']
$monitor['Events']['Archived']
@kylejohnson
kylejohnson / Config.php
Created May 5, 2013 15:23
My Config View and the associated returned array structure
<h2>Configs</h2>
<?php
echo $this->Form->create('Config', array(
'url' => '/config/edit'
));
foreach ($configs as $config):
$inputname = "Config.";
$inputname.= $config['Config']['Id'];
$inputname.= ".";
$inputname.= $config['Config']['Name'];
<h2>Configs</h2>
<?php
echo $this->Form->create('Config', array(
'url' => '/config/edit'
));
foreach ($configs as $index => $config):
$inputname = 'Config.' . $index . '.' . $config['Config']['Name'];
echo $this->Form->input($inputname, array(
'default' => $config['Config']['Value'],
'label' => $config['Config']['Name'],
function edit() {
if (!empty($this->data)) {
foreach ($this->data['Config'] as $key => $value) {
foreach ($value as $fieldName => $fieldValue) {
$id = intval($key);
$this->Config->id = $id;
$this->Config->read(); // Removing this has no affect
$this->Config->saveField($fieldName, $fieldValue, array('validate' => false, 'callbacks' => false));
$this->Config->create(); // Removing this has no affect
}
array(
'Config' => array(
(int) 25 => array(
'ZM_TIMESTAMP_ON_CAPTURE' => '1'
),
(int) 26 => array(
'ZM_CPU_EXTENSIONS' => '1'
),
(int) 27 => array(
'ZM_FAST_IMAGE_BLENDS' => '1'
@kylejohnson
kylejohnson / gist:5525356
Created May 6, 2013 14:01
debug(array_keys($this->Config->schema()));
array(
(int) 0 => 'Id',
(int) 1 => 'Name',
(int) 2 => 'Value',
(int) 3 => 'Type',
(int) 4 => 'DefaultValue',
(int) 5 => 'Hint',
(int) 6 => 'Pattern',
(int) 7 => 'Format',
(int) 8 => 'Prompt',
mysql> SELECT IFNULL(COUNT(`Event`.`Id`), 0) AS count FROM `zm`.`Events` AS `Event` LEFT JOIN `zm`.`Monitors` AS `Monitor` ON (`Event`.`MonitorId` = `Monitor`.`Id`) WHERE `Event`.`StartTime` > DATE_SUB(NOW(), INTERVAL 1 DAY) GROUP BY `Event`.`MonitorId`;
+-------+
| count |
+-------+
| 16 |
| 27 |
+-------+
2 rows in set (0.00 sec)
mysql> SELECT IFNULL(COUNT(`Event`.`Id`), 0) AS count FROM `zm`.`Events` AS `Event` LEFT JOIN `zm`.`Monitors` AS `Monitor` ON (`Event`.`MonitorId` = `Monitor`.`Id`) WHERE `Event`.`StartTime` > DATE_SUB(NOW(), INTERVAL 1 HOUR) GROUP BY `Event`.`MonitorId`;