Show
Ignore:
Timestamp:
09/05/08 13:32:48 (4 months ago)
Author:
bjohnson
Message:

schema06: Added some ACL support to the Post class. Also added the backend for 'minor edits'.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • branches/schema06/system/classes/post.php

    r2410 r2448  
    582582    public function insert() 
    583583    { 
    584         $this->newfields[ 'updated' ]= HabariDateTime::date_create(); 
     584        $this->newfields['updated']= HabariDateTime::date_create(); 
     585        $this->newfields['modified'] = $this->newfields['updated']; 
    585586        $this->setslug(); 
    586587        $this->setguid(); 
     
    606607        $this->info->commit( DB::last_insert_id() ); 
    607608        $this->save_tags(); 
     609        $this->create_default_permissions(); 
    608610        EventLog::log( sprintf(_t('New post %1$s (%2$s);  Type: %3$s; Status: %4$s'), $this->id, $this->slug, Post::type_name( $this->content_type ), $this->statusname), 'info', 'content', 'habari' ); 
    609611        Plugins::act( 'post_insert_after', $this ); 
     
    620622     * function update 
    621623     * Updates an existing post in the posts table 
    622      */ 
    623     public function update() 
    624     { 
    625         $this->updated= HabariDateTime::date_create(); 
     624     * @param bool $minor Indicates if this is a major or minor update 
     625     */ 
     626    public function update( $minor = true ) 
     627    { 
     628        $this->modified = HabariDateTime::date_create(); 
     629        if ( ! $minor ) { 
     630            $this->updated = $this->modified; 
     631        } 
    626632        if ( isset( $this->fields['guid'] ) ) { 
    627633            unset( $this->newfields['guid'] ); 
     
    691697            $this->info->delete_all(); 
    692698        } 
     699        // Delete all permissions associated with this post 
     700        $this->delete_permissions(); 
     701 
    693702        $result= parent::deleteRecord( DB::table( 'posts' ), array( 'slug'=>$this->slug ) ); 
    694703        EventLog::log( sprintf(_t('Post %1$s (%2$s) deleted.'), $this->id, $this->slug), 'info', 'content', 'habari' ); 
     
    982991    } 
    983992 
     993    /** 
     994     * Creates default permissions on a post 
     995     */ 
     996    public function create_default_permissions() 
     997    { 
     998        $this->add_permission( $this->content_type() ); 
     999    } 
     1000 
     1001    /** 
     1002     * Add a permission to a post 
     1003     * @param string $permission The name of the permission to add 
     1004     **/ 
     1005    public function add_permission( $permission ) 
     1006    { 
     1007        $token_id = ACL::token_id( $permission ); 
     1008        if ( $token_id !== FALSE ) { 
     1009            DB::insert( '{post_tokens}', array( 'post_id' => $this->id, 'token_id' => $token_id ) ); 
     1010        } 
     1011    } 
     1012 
     1013    /** 
     1014     * Deletes permissions on a post 
     1015     */ 
     1016    public function delete_permissions() 
     1017    { 
     1018        DB::delete( '{post_tokens}', array( 'post_id', => $this->id ) ); 
     1019    } 
    9841020} 
    9851021?>