Ejemplo n.º 1
0
 public function save(array $person = array(), $person_id = null)
 {
     $result = array('success' => false, 'error' => '');
     $valid = true;
     $person = $this->get_trimmed_allowed($person, array('space_id', 'email', 'x', 'y', 'active'));
     if (isset($person['space_id']) && !valid::digit($person['space_id'])) {
         $valid = false;
     }
     if (isset($person['email']) && !valid::email($person['email'])) {
         $valid = false;
     }
     if (isset($person['x']) && !valid::numeric($person['x'])) {
         $valid = false;
     }
     if (isset($person['y']) && !valid::numeric($person['y'])) {
         $valid = false;
     }
     if (isset($person['active']) && !valid::digit($person['active'])) {
         $valid = false;
     }
     if ($valid) {
         if ($person_id) {
             //UPDATE
             $this->db->from('people')->set($person)->where(array('id' => (int) $person_id))->update();
             $result['success'] = true;
         } else {
             // INSERT
             $new_person = $this->db->from('people')->set($person)->insert();
             $result['success'] = true;
             $person_id = $new_person->insert_id();
         }
         $person = $this->db->select('people.*')->from('people')->where(array('id' => $person_id))->get();
         $person = $this->result_as_array($person);
         $result['person'] = $person;
     } else {
         $result['error'] = "The supplied data was invalid";
     }
     return $result;
 }
Ejemplo n.º 2
0
 public function valid_digit_test()
 {
     $this->assert_true_strict(valid::digit('123'))->assert_false_strict(valid::digit('abc'));
 }
Ejemplo n.º 3
0
 /**
  * Tests the valid::digit() function.
  * @dataProvider digit_provider
  * @group core.helpers.valid.digit
  * @test
  */
 public function digit($input_digit, $expected_result)
 {
     $result = valid::digit($input_digit);
     $this->assertEquals($expected_result, $result);
 }
Ejemplo n.º 4
0
 /**
  * edit an item
  *
  * @param object $setup 
  * @return void
  * @author Andy Bennett
  */
 public function edit($setup = false)
 {
     // acl check
     $data = array('action' => 'edit', 'name' => $this->name, 'role' => Steamauth::instance()->get_role());
     Event::run('steamcore.aclcheck', $data);
     // are we using a passed id or one POSTed
     $id = isset($setup->id) ? $setup->id : $this->input->post('form_id');
     // set up the defaults
     $d = array('model' => $this->model, 'form_name' => $this->setup['name'] . '_edit', 'form_data' => array(), 'update' => valid::digit($id) ? $id : FALSE);
     $setup = steamcore::array_object($d, $setup);
     // try running the form, throw exception on error (shouldn't happen)
     try {
         steamform_helper::run_form($setup);
     } catch (Exception $e) {
         throw new Kohana_User_Exception('SteamCore Edit Error', $e->getMessage());
     }
 }