public function testFindCompositeKey()
 {
     if (!$this->storage->supportsCompositePrimaryKeys()) {
         $this->markTestSkipped('Composite keys need to be supported for this test to run.');
     }
     $key = ['dist' => 'foo', 'range' => 100];
     $this->mockFindCompositeKey($key);
     $data = $this->storage->find('stdClass', $key);
     $this->assertEquals(['dist' => 'foo', 'range' => '100', 'timestamp' => new \DateTime('2008-09-18 23:46:19', new \DateTimeZone('UTC')), 'name' => 'Test', 'value' => 23, 'amount' => 200.23, 'bool' => true], $data);
 }
Ejemplo n.º 2
0
 public function postSave($id = false)
 {
     Allow::permission($this->module['group'], $this->module['name']);
     $json_request = array('status' => FALSE, 'responseText' => '', 'responseErrorText' => '', 'redirect' => FALSE);
     if (!Request::ajax()) {
         App::abort(404);
     }
     if ($id > 0 && NULL !== ($element = Storage::find($id))) {
         $exist = true;
         $rules = array();
         $redirect = false;
         $input = $element->toArray();
         $input['value'] = json_decode($input['value'], 1);
     } else {
         $exist = false;
         $rules = Storage::$rules;
         $redirect = true;
         $element = new Storage();
         $input = array('module' => 'menu');
     }
     #Helper::dd($input);
     #Helper::dd(is_null(Input::get('nesting_level2')));
     /**
      * Основные параметры
      */
     if (!is_null(Input::get('name'))) {
         $input['name'] = Input::get('name');
     }
     if (!is_null(Input::get('title'))) {
         $input['value']['title'] = Input::get('title');
     }
     if (!is_null(Input::get('nesting_level'))) {
         $input['value']['nesting_level'] = Input::get('nesting_level');
     }
     /**
      * Дополнительные параметры
      */
     if (!is_null(Input::get('container'))) {
         $input['value']['container'] = Input::get('container');
     }
     if (!is_null(Input::get('element_container'))) {
         $input['value']['element_container'] = Input::get('element_container');
     }
     if (!is_null(Input::get('element'))) {
         $input['value']['element'] = Input::get('element');
     }
     if (!is_null(Input::get('active_class'))) {
         $input['value']['active_class'] = Input::get('active_class');
     }
     /**
      * Элементы меню и их порядок
      */
     if (!is_null(Input::get('items'))) {
         $input['value']['items'] = Input::get('items');
     }
     if (!is_null(Input::get('order'))) {
         $input['value']['order'] = Input::get('order');
     }
     #Helper::dd($input);
     $input['value'] = json_encode($input['value']);
     #Helper::dd($input);
     $validation = Validator::make($input, $rules);
     if ($validation->passes()) {
         ## CREATE OR UPDATE CURRENT MENU
         if ($exist) {
             $element->update($input);
         } else {
             $element = $element->create($input);
         }
         /**
          * Предустановленные места для меню
          */
         if (!is_null(Input::get('update_placements'))) {
             $placements = (array) Input::get('placements');
             #Helper::dd($placements);
             #dd($placements);
             $placements_values = array_flip($placements);
             #Helper::dd($placements_values);
             $layout_placements = Helper::getLayoutProperties();
             $layout_placements = @(array) $layout_placements['MENU_PLACEMENTS'];
             #Helper::dd($layout_placements);
             $menu_placement = Storage::firstOrNew(array('module' => 'menu_placement', 'name' => 'menu_placement'));
             #Helper::dd($menu_placement);
             $menu_placement_value = is_object($menu_placement) ? json_decode($menu_placement->value, 1) : array();
             $array = array();
             foreach ($layout_placements as $layout_placement_key => $layout_placement_value) {
                 #Helper::d("$layout_placement_key => $layout_placement_value");
                 $value = false;
                 if (isset($placements_values[$layout_placement_key])) {
                     $value = $element->name;
                 } elseif (isset($menu_placement_value[$layout_placement_key]) && $menu_placement_value[$layout_placement_key] != $element->name) {
                     $value = $menu_placement_value[$layout_placement_key];
                 } else {
                     $value = false;
                 }
                 $array[$layout_placement_key] = $value;
             }
             #Helper::d($array);
             $menu_placement->value = json_encode($array);
             #Helper::ta($menu_placement);
             $menu_placement->save();
             #Setting::where('module', 'menu_placement')->whereIn('name', $layout_placements);
         }
         $json_request['responseText'] = 'Сохранено';
         if ($redirect && Input::get('redirect')) {
             $json_request['redirect'] = Input::get('redirect');
         }
         $json_request['status'] = TRUE;
     } else {
         $json_request['responseText'] = 'Неверно заполнены поля';
         $json_request['responseErrorText'] = implode($validation->messages()->all(), '<br />');
     }
     return Response::json($json_request, 200);
 }