本文整理汇总了PHP中Zone::find方法的典型用法代码示例。如果您正苦于以下问题:PHP Zone::find方法的具体用法?PHP Zone::find怎么用?PHP Zone::find使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zone
的用法示例。
在下文中一共展示了Zone::find方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: destroy
public function destroy($id)
{
if (Auth::user()->is_admin) {
$count = 0;
$zone = Zone::find($id);
$clients = Client::select('zone_id')->get();
foreach ($clients as $key => $client) {
$u = $client->zone_id;
$uarray = explode(',', $u);
if (in_array($id, $uarray, true)) {
$count = $count + 1;
}
}
if ($count > 0) {
$field = $count == 1 ? ' ' : 's';
$field2 = $count == 1 ? ' pertenece' : ' pertenecen';
$message = $count . " Cliente" . $field . $field2 . " a la zona " . $zone->name;
Session::flash('error', $message);
return Redirect::to('zonas/' . $id);
} else {
$zone->delete();
$message = "Zona Eliminada con éxito";
Session::flash('message', $message);
return Redirect::to('zonas');
}
}
}
示例2: update
public function update()
{
$zone = Zone::find(Input::get('zone_id'));
$users = User::all();
foreach ($users as $key => $value) {
$user_access = Input::get('user_access_' . $value->rfid);
if ($user_access) {
$sites = $zone->Sites;
if ($zone->GivesAccessToUser($value->rfid) == 'Denied') {
DB::table('user_zone')->insert(array('user_id' => $value->rfid, 'zone_id' => $zone->id));
foreach ($sites as $site) {
DB::table('site_user')->insert(array('user_id' => $value->rfid, 'site_id' => $site->id));
}
} else {
DB::table('user_zone')->where('user_id', '=', $value->rfid)->where('zone_id', '=', $zone->id)->delete();
foreach ($sites as $site) {
DB::table('site_user')->where('user_id', '=', $value->rfid)->where('site_id', '=', $site->id)->delete();
}
}
}
}
return Redirect::to('zoneUser/' . $zone->id);
}
示例3: zonename
function zonename($char) {
if (isset($char->zone)) {
$zone = null;
$zone = Zone::find(intval($char->zone));
if (is_object($zone)) {
return $zone->name;
} else {
return $char->zone;
}
} else {
return 'Unknown';
}
}
示例4: addressMetaData
function addressMetaData($action)
{
// $optionState = array();
// $optionState['order'] = array('state_name' => 'asc', 'active' => '1');
// $optionState['conditions'] = array('zone_id' => $address['zone_id'], 'active' => '1');
if (isset($this->params['named']['copy_address']) || $action == 'edit' || $action == 'copy') {
App::import('Model', 'Country');
$objCountry = new Country();
App::import('Model', 'Zone');
$objZone = new Zone();
App::import('Model', 'State');
$objState = new State();
App::import('Model', 'District');
$objDistrict = new District();
App::import('Model', 'City');
$objCity = new City();
$optionZone = array();
$optionDistrict = array();
$optionCity = array();
if (!empty($this->viewVars[lcfirst($this->modelClass)]['Address'])) {
$address = $this->viewVars[lcfirst($this->modelClass)]['Address'];
$optionCountry['conditions'] = array('id' => $address['country_id'], 'active' => '1');
$optionZone['conditions'] = array('id' => $address['zone_id'], 'active' => '1');
$optionState['conditions'] = array('id' => $address['state_id'], 'active' => '1');
$optionDistrict['conditions'] = array('id' => $address['district_id'], 'active' => '1');
$optionCity['conditions'] = array('id' => $address['city_id'], 'active' => '1');
}
$countries = $objCountry->find('list', $optionCountry);
$zones = $objZone->find('list', $optionZone);
$states = $objState->find('list', $optionState);
$districts = $objDistrict->find('list', $optionDistrict);
$cities = $objCity->find('list', $optionCity);
$this->set(compact('countries', 'zones', 'states', 'districts', 'cities'));
}
}
示例5: OffCommand
public function OffCommand($zone_id, $relay_id)
{
$zone = Zone::find($zone_id);
$zone_sites = $zone->Sites;
$zone_relays = $zone->Relays;
if (!$zone_relays->count()) {
for ($i = 0; $i < 6; $i++) {
ZoneRelay::create(array('zone_id' => $zone_id, 'relay_id' => $i, 'status' => 'False'));
}
}
$zone_relay = ZoneRelay::withZoneAndRelay($zone_id, $relay_id)->get()->first();
$relay = ZoneRelay::find($zone_relay->id);
$relay->status = 'False';
$relay->save();
$entry = new ZoneRecord();
$entry->zone_id = $zone->id;
$entry->zone_name = $zone->name;
$entry->switch = $relay->relay_id;
$entry->status = 'Off';
$entry->command = 0;
$entry->admin_id = Auth::admin()->get()->id;
$entry->save();
foreach ($zone_sites as $zone_site) {
$site_relays = $zone_site->Relays;
if (!$site_relays->count()) {
for ($i = 0; $i < 6; $i++) {
Relay::create(array('site_id' => $zone_site->id, 'relay_id' => $i, 'status' => 'False'));
}
}
$site_relay = Relay::withSiteAndRelay($zone_site->id, $zone_relay->relay_id)->get()->first();
$relay = Relay::find($site_relay->id);
$relay->status = 'False';
$relay->save();
$entry = new Record();
$entry->site_id = $zone_site->id;
$entry->site_name = $zone_site->name;
$entry->switch = $relay->relay_id;
$entry->status = 'Off';
$entry->command = 0;
$entry->save();
}
return Redirect::to('zone/' . $zone_id);
}
示例6: update
public function update()
{
$zone = Zone::find(Input::get('zone_id'));
$sites = Site::all();
$zone_sites = $zone->Sites;
$zone_relays = $zone->Relays;
//add sites to zone
foreach ($sites as $key => $value) {
$selected_sites = Input::get('selected_sites_' . $value->id);
if ($selected_sites) {
$value->zone_id = $zone->id;
$value->save();
} else {
// $value->zone_id = null;
// $value->save();
}
}
$zone = Zone::find(Input::get('zone_id'));
$zone_sites = $zone->Sites;
$zone_relays = $zone->Relays;
//create new zone relays if not present
if (!$zone_relays->count()) {
for ($i = 0; $i < 6; $i++) {
ZoneRelay::create(array('zone_id' => $zone->id, 'relay_id' => $i, 'status' => 'False'));
}
}
//for all sites of the zone
$zone_sites = $zone->Sites;
foreach ($zone_sites as $site) {
//update site relays
$zone_relays = $zone->Relays;
foreach ($zone_relays as $relay) {
$site_relays = $site->Relays;
//create new site relays if not present
if (!$site_relays->count()) {
Relay::create(array('site_id' => $site->id, 'relay_id' => $relay->relay_id, 'status' => $relay->status));
}
$site_relay = Relay::where('site_id', '=', $site->id)->where('relay_id', '=', $relay->relay_id)->get()->first();
$relay_status = $site_relay->status;
//when zone relay is true
if ($relay->status == 'True') {
$site_relay->status = 'True';
$site_relay->save();
//log this change
$entry = new Record();
$entry->site_id = $site->id;
$entry->site_name = $site->name;
$entry->switch = $relay->relay_id;
$entry->status = 'On';
$entry->command = 1;
$entry->save();
//when zone relay is false
} else {
$site_relay->status = 'False';
$site_relay->save();
//log this change
$entry = new Record();
$entry->site_id = $site->id;
$entry->site_name = $site->name;
$entry->switch = $relay->relay_id;
$entry->status = 'Off';
$entry->command = 0;
$entry->save();
}
}
}
$users = User::all();
foreach ($users as $user) {
if ($zone->GivesAccessToUser($user->rfid) == 'Granted') {
DB::table('user_zone')->insert(array('user_id' => $user->rfid, 'zone_id' => $zone->id));
foreach ($zone_sites as $zone_site) {
DB::table('site_user')->insert(array('user_id' => $user->rfid, 'site_id' => $zone_site->id));
}
} else {
DB::table('user_zone')->where('user_id', '=', $user->rfid)->where('zone_id', '=', $zone->id)->delete();
foreach ($zone_sites as $zone_site) {
DB::table('site_user')->where('user_id', '=', $user->rfid)->where('site_id', '=', $zone_site->id)->delete();
}
}
}
return Redirect::to('zoneSite/' . $zone->id);
}
示例7: getZone
public function getZone()
{
$str = '';
if ($this->zone_id) {
$zone = Zone::find(1)->select('name')->where('id', '=', $this->zone_id)->first();
$result = $zone->name;
$str .= $result . '<br/>';
}
return $str;
}