/**
* Table Definition for Companies
*/
-require_once 'DB/DataObject.php';
+class_exists('DB_DataObject') ? '' : require_once 'DB/DataObject.php';
class Pman_Core_DataObjects_Core_Company extends DB_DataObject
{
function applyFilters($q, $au)
{
- $tn = $this->tableName();
+
+ $tn = $this->tableName();
$this->selectAdd("i18n_translate('c' , {$tn}.country, 'en') as country_display_name ");
$tn = $this->tableName();
$x = DB_DataObject::factory('core_company');
$x->comptype= 'OWNER';
$x->find(true);
-
+
if (!empty($q['query']['company_project_id'])) {
$add = '';
if (!empty($q['query']['company_include_self'])) {
if (!empty($q['query']['company_not_self'])) {
$add = " AND {$tn}.id != {$x->id}";
}
+
$pids = array();
$pid = $q['query']['company_project_id'];
if (strpos($pid, ',')) {
$this->whereAddIn('comptype', explode(',', $q['query']['comptype']), 'string');
}
-
+ /*if (!empty($q['query']['deleted_by'])) {
+ $deleted_by = $this->escape($q['query']['deleted_by']);
+ $this->whereAdd("deleted_by = '$deleted_by'");
+ }*/
// depricated - should be moved to module specific (texon afair)
if (!empty($q['query']['province'])) {
) as comptype_display_name
");
- if(!empty($q['search']['name'])){
- $s = $this->escape($q['search']['name']);
+ if(!empty($q['query']['name'])){
+ $s = $this->escape($q['query']['name']);
$this->whereAdd("
{$tn}.name LIKE '%$s%'
");
}
// ---------- AUTHENTICATION
- function isAuth()
+ // not sure where authetnication via company is used?? posibly media-outreach
+
+ function isAuth()
{
$db = $this->getDatabaseConnection();
$sesPrefix = $db->dsn['database'];
function beforeInsert($q, $roo)
{
if(!empty($q['_check_name'])){
- $this->checkName($roo);
+ if($this->checkName()){
+ $roo->jok('OK');
+ }
+
+ $roo->jerr('EXIST');
}
}
function beforeUpdate($old, $q,$roo)
{
+
+ if(!empty($q['_flag_delete']) && $q['_flag_delete'] * 1 == 1){
+ $delete_dt = date('Y-m-d H:i:s');
+ var_dump($old);
+ var_dump($q); die;
+ $this->update();
+ //$roo->query("UPDATE {$old->tableName()} SET deleted_by = {$roo->getAuthUser()} , deleted_dt = {$delete_dt} WHERE id = {$req['_update_id']}");
+ //$this->addEvent("UPDATE", false, "update core_company record");
+ }
if(!empty($q['_check_name'])){
- $this->checkName($roo);
+ if($this->checkName()){
+ $roo->jok('OK');
+ }
+
+ $roo->jerr('EXIST');
}
if(!empty($q['_merge_id'])){
function beforeDelete($req, $roo)
{
+
// should check for members....
if(!empty($this->is_system) &&
($old->code != $this->code || $old->name != $this->name)
){
$roo->jerr('This company is not allow to delete');
}
+
+
+ }
+ function onDelete($req, $roo)
+ {
$img = DB_DataObject::factory('Images');
$img->ontable = $this->tableName();
$img->onid = $this->id;
$companies->insert();
$companies->onInsert(array(), $roo);
}
- function lookupOwner()
+ static function lookupOwner()
{
$enum = DB_DataObject::Factory('core_enum')->lookup('COMPTYPE', 'OWNER' );
$companies = DB_DataObject::factory('core_company');
{
$affects = array();
- $all_links = $GLOBALS['_DB_DATAOBJECT']['LINKS'][$this->_database];
+ $all_links = $this->databaseLinks();
foreach($all_links as $tbl => $links) {
foreach($links as $col => $totbl_col) {
}
- function checkName($roo)
+ function checkName()
{
+ $company = DB_DataObject::factory('core_company');
+ $company->setFrom(array(
+ 'name' => $this->name
+ ));
+ if(!empty($this->id)){
+ $company->whereAdd("id != {$this->id}");
+ }
+
+ if(!$company->find(true)){
+ return true;
+ }
+
+ return false;
}
}