public function afterExecution() { //report execution time in header (not in response body, that will ruin the etag) $this->response->setHttpHeader('Ls-Execution-Time', LsApi::getResponseTime()); // Etag support if (sfConfig::get('sf_etag')) { $etag = '"' . md5($this->response->getContent()) . '"'; $this->response->setHttpHeader('ETag', $etag); if ($this->request->getHttpHeader('IF_NONE_MATCH') == $etag) { $this->response->setStatusCode(304); $this->response->setHeaderOnly(true); if (sfConfig::get('sf_logging_enabled')) { $this->context->getEventDispatcher()->notify(new sfEvent($this, 'application.log', array('ETag matches If-None-Match (send 304)'))); } } } // conditional GET support // never in debug mode if ($this->response->hasHttpHeader('Last-Modified') && !sfConfig::get('sf_debug')) { $last_modified = $this->response->getHttpHeader('Last-Modified'); if ($this->request->getHttpHeader('IF_MODIFIED_SINCE') == $last_modified) { $this->response->setStatusCode(304); $this->response->setHeaderOnly(true); if (sfConfig::get('sf_logging_enabled')) { $this->context->getEventDispatcher()->notify(new sfEvent($this, 'application.log', array('Last-Modified matches If-Modified-Since (send 304)'))); } } } }
static function getRelationships($ids, $options) { $db = Doctrine_Manager::connection(); $sql = 'SELECT ' . LsApi::generateSelectQuery(array('r' => 'Relationship')) . ' FROM relationship r WHERE r.id IN (' . implode(',', $ids) . ')'; $stmt = $db->execute($sql); if (@$options['details']) { $rels = array(); if ($catId = @$options['cat_id']) { //make Relationships accessible by id foreach ($stmt->fetchAll(PDO::FETCH_ASSOC) as $rel) { $rels[$rel['id']] = $rel; } //get category data $categoryName = RelationshipCategoryTable::$categoryNames[$catId]; $db = Doctrine_Manager::connection(); $sql = 'SELECT * FROM ' . Doctrine_Inflector::tableize($categoryName) . ' WHERE relationship_id IN (' . implode(',', $ids) . ')'; $stmt = $db->execute($sql, array($id)); //merge category data with relationship data foreach ($stmt->fetchAll(PDO::FETCH_ASSOC) as $row) { $relId = $row['relationship_id']; unset($row['id'], $row['relationship_id']); $rels[$relId] = array_merge($rels[$relId], $row); } return array_values($rels); } else { foreach ($stmt->fetchAll(PDO::FETCH_ASSOC) as $rel) { $rels[] = array_merge($rel, RelationshipApi::getDetails($rel['id'], $rel['category_id'])); } return $rels; } } else { return $stmt->fetchAll(PDO::FETCH_ASSOC); } }
static function getReferences($id) { $db = Doctrine_Manager::connection(); $select = LsApi::generateSelectQuery(array('r' => 'Reference')); $sql = 'SELECT ' . $select . ' FROM reference r WHERE r.object_model = ? AND r.object_id = ?'; $stmt = $db->execute($sql, array('Relationship', $id)); return $stmt->fetchAll(PDO::FETCH_ASSOC); }
public function executeEntitiesWithOrgs($request) { $this->setResponseFormat(array('xml', 'json')); $options = $this->getParams(array('is_current', 'num', 'page')); $results = LsListApi::getEntitiesWithOrgs($this->list['id'], $options); $this->entities = LsApi::sliceArrayFromOptions($results, $options, $defaultNum = 100); $this->getResponse()->setSlot('total', count($results)); return 'Xml'; }
static function getLists($options = array()) { $q = Doctrine_Query::create()->select('DISTINCT l.*, COUNT(le.id) AS num_entities')->from('LsList l')->leftJoin('l.LsListEntity le')->groupBy('l.id')->orderBy('num_entities DESC')->setHydrationMode(Doctrine::HYDRATE_ARRAY); $q = LsApi::setPagingFromOptions($q, $options, $defaultNum = 100, $maxNum = 100); if ($text = @$options['q']) { $q->addWhere('l.name LIKE ? OR l.description LIKE ?', array('%' . $text . '%', '%' . $text . '%')); } return $q->execute(); }
public function getConnections($db, $num = 5, $primary_ext = null) { $params = array($this->id); $select = LsApi::generateSelectQuery(array('e' => 'Entity')) . ', COUNT(l.id) AS num'; $from = 'link l LEFT JOIN entity e ON (l.entity2_id = e.id)'; $where = 'l.entity1_id = ?'; if ($primary_ext) { $where .= ' AND e.primary_ext = ?'; array_push($params, $primary_ext); } $sql = 'SELECT ' . $select . ' FROM ' . $from . ' WHERE ' . $where . ' GROUP BY l.entity2_id ORDER BY num DESC LIMIT ' . $num; $stmt = $db->execute($sql, $params); $this->connections = $stmt->fetchAll(PDO::FETCH_ASSOC); }
public function executeEntities($request) { $options = $this->getParams(array('q', 'type_ids', 'num', 'page', 'list_ids', 'search_all')); $result = SearchApi::getEntities($options); $this->entities = array(); if ($result['total_found'] > 0 && isset($result['matches'])) { $db = Doctrine_Manager::connection(); $ids = array_keys($result['matches']); $tmp = array(); $select = LsApi::generateSelectQuery(array('e' => 'Entity')); $from = 'entity e'; $where = 'e.id IN (' . implode(',', $ids) . ') AND e.is_deleted = 0'; $sql = 'SELECT ' . $select . ' FROM ' . $from . ' WHERE ' . $where . ' ORDER BY FIELD(e.id, ' . implode(',', $ids) . ')'; $stmt = $db->execute($sql); $this->entities = $stmt->fetchAll(PDO::FETCH_ASSOC); } $this->getResponse()->setSlot('total', $result['total_found']); return 'Xml'; }
static function getSecondDegreeNetwork($id, $options = array(), $countOnly = false) { $db = Doctrine_Manager::connection(); $select = LsApi::generateSelectQuery(array('e2' => 'Entity')) . ', GROUP_CONCAT(DISTINCT l.entity1_id) degree1_ids, COUNT(DISTINCT l.entity1_id) degree1_num, SUM(r.amount) degree1_total'; $from = 'ls_list_entity le ' . 'LEFT JOIN link l ON (l.entity1_id = le.entity_id) ' . 'LEFT JOIN relationship r ON (r.id = l.relationship_id) ' . 'LEFT JOIN entity e1 ON (e1.id = l.entity1_id) ' . 'LEFT JOIN entity e2 ON (e2.id = l.entity2_id)'; if ($order = @$options['order']) { $isReverse = (int) ($order == 2); $where = 'le.list_id = ? AND le.is_deleted = 0 AND l.is_reverse = ? AND e1.is_deleted = 0 AND e2.is_deleted = 0'; $params = array($id, $isReverse); } else { $where = 'le.list_id = ? AND le.is_deleted = 0 AND e1.is_deleted = 0 AND e2.is_deleted = 0'; $params = array($id); } if ($catIds = @$options['cat_ids']) { if (count(explode(',', $catIds)) == 1) { $where .= ' AND l.category_id = ?'; $params[] = $catIds; } else { $where .= ' AND l.category_id IN (' . $catIds . ')'; } } if ($degree1Type = @$options['degree1_type']) { $where .= ' AND e1.primary_ext = ?'; $params[] = $degree1Type; } if ($degree2Type = @$options['degree2_type']) { $where .= ' AND e2.primary_ext = ?'; $params[] = $degree2Type; } if ($countOnly) { $sql = 'SELECT COUNT(DISTINCT l.entity2_id) FROM ' . $from . ' WHERE ' . $where; } else { $paging = LsApi::getPagingFromOptions($options, $defaultNum = 10, $maxNum = 20); $sql = 'SELECT ' . $select . ' FROM ' . $from . ' WHERE ' . $where . ' GROUP BY e2.id ORDER BY ' . (@$options['sort'] == 'amount' ? 'degree1_total DESC, degree1_num DESC' : 'degree1_num DESC, degree1_total DESC') . ' ' . $paging; } $stmt = $db->execute($sql, $params); if ($countOnly) { return $stmt->fetchColumn(); } return $stmt->fetchAll(PDO::FETCH_ASSOC); }
static function getChildOrgs($id) { $db = Doctrine_Manager::connection(); $select = LsApi::generateSelectQuery(array('e' => 'Entity')); $sql = 'SELECT ' . $select . ' FROM entity e WHERE e.parent_id = ?'; $stmt = $db->execute($sql, array($id)); return $stmt->fetchAll(PDO::FETCH_ASSOC); }
<?php ob_start(); echo '<?xml version="1.0" encoding="UTF-8"?>' . "\n"; ?> <Response> <Meta> <ExecutionTime><?php echo LsApi::getResponseTime(); ?> </ExecutionTime> </Meta> <Data> <?php echo $sf_content; ?> </Data> </Response> <?php $xml = ob_get_contents(); ob_end_clean(); echo Zend_Json::fromXml($xml);
public function executeRelationshipReferences($request) { $options = $this->getParams(array('cat_ids', 'order', 'num', 'page')); //get full results, then limit $results = EntityApi::getRelationshipReferences($this->entity['id'], $options); $this->rels = LsApi::sliceArrayFromOptions($results, $options, $defaultNum = null, $maxNum = null); $this->getResponse()->setSlot('total', count($results)); return 'Xml'; }
<Entities> <?php foreach ($entities as $entity) { ?> <?php echo LsDataFormat::toXml(LsApi::filterResponseFields($entity, 'Entity'), 'Entity'); } ?> </Entities> <?php slot('num_results', array('Entities' => count($entities)));
<Lists> <?php foreach ($lists as $list) { ?> <List> <?php $num = $list['num_entities']; ?> <?php echo LsDataFormat::toXml(LsApi::filterResponseFields($list, 'LsList')); ?> <num_entities><?php echo $num; ?> </num_entities> </List> <?php } ?> </Lists> <?php slot('num_results', array('Lists' => count($lists)));