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


PHP Device::save方法代码示例

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


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

示例1: actionCreate

 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $model = new Device();
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['Device'])) {
         $model->attributes = $_POST['Device'];
         $model->status = 1;
         if (Person::model()->findByPk($model->person_id)->company_id == User::getMyCompany() || Yii::app()->user->role == 1) {
             if ($model->save()) {
                 $fp = fopen('images/barcode/' . $model->barcode . '.png', 'wb');
                 // Открываем файл
                 $ch = curl_init("http://barcode.tec-it.com/barcode.ashx?translate-esc=off&data={$model->barcode}&code=Code128&unit=Fit&dpi=96&imagetype=Png&rotation=0&color=000000&bgcolor=FFFFFF&qunit=Mm&quiet=0");
                 curl_setopt($ch, CURLOPT_FILE, $fp);
                 // Передаём дескриптор файла, туда сбросится результат
                 curl_setopt($ch, CURLOPT_HEADER, 0);
                 curl_exec($ch);
                 curl_close($ch);
                 fclose($fp);
                 //Перечмодим файлик
                 chmod('images/barcode/' . $model->barcode . '.png', 0777);
                 //Теперь мы его обрежем, чтобы не нам не мешал водознак
                 UserFunctions::crop('images/barcode/' . $model->barcode . '.png');
                 $this->redirect(array('view', 'id' => $model->id));
             }
         } else {
             throw new CHttpException(403, 'Вы не имеете прав в этой организации');
         }
     }
     $this->render('create', array('model' => $model));
 }
开发者ID:griffindor,项目名称:new-inventory,代码行数:35,代码来源:DeviceController.php

示例2: actionLoginApi

 public function actionLoginApi($uid, $planet, $ver = NULL, $token = NULL)
 {
     $transaction = Yii::app()->db->beginTransaction();
     try {
         $device = Device::model()->findByAttributes(array('uid' => $uid));
         $isSuccess = true;
         $session = Yii::app()->session;
         if (empty($device->usr_id)) {
             if ($device === NULL) {
                 $device = new Device();
                 $device->uid = $uid;
                 //$device->token = $token;
                 $device->create_time = time();
                 $device->save();
             }
             $session['id'] = $device->id;
             $session['not_registered'] = TRUE;
             $isSuccess = false;
         } else {
             $session['usr_id'] = $device->usr_id;
             $user = User::model()->findByAttributes(array('usr_id' => $device->usr_id));
             $user->login();
         }
         $session['planet'] = $planet;
         $device->sid = $session->sessionID;
         $device->saveAttributes(array('sid'));
         $transaction->commit();
         $this->echoJsonData(array('isSuccess' => $isSuccess, 'usr_id' => $device->usr_id, 'SID' => $session->sessionID));
     } catch (Exception $e) {
         $transaction->rollback();
         throw $e;
     }
 }
开发者ID:sr71k,项目名称:pet,代码行数:33,代码来源:UserController.php

示例3: actionTambah

 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionTambah()
 {
     $model = new Device();
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['Device'])) {
         $model->attributes = $_POST['Device'];
         if ($model->save()) {
             $this->redirect(array('ubah', 'id' => $model->id));
         }
     }
     $this->render('tambah', array('model' => $model));
 }
开发者ID:AbuMuhammad,项目名称:ap3,代码行数:17,代码来源:DeviceController.php

示例4: actionCreate

 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $model = new Device();
     $modelsBrands = Brand::model()->findAll();
     $brandsArray = CHtml::listData($modelsBrands, 'id', 'brand_name');
     $modelsPlatforms = Platforms::model()->findAll();
     $platformsArray = CHtml::listData($modelsPlatforms, 'id', 'name');
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['buttonCancel'])) {
         $this->redirect(array('admin'));
     }
     if (isset($_POST['Device'])) {
         $model->attributes = $_POST['Device'];
         /*GARENTE QUE O NOME DO DEVICE SEMPRE SEJA SALVO EM MAIÚSCULO*/
         $model->description = strtoupper($model->description);
         if ($model->save()) {
             $this->redirect(array('admin', 'id' => $model->id));
         }
     }
     $this->render('create', array('model' => $model, 'brandsArray' => $brandsArray, 'platformsArray' => $platformsArray));
 }
开发者ID:raphaelrocha,项目名称:mtcontrool_mtcontext,代码行数:26,代码来源:DeviceController.php

示例5: beat

 public function beat()
 {
     $data = Input::all();
     // return EndorphinHelpers::apiResponse(EndorphinHelpers::STATUS_SUCCESS, $data['data']);
     if (is_null($data)) {
         return EndorphinHelpers::apiResponse(EndorphinHelpers::STATUS_ERROR, array('item' => 'data'));
     }
     if (is_null($data['phone_imei'])) {
         return EndorphinHelpers::apiResponse(EndorphinHelpers::STATUS_ERROR, array('item' => 'phone_imei'));
     }
     $heartbeat = new Heartbeat($data);
     $heartbeat->save();
     $device = Device::with(array('users' => function ($query) {
         $query->where('device_user.user_id', '=', Auth::user()->id);
     }, 'heartbeats' => function ($query) {
     }))->where('hardware_id', '=', $data['phone_imei'])->whereNull('deleted_at')->get();
     if (is_null($device)) {
         $device = new Device(array('name' => $data['phone_imei'], 'hardware_id' => $data['phone_imei']));
         $device->save();
     }
     $device->heartbeats()->attach($heartbeat);
     return EndorphinHelpers::apiResponse(EndorphinHelpers::STATUS_SUCCESS, $device);
 }
开发者ID:soitun,项目名称:endorphin,代码行数:23,代码来源:ApiHeartbeatsController.php

示例6:

    $p->set_surcharge(0);
    $p->set_discount(0);
    $p->set_comment('');
    $p->set_status(1);
    $p->set_date(strtotime('now'));
    $payment_id = Payment::save($p);
    exit;
}
if (!empty($_GET['switch'])) {
    // Update status of old device
    $d = Device::getById($device_id);
    $d->set_status(0);
    Device::save($d);
    // Update status of new device
    $device_id = (int) $_GET['new_device_id'];
    $d = Device::getById($device_id);
    $d->set_status(1);
    Device::save($d);
    $p = Payment::getById($payment_id);
    $p->set_device($device_id);
    Payment::save($p);
    echo $device_id;
    exit;
}
$smarty->assign('start', $start);
$smarty->assign('stop', $stop);
$smarty->assign('total', $total);
$smarty->assign('total1', $total1);
$smarty->assign('payment', Payment::getById($payment_id));
$smarty->assign('device', $device);
$smarty->display('payment.tpl');
开发者ID:nguyentien,项目名称:ps3,代码行数:31,代码来源:payment.php

示例7: die

    Device::save($device);
    die('1');
}
// Update
if (isset($_POST['update'])) {
    $device = new Device();
    $device->set_id((int) $_POST['id']);
    $device->set_uid((string) $_POST['uid']);
    $device->set_name((string) $_POST['name']);
    // Get default cost for device
    if ($_POST['default']) {
        foreach (System::getValue() as $r) {
            if ($r->get_var() == 'default_cost') {
                $device->set_cost($r->get_val());
            }
        }
    } else {
        $device->set_cost((double) $_POST['cost']);
    }
    $device->set_range((int) $_POST['range']);
    Device::save($device);
    die('1');
}
// Delete
if (isset($_POST['delete'])) {
    Device::delete((int) $_POST['id']);
    die('1');
}
$devices = Device::getAll();
$smarty->assign('devices', $devices);
$smarty->display('device.tpl');
开发者ID:nguyentien,项目名称:ps3,代码行数:31,代码来源:device.php

示例8: 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

示例9: createUserExtension

 public static function createUserExtension($user_id, $extension = NULL, $context_id = NULL, $location_id = NULL, $options = array())
 {
     Doctrine::getTable('User')->getRecordListener()->get('MultiTenant')->setOption('disabled', TRUE);
     $user = Doctrine::getTable('User')->find($user_id);
     Doctrine::getTable('User')->getRecordListener()->get('MultiTenant')->setOption('disabled', TRUE);
     if (!$user) {
         kohana::log('debug', 'Could not locate user_id ' . $user_id);
         return FALSE;
     }
     $account_id = $user['account_id'];
     if (!$context_id) {
         $context_id = Context::getContextByType('private', $account_id);
     }
     if (!$location_id) {
         Doctrine::getTable('Location')->getRecordListener()->get('MultiTenant')->setOption('disabled', TRUE);
         $locations = Doctrine_Query::create()->from('Location')->where('account_id = ?', array($account_id))->execute();
         Doctrine::getTable('Location')->getRecordListener()->get('MultiTenant')->setOption('disabled', FALSE);
         if (empty($locations[0]['location_id'])) {
             kohana::log('error', 'Unable to initialize device number: could not determine location_id');
             return FALSE;
         }
         $location_id = $locations[0]['location_id'];
     }
     Doctrine::getTable('Device')->getRecordListener()->get('MultiTenant')->setOption('disabled', TRUE);
     $deviceNum = Doctrine_Query::create()->from('Device')->where('account_id = ?', array($account_id))->count() + 1;
     if (!$extension) {
         $baseExt = kohana::config('telephony.device_exten_start', 2000);
         if (!$baseExt) {
             $baseExt = 2000;
         }
         $extension = $baseExt + $deviceNum;
     }
     Kohana::log('debug', 'Generating a device for user ' . $user_id . ' in account ' . $account_id . ' as extension ' . $extension . ' in context ' . $context_id);
     try {
         $conn = Doctrine_Manager::connection();
         $conn->beginTransaction();
         $device = new Device();
         $device['account_id'] = $account_id;
         $device['user_id'] = $user_id;
         $device['context_id'] = $context_id;
         $device['name'] = 'Exten ' . $extension . ' for ' . $user['first_name'] . ' ' . $user['last_name'];
         $device['type'] = 'SipDevice';
         $data = array('device' => &$device, 'user' => &$user, 'extension' => $extension, 'user_id' => $user_id, 'context_id' => $context_id, 'account_id' => $account_id, 'location_id' => $location_id, 'owner_name' => $user['first_name'] . ' ' . $user['last_name']);
         $data += $options;
         Event::run('bluebox.create.extension', $data);
         $device->save();
         Event::run('bluebox.create.extensionnumber', $data);
         $conn->commit();
     } catch (Exception $e) {
         $conn->rollback();
         Doctrine::getTable('Device')->getRecordListener()->get('MultiTenant')->setOption('disabled', FALSE);
         kohana::log('error', 'Unable to generate device ' . $deviceNum . ' as ' . $extension . ' because: ' . $e->getMessage());
         return FALSE;
     }
     Doctrine::getTable('Device')->getRecordListener()->get('MultiTenant')->setOption('disabled', FALSE);
     return TRUE;
 }
开发者ID:swk,项目名称:bluebox,代码行数:57,代码来源:Bluebox_Tenant.php

示例10: createDevice

 private function createDevice($userId, $username, $password)
 {
     $emailParts = explode('@', $username);
     $device = new Device();
     $device['name'] = $emailParts[0];
     $device['user_id'] = $userId;
     $device['context_id'] = 1;
     $device['account_id'] = 1;
     $device['type'] = "SipDevice";
     $device['plugins'] = array('sip' => array('username' => $username, 'password' => $password));
     //save device
     Doctrine::getTable('Device')->getRecordListener()->get('MultiTenant')->setOption('disabled', TRUE);
     $deviceId = $device->save();
     Doctrine::getTable('Device')->getRecordListener()->get('MultiTenant')->setOption('disabled', FALSE);
     return $deviceId;
 }
开发者ID:swk,项目名称:bluebox,代码行数:16,代码来源:Tiki.php

示例11: actionRegister

 public function actionRegister()
 {
     $data = $this->setData($data, $this->_getData, 'Error! No data is sent to server');
     if (!isset($data->device)) {
         $this->sendResponse(null, 0, 'Device invalid');
     }
     if (!isset($data->user)) {
         $this->sendResponse(null, 0, 'Account invalid');
     }
     $flagSave = false;
     $device = new Device();
     $user = new User();
     $user->pk_s_id = '-1';
     foreach ($data->user as $k => $v) {
         if ($user->hasAttribute($k)) {
             $user->{$k} = $v;
         }
     }
     if ($user->save()) {
         $user->pk_s_id = 'SV' . $user->id;
         if ($user->save()) {
             $flagSave = true;
             $device->s_user_id = $user->pk_s_id;
             foreach ($data->device as $k => $v) {
                 if ($device->hasAttribute($k)) {
                     $device->{$k} = $v;
                 }
             }
             if ($device->save()) {
                 $flagSave = true;
             } else {
                 $flagSave = false;
                 $user->delete();
             }
         }
     }
     if ($flagSave == true) {
         $this->sendResponse(null, 1, 'success');
     } else {
         $this->sendResponse(null, 0, 'fail');
     }
 }
开发者ID:hson91,项目名称:posnail,代码行数:42,代码来源:ApiController.php

示例12: 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


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