Root/
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 | <?php /* -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* # ***** BEGIN LICENSE BLOCK ***** # This file is part of Plume Framework, a simple PHP Application Framework. # Copyright (C) 2001-2006 Loic d'Anterroches and contributors. # # Plume Framework is free software; you can redistribute it and/or modify # it under the terms of the GNU Lesser General Public License as published by # the Free Software Foundation; either version 2.1 of the License, or # (at your option) any later version. # # Plume Framework is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU Lesser General Public License for more details. # # You should have received a copy of the GNU Lesser General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA # # ***** END LICENSE BLOCK ***** */ /** * The Todo_Item is refering to the Todo_List through a foreign key. */ class Todo_Item extends Pluf_Model { public $_model = __CLASS__ ; /** * The init method is used to define your model. */ function init() { /** * The database table to store the model. * The table name will be prefixed with the prefix define * in the global configuration. */ $this ->_a[ 'table' ] = 'todo_items' ; /** * 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' : '' ); } } |