private function loadAll($structureDo, $query) { $aContents = $this->_loadAll($structureDo); // Purge to limits $limits = $query->getLimits(); $limits->setTotal(count($aContents)); $contents = new ContentsDo(); $contents->loadFromArray(array_slice($aContents, $limits->getLower(), $limits->getUpper()), $structureDo); $contents->setLimits($limits); //d("FER", $aContents, $limits, $contents); return $contents; }
private function loadEditorSearch($structureDo, $query) { //db.content.find({"id_structure": "item_mosaico", "title" : /.*quinto.*/i}).pretty() //db.getCollection('content').find({$or : [{"alias_id" : "dos"}, {"title" : "dos"}, {"tags" : [{$in : 'dos'}]}], 'id_structure' : 'unimongo'}) $filter = array(); $stringFilter = array(); if (isset($query->getCondition()['title'])) { $search = $query->getCondition()['title']; $stringFilter[] = array('title' => array('$regex' => new \MongoRegex("/^.*{$search}.*/i"))); $stringFilter[] = array('alias_id' => array('$regex' => new \MongoRegex("/^.*{$search}.*/i"))); $stringFilter[] = array('tags' => array('$in' => array($search))); $filter['$or'] = $stringFilter; } if (isset($query->getCondition()['idStructure'])) { $filter['id_structure'] = $query->getCondition()['idStructure']; } if (!$this->isInitialized($structureDo)) { $this->initialize($structureDo); } // Set pagination limits $limits = $query->getLimits(); $mongoCollection = $this->db->selectCollection('content'); $cursor = $mongoCollection->find($filter); $cursor->sort(array('_id' => -1))->skip($limits->getLower())->limit($limits->getUpper() - $limits->getLower()); // Limits $limits->setTotal($cursor->count()); $result = new ContentsDo(); foreach ($cursor as $documentFound) { $documentFound = $this->normalizeDocument($documentFound); $contentFound = new ContentDo(); $contentFound->load($documentFound, $structureDo); $result->add($contentFound, $documentFound['id']); } $result->setLimits($limits); return $result; }
private function loadEditorSearch($structureDo, $query) { // SELECT id, title, data FROM content WHERE id_structure = 'directo' AND title LIKE '%foo%'; // SELECT distinct c.id as id, title, data FROM content as c, content_tag as ct WHERE // (title LIKE '%zzz%' OR alias_id LIKE '%zzz%' OR // (ct.tag = 'zzz' AND c.id = ct.id)) AND c.id_structure = 'una_mysql' LIMIT 0, 20" // Set pagination limits $limits = $query->getLimits(); $limitLower = $limits->getLower(); $limitUpper = $limits->getUpper(); $filter = array(); if (isset($query->getCondition()['title'])) { $search = $this->mysqli->real_escape_string($query->getCondition()['title']); $filter['title'] = "(title LIKE '%" . $search . "%' OR alias_id LIKE '%" . $search . "%' OR (ct.tag = '{$search}' AND c.id = ct.id))"; } if (isset($query->getCondition()['idStructure'])) { $search = $this->mysqli->real_escape_string($query->getCondition()['idStructure']); $filter['id_structure'] = "id_structure = '" . $search . "'"; } $where = ''; if ($filter) { $whereCondition = 'FROM content as c, content_tag as ct WHERE ' . implode(' AND ', $filter); } $select = "SELECT distinct c.id as id, title, data {$whereCondition} LIMIT {$limitLower}, {$limitUpper}"; $selectCount = "SELECT count(distinct c.id) as total {$whereCondition}"; $result = new ContentsDo(); if ($dbResult = $this->mysqli->query($select)) { while ($obj = $dbResult->fetch_object()) { $documentFound = array(); $documentFound['id'] = $obj->id; $documentFound['title'] = $obj->title; $documentFound['data'] = unserialize($obj->data); $contentFound = new ContentDo(); $contentFound->load($documentFound, $structureDo); $result->add($contentFound, $obj->id); } /* free result set */ $dbResult->close(); } $dbResult = $this->mysqli->query($selectCount); $data = $dbResult->fetch_assoc(); $limits->setTotal($data['total']); $result->setLimits($limits); return $result; }