/* the code above is auto generated do not remove the tag below */
###END_AUTOCODE
+
function applyFilters($q, $au)
{
if (!empty($q['query']['empty_etype'])) {
$this->whereAdd("etype = ''");
}
+
+ if(!empty($q['!name'])){
+ $names = explode(',', $q['!name']);
+ foreach($names as $name){
+ $this->whereAdd("
+ core_enum.name NOT IN ('$name')
+ ");
+ }
+ }
+ }
+
+ function postListFilter($data, $authUser, $q) {
+
+ if(!empty($q['cmsTab'])){
+ $ret = array();
+ foreach($data as $k=>$v){
+ if($v['name'] == 'element'){
+ continue;
+ }
+ $ary = $v;
+ if($ary['name'] == 'page'){
+ $ary['display_name'] = $v['display_name'].' / Elements';
+ }
+ $ret[] = $ary;
+ }
+ $data = $ret;
+ }
+
+ return $data;
+
}
function onUpdate($old, $req)
{
$tn = $this->tableName();
$x = $this->factory($tn);
- print_r($old);
- $x->whereAdd("etype = '{$request['etype']}' AND name = '{$request['name']}'");
- $x->find(true);
- if($x->count() > 0){
- $roo->jerr('is exsiting');
+ if(!($old->etype == $request['etype'] && $old->name == $request['name'])){
+ $x->whereAdd("etype = '{$request['etype']}' AND name = '{$request['name']}'");
+ $x->find(true);
+ if($x->count() > 0){
+ $roo->jerr('is exsiting');
+ }
}
-
}
function beforeInsert($req, $roo)
{
}
+ function fetchAllByType($etype, $fetchArg1=false, $fetchArg2=false, $fetchArg3=false)
+ {
+ $x = DB_DataObject::factory('core_enum');
+ $x->etype = $etype;
+ $x->active = 1;
+ return $x->fetchAll($fetchArg1, $fetchArg2, $fetchArg3);
+ }
+
function lookupObject($etype,$name, $create= false)
{
return false;
}
+ /**
+ * The base enums that the system always needs,
+ * If we need to add modular enums, then this can be extended, and the two
+ * base data applied.
+ *
+ * This might be moved to an external file later? - eg json...
+ *
+ */
+ function baseEnums()
+ {
+ //
+ return array(
+ array(
+ 'etype' => '',
+ 'name' => 'COMPTYPE',
+ 'display_name' => 'Company Types',
+ 'cn' => array(
+ array(
+ 'name' => 'OWNER',
+ 'display_name' => 'Owner',
+ 'seqid' => 999, // last...
+ )
+
+ )
+ )
+ );
+
+
+
+ }
+
+ function initEnums($data, $base = array())
+ {
+
+
+ $seq_id = 0;
+ if (!empty($base['etype'])) {
+ $seq_id = 1;
+ $t = DB_DAtaObject::Factory('core_enum');
+ $t->etype = $base['etype'];
+ $t->selectAdD();
+ $t->selectAdD('max(seqid) as seqid');
+ if ($t->find(true)) {
+ $seq_id = $t->seqid+1;
+ }
+ }
+ foreach($data as $row) {
+ $t = DB_DAtaObject::Factory('core_enum');
+
+ $t->setFrom($row);
+ $t->setFrom($base);
+ unset($t->seqid); // these might have been changed
+ unset($t->display_name); // these might have been changed
+
+
+ if (!$t->find(true))
+ {
+ $t->setFrom($row);
+ $t->setFrom($base);
+
+ if (!empty($base['etype']) && empty($row['seqid'])) {
+ $t->seqid = $seq_id;
+ $seq_id++;
+ }
+ $t->insert();
+ }
+ if (!empty($row['cn'])) {
+ $this->initEnums($row['cn'], array('etype' => $t->name));
+ }
+ }
+
+ }
+
}