Beispiel #1
0
 public function afterConstruct()
 {
     foreach ($this->Language->findAll() as $Language) {
         $modelName = 'Text' . ucFirst($Language->id);
         $this->bind($modelName, 'hasOne', array('class' => 'MediaText', 'foreignKey' => 'media_file_id', 'dependent' => true, 'conditions' => array($modelName . '.language_id' => DBQuery::quote($Language->id))));
         $this->{$modelName}->language_id = $Language->id;
     }
     return parent::afterConstruct();
 }
Beispiel #2
0
 /**
  *	Tests if the user is unique
  * 	@return boolean
  */
 public function isUnique()
 {
     $params = array('conditions' => array('User.email' => DBQuery::quote($this->email)));
     if ($this->exists()) {
         $params['conditions']['User.id <>'] = (int) $this->id;
     }
     if ($doubleUser = $this->find($params)) {
         return false;
     }
     return true;
 }
Beispiel #3
0
 public function similarEntries()
 {
     if (!$this->exists() || $this->Tags->count() == 0) {
         return false;
     }
     $queryFile = dirname(__FILE__) . '/../../console/sql/similarBlogPosts.sql';
     if (!file_exists($queryFile)) {
         return false;
     }
     $tmp = new IndexedArray();
     foreach ($this->Tags as $Tag) {
         $tmp[] = 'Tag.name = ' . DBQuery::quote($Tag->get('name'));
     }
     $tagConditions = $tmp->implode(' OR ');
     $query = sprintf(file_get_contents($queryFile), $tagConditions, $this->id);
     return $this->query($query);
 }
 public function toModel(Model $model, $fields = null, $ignore = null)
 {
     if ($model->behaviors->hasBehavior('Flagable')) {
         if ($this->hasField('allowComments')) {
             $model->setFlag(BlogPostFlag::ALLOW_COMMENTS, $this->allowComments->value());
         }
         if ($this->hasField('sticky')) {
             $model->setFlag(BlogPostFlag::STICKY, $this->sticky->value());
         }
     }
     // saving tags
     $this->Tags = new IndexedArray();
     $tags = array_filter(array_unique(preg_split('/\\s+/i', $this->tags->value())));
     foreach ($tags as $tag) {
         $Tag = new Tag(array('name' => $tag, 'model' => DBQuery::quote($model->name)));
         $Tag->set('BlogPostTag', array('model' => DBQuery::quote($model->name)));
         $model->Tags[] = $Tag;
     }
     return parent::toModel($model, $fields, $ignore);
 }
}
require_once $AppUI->getModuleClass('companies');
global $dPconfig, $canEdit, $stub, $where, $orderby;
$q = new DBQuery();
$q->addTable('users', 'u');
$q->addQuery('DISTINCT(user_id), user_username, contact_last_name, contact_first_name,
	permission_user, contact_email, company_name, contact_company');
$q->addJoin('contacts', 'con', 'user_contact = contact_id');
$q->addJoin('companies', 'com', 'contact_company = company_id');
$q->addJoin('permissions', 'per', 'user_id = permission_user');
$obj = new CCompany();
$companies = $obj->getAllowedRecords($AppUI->user_id, 'company_id,company_name', 'company_name');
if (count($companies) > 0) {
    $companyList = '0';
    foreach ($companies as $k => $v) {
        $companyList .= ', ' . $k;
    }
    $q->addWhere('user_company in (' . $companyList . ')');
}
if ($stub) {
    $q->addWhere("(UPPER(user_username) LIKE '{$stub}%'" . " OR UPPER(contact_first_name) LIKE '{$stub}%'" . " OR UPPER(contact_last_name) LIKE '{$stub}%')");
} else {
    if ($where) {
        $where = $q->quote("%{$where}%");
        $q->addWhere("(UPPER(user_username) LIKE {$where}" . " OR UPPER(contact_first_name) LIKE {$where}" . " OR UPPER(contact_last_name) LIKE {$where})");
    }
}
$q->addOrder($orderby);
$users = $q->loadList();
$canLogin = true;
require DP_BASE_DIR . '/modules/admin/vw_usr.php';
Beispiel #6
0
 function getDepartmentDetails()
 {
     $result = array('dept_id' => 0, 'dept_name' => '');
     if (!$this->contact_department) {
         return $result;
     }
     $sql = "select dept_id, dept_name from departments";
     $q = new DBQuery();
     $q->addTable('departments');
     $q->addQuery('dept_id, dept_name');
     if ($this->is_alpha($this->contact_department)) {
         $q->addWhere('dept_name = ' . $q->quote($this->contact_department));
     } else {
         $q->addWhere("dept_id = '" . $this->contact_department . "'");
     }
     $sql = $q->prepare();
     $q->clear();
     db_loadHash($sql, $result);
     return $result;
 }
Beispiel #7
0
function w2PgetUsersHashList($stub = null, $where = null, $orderby = 'contact_first_name, contact_last_name')
{
    global $AppUI;
    $q = new DBQuery();
    $q->addTable('users');
    $q->addQuery('DISTINCT(user_id), user_username, contact_last_name, contact_first_name,
		 contact_email, company_name, contact_company, dept_id, dept_name, CONCAT(contact_first_name,\' \',contact_last_name) contact_name, user_type');
    $q->addJoin('contacts', 'con', 'contact_id = user_contact', 'inner');
    if ($stub) {
        $q->addWhere('(UPPER(user_username) LIKE \'' . $stub . '%\' or UPPER(contact_first_name) LIKE \'' . $stub . '%\' OR UPPER(contact_last_name) LIKE \'' . $stub . '%\')');
    } elseif ($where) {
        $where = $q->quote('%' . $where . '%');
        $q->addWhere('(UPPER(user_username) LIKE ' . $where . ' OR UPPER(contact_first_name) LIKE ' . $where . ' OR UPPER(contact_last_name) LIKE ' . $where . ')');
    }
    $q->addGroup('user_id');
    $q->addOrder($orderby);
    // get CCompany() to filter by company
    $obj = new CCompany();
    $companies = $obj->getAllowedSQL($AppUI->user_id, 'company_id');
    $q->addJoin('companies', 'com', 'company_id = contact_company');
    if ($companies) {
        $q->addWhere('(' . implode(' OR ', $companies) . ' OR contact_company=\'\' OR contact_company IS NULL OR contact_company = 0)');
    }
    $dpt = new CDepartment();
    $depts = $dpt->getAllowedSQL($AppUI->user_id, 'dept_id');
    $q->addJoin('departments', 'dep', 'dept_id = contact_department');
    if ($depts) {
        $q->addWhere('(' . implode(' OR ', $depts) . ' OR contact_department=0)');
    }
    return $q->loadHashList('user_id');
}
Beispiel #8
0
 /**
  * Tries to find a node by the passed $idOrNodeName
  *	
  * @param integer|string $idOrNodeName
  * @return Node|boolean
  */
 public function findNode($idOrNodeName, $languageId = null)
 {
     $this->depth = 1;
     $languageId = coalesce(@$languageId, I18n::locale());
     if (is_int($idOrNodeName)) {
         $conditions = array('id' => $idOrNodeName);
     } else {
         $conditions = array('NodeText' . ucfirst(substr($languageId, 0, 2)) . '.uri' => DBQuery::quote($idOrNodeName));
     }
     return $this->find(array('conditions' => $conditions));
 }
Beispiel #9
0
 public function getDepartmentDetails()
 {
     $result = array('dept_id' => 0, 'dept_name' => '');
     if (!$this->contact_department) {
         return $result;
     }
     $q = new DBQuery();
     $q->addTable('departments');
     $q->addQuery('dept_id, dept_name');
     if ($this->is_alpha($this->contact_department)) {
         $q->addWhere('dept_name = ' . $q->quote($this->contact_department));
     } else {
         $q->addWhere('dept_id = ' . (int) $this->contact_department);
     }
     return $q->loadHash();
 }
Beispiel #10
0
 public function getModuleByName($name)
 {
     $q = new DBQuery();
     $name = $q->quote($name);
     $q->addTable('modules');
     $q->addQuery('mod_directory');
     $q->addWhere("permissions_item_table = '" . $name . "' OR mod_directory = '" . $name . "'");
     return $q->loadResult();
 }
Beispiel #11
0
 /**
  * Standard search action, searches for a $key $keyword match and lists
  * all matches
  * @deprecated move this to component
  * @param string $keyword
  */
 public function search($q = null, $fields = array())
 {
     $results = new IndexedArray();
     $this->data->set('q', $q);
     if (strlen($q) <= 0 || !isset($this->{$this->name}) || empty($fields)) {
         return $results;
     }
     foreach ($fields as $fieldname) {
         if (strstr($fieldname, '.') == false) {
             $conditions[] = $this->{$this->name}->name . '.' . $fieldname . ' LIKE ' . DBQuery::quote('%' . $q . '%') . ' OR';
         } else {
             $conditions[] = $fieldname . ' LIKE ' . DBQuery::quote('%' . $q . '%') . ' OR';
         }
     }
     $page = isset($this->params['page']) ? $this->params['page'] : 1;
     $pagination = $this->{$this->name}->paginate($page, null, $conditions);
     $pagination['url'] = Router::getRoute(lcfirst($this->name) . 'SearchPaged', array('q' => $q));
     $this->data->set('pagination', $pagination);
     $params = array('conditions' => $conditions, 'offset' => ($page - 1) * $this->{$this->name}->perPage, 'limit' => $this->{$this->name}->perPage);
     $results = $this->{$this->name}->findAll($params);
     $this->data->set(Inflector::pluralize($this->name), $results);
     return $results;
 }