/* the code above is auto generated do not remove the tag below */
###END_AUTOCODE
+
function applyFilters($q, $au)
{
- //DB_DataObject::debugLevel(1);
+// DB_DataObject::debugLevel(1);
if (!empty($q['query']['empty_etype'])) {
$this->whereAdd("etype = ''");
}
+
+ // this should be handled by roo... using '!name[0]' ....
+ if(!empty($q['!name'])){
+ $names = is_array($q['!name']) ? $q['!name'] : explode(',', $q['!name']);
+ foreach($names as $name){
+ $name = $this->escape($name);
+ $this->whereAdd("
+ core_enum.name NOT IN ('$name')
+ ");
+ }
+ }
+ if(!empty($q['search']['display_name'])) {
+ $name = $this->escape($q['search']['display_name']);
+ // ilike on postgres?!?
+ $this->whereAdd("
+ core_enum.display_name LIKE '{$name}%'
+ ");
+
+ }
+
+// print_r($this);
+ if(!empty($q['id'])){
+ $this->id = $q['id'];
+ }
+
}
- function onUpdate($old, $req)
+ function autoJoinCmsTranslate($lang)
{
- $x = $this->factory($this->tableName());
- $x->query("SELECT core_enum_seqmax_update('". $this->escape($this->etype) ."')");
- if ($old->etype != $this->etype) {
- $x->query("SELECT core_enum_seqmax_update('". $this->escape($old->etype) ."')");
+ $l = $this->escape($lang);
+
+ $this->_join .= "
+ LEFT JOIN
+ cms_templatestr
+ ON
+ cms_templatestr.lang = '$l'
+ AND
+ cms_templatestr.on_table = 'core_enum'
+ AND
+ cms_templatestr.on_id = core_enum.id
+ AND
+ cms_templatestr.on_col = 'display_name'
+ ";
+
+ $this->selectAdd("
+ CASE WHEN
+ '$l' = 'en' THEN display_name
+ ELSE
+ CASE WHEN cms_templatestr.txt IS NOT NULL AND cms_templatestr.txt != '' THEN
+ cms_templatestr.txt
+ ELSE
+ display_name
+ END
+ END as display_name_tr
+ ");
+
+ }
+
+ 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 beforeUpdate($old, $request,$roo)
{
$tn = $this->tableName();
}
}
}
+
function onInsert($req)
{
$x = $this->factory($this->tableName());
- $x->query("SELECT core_enum_seqmax_update('". $this->escape($this->etype) ."')");
+ $x->query("SELECT core_enum_seqmax_update('". $this->escape($this->etype) ."')"); // no idea why need to do this!!??
}
+ function onUpdate($old, $req)
+ {
+ $x = $this->factory($this->tableName());
+ $x->query("SELECT core_enum_seqmax_update('". $this->escape($this->etype) ."')"); // no idea why need to do this!!??
+ if ($old->etype != $this->etype) {
+ $x->query("SELECT core_enum_seqmax_update('". $this->escape($old->etype) ."')");
+ }
+ }
+ /**
+ * lookup by etype/name and return id
+ */
function lookup($etype,$name) {
$ce = DB_DataObject::Factory('core_enum');
$ce->etype = $etype;
return $ce->id;
}
return 0;
+ }
+
+
+ function lookupById($id) {
+ $ce = DB_DataObject::Factory('core_enum');
+ $ce->get($id);
+ return $ce;
+ }
+
+ /**
+ *
+ *
+ *
+ * @param string $etype
+ * @param array $name array of name
+ * @return array ID of core_enum
+ */
+
+ function lookupAllByName($etype,$names) {
+ $ce = DB_DataObject::Factory('core_enum');
+ $ce->etype = $etype;
+ $ce->whereAddIn('name', $names, 'string');
+ if ($ce->count() > 0) {
+ return $ce->fetchAll('id');
+ }
+ return array();
+ }
+
+ function fetchAllByType($etype, $fetchArg1=false, $fetchArg2=false, $fetchArg3=false)
+ {
+ $x = DB_DataObject::factory('core_enum');
+ $x->etype = $etype;
+ $x->active = 1;
+ $x->orderBy('seqid ASC');
+ 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()
+ // fixme - all calls should be to initDatabase, we need to remove initEnums
+ function initDatabase($roo, $data)
{
- //
- return array(
- array(
- 'etype' => '',
- 'name' => 'company_type',
- 'display_name' => 'Company Types',
- 'cn' => array(
- array(
- 'name' => 'OWNER',
- 'display_name' => 'Owner',
- 'seqid' => 999, // last...
- )
-
- )
- )
- );
-
-
-
+ $this->initEnums($data);
}
- function initEnums($data = false, $base = array())
+
+ function initEnums($data, $base = array())
{
- DB_DataObject::DebugLevel(1);
- if ($data === false) {
- $this->initEnums($this->baseEnums());
- return;
+ // base only contains etype...
+ //print_r($data);
+ $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');
- print_r(array_merge($base, $row ));
- $t->setFrom(array_merge($base, $row ));
- echo '<PRE>';print_r($t);
+ $t->etype = isset($row['etype']) ? $row['etype'] : '';
+ $t->etype = isset($base['etype']) ? $base['etype'] : $t->etype ;
+
+ $t->name = isset($row['name']) ? $row['name'] : '';
- if (!$t->find(true)) {
+ if (empty($t->name)) {
+ print_R($data);
+ die("ERROR: invalid name used for core_enum\n\n");
+ }
+
+ if (!$t->count()) {
+ // base already gave it the etype..
+ $t->setFrom($row);
+
+
+ //$t->is_system_enum = 1; // this should be on the caller..
+
+ if (!empty($row['seqid'])) {
+ $t->seqid = $seq_id;
+ $seq_id++;
+ }
+
$t->insert();
+ }else{
+ $t->find(true); // fetch it..
+ if ( isset($row['is_system_enum'])) {
+ $t->is_system_enum = isset($row['is_system_enum']) ? $row['is_system_enum'] : $t->is_system_enum;
+
+ $t->update();
+ }
}
if (!empty($row['cn'])) {
- $this->initEnums($row['cn'], array('etype', $t->name));
+ $this->initEnums($row['cn'], array('etype' => $t->name));
}
}