1: <?php
2:
3: namespace cli_db;
4:
5: require_once ROOT . 'classes/AbstractTable.php';
6:
7: class Biomaterial extends AbstractTable {
8:
9: 10: 11:
12: public static function getKeys() {
13: return array(
14: 'id' => array(
15: 'colname' => 'BiomaterialId',
16: 'actions' => array(
17: 'details' => 'required',
18: 'update' => 'required',
19: 'delete' => 'required',
20: ),
21: 'description' => 'biomaterial id'
22: ),
23: 'name' => array(
24: 'colname' => 'Name',
25: 'actions' => array(
26: 'insert' => 'required',
27: 'add_condition' => 'required',
28: 'add_condition_sample' => 'required',
29: 'update' => 'optional',
30: ),
31: 'description' => 'name'
32: ),
33: 'description' => array(
34: 'colname' => 'Description',
35: 'actions' => array(
36: 'insert' => 'optional',
37: 'add_condition' => 'optional',
38: 'add_condition_sample' => 'optional',
39: 'update' => 'optional',
40: ),
41: 'description' => 'description'
42: ),
43: 'organism_id' => array(
44: 'colname' => 'TaxonId',
45: 'actions' => array(
46: 'insert' => 'optional',
47: 'update' => 'optional',
48: ),
49: 'description' => 'organism id'
50: ),
51: 'biosourceprovider_id' => array(
52: 'colname' => 'BiosourceproviderId',
53: 'actions' => array(
54: 'insert' => 'optional',
55: 'add_condition' => 'optional',
56: 'add_condition_sample' => 'optional',
57: 'update' => 'optional',
58: ),
59: 'description' => 'contact id'
60: ),
61: 'short' => array(
62: 'actions' => array(
63: 'insert' => 'optional',
64: 'add_condition' => 'optional',
65: 'add_condition_sample' => 'optional',
66: ),
67: 'description' => 'if set, will just output the ID of newly inserted line on success',
68: 'action' => 'StoreTrue'
69: ),
70: 'parent_biomaterial_name' => array(
71: 'actions' => array(
72: 'add_condition' => 'required',
73: ),
74: 'description' => 'parent biomaterial name'
75: ),
76: 'parent_condition_name' => array(
77: 'actions' => array(
78: 'add_condition_sample' => 'required',
79: ),
80: 'description' => 'parent condition name'
81: ),
82: 'type' => array('colname' => 'Type'),
83: 'parent' => array('colname' => 'Parent')
84: );
85: }
86:
87: 88: 89:
90: public static function CLI_commandDescription() {
91: return 'Manipulate biomaterials, conditions and samples.';
92: }
93:
94: 95: 96:
97: public static function CLI_commandName() {
98: return 'biomaterial';
99: }
100:
101: 102: 103:
104: public static function CLI_longHelp() {
105:
106: }
107:
108: 109: 110:
111: public static function getSubCommands() {
112: return array('insert', 'update', 'delete', 'details', 'list', 'add_condition', 'add_condition_sample');
113: }
114:
115: 116: 117: 118:
119: protected static function command_insert($options, $keys) {
120: $biomat = new propel\Biomaterial();
121: self::setKeys($options, $keys, 'insert', $biomat);
122:
123: $lines = $biomat->save();
124: $biomat->setType('biomaterial');
125: $lines += $biomat->save();
126:
127: if (isset($options['short']) && $options['short'])
128: print $biomat->getPrimaryKey();
129: else
130: printf("%d line(s) inserted.\n", $lines);
131: }
132:
133: 134: 135: 136: 137:
138: protected static function command_add_condition($options, $keys) {
139: $parent = propel\BiomaterialQuery::create()->findOneByName($options['parent_biomaterial_name']);
140: if ($parent == null)
141: trigger_error('This parent Biomaterial does not exist!', E_USER_ERROR);
142: if ($parent->getType() != 'biomaterial')
143: trigger_error('Specified parent is of wrong type!' . $parent->getType(), E_USER_ERROR);
144:
145:
146: $biomat = new propel\Biomaterial();
147: self::setKeys($options, $keys, 'insert', $biomat);
148:
149: $lines = $biomat->save();
150: $biomat->setType('condition');
151: $biomat->setParent($parent);
152: $lines += $biomat->save();
153:
154: if (isset($options['short']) && $options['short'])
155: print $biomat->getPrimaryKey();
156: else
157: printf("%d line(s) inserted.\n", $lines);
158: }
159:
160: 161: 162: 163: 164:
165: protected static function command_add_condition_sample($options, $keys) {
166: $parent = propel\BiomaterialQuery::create()->findOneByName($options['parent_condition_name']);
167: if ($parent == null)
168: trigger_error('This parent Biomaterial does not exist!', E_USER_ERROR);
169: if ($parent->getType() != 'condition')
170: trigger_error('Specified parent is of wrong type!', E_USER_ERROR);
171:
172: $biomat = new propel\Biomaterial();
173: self::setKeys($options, $keys, 'insert', $biomat);
174:
175: $lines = $biomat->save();
176: $biomat->setType('condition_sample');
177: $biomat->setParent($parent);
178: $lines += $biomat->save();
179:
180: if (isset($options['short']) && $options['short'])
181: print $biomat->getPrimaryKey();
182: else
183: printf("%d line(s) inserted.\n", $lines);
184: }
185:
186: 187: 188: 189:
190: protected static function command_details($options, $keys) {
191: parent::command_details($options, $keys);
192:
193: $references = array();
194:
195: $child_relationships = propel\BiomaterialRelationshipQuery::create()->findByObjectId($options['id']);
196: foreach ($child_relationships as $child_relationship) {
197: $child = $child_relationship->getBiomaterialRelatedBySubjectId();
198: $references[] = array($child->getType(), sprintf("Id: %s\nName: %s", $child->getBiomaterialId(), $child->getName()));
199: }
200:
201: if (count($references) > 0) {
202: print "has relationships:\n";
203: self::printTable(array('', 'Row'), $references);
204: }
205: }
206:
207: 208: 209:
210: public static function getPropelClass() {
211: return '\\cli_db\\propel\\Biomaterial';
212: }
213:
214: }
215:
216: ?>
217: