当前位置: 首页>>代码示例>>PHP>>正文


PHP Action::write方法代码示例

本文整理汇总了PHP中Action::write方法的典型用法代码示例。如果您正苦于以下问题:PHP Action::write方法的具体用法?PHP Action::write怎么用?PHP Action::write使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Action的用法示例。


在下文中一共展示了Action::write方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: radiorelay_plugin_action

function radiorelay_plugin_action()
{
    global $_, $conf, $myUser;
    //Action de réponse à la commande vocale "Yana, commande de test"
    switch ($_['action']) {
        case 'radioRelay_save_radioRelay':
            Action::write(function ($_, &$response) {
                $radioRelayManager = new RadioRelay();
                if (empty($_['nameRadioRelay'])) {
                    throw new Exception("Le nom est obligatoire");
                }
                if (!is_numeric($_['radioCodeRadioRelay'])) {
                    throw new Exception("Le code radio est obligatoire et doit être numerique");
                }
                $radioRelay = !empty($_['id']) ? $radioRelayManager->getById($_['id']) : new RadioRelay();
                $radioRelay->name = $_['nameRadioRelay'];
                $radioRelay->description = $_['descriptionRadioRelay'];
                $radioRelay->room = $_['roomRadioRelay'];
                $radioRelay->pulse = $_['pulseRadioRelay'];
                $radioRelay->onCommand = $_['onRadioRelay'];
                $radioRelay->offCommand = $_['offRadioRelay'];
                $radioRelay->icon = $_['iconRadioRelay'];
                $radioRelay->radiocode = $_['radioCodeRadioRelay'];
                $radioRelay->save();
                $response['message'] = 'Relais enregistré avec succès';
            }, array('plugin_radiorelay' => 'c'));
            break;
        case 'radioRelay_delete_radioRelay':
            Action::write(function ($_, $response) {
                $radioRelayManager = new RadioRelay();
                $radioRelayManager->delete(array('id' => $_['id']));
            }, array('plugin_radiorelay' => 'd'));
            break;
        case 'radioRelay_plugin_setting':
            Action::write(function ($_, &$response) {
                global $conf;
                $conf->put('plugin_radioRelay_emitter_pin', $_['emiterPin']);
                $conf->put('plugin_radioRelay_emitter_code', $_['emiterCode']);
                $response['message'] = 'Configuration enregistrée';
            }, array('plugin_radiorelay' => 'c'));
            break;
        case 'radioRelay_manual_change_state':
            Action::write(function ($_, &$response) {
                radiorelay_plugin_change_state($_['engine'], $_['state']);
            }, array('plugin_radiorelay' => 'c'));
            break;
        case 'radioRelay_vocal_change_state':
            global $_, $myUser;
            try {
                $response['responses'][0]['type'] = 'talk';
                if (!$myUser->can('plugin_radiorelay', 'u')) {
                    throw new Exception('Je ne vous connais pas, ou alors vous n\'avez pas le droit, je refuse de faire ça!');
                }
                radiorelay_plugin_change_state($_['engine'], $_['state']);
                $response['responses'][0]['sentence'] = Personality::response('ORDER_CONFIRMATION');
            } catch (Exception $e) {
                $response['responses'][0]['sentence'] = Personality::response('WORRY_EMOTION') . '! ' . $e->getMessage();
            }
            $json = json_encode($response);
            echo $json == '[]' ? '{}' : $json;
            break;
        case 'radioRelay_plugin_setting':
            Action::write(function ($_, &$response) {
                global $conf;
                $conf->put('plugin_radioRelay_emitter_pin', $_['emiterPin']);
                $conf->put('plugin_radioRelay_emitter_code', $_['emiterCode']);
                $response['message'] = 'Configuration modifiée avec succès';
            }, array('plugin_radiorelay' => 'u'));
            break;
        case 'radioRelay_load_widget':
            require_once dirname(__FILE__) . '/../dashboard/Widget.class.php';
            Action::write(function ($_, &$response) {
                $widget = new Widget();
                $widget = $widget->getById($_['id']);
                $data = $widget->data();
                $content = '';
                if (empty($data['relay'])) {
                    $content = 'Choisissez un relais en cliquant sur l \'icone <i class="fa fa-wrench"></i> de la barre du widget';
                } else {
                    if (fileperms(Plugin::path() . 'radioEmission') != '36333') {
                        $content .= '<div style="margin:0px;" class="flatBloc pink-color">Attention, les droits vers le fichier <br/> radioEmission sont mal réglés.<br/> Référez vous à <span style="cursor:pointer;text-decoration:underline;" onclick="window.location.href=\'https://github.com/ldleman/yana-server#installation\';">la doc</span> pour les régler</div>';
                    }
                    $relay = new RadioRelay();
                    $relay = $relay->getById($data['relay']);
                    $response['title'] = $relay->name;
                    $content .= '
						<!-- CSS -->
						<style>
							
							.radiorelay_relay_pane {
							    background: none repeat scroll 0 0 #50597b;
							    list-style-type: none;
							    margin: 0;
							    cursor:default;
							    width: 100%;
							}
							.radiorelay_relay_pane li {
							    background: none repeat scroll 0 0 #50597b;
							    display: inline-block;
							    margin: 0 1px 0 0;
//.........这里部分代码省略.........
开发者ID:kofeve,项目名称:yana-server,代码行数:101,代码来源:radioRelay.plugin.php

示例2: story_plugin_action

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();
//.........这里部分代码省略.........
开发者ID:maditnerd,项目名称:yana-server,代码行数:101,代码来源:story.plugin.php

示例3: wirerelay_plugin_action

function wirerelay_plugin_action()
{
    global $_, $conf, $myUser;
    //Action de réponse à la commande vocale "Yana, commande de test"
    switch ($_['action']) {
        case 'wireRelay_save_wireRelay':
            Action::write(function ($_, &$response) {
                $wireRelayManager = new WireRelay();
                if (empty($_['nameWireRelay'])) {
                    throw new Exception("Le nom est obligatoire");
                }
                if (!is_numeric($_['pinWireRelay'])) {
                    throw new Exception("Le PIN GPIO est obligatoire et doit être numerique");
                }
                $wireRelay = !empty($_['id']) ? $wireRelayManager->getById($_['id']) : new WireRelay();
                $wireRelay->name = $_['nameWireRelay'];
                $wireRelay->description = $_['descriptionWireRelay'];
                $wireRelay->pin = $_['pinWireRelay'];
                $wireRelay->room = $_['roomWireRelay'];
                $wireRelay->pulse = $_['pulseWireRelay'];
                $wireRelay->oncommand = $_['onWireRelay'];
                $wireRelay->offcommand = $_['offWireRelay'];
                $wireRelay->icon = $_['iconWireRelay'];
                $wireRelay->save();
                //Reference device for other plugins
                $device = new Device();
                $device->label = $wireRelay->name;
                $device->plugin = 'wireRelay';
                $device->type = Device::ACTUATOR;
                $device->location = $wireRelay->room;
                $device->icon = $wireRelay->icon;
                $device->setValue('value', 0);
                $device->state = 1;
                $device->uid = $wireRelay->id;
                $device->save();
                $response['message'] = 'Relais enregistré avec succès';
            }, array('plugin_wirerelay' => 'c'));
            break;
        case 'wireRelay_delete_wireRelay':
            Action::write(function ($_, $response) {
                $wireRelayManager = new WireRelay();
                $wireRelayManager->delete(array('id' => $_['id']));
            }, array('plugin_wirerelay' => 'd'));
            break;
        case 'wireRelay_plugin_setting':
            Action::write(function ($_, $response) {
                $conf->put('plugin_wireRelay_emitter_pin', $_['emiterPin']);
                $conf->put('plugin_wireRelay_emitter_code', $_['emiterCode']);
            }, array('plugin_wirerelay' => 'c'));
            break;
        case 'wireRelay_manual_change_state':
            Action::write(function ($_, &$response) {
                wirerelay_plugin_change_state($_['engine'], $_['state']);
            }, array('plugin_wirerelay' => 'c'));
            break;
        case 'wireRelay_vocal_change_state':
            global $_, $myUser;
            try {
                $response['responses'][0]['type'] = 'talk';
                if (!$myUser->can('plugin_wirerelay', 'u')) {
                    throw new Exception('Je ne vous connais pas, ou alors vous n\'avez pas le droit, je refuse de faire ça!');
                }
                wirerelay_plugin_change_state($_['engine'], $_['state']);
                $response['responses'][0]['sentence'] = Personality::response('ORDER_CONFIRMATION');
            } catch (Exception $e) {
                $response['responses'][0]['sentence'] = Personality::response('WORRY_EMOTION') . '! ' . $e->getMessage();
            }
            $json = json_encode($response);
            echo $json == '[]' ? '{}' : $json;
            break;
        case 'wireRelay_load_widget':
            require_once dirname(__FILE__) . '/../dashboard/Widget.class.php';
            Action::write(function ($_, &$response) {
                $widget = new Widget();
                $widget = $widget->getById($_['id']);
                $data = $widget->data();
                if (empty($data['relay'])) {
                    $content = 'Choisissez un relais en cliquant sur l \'icone <i class="fa fa-wrench"></i> de la barre du widget';
                } else {
                    $relay = new WireRelay();
                    $relay = $relay->getById($data['relay']);
                    $response['title'] = $relay->name;
                    $content = '
						<!-- CSS -->
						<style>
							
							.relay_pane {
							    background: none repeat scroll 0 0 #50597b;
							    list-style-type: none;
							    margin: 0;
							    cursor:default;
							    width: 100%;
							}
							.relay_pane li {
							    background: none repeat scroll 0 0 #50597b;
							    display: inline-block;
							    margin: 0 1px 0 0;
							    padding: 10px;
							    cursor:default;
							    vertical-align: top;
//.........这里部分代码省略.........
开发者ID:kofeve,项目名称:yana-server,代码行数:101,代码来源:wireRelay.plugin.php

示例4: ipcam_action

function ipcam_action()
{
    global $_, $conf;
    switch ($_['action']) {
        case 'ipcam_save_camera':
            Action::write(function ($_, &$response) {
                require_once 'Camera.class.php';
                $camera = new Camera();
                if (empty($_['labelCamera'])) {
                    throw new Exception("Le nom est obligatoire");
                }
                if (empty($_['ipCamera'])) {
                    throw new Exception("L'IP est obligatoire");
                }
                $camera = !empty($_['id']) ? $camera->getById($_['id']) : new Camera();
                $camera->label = $_['labelCamera'];
                $camera->location = $_['locationCamera'];
                $camera->ip = $_['ipCamera'];
                $camera->login = $_['loginCamera'];
                $camera->password = $_['passwordCamera'];
                $camera->save();
                $response['message'] = 'Caméra enregistrée avec succès';
            }, array('ipcam' => 'c'));
            break;
        case 'ipcam_delete_camera':
            Action::write(function ($_, $response) {
                require_once 'Camera.class.php';
                $camera = new Camera();
                $camera->delete(array('id' => $_['id']));
            }, array('ipcam' => 'd'));
            break;
        case 'ipcam_load_widget':
            require_once dirname(__FILE__) . '/../dashboard/Widget.class.php';
            Action::write(function ($_, &$response) {
                $widget = new Widget();
                $widget = $widget->getById($_['id']);
                $parameters = $widget->data();
                if (empty($parameters['camera'])) {
                    $content = 'Choisissez une camera en cliquant sur l \'icone <i class="fa fa-wrench"></i> de la barre du widget';
                } else {
                    global $conf;
                    require_once 'Camera.class.php';
                    $camera = new Camera();
                    $camera = $camera->getById($parameters['camera']);
                    $room = new Room();
                    $room = $room->getById($camera->location);
                    $response['title'] = 'Sonde ' . $camera->label . ' (' . $room->getName() . ')';
                    $content = '
						<!-- CSS -->
						<style>
						</style>
						
						<!-- HTML -->
						';
                    $content .= '<div class="ipcam_widget"><img name="main" id="main" border="0" src="http://' . $camera->login . ':' . $camera->password . '@' . $camera->ip . '/videostream.cgi">';
                    $content .= '</div>';
                    $content .= '
						<!-- JS -->
						<script type="text/javascript">
						</script>
						';
                }
                $response['content'] = $content;
            });
            break;
        case 'ipcam_edit_widget':
            require_once dirname(__FILE__) . '/../dashboard/Widget.class.php';
            require_once dirname(__FILE__) . '/Camera.class.php';
            $widget = new Widget();
            $widget = $widget->getById($_['id']);
            $data = $widget->data();
            $camera = new Camera();
            $cameras = $camera->populate();
            $content = '<h3>Choix de la camera</h3>';
            if (count($cameras) == 0) {
                $content = 'Aucune camera enregistrée,<a href="setting.php?section=ipcam">enregistrer une camera<a>';
            } else {
                $content .= '<select id="camera">';
                foreach ($cameras as $camera) {
                    $content .= '<option ' . ($camera->id == $data['camera'] ? 'selected="selected"' : '') . ' value="' . $camera->id . '">' . $camera->label . ' (' . $camera->uid . ')</option>';
                }
                $content .= '</select>';
            }
            echo $content;
            break;
        case 'ipcam_save_widget':
            require_once dirname(__FILE__) . '/../dashboard/Widget.class.php';
            $widget = new Widget();
            $widget = $widget->getById($_['id']);
            $data = $widget->data();
            $data['camera'] = $_['camera'];
            $widget->data($data);
            $widget->save();
            echo $content;
            break;
    }
}
开发者ID:rikimaruneo,项目名称:yana-server,代码行数:97,代码来源:ipcam.plugin.php

示例5: Exception

        } else {
            Gpio::write($_["pin"], $_["state"], true);
        }
        break;
        // Gestion des interfaces de seconde génération
    // Gestion des interfaces de seconde génération
    case 'SUBSCRIBE_TO_CLIENT':
        Action::write(function ($_, &$response) {
            global $myUser, $conf;
            if (!isset($_['ip'])) {
                throw new Exception("IP invalide");
            }
            if (!isset($_['port']) || !is_numeric($_['port'])) {
                throw new Exception("Port invalide");
            }
            $url = Functions::getBaseUrl('action.php') . '/action.php';
            $client = new CLient($_['ip'], $_['port']);
            Plugin::callHook("vocal_command", array(&$vocal, $url));
            $conf = array('VOCAL_ENTITY_NAME' => $conf->put('VOCAL_ENTITY_NAME', 'YANA'), 'SPEECH_COMMAND' => $vocal);
            if (!$client->suscribe($url, $myUser->getToken())) {
                throw new Exception("Appairage impossible");
            }
            if (!$client->configure($conf)) {
                throw new Exception("Configuration impossible");
            }
        }, array('user' => 'u'));
        break;
    default:
        Plugin::callHook("action_post_case", array());
        break;
}
开发者ID:parrain27,项目名称:yana-server,代码行数:31,代码来源:action.php

示例6: unlink

            } else {
                Functions::rmFullDir($tempZipFolder);
                echo '<br/>Impossible de renommer le plugin <span class="label label-error">Erreur</span>';
            }
            unlink($tempZipName);
        } catch (Exception $e) {
            echo '<br/>' . $e->getMessage() . ' <span class="label label-error">Erreur</span>';
        }
        break;
    case 'CHANGE_GPIO_STATE':
        if ($myUser == false) {
            exit('Vous devez vous connecter pour cette action.');
        } else {
            Gpio::write($_["pin"], $_["state"], true);
        }
        break;
        // Gestion des interfaces de seconde génération
    // Gestion des interfaces de seconde génération
    case 'ADD_CLIENT':
        Action::write(function ($_, &$response) {
            global $myUser, $conf, $client;
            if (!isset($_SERVER['argv'][2])) {
                throw new Exception("Type client invalide");
            }
            file_put_contents('filename', $_SERVER['argv'][2]);
        });
        break;
    default:
        Plugin::callHook("action_post_case", array());
        break;
}
开发者ID:kofeve,项目名称:yana-server,代码行数:31,代码来源:action.php

示例7: propise_action

function propise_action()
{
    global $_, $conf;
    switch ($_['action']) {
        case 'propise_save_sensor':
            Action::write(function ($_, &$response) {
                require_once 'Sensor.class.php';
                $sensor = new Sensor();
                if (empty($_['labelSensor'])) {
                    throw new Exception("Le nom est obligatoire");
                }
                if (empty($_['uidSensor'])) {
                    throw new Exception("L'UID est obligatoire");
                }
                $sensor = !empty($_['id']) ? $sensor->getById($_['id']) : new Sensor();
                $sensor->label = $_['labelSensor'];
                $sensor->location = $_['locationSensor'];
                $sensor->uid = $_['uidSensor'];
                $sensor->save();
                //Reference device for other plugins
                $device = new Device();
                $device->label = $sensor->label;
                $device->plugin = 'propise';
                $device->type = Device::CAPTOR;
                $device->location = $sensor->location;
                $device->icon = 'fa-heartbeat';
                $device->setValue('humidity', 0);
                $device->setValue('temperature', 0);
                $device->setValue('light', 0);
                $device->setValue('mouvment', 0);
                $device->setValue('sound', 0);
                $device->state = 1;
                $device->uid = $sensor->id;
                $device->save();
                $response['message'] = 'Sonde enregistrée avec succès';
            }, array('propise' => 'c'));
            break;
        case 'propise_delete_sensor':
            Action::write(function ($_, $response) {
                require_once 'Sensor.class.php';
                $sensor = new Sensor();
                $sensor->delete(array('id' => $_['id']));
            }, array('propise' => 'd'));
            break;
        case 'propise_add_data':
            /*for($i=0;$i<60;$i++){
            		$_ = array(
            		'uid'=>'sensor-2',
            		'humidity'=>rand(0,100),
            		'temperature'=>rand(0,100),
            		'light'=>rand(0,100),
            		'mouvment'=>rand(0,1),
            		'sound'=>rand(0,1)
            		);*/
            require_once 'Sensor.class.php';
            require_once 'Data.class.php';
            $sensor = new Sensor();
            $data = new Data();
            $sensor = $sensor->load(array('uid' => $_['uid']));
            if ($sensor == null || $sensor->id == 0) {
                return;
            }
            $data->time = time();
            //$data->time = strtotime(date('Ymd H:').$i.':00');
            $data->humidity = $_['humidity'];
            $data->temperature = $_['temperature'];
            $data->light = $_['light'];
            $data->mouvment = $_['mouvment'];
            $data->sound = $_['sound'];
            $data->sensor = $sensor->id;
            $data->save();
            //}
            break;
        case 'propise_load_widget':
            require_once dirname(__FILE__) . '/../dashboard/Widget.class.php';
            Action::write(function ($_, &$response) {
                $widget = new Widget();
                $widget = $widget->getById($_['id']);
                $parameters = $widget->data();
                if (empty($parameters['sensor'])) {
                    $content = 'Choisissez une localisation en cliquant sur l \'icone <i class="fa fa-wrench"></i> de la barre du widget';
                } else {
                    global $conf;
                    require_once 'Data.class.php';
                    require_once 'Sensor.class.php';
                    $sensor = new Sensor();
                    $data = new Data();
                    $sensor = $sensor->getById($parameters['sensor']);
                    $datas = $data->loadAll(array('sensor' => $sensor->id), 'time DESC', 1);
                    $response['title'] = 'Sonde ' . $sensor->label . ' (' . $sensor->uid . ')';
                    $content = '
						<!-- CSS -->
						<style>
							.propise_view{
								background:#36B3E1;
								color:#ffffff;
								margin:0px;
								padding:10px;
								width:100%;
								list-style-type:none;
//.........这里部分代码省略.........
开发者ID:rikimaruneo,项目名称:yana-server,代码行数:101,代码来源:propise.plugin.php

示例8: write

 public function write($output)
 {
     $xfer = 0;
     $xfer += $output->writeStructBegin('ActionService_get_action_result');
     if ($this->success !== null) {
         if (!is_object($this->success)) {
             throw new TProtocolException('Bad type in structure.', TProtocolException::INVALID_DATA);
         }
         $xfer += $output->writeFieldBegin('success', TType::STRUCT, 0);
         $xfer += $this->success->write($output);
         $xfer += $output->writeFieldEnd();
     }
     $xfer += $output->writeFieldStop();
     $xfer += $output->writeStructEnd();
     return $xfer;
 }
开发者ID:Rantelo,项目名称:Hackantonio,代码行数:16,代码来源:ActionService.php

示例9: story_plugin_action

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;
    }
}
开发者ID:kofeve,项目名称:yana-server,代码行数:98,代码来源:story.plugin.php


注:本文中的Action::write方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。