api/model/order.model.php
/** ----------------------------------------
     *  SAVE THE OBJECT INSTANCE WITH NEW DATA
     *  ----------------------------------------
     */
SAVE THE OBJECT INSTANCE WITH NEW DATA
SAVE THE OBJECT INSTANCE WITH NEW DATA
public function save($o = null)
    {
        $o_id = null;
        $db_columns = Array();
        if($o == null && !is_numeric($this->id))
        {
            return $this->add_row($this);
        }
        if(!is_array($o) && $o instanceof Order) $o = $o->id;
        if($o != null && is_array($o))
        {
            $o_id = $this->id;
            $data = $o;
            $_properties = get_object_vars($this);
            foreach($data as $key=>$val)
            {
                foreach($_properties as $column=>$v)
                {
                    if($key == self::TABLE_PREFIX . $column && !is_array($this->$column) && trim($val) !== trim($this->$column))
                    {
                        log_error('[' . $column . '] ' . $val . ' -> ' . $this->$column);
                        $db_columns[$key] = $val;
                    }
                }
            }
            if(empty($db_columns)) return false;
            log_error('DIFF: ' . print_r($db_columns,true));
            $db_columns[self::TABLE_PREFIX . 'tmodified'] = current_timestamp();
        } elseif($o != null && is_numeric($o))
        {
            $o_id = $o;
            $this->id = $o_id;
            $_properties = get_object_vars($this);
            foreach($_properties as $column=>$v)
            {
                if($this->$column !== null && !is_array($v))
                    $db_columns[self::TABLE_PREFIX . $column] = $v;
            }
            $db_columns[self::TABLE_PREFIX . 'tmodified'] = current_timestamp();
        } elseif($o == null && is_numeric($this->id) && $this->id > 0 )
        {
            $db_columns = $this->serialize_object();
            $o_id = $this->id;
            $db_columns[self::TABLE_PREFIX . 'tmodified'] = current_timestamp();
        }
        if(empty($db_columns))
            throw new Exception('No data provided to update ' . self::TABLE_NAME);
        $db_conditions = array(self::TABLE_PREFIX . 'id'=>$o_id);
        try {
            $this->db_update(self::TABLE_NAME,$db_columns,$db_conditions,false);
        } catch(Exception $e) {
            log_error('Error'. $e->getCode() .': '. $e->getMessage());
        }
    }
public function save ( $ o = null ) { $ o_id = null ; $ db_columns = Array ( ) ; if ( $ o == null && ! is_numeric ( $ this -> id ) ) { return $ this -> add_row ( $ this ) ; } if ( ! is_array ( $ o ) && $ o instanceof Order ) $ o = $ o -> id ; if ( $ o != null && is_array ( $ o ) ) { $ o_id = $ this -> id ; $ data = $ o ; $ _properties = get_object_vars ( $ this ) ; foreach ( $ data as $ key => $ val ) { foreach ( $ _properties as $ column => $ v ) { if ( $ key == self :: TABLE_PREFIX . $ column && ! is_array ( $ this -> $ column ) && trim ( $ val ) !== trim ( $ this -> $ column ) ) { log_error ( '[' . $ column . '] ' . $ val . ' -> ' . $ this -> $ column ) ; $ db_columns [ $ key ] = $ val ; } } } if ( empty ( $ db_columns ) ) return false ; log_error ( 'DIFF: ' . print_r ( $ db_columns , true ) ) ; $ db_columns [ self :: TABLE_PREFIX . 'tmodified' ] = current_timestamp ( ) ; } elseif ( $ o != null && is_numeric ( $ o ) ) { $ o_id = $ o ; $ this -> id = $ o_id ; $ _properties = get_object_vars ( $ this ) ; foreach ( $ _properties as $ column => $ v ) { if ( $ this -> $ column !== null && ! is_array ( $ v ) ) $ db_columns [ self :: TABLE_PREFIX . $ column ] = $ v ; } $ db_columns [ self :: TABLE_PREFIX . 'tmodified' ] = current_timestamp ( ) ; } elseif ( $ o == null && is_numeric ( $ this -> id ) && $ this -> id > 0 ) { $ db_columns = $ this -> serialize_object ( ) ; $ o_id = $ this -> id ; $ db_columns [ self :: TABLE_PREFIX . 'tmodified' ] = current_timestamp ( ) ; } if ( empty ( $ db_columns ) ) throw new Exception ( 'No data provided to update ' . self :: TABLE_NAME ) ; $ db_conditions = array ( self :: TABLE_PREFIX . 'id' => $ o_id ) ; try { $ this -> db_update ( self :: TABLE_NAME , $ db_columns , $ db_conditions , false ) ; } catch ( Exception $ e ) { log_error ( 'Error' . $ e -> getCode ( ) . ': ' . $ e -> getMessage ( ) ) ; } }
SAVE THE OBJECT INSTANCE WITH NEW DATA
SAVE THE OBJECT INSTANCE WITH NEW DATA
/** ----------------------------------------------------------------
             *  CREATE A NEW RECORD IF ID ISN'T SET OR OBJECT ISN'T BEING PASSED
             *  ----------------------------------------------------------------
             */ /** -------------------------------
         *  SIMPLY UPDATE ALL INSTANCE VARS
         *  -------------------------------
         */ /** ----------------------------------
         *  OR PASS AN ARRAY WITH UPDATED DATA
         *  ----------------------------------
         */ /**
         *  This method can either take an array of valid user table columns
         *  and store it, if it is not provided, it will assume to save all
         *  the properties within the object
         */ //Nothing new to update /**
             *  No array data provided, then lets just save the properties within the object **/