All pastes #161759 Raw Edit

Stuff

public text v1 · immutable
·published 2006-09-05 19:53 UTC
rendered paste body
<?php
/**
 * Table Definition for jobs
 */
require_once 'DB/DataObject.php';

class DataObjects_Jobs extends DB_DataObject 
{
    ###START_AUTOCODE
    /* the code below is auto generated do not remove the above tag */

    var $__table = 'jobs';                            // table name
    var $id;                              // int(11)  not_null primary_key auto_increment
    var $title;                           // string(128)  not_null
    var $description;                     // blob(65535)  not_null blob
    var $active;                          // int(4)  not_null
    var $file_path;                       // string(128)  not_null

    //Extra DB_DataObject_FormBuilder stuff
    var $fb_booleanFields;
    var $fb_fieldLabels;
    var $fb_preDefElements;

    /* ZE2 compatibility trick*/
    function __clone() { return $this;}

    /* Static get */
    function staticGet($k,$v=NULL) { return DB_DataObject::staticGet('DataObjects_Jobs',$k,$v); }

    /* the code above is auto generated do not remove the tag below */
    ###END_AUTOCODE
    /* getters, setters */
    function set_fb_booleanFields($val)
    {
        $this->fb_booleanFields = $val;
    }

    function set_id ($val)  {
           $this->id = $val;
    }

    function get_id ()      {
           return $this->id ;
    }
    function set_title ($val)       {
           $this->title = $val;
    }

    function get_title ()   {
           return $this->title ;
    }
    function set_description ($val)         {
           $this->description = $val;
    }

    function get_description ()     {
           return $this->description ;
    }
    function set_active ($val)      {
           $this->active = $val;
    }

    function get_active ()  {
           return $this->active ;
    }
    function set_file_path ($val)   {
           $this->file_path = $val;
    }

    function get_file_path ()       {
           return $this->file_path ;
    }
    //Begin code taken from http://pear.reversefold.com/dokuwiki/doku.php?id=pear:db_dataobject_formbuilder:beyond_advanced#file_upload_handling 

    // Prepare the form so it contains a file upload field
    function preGenerateForm(&$fg)
    {
        $this->fb_fieldLabels =  array ('Image_Path' => 'Choose image to upload');
        $this->fb_preDefElements['Image_Path'] = & HTML_QuickForm::createElement('file', 'Image_Path', ('File to upload'), 'maxfilesize=5000000');
    }
      
    function insert() 
    {
        if (is_uploaded_file($_FILES['Image_Path']["tmp_name"])) {
            // You should do some file name checking here, for example disallow spaces etc.
            $this->Image_Path = $_FILES['Image_Path']["name"];
            
            // I've used a constant "UPLOADDIR" here, which must be defined somewhere of course
            if (move_uploaded_file($_FILES['Image_Path']["tmp_name"], UPLOADDIR.$this->Image_Path)
                && chmod(UPLOADDIR.$this->Image_Path, 0644)) {
                    
                // You could do some additional image manipulation, like scaling, here...
                
                return parent::insert();
            }
        }
        return false;
    }
    
    function delete()
    {
        $result = parent::delete();
        
        if ($result) {
            unlink(UPLOADDIR . $this->Image_Path);
        }
        
        return $result;
    }

// End code taken from FormBuilder wiki
//    function DataObjects_Jobs()
//    {
//        $this->set_fb_booleanFields(array('active'));
//    }
}
?>




<?php
    include_once 'code/common_includes.php';
    $jobs = new DataObjects_Jobs ();
    //this should actually be in the ctor, but uncommenting the ctor makes a mess.
    $jobs->set_fb_booleanFields(array('active'));

    //example from doc
    // Insert "$jobs->get($some_id);" here to edit an 
    // existing object instead of making a new one
    $fg =& DB_DataObject_FormBuilder::create($jobs);
    $form =& $fg->getForm();
    if ($form->validate()) {
        $form->process(array(&$fg,'processForm'), false);
        $form->freeze();
    }
    $form->display();
?>