public function __get($var)
 {
     switch ($var) {
         case 'chat':
             $this->chat = false;
             if ($this->chat_id > 0) {
                 try {
                     $this->chat = erLhcoreClassModelChat::fetch($this->chat_id);
                 } catch (Exception $e) {
                     erLhcoreClassChatbox::getSession()->delete($this);
                 }
             } else {
                 $this->chat = new erLhcoreClassModelChat();
                 $this->chat->hash = erLhcoreClassChat::generateHash();
             }
             return $this->chat;
             break;
         default:
             break;
     }
 }
Ejemplo n.º 2
0
 public static function getCount($params = array(), $table = 'lh_chatbox', $operation = 'COUNT(id)')
 {
     $session = erLhcoreClassChatbox::getSession();
     $q = $session->database->createSelectQuery();
     $q->select($operation)->from($table);
     $conditions = array();
     if (isset($params['filter']) && count($params['filter']) > 0) {
         foreach ($params['filter'] as $field => $fieldValue) {
             $conditions[] = $q->expr->eq($field, $q->bindValue($fieldValue));
         }
     }
     if (isset($params['filterin']) && count($params['filterin']) > 0) {
         foreach ($params['filterin'] as $field => $fieldValue) {
             $conditions[] = $q->expr->in($field, $fieldValue);
         }
     }
     if (isset($params['filterlt']) && count($params['filterlt']) > 0) {
         foreach ($params['filterlt'] as $field => $fieldValue) {
             $conditions[] = $q->expr->lt($field, $q->bindValue($fieldValue));
         }
     }
     if (isset($params['filtergt']) && count($params['filtergt']) > 0) {
         foreach ($params['filtergt'] as $field => $fieldValue) {
             $conditions[] = $q->expr->gt($field, $q->bindValue($fieldValue));
         }
     }
     if (isset($params['customfilter']) && count($params['customfilter']) > 0) {
         foreach ($params['customfilter'] as $fieldValue) {
             $conditions[] = $fieldValue;
         }
     }
     if (count($conditions) > 0) {
         $q->where($conditions);
     }
     if (isset($params['use_index'])) {
         $q->useIndex($params['use_index']);
     }
     $stmt = $q->prepare();
     $stmt->execute();
     $result = $stmt->fetchColumn();
     return $result;
 }