function story_plugin_action() { global $_, $myUser; switch ($_['action']) { case 'DELETE_STORY': $storyManager = new Story(); $causeManager = new Cause(); $effectManager = new Effect(); $storyManager->delete(array('id' => $_['id'])); $causeManager->delete(array('story' => $_['id'])); $effectManager->delete(array('story' => $_['id'])); break; case 'plugin_story_check': require_once 'Cause.class.php'; $vocal = new Cause(); $vocal = $vocal->getById($_['event']); Story::check($vocal); break; case 'SAVE_STORY': $causeManager = new Cause(); $effectManager = new Effect(); $story = new Story(); if (isset($_['story']['id']) && $_['story']['id'] != '0') { $story = $story->getById($_['story']['id']); $causeManager->delete(array('story' => $story->id)); $effectManager->delete(array('story' => $story->id)); } $story->label = $_['story']['label']; $story->date = time(); $story->state = 1; $story->save(); $i = 0; foreach ($_['story']['cause'] as $cause) { $current = new Cause(); $current->type = $cause['type']; $current->target = is_array(@$cause['target']) ? implode('|', @$cause['target']) : @$cause['target']; $current->operator = @$cause['operator']; $current->value = $cause['value']; $current->sort = $i; $current->union = $cause['union']; $current->story = $story->id; $current->save(); $i++; } $i = 0; foreach ($_['story']['effect'] as $effect) { $current = new Effect(); $current->type = $effect['type']; $current->target = is_array(@$effect['target']) ? implode('|', @$effect['target']) : @$effect['target']; $current->value = $effect['value']; $current->sort = $i; $current->union = $cause['union']; $current->story = $story->id; $current->save(); $i++; } break; } }
function story_plugin_action() { global $_, $myUser; switch ($_['action']) { case 'plugin_story_get_type_template': Action::write(function ($_, &$response) { $templates = array_merge(Cause::types(), Effect::types()); $template = $templates[$_['type']]; preg_match_all("/(\\{)(.*?)(\\})/", $template['template'], $matches, PREG_SET_ORDER); foreach ($matches as $match) { $template['template'] = str_replace($match[0], $_['data'][$match[2]], $template['template']); } /* $matches = preg_split("/\[(.*?)\]/", $template['template'],-1,PREG_SPLIT_DELIM_CAPTURE); $tpl = ''; for($i=0;$i<count($matches);$i+=2){ $start = $matches[$i]; $var = $matches[$i+1]; list($name,$value) = explode(':',$var); if($_['data'][$name] == $value) { $tpl.= 'selected="selected"'; } $tpl.= $start; } $template['template'] = $tpl; */ $response['html'] = '<li class="line" data-type="' . $_['type'] . '"> <i class="fa ' . $template['icon'] . '"></i> <strong>' . $template['label'] . '</strong> ' . $template['template'] . ' <div class="delete"><i onclick="deleteLine(this);" class="fa fa-times"></i></div> </li>'; }, array()); break; case 'plugin_story_get_causes_effects': Action::write(function ($_, &$response) { $cause = new Cause(); $effect = new Effect(); $effects = $effect->loadAll(array('story' => $_['id']), 'sort'); $causes = $cause->loadAll(array('story' => $_['id']), 'sort'); foreach ($causes as $caus) { $data = $caus->getValues(); $response['results'][] = array('type' => $caus->type, 'panel' => "CAUSE", 'data' => array('value' => $data->value, 'target' => $data->target, 'operator' => $data->operator, 'union' => $data->union)); } foreach ($effects as $eff) { $data = $eff->getValues(); $response['results'][] = array('type' => $eff->type, 'panel' => "EFFECT", 'data' => array('value' => $data->value, 'target' => $data->target, 'operator' => $data->operator, 'union' => $data->union)); } }, array()); break; case 'plugin_story_get_captors_plugins': Action::write(function ($_, &$response) { $deviceManager = new Device(); $devices = $deviceManager->loadAll(array('state' => 1, 'type' => Device::CAPTOR)); $response['plugins'] = array(); foreach ($devices as $device) { if (!isset($response['plugins'][$device->plugin])) { $response['plugins'][] = $device->plugin; } } }, array()); break; case 'plugin_story_get_captors': Action::write(function ($_, &$response) { $deviceManager = new Device(); $devices = $deviceManager->loadAll(array('state' => 1, 'plugin' => $_['plugin'], 'type' => Device::CAPTOR)); foreach ($devices as $device) { $response['devices'][] = array('plugin' => $device->plugin, 'label' => $device->label, 'id' => $device->id); } }, array()); break; case 'plugin_story_get_captor_values': Action::write(function ($_, &$response) { $deviceManager = new Device(); $device = $deviceManager->getById($_['id']); $response['values'] = $device->getValues(); }, array()); break; case 'plugin_story_delete_story': Action::write(function ($_, &$response) { $storyManager = new Story(); $causeManager = new Cause(); $effectManager = new Effect(); $storyManager->delete(array('id' => $_['id'])); $causeManager->delete(array('story' => $_['id'])); $effectManager->delete(array('story' => $_['id'])); }, array()); break; case 'plugin_story_check': require_once dirname(__FILE__) . '/Cause.class.php'; $vocal = new Cause(); $vocal = $vocal->getById($_['event']); Story::check($vocal); break; case 'plugin_story_save_story': Action::write(function ($_, &$response) { $causeManager = new Cause(); $effectManager = new Effect(); $story = new Story(); if (isset($_['story']['id']) && $_['story']['id'] != '0') { $story = $story->getById($_['story']['id']); $causeManager->delete(array('story' => $story->id)); $effectManager->delete(array('story' => $story->id)); } $story->label = $_['story']['label']; $story->date = time(); $story->state = 1; $story->save(); $i = 0; foreach ($_['story']['causes'] as $cause) { $current = new Cause(); $current->type = $cause['type']; $current->operator = @$cause['operator']; $current->setValues($cause); $current->sort = $i; $current->union = $cause['union']; $current->story = $story->id; $current->save(); $i++; } $i = 0; foreach ($_['story']['effects'] as $effect) { $current = new Effect(); $current->type = $effect['type']; $current->setValues($effect); $current->sort = $i; $current->union = $cause['union']; $current->story = $story->id; $current->save(); $i++; } }, array()); break; } }
function story_plugin_action() { global $_, $myUser; switch ($_['action']) { case 'plugin_story_get_type_template': Action::write(function ($_, &$response) { $templates = array_merge(Cause::types(), Effect::types()); $template = $templates[$_['type']]; $response['html'] = '<li class="line" data-type="' . $_['type'] . '"> <i class="fa ' . $template['icon'] . '"></i> <strong>' . $template['label'] . '</strong> ' . $template['template'] . ' <div class="delete"><i onclick="deleteLine(this);" class="fa fa-times"></i></div> </li>'; }, array()); break; case 'plugin_story_get_captors_plugins': Action::write(function ($_, &$response) { $deviceManager = new Device(); $devices = $deviceManager->loadAll(array('state' => 1, 'type' => Device::CAPTOR)); $response['plugins'] = array(); foreach ($devices as $device) { if (!isset($response['plugins'][$device->plugin])) { $response['plugins'][] = $device->plugin; } } }, array()); break; case 'plugin_story_get_captors': Action::write(function ($_, &$response) { $deviceManager = new Device(); $devices = $deviceManager->loadAll(array('state' => 1, 'plugin' => $_['plugin'], 'type' => Device::CAPTOR)); foreach ($devices as $device) { $response['devices'][] = array('plugin' => $device->plugin, 'label' => $device->label, 'id' => $device->id); } }, array()); break; case 'plugin_story_get_captor_values': Action::write(function ($_, &$response) { $deviceManager = new Device(); $device = $deviceManager->getById($_['id']); $response['values'] = $device->getValues(); }, array()); break; case 'plugin_story_delete_story': Action::write(function ($_, &$response) { $storyManager = new Story(); $causeManager = new Cause(); $effectManager = new Effect(); $storyManager->delete(array('id' => $_['id'])); $causeManager->delete(array('story' => $_['id'])); $effectManager->delete(array('story' => $_['id'])); }, array()); break; case 'plugin_story_check': require_once dirname(__FILE__) . '/Cause.class.php'; $vocal = new Cause(); $vocal = $vocal->getById($_['event']); Story::check($vocal); break; case 'plugin_story_save_story': Action::write(function ($_, &$response) { $causeManager = new Cause(); $effectManager = new Effect(); $story = new Story(); if (isset($_['story']['id']) && $_['story']['id'] != '0') { $story = $story->getById($_['story']['id']); $causeManager->delete(array('story' => $story->id)); $effectManager->delete(array('story' => $story->id)); } $story->label = $_['story']['label']; $story->date = time(); $story->state = 1; $story->save(); $i = 0; foreach ($_['story']['causes'] as $cause) { $current = new Cause(); $current->type = $cause['type']; $current->operator = @$cause['operator']; $current->setValues($cause); $current->sort = $i; $current->union = $cause['union']; $current->story = $story->id; $current->save(); $i++; } $i = 0; foreach ($_['story']['effects'] as $effect) { $current = new Effect(); $current->type = $effect['type']; $current->setValues($effect); $current->sort = $i; $current->union = $cause['union']; $current->story = $story->id; $current->save(); $i++; } }, array()); break; } }