Example #1
0
 /**
  * @param CM_Model_Language $language
  * @param string|null       $searchPhrase
  * @param string|null       $section
  * @param bool|null         $translated
  * @param bool|null         $javascriptOnly
  */
 public function __construct(CM_Model_Language $language, $searchPhrase = null, $section = null, $translated = null, $javascriptOnly = null)
 {
     $this->_language = $language;
     $where = array();
     $parameters = array();
     if ($searchPhrase) {
         $where[] = '(k.name LIKE ? OR v.value LIKE ?)';
         $parameters[] = '%' . $searchPhrase . '%';
         $parameters[] = '%' . $searchPhrase . '%';
     }
     if ($section) {
         $where[] = 'k.name LIKE ?';
         $parameters[] = $section . '%';
     }
     if ($translated === true) {
         $where[] = 'v.value IS NOT NULL';
     }
     if ($translated === false) {
         $where[] = 'v.value IS NULL';
     }
     if ($javascriptOnly) {
         $where[] = 'k.javascript = 1';
     }
     $orderBy = 'k.name ASC';
     $join = 'LEFT JOIN `cm_languageValue` AS v ON k.id = v.languageKeyId AND v.languageId = ' . $this->_language->getId() . ' ';
     $groupBy = 'BINARY k.name';
     $source = new CM_PagingSource_Sql_Deferred('k.name AS `key`, v.value, k.variables', 'cm_model_languagekey` as `k', implode(' AND ', $where), $orderBy, $join, $groupBy, $parameters);
     parent::__construct($source);
 }
Example #2
0
 /**
  * @param array            $filterLevelList
  * @param int|boolean|null $filterType
  * @param boolean|null     $aggregate
  * @param int|null         $ageMax
  * @throws CM_Exception_Invalid
  */
 public function __construct(array $filterLevelList = null, $filterType = null, $aggregate = null, $ageMax = null)
 {
     if (null !== $filterLevelList) {
         foreach ($filterLevelList as $level) {
             $level = (int) $level;
             if (!CM_Log_Logger::hasLevel($level)) {
                 throw new CM_Exception_Invalid('Log level does not exist.', null, ['level' => $level]);
             }
         }
     }
     if (null !== $filterType && false !== $filterType && !self::isValidType((int) $filterType)) {
         throw new CM_Exception_Invalid('Type is not a children of CM_Paging_Log.');
     }
     if (null !== $ageMax) {
         $ageMax = (int) $ageMax;
     }
     $this->_filterLevelList = $filterLevelList;
     $this->_filterType = $filterType;
     $this->_ageMax = $ageMax;
     $criteria = $this->_getCriteria();
     if (true === $aggregate) {
         $aggregate = [['$match' => $criteria], ['$group' => ['_id' => ['level' => '$level', 'message' => '$message', 'exception_message' => '$context.exception.message', 'exception_class' => '$context.exception.class', 'exception_line' => '$context.exception.line', 'exception_file' => '$context.exception.file'], 'count' => ['$sum' => 1], 'createdAt' => ['$max' => '$createdAt'], 'exception' => ['$last' => '$context.exception']]], ['$sort' => ['count' => -1]], ['$project' => ['level' => '$_id.level', 'message' => '$_id.message', 'exception' => '$exception', 'count' => '$count', 'createdAt' => '$createdAt', '_id' => false]]];
         $source = new CM_PagingSource_MongoDb(self::COLLECTION_NAME, null, null, $aggregate);
     } else {
         $sorting = empty($criteria) ? ['_id' => -1] : ['createdAt' => -1];
         $source = new CM_PagingSource_MongoDb(self::COLLECTION_NAME, $criteria, null, null, $sorting);
     }
     parent::__construct($source);
 }
Example #3
0
 /**
  * @param int $type
  */
 public function __construct($type)
 {
     $this->_type = (int) $type;
     $source = new CM_PagingSource_Sql_Deferred('string', 'cm_string', '`type`=' . $this->_type, 'string ASC');
     $source->enableCache();
     parent::__construct($source);
 }
Example #4
0
 /**
  * @param CM_PagingSource_Array|array $source
  * @throws CM_Exception_Invalid
  */
 public function __construct($source)
 {
     if (is_array($source)) {
         $source = new CM_PagingSource_Array($source);
     }
     if (!$source instanceof CM_PagingSource_Array) {
         throw new CM_Exception_Invalid('CM_Paging_List should be instantiated with either an array or CM_PagingSource_Array instance.');
     }
     parent::__construct($source);
 }
Example #5
0
 /**
  * @param boolean $aggregate
  * @param int     $ageMax
  */
 public function __construct($aggregate = false, $ageMax = null)
 {
     $select = '`id`, `msg`, `timeStamp`, `metaInfo`';
     $where = '`type` = ' . $this->getType();
     $order = '`timeStamp` DESC';
     $group = null;
     if ($ageMax) {
         $where .= ' AND `timeStamp` > ' . (time() - (int) $ageMax);
     }
     if ($aggregate) {
         $select = '`msg`, COUNT(*) AS `count`';
         $group = '`msg`';
         $order = '`count` DESC';
     }
     $source = new CM_PagingSource_Sql_Deferred($select, 'cm_log', $where, $order, null, $group);
     parent::__construct($source);
 }
Example #6
0
 public function __construct()
 {
     $source = new CM_PagingSource_Sql('`id`, `num`', 'test_b');
     parent::__construct($source);
 }