/** * Remove the specified widget from storage. * @internal param $id * @return Response */ public function destroy($id) { $widget = $this->widget->find($id); // Was the widget deleted? if ($widget->delete()) { // Redirect to the widget management page return Redirect::to('widgets')->with('success', Lang::get('widget/messages.delete.success')); } // There was a problem deleting the widget return Redirect::to('widgets')->with('error', Lang::get('widget/messages.delete.error')); }
public function getList() { $json = array(); App::uses('Widget', 'Model'); $WidgetModel = new Widget(); $params = array(); $params['recursive'] = -1; $params['fields'] = array('id', 'controller', 'action', 'title'); $params['order'] = 'title asc'; if ($widgets = $WidgetModel->find('all', $params)) { $json['widgets'] = $widgets; } else { $json['msg'] = __("You don't have any MushRaider's widget to insert"); } return json_encode($json); }
public function generatemenu() { $menu = new MenuItem(); $getall = $menu->getall(1); $menu = array('items' => array(), 'parents' => array()); foreach ($getall as $key => $items) { $menu['items'][$items['id']] = $items->toArray(); $menu['parents'][$items['parent']][] = $items->id; } $items = $this->buildMenu(0, $menu); $menufind = Menu::find(Input::get("id")); $widget = new Widget(); $widgetbymenu = $widget->getWidgetByMenu(Input::get("id")); if ($widgetbymenu->count()) { $widget = Widget::find($widgetbymenu[0]->id); } $widget->name = $menufind->name; $widget->id_component = Input::get("id"); $widget->description = $this->generarmenu($items); $widget->save(); }
/** * saveWidgetPosition * -------------------------------------------------- * Saves the widget position. * @param (int) ($userID) The ID of the user * @return Json with status code * -------------------------------------------------- */ public function saveWidgetPosition($userID) { /* Escaping invalid data. */ if (!isset($_POST['positioning'])) { throw new BadPosition("Missing positioning data.", 1); } /* Find user and save positioning if possible */ if (User::find($userID)) { /* Get widgets data */ $widgets = json_decode($_POST['positioning'], TRUE); /* Iterate through all widgets */ foreach ($widgets as $widgetData) { /* Escaping invalid data. */ if (!isset($widgetData['id'])) { return Response::json(array('error' => 'Invalid JSON input.')); } /* Find widget */ $widget = Widget::find($widgetData['id'])->getSpecific(); /* Skip widget if not found */ if ($widget === null) { continue; } /* Set position */ try { $widget->setPosition($widgetData); } catch (BadPosition $e) { return Response::json(array('error' => $e->getMessage())); } } /* No user found with the requested ID */ } else { return Response::json(array('error' => 'No user found with the requested ID')); } /* Everything OK, return response with 200 status code */ return Response::make('Widget positions saved.', 200); }
require_once '../paragon.php'; require_once '../drivers/mysqli_master_slave_driver.php'; // setting the connection // you only need to do this once in the whole script $mysqli = new Mysqli('localhost', 'username', 'password', 'database'); $driver = new MysqliMasterSlaveDriver(array('master' => $mysqli, 'slave' => $mysqli)); Paragon::set_connection($driver); // include a model require_once 'widget.php'; // find by id $widget = Widget::find(1); // find one by conditions $widgets = Widget::find_one(array('conditions' => array('name' => 'foo'))); // find by conditions, with limit, order, and start parameters $widgets = Widget::find(array('conditions' => array('name' => self::condition('like', 'bar')), 'limit' => 10, 'order' => 'name', 'start' => 0)); // index widgets by id $widgets_by_id = Widget::find(array('index' => 'id', 'order' => 'name')); // find widget ids $widget_ids = Widget::find_primary_keys(array('conditions' => array('name' => 'foo'))); // save a widget $widget->name = 'bar'; $widget->save(); // create a new widget $widget = new Widget(); $widget->name = 'foo'; $widget->description = 'i am a widget'; $widget->save(); // using a widget echo $widget->id; echo $widget->name; echo $widget->date_created;
private function sendStats() { $stats = array(); // Website $stats['Website']['url'] = Router::url('/', true); $stats['Website']['version'] = Configure::read('mushraider.version'); $stats['Website']['php'] = phpversion(); $stats['Website']['lang'] = Configure::read('Settings.language'); // Events App::uses('Event', 'Model'); $EventModel = new Event(); $params = array(); $params['recursive'] = -1; $params['order'] = array('time_start ASC'); if ($firstEvent = $EventModel->find('first', $params)) { $stats['Event']['first'] = $firstEvent['Event']['time_start']; } else { $stats['Event']['first'] = null; } $params['conditions']['time_start <='] = date('Y-m-d'); $params['order'] = array('time_start DESC'); if ($lastEvent = $EventModel->find('first', $params)) { $stats['Event']['last'] = $lastEvent['Event']['time_start']; } else { $stats['Event']['last'] = null; } $params = array(); $params['recursive'] = -1; $params['conditions']['time_start <='] = date('Y-m-d'); $countEvents = $EventModel->find('count', $params); $stats['Event']['total'] = $countEvents; // Reports App::uses('Report', 'Model'); $ReportModel = new Report(); $params = array(); $params['recursive'] = -1; $countReports = $ReportModel->find('count', $params); $stats['Report']['total'] = $countReports; // Users App::uses('User', 'Model'); $UserModel = new User(); $params = array(); $params['recursive'] = -1; $countUsers = $UserModel->find('count', $params); $stats['User']['total'] = $countUsers; // Characters App::uses('Character', 'Model'); $CharacterModel = new Character(); $params = array(); $params['recursive'] = -1; $countCharacters = $CharacterModel->find('count', $params); $stats['Character']['total'] = $countCharacters; // Games App::uses('Game', 'Model'); $GameModel = new Game(); $params = array(); $params['recursive'] = -1; if ($games = $GameModel->find('all', $params)) { foreach ($games as $game) { $stats['Game'][$game['Game']['slug']]['title'] = $game['Game']['title']; $stats['Game'][$game['Game']['slug']]['imported'] = $game['Game']['import_modified'] > 0 ? 1 : 0; $params = array(); $params['recursive'] = -1; $params['conditions']['game_id'] = $game['Game']['id']; $params['group'] = array('user_id'); $countCharacters = $CharacterModel->find('count', $params); $stats['Game'][$game['Game']['slug']]['players'] = $countCharacters; } } // Bridge $bridgeSetting = json_decode($this->SettingModel->getOption('bridge')); $stats['Bridge']['enabled'] = !empty($bridgeSetting) && $bridgeSetting->enabled ? 1 : 0; // Widgets App::uses('Widget', 'Model'); $WidgetModel = new Widget(); $params = array(); $params['recursive'] = -1; if ($widgets = $WidgetModel->find('all', $params)) { foreach ($widgets as $widget) { if (!isset($stats['Widget'][$widget['Widget']['controller']])) { $stats['Widget'][$widget['Widget']['controller']]['total'] = 1; } else { $stats['Widget'][$widget['Widget']['controller']]['total']++; } } } App::uses('HttpSocket', 'Network/Http'); $this->http = new HttpSocket(); $this->http->post('http://stats.mushraider.com/acquire', $stats); }