Пример #1
0
 public function delete()
 {
     $id = $this->pk();
     if (isset($this->_log_fields['title'])) {
         $title = $this->{$this->_log_fields['title']};
     } else {
         $title = 'Без заголовка';
     }
     $delete = parent::delete();
     if (count($this->_log_fields) && $delete) {
         $log = ORM::factory('Log');
         $log->event = 'delete';
         $log->model = get_class($this);
         $log->content_id = $id;
         $log->date = date("Y.m.d H:i:s");
         $log->title = $title;
         if (isset(Auth::instance()->get_user()->id)) {
             $log->user_id = Auth::instance()->get_user()->id;
         } else {
             $log->user_id = 0;
         }
         $log->save();
     }
     return $delete;
 }
Пример #2
0
 protected function _update()
 {
     if (empty($this->_changed)) {
         return $this;
     }
     if ($this->_read_only) {
         return $this;
     }
     $vr = $this->_version_coloumn_reason;
     $old_item = ORM::factory($this->_object_name, $this->pk());
     $data = $old_item->as_array();
     $data[$vr] = $this->{$vr};
     $data[$this->_version_of] = $data[$this->_primary_key];
     unset($data[$this->_primary_key]);
     $result = DB::insert($this->_version_table_name)->columns(array_keys($data))->values(array_values($data))->execute($this->_db);
     if ($result) {
         if ($this->empty_pk()) {
             // $result is array(insert_id, total_rows)
             $this->_object[$this->_primary_key] = $result[0];
         }
     } else {
         throw "Error saving";
     }
     unset($data[$this->_version_coloumn_reason]);
     $v = $this->_version_coloumn_name;
     $this->{$v} += 1;
     if (is_array($this->_created_column)) {
         // Fill the created column
         $column = $this->_created_column['column'];
         $format = $this->_created_column['format'];
         $this->{$column} = $this->_object[$column] = $format === TRUE ? time() : date($format);
     }
     parent::_update();
 }
Пример #3
0
 protected function _validation()
 {
     parent::_validation();
     foreach ($this->_empty_rules as $rule) {
         $this->_validation->add_empty_rule($rule);
     }
 }
Пример #4
0
 public function action_index()
 {
     $kosher_options = Kohana::config('global.kosher_level');
     $payment_method = Kohana::config('global.payment_method');
     $categories = Kohana_ORM::factory('category')->where('model', '=', 'restaurant')->find_all()->as_array('id', 'name');
     $this->template->content = View::factory('site/main_index')->set('kosher_options', $kosher_options)->set('payment_method', $payment_method)->set('categories', $categories);
 }
Пример #5
0
 /**
  * Finds multiple database rows and returns an array of the rows found.
  *
  * @return Database_Result or array
  */
 public function find_all()
 {
     $res = parent::find_all();
     if ($this->entity_exists()) {
         $res = $this->entity($res);
     }
     return $res;
 }
Пример #6
0
 /**
  * Insert a new object to the database - Overwrite!
  * @param  Validation $validation Validation object
  * @throws Kohana_Exception
  * @return ORM
  */
 public function create(Validation $validation = NULL)
 {
     //Hack to use the PHP date time instead of the MySQL for created
     $cols = $this->list_columns();
     // the column created exists and we didnt pass any value before
     if (isset($cols['created']) and !array_key_exists('created', $this->_changed)) {
         //add the value, forcing it so wont use the DB default ;)
         $this->set('created', Date::unix2mysql());
     }
     return parent::create($validation);
 }
 /**
  * wrapper for delete
  *
  * @return ORM
  */
 public function delete()
 {
     // hook
     Event::raise($this, Event::BEFORE_DELETE, array('model' => $this));
     // delete
     $result = parent::delete();
     // hook
     Event::raise($this, Event::AFTER_DELETE, array('model' => $this));
     // return orm
     return $result;
 }
Пример #8
0
  private function _is_jsoncol($col)
  {
    if ( array_key_exists($col, $this->_jsoncol) ) return TRUE;
    if ( array_key_exists($col, $this->_jsoncols) )
    {
      $this->_jsoncol[$col] = (object) array_merge(
        (array) $this->_jsoncols[$col], (array) json_decode(parent::__get($col) )
      );
      return TRUE;
    }

    return FALSE;
  }
Пример #9
0
 public function save()
 {
     if (($this->empty_pk() || isset($this->_changed[$this->_primary_key])) && $this->_get_currval) {
         $connection = $this->_db->get_connection();
         $connection->beginTransaction();
         try {
             parent::save();
             $result = $this->_db->query(Database::SELECT, 'select currval(\'' . $this->sequence_name() . '\') ' . 'as last_insert_id', false);
             $result = $result->as_array();
             $last_insert_id = $result[0]['last_insert_id'];
             $this->_object[$this->_primary_key] = $last_insert_id;
         } catch (Exception $e) {
             try {
                 $connection->rollBack();
             } catch (Exception $ee) {
             }
             throw $e;
         }
         $connection->commit();
     } else {
         return parent::save();
     }
 }
Пример #10
0
 protected static function _process_has_many($alias, Kohana_ORM $model, stdClass $std, Formo $form)
 {
     if (empty($std->has_many)) {
         // No need to process non-has-many fields here
         return NULL;
     }
     foreach (Arr::get($std->has_many, 'definitions', array()) as $key => $values) {
         if (Arr::get($values, 'formo') === true) {
             $rs_all = ORM::factory($values['model'])->find_all();
             $foreign_model = ORM::factory($values['model']);
             $rs_in = $foreign_model->where($values['foreign_key'], '=', $model->pk())->find_all();
             $opts = static::select_list($rs_all, $foreign_model->primary_key(), static::_get_field_name($foreign_model));
             $val = static::select_list($rs_in, $foreign_model->primary_key(), $foreign_model->primary_key());
             $form->add($key, 'checkboxes', $val, array('opts' => $opts));
         } else {
             $form->add($key, 'checkboxes', null, array('render' => false));
         }
     }
 }
Пример #11
0
 public function check(Validation $validation = NULL)
 {
     $this->before_validation();
     parent::check($validation);
     $this->after_validation();
     return $this;
 }
Пример #12
0
 /**
  * Deletes a single record while ignoring relationships.
  *
  * @chainable
  * @throws Kohana_Exception
  * @return ORM
  */
 public function delete()
 {
     if (!$this->before_delete()) {
         return FALSE;
     }
     $id = $this->pk();
     parent::delete();
     $this->after_delete($id);
     return $this;
 }
Пример #13
0
 public static function factory($model, $id = NULL)
 {
     return parent::factory($model, $id);
 }
Пример #14
0
Файл: ORM.php Проект: stecj/sime
 public function __construct($id = NULL)
 {
     parent::__construct($id);
 }