_a['table'] = 'todoitems'; /** * The name of the model in the class definition. */ $this->_a['model'] = 'Todo_Item'; /** * The definition of the model. Each key of the associative array * corresponds to a "column" and the definition of the column is * given in the corresponding array. */ $this->_a['cols'] = array( // It is mandatory to have an "id" column. 'id' => array( 'type' => 'Pluf_DB_Field_Sequence', //It is automatically added. 'blank' => true, ), 'item' => array( 'type' => 'Pluf_DB_Field_Varchar', 'blank' => false, 'size' => 250, // The verbose name is all lower case 'verbose' => __('todo item'), ), 'completed' => array( 'type' => 'Pluf_DB_Field_Boolean', 'default' => false, 'verbose' => __('completed'), ), 'list' => array( // Here we relate the model to a Todolist // model. This is like saying that a Todoitem // belongs to a given Todolist 'type' => 'Pluf_DB_Field_Foreignkey', 'blank' => false, 'model' => 'Todo_List', 'verbose' => __('in list'), 'help_text' => __('To easily manage your todo items, you are invited to organize your todo items in lists.'), ), ); /** * You can define the indexes. * Indexes are you to sort and find elements. Here we define * an index on the completed column to easily select the list * of completed or not completed elements. */ $this->_a['idx'] = array('completed_idx' => array('col' => 'completed', 'type' => 'normal'), ); $this->_a['views'] = array( 'todo' => array( 'where' => 'completed=false', ), ); } public function __toString() { return $this->item.(($this->completed) ? ' - Done' : ''); } }