public function run() { $whereGeo = array(); //$this->getGeoQuery($_POST); $where = array('geo' => array('$exists' => true)); $where = array_merge($where, $whereGeo); $events = PHDB::find(PHType::TYPE_EVENTS, $where); foreach ($events as $event) { //dans le cas où un événement n'a pas de position geo, //on lui ajoute grace au CP //il sera visible sur la carte au prochain rechargement if (!isset($event["geo"])) { $cp = $event["location"]["address"]["addressLocality"]; $queryCity = array("cp" => strval(intval($cp)), "geo" => array('$exists' => true)); $city = Yii::app()->mongodb->cities->findOne($queryCity); //->limit(1) if ($city != null) { $newPos = array('geo' => array("@type" => "GeoCoordinates", "longitude" => floatval($city['geo']['coordinates'][0]), "latitude" => floatval($city['geo']['coordinates'][1])), 'geoPosition' => $city['geo']); Yii::app()->mongodb->events->update(array("_id" => $event["_id"]), array('$set' => $newPos)); } } } $events["origine"] = "ShowLocalEvents"; Rest::json($events); Yii::app()->end(); }
public function run() { //récupère seulement les citoyens qui ont un nom et une position géo $users = PHDB::find(PHType::TYPE_CITOYEN); Rest::json($users); Yii::app()->end(); }
public static function buildMenuChildren($collection) { $menu = array(); $cols = PHDB::find($collection); foreach ($cols as $e) { array_push($menu, array("label" => $e["name"], "href" => Yii::app()->createUrl("/" . $e["key"]))); } return $menu; }
public function run() { //récupère seulement les citoyens qui ont un code postal (et une position geo) $where = array('cp' => array('$exists' => true), 'geo' => array('$exists' => true), 'geo.latitude' => array('$gt' => floatval($_POST['latMinScope']), '$lt' => floatval($_POST['latMaxScope'])), 'geo.longitude' => array('$gt' => floatval($_POST['lngMinScope']), '$lt' => floatval($_POST['lngMaxScope']))); $users = PHDB::find(PHType::TYPE_CITOYEN, $where); $users["origine"] = "getCommunected"; Rest::json($users); Yii::app()->end(); }
/** * Retrieve a lists of list by name * @param array $listNames List of * @return array List of list */ public static function get($listNames) { $lists = PHDB::find(self::COLLECTION, array("name" => array('$in' => $listNames)), array("name", "list")); $res = array(); foreach ($lists as $key => $value) { $res[$value["name"]] = $value["list"]; } return $res; }
public function run() { $whereGeo = $this->getGeoQuery($_POST, 'geo'); $where = array('type' => "company"); $where = array_merge($where, $whereGeo); $companies = PHDB::find(Organization::COLLECTION, $where); $companies["origine"] = "ShowLocalCompanies"; Rest::json($companies); Yii::app()->end(); }
public function run() { $whereGeo = SIG::getGeoQuery($_POST, 'geo'); $where = array(); //'cp' => array( '$exists' => true )); $where = array_merge($where, $whereGeo); $citoyens = PHDB::find(PHType::TYPE_CITOYEN, $where); $citoyens["origine"] = "ShowMyNetwork"; Rest::json($citoyens); Yii::app()->end(); }
public function run($filter = null) { $query = array("name" => new MongoRegex("/" . $_POST['name'] . "/i")); $res = array(); if (strcmp($filter, Person::COLLECTION) != 0) { $allCitoyen = PHDB::find(PHType::TYPE_CITOYEN, $query, array("name")); foreach ($allCitoyen as $key => $value) { $profil = Document::getLastImageByKey($key, Person::COLLECTION, Document::IMG_PROFIL); if ($profil != "") { $value["imagePath"] = $profil; } $allCitoyen[$key] = $value; } $res["citoyen"] = $allCitoyen; } if (strcmp($filter, Organization::COLLECTION) != 0) { $allOrganizations = PHDB::find(Organization::COLLECTION, $query, array("name", "type")); foreach ($allOrganizations as $key => $value) { $profil = Document::getLastImageByKey($key, Organization::COLLECTION, Document::IMG_PROFIL); if ($profil != "") { $value["imagePath"] = $profil; } $allOrganizations[$key] = $value; } $res["organization"] = $allOrganizations; } if (strcmp($filter, Event::COLLECTION) != 0) { $allEvents = PHDB::find(PHType::TYPE_EVENTS, $query, array("name")); foreach ($allEvents as $key => $value) { $profil = Document::getLastImageByKey($key, Event::COLLECTION, Document::IMG_PROFIL); if ($profil != "") { $value["imagePath"] = $profil; } $allEvents[$key] = $value; } $res["event"] = $allEvents; } if (strcmp($filter, Project::COLLECTION) != 0) { $allProject = PHDB::find(Project::COLLECTION, $query, array("name")); foreach ($allProject as $key => $value) { $profil = Document::getLastImageByKey($key, Project::COLLECTION, Document::IMG_PROFIL); if ($profil != "") { $value["imagePath"] = $profil; } $allProject[$key] = $value; } $res["project"] = $allProject; } Rest::json($res); Yii::app()->end(); }
/** * get Entries from a collection and converts ID and applies a dummyData field for easy export and remove * @param type $type * @param type $where * @return type */ public static function getByAttributeForExport($type, $where) { $list = PHDB::find($type, $where); if ($list) { $res = array(); foreach ($list as $key => $value) { $value["_id"] = array('$oid' => (string) $value["_id"]); $value["dummyData"] = "myData." . Yii::app()->session["userId"]; unset($value["_id"]['$id']); array_push($res, $value); } return $res; } }
public function run() { $where = array('_id' => new MongoId(Yii::app()->session["userId"])); $user = PHDB::find(PHType::TYPE_CITOYEN, $where); //si l'utilisateur connecté n'a pas enregistré sa position geo //on prend la position de son CP foreach ($user as $me) { if (!isset($me["geo"]) && isset($me["cp"])) { $res = array(Yii::app()->session["userId"] => SIG::getGeoPositionByCp($me["cp"])); Rest::json($res); Yii::app()->end(); } } Rest::json($user); Yii::app()->end(); }
public function run() { //début de la requete => scope geographique $where = array('geo' => array('$exists' => true)); //rajoute les filtres choisi dans le panel (seulement s'il y a au moins 1 filtre selectionné) if (isset($_POST['types'])) { //TAG = TYPE = "citoyen,pixelActif,partnerPH,commune,association,projectLeader $where['type'] = array('$in' => $_POST['types']); } else { Rest::json(array("result" => "Aucun résultat")); Yii::app()->end(); } $users = PHDB::find(PHType::TYPE_CITOYEN, $where); $users["origine"] = "getPixelActif"; Rest::json($users); Yii::app()->end(); }
public static function removeNotificationsByUser() { try { $userNotifcations = PHDB::find(PHType::TYPE_ACTIVITYSTREAM, array("notify.id" => Yii::app()->session["userId"])); foreach ($userNotifcations as $key => $value) { if (count($value["notify"]["id"]) == 1) { PHDB::update(PHType::TYPE_ACTIVITYSTREAM, array("_id" => $value["_id"]), array('$unset' => array("notify" => true))); } else { PHDB::update(PHType::TYPE_ACTIVITYSTREAM, array("_id" => $value["_id"]), array('$pull' => array("notify.id" => Yii::app()->session["userId"]))); } } /*PHDB::updateWithOptions( PHType::TYPE_ACTIVITYSTREAM, array("notify.id" => Yii::app()->session["userId"] ), array('$pull' => array( "notify.id" => Yii::app()->session["userId"] )), array("multi"=>1));*/ $res = array("result" => true, "msg" => "Removed succesfully"); } catch (Exception $e) { $res = array("result" => false, "msg" => "Something went wrong :" . $e->getMessage()); } return $res; }
public function run() { $params = $_POST; $where = isset($params["where"]) ? $params["where"] : array(); $fields = isset($params["fields"]) ? $params["fields"] : null; if (isset($where["_id"])) { $where["_id"] = new MongoId($where["_id"]); } if (!isset($params["count"])) { if ($fields) { $res = PHDB::find($_POST['collection'], $where, $fields); } else { $res = PHDB::find($_POST['collection']); } } else { $res = array('count' => PHDB::countWFileds($_POST['collection'], $where, $fields)); } //$res["where"]=$where; Rest::json($res); Yii::app()->end(); }
<?php $cs = Yii::app()->getClientScript(); $cs->registerScriptFile(Yii::app()->request->baseUrl . '/js/api.js', CClientScript::POS_END); $this->pageTitle = "Convert RDF instance to Formatted Json Schema"; ?> <h1> Convert RDF instance to Formatted Json Schema </h1> <div class="fl col-md-6"> Get Existing Microformats <select id="getMicroformat"> <option></option> <?php $microformats = PHDB::find(PHType::TYPE_MICROFORMATS, array(), array("key")); foreach ($microformats as $u) { echo '<option value="' . $u["_id"] . '">' . $u["key"] . '</option>'; } ?> </select> <br/> <a class="btn btn-primary " href="javascript:getMicroformat()">Get Json</a> <a class="btn btn-primary hide showBtn" href="javascript:showForm()">Show Form</a> </div> <div class="fl col-md-6" id="getMicroformatSection"> Get An Ontology<br/> TODO : import all schemas <br/> TODO : list all ontologies in select <br/> TODO : and build a sample instance <br/> TODO : microformat builder checkbox interface of all field of an ontology<br/> <select id="getOntology"></select>
<div class="apiForm addAdminEntry"> <select id="citizenaddAdmin"> <option></option> <?php $users = PHDB::find(PHType::TYPE_CITOYEN, array("applications." . $this->module->id => array('$exists' => true))); foreach ($users as $u) { echo '<option value="' . $u["_id"] . '">' . (isset($u["email"]) ? $u["email"] : $u["_id"]) . " " . '</option>'; } ?> </select><br/> <select id="rightaddAdmin"> <option></option> <option value="admin">admin</option> </select><br/> <a class="btn" href="javascript:addAdminEntry()">Test it</a><br/> <div id="addAdminEntryResult" class="result fss"></div> <script> function addAdminEntry(){ params = { "id" : $("#citizenaddAdminEntry").val() , "app" : "<?php echo $this->module->id; ?> "}; ajaxPost("addAdminEntryResult",baseUrl+'/<?php echo $this->module->id; ?> /api/addappadmin',params); } </script> </div>
<div class="apiForm deleteEntry"> <select id="sessiondeleteEntry"> <option></option> <?php $surveys = PHDB::find(PHType::TYPE_SURVEYS, array("type" => Survey::TYPE_ENTRY)); foreach ($surveys as $value) { echo '<option value="' . $value["_id"] . '">' . $value["name"] . ' - ' . $value["survey"] . '</option>'; } ?> </select><br/> <a class="btn" href="javascript:deleteEntry()">Test it</a><br/> <div id="deleteEntryResult" class="result fss"></div> <script> function deleteEntry() { params = { "survey" : $("#sessiondeleteEntry").val() , "app" : "<?php echo $this->module->id; ?> "}; ajaxPost("deleteEntryResult",baseUrl+'/<?php echo $this->module->id; ?> /api/deletesurvey',params); } </script> </div>
public static function getWhere($params = array()) { return PHDB::find(self::COLLECTION, $params); }
public function updateGeoPositionGroups() { $groups = PHDB::find(PHType::TYPE_GROUPS); $result = "deb"; $i = 0; foreach ($groups as $group) { $i++; //trouve la ville qui correspond au cp $queryCity = array("cp" => strval(intval($group["cp"])), "geo" => array('$exists' => true)); $city = Yii::app()->mongodb->cities->findOne($queryCity); //->limit(1) if ($city != null) { $i++; $newPos = array('geo' => array("@type" => "GeoCoordinates", "longitude" => floatval($city['geo']['coordinates'][0]), "latitude" => floatval($city['geo']['coordinates'][1])), 'geoPosition' => $city['geo']); $result .= " <" . $i . "> " . $city['name'] . $group["cp"]; //Yii::app()->mongodb->groups->update( array("_id" => $group["_id"]), // array('$set' => $newPos ) ); } $result .= " - count : " . count($groups) . " - latlng : " . $city['geo']['coordinates'][1]; return $result; } }
public function run() { /* params = { "title" : $("#titleSaveNews").val() , "msg" : $("#contentSaveNews").val() , "tags" : $("#tagsSaveNews").val() , "nature":$("#natureSaveNews").val(), "scopeType" : scopeType }; if(scopeType == "geoArea"){ var bounds = getBoundsValue(); params["latMinScope"] = bounds.getSouthWest().lat; params["lngMinScope"] = bounds.getSouthWest().lng; params["latMaxScope"] = bounds.getNorthEast().lat; params["lngMaxScope"] = bounds.getNorthEast().lng; } if(scopeType == "cp") { params["cpScope"] = $("#cpScope").val(); } if(scopeType == "departement") { params["depScope"] = $("#depScope").val(); } if(scopeType == "groups") { params["groupScope"] = $("#groupsListScope").val(); } */ $newsData = array(); if (isset($_POST['title'])) { $newsData['title'] = $_POST['title']; } if (isset($_POST['msg'])) { $newsData['msg'] = $_POST['msg']; } if (isset($_POST['tags'])) { $newsData['tags'] = explode(",", $_POST['tags']); } if (isset($_POST['nature'])) { $newsData['nature'] = $_POST['nature']; } if (isset($_POST['scopeType'])) { $newsData['scope']['scopeType'] = $_POST['scopeType']; } if ($newsData['scope']['scopeType'] == "geoArea") { if (isset($_POST['latMinScope'])) { $newsData['scope']['geoArea']['latMinScope'] = floatval($_POST['latMinScope']); } if (isset($_POST['lngMinScope'])) { $newsData['scope']['geoArea']['lngMinScope'] = floatval($_POST['lngMinScope']); } if (isset($_POST['latMaxScope'])) { $newsData['scope']['geoArea']['latMaxScope'] = floatval($_POST['latMaxScope']); } if (isset($_POST['lngMaxScope'])) { $newsData['scope']['geoArea']['lngMaxScope'] = floatval($_POST['lngMaxScope']); } } if ($newsData['scope']['scopeType'] == "cp") { if (isset($_POST['cpScope'])) { $newsData['scope']['cpScope'] = $_POST['cpScope']; } } if ($newsData['scope']['scopeType'] == "groups") { if (isset($_POST['groupScope'])) { $newsData['scope']['groupScope'] = $_POST['groupScope']; } } if ($newsData['scope']['scopeType'] == "departement") { if (isset($_POST['depScope'])) { $newsData['scope']['depScope'] = $_POST['depScope']; } } //recuperation de la position de l'auteur du message $myEmail = Yii::app()->session["userEmail"]; $user = PHDB::findOne(PHType::TYPE_CITOYEN, array("email" => $myEmail)); $myCp = 0; //si l'utilisateur a enregistré sa position, on recopie lat lng if (isset($user['geo'])) { $newsData['from']['latitude'] = floatval($user['geo']['latitude']); $newsData['from']['longitude'] = floatval($user['geo']['longitude']); } else { //sinon on utilise la position geo de sa ville $myCp = $me['cp']; $city = PHDB::find('cities', array("cp" => $myCp)); if ($city != null) { $newsData['from']['latitude'] = floatval($city['geo']['latitude']); $newsData['from']['longitude'] = floatval($city['geo']['longitude']); } } $newsData['author'] = new MongoId(Yii::app()->session["userId"]); PHDB::insert(PHType::TYPE_NEWS, $newsData); Rest::json($newsData); Yii::app()->end(); }
public static function listProjectsIamAdminOf($userId) { $projectList = array(); //project i'am admin $where = array("links.contributors." . $userId . ".isAdmin" => true); $projectList = PHDB::find(PHType::TYPE_PROJECTS, $where); //projects of organization i'am admin //$listOrganizationAdmin = Authorisation::listUserOrganizationAdmin($userId); return $projectList; }
public static function noAdminExist($moduleId) { return PHDB::find(PHType::TYPE_CITOYEN, array("applications." . $moduleId . ".isAdmin" => true)); }
public function actionGet($type, $id = null, $format = null, $limit = 50) { $bindMap = null; $data = null; if ($type == Person::COLLECTION) { if ($format == Translate::FORMAT_SCHEMA) { $bindMap = TranslateSchema::$dataBinding_person; } else { if ($format == Translate::FORMAT_PLP) { $bindMap = TranslatePlp::$dataBinding_person; } else { if ($format == Translate::FORMAT_AS) { $bindMap = TranslateActivityStream::$dataBinding_person; } } } } else { if ($type == Event::COLLECTION && $format == Translate::FORMAT_SCHEMA) { $bindMap = TranslateSchema::$dataBinding_event; } else { if ($type == Organization::COLLECTION && $format == Translate::FORMAT_SCHEMA) { $bindMap = TranslateSchema::$dataBinding_organization; } else { if ($type == Project::COLLECTION && $format == Translate::FORMAT_SCHEMA) { $bindMap = TranslateSchema::$dataBinding_project; } else { if ($type == City::COLLECTION && $format == Translate::FORMAT_SCHEMA) { $bindMap = TranslateSchema::$dataBinding_city; } } } } } $params = array('isOpendata' => true); if (@$id) { $params["_id"] = new MongoId($id); } if ($type == City::COLLECTION && @$_GET["insee"]) { $params["insee"] = $_GET["insee"]; unset($params["isOpendata"]); } if (@$id || @$_GET["insee"]) { $data = PHDB::find($type, $params); /*if($limit) $data = $data->limit($limit);*/ if ($data && $bindMap) { $data = Translate::convert($data, $bindMap); } } Rest::json($data); }
public static function save($params) { //check a user is loggued $user = Person::getById(Yii::app()->session["userId"]); //TODO : if type is Organization check the connected user isAdmin if (empty($user)) { throw new CTKException("You must be loggued in to add a news entry."); } if (isset($_POST["name"]) && isset($_POST["text"])) { $news = array("name" => $_POST["name"], "text" => $_POST["text"], "author" => Yii::app()->session["userId"], "created" => time()); if (isset($_POST["tags"])) { $news["tags"] = $_POST["tags"]; } if (isset($_POST["typeId"])) { $news["id"] = $_POST["typeId"]; } if (isset($_POST["type"])) { $news["type"] = $_POST["type"]; if ($_POST["type"] == Person::COLLECTION) { $person = Person::getById($_POST["typeId"]); if (isset($person['geo'])) { $news["from"] = $person['geo']; } } else { if ($_POST["type"] == Organization::COLLECTION) { $person = Person::getById($_POST["typeId"]); if (isset($person['geo'])) { $news["from"] = $person['geo']; } } } /*if( $_POST["type"] == Organization::COLLECTION && Authorisation::isOrganizationAdmin( Yii::app()->session["userId"], $_POST["typeId"]) ) throw new CTKException("You must be admin of this organization to post.");*/ } if (isset($_POST["scope"])) { foreach ($_POST["scope"] as $scope) { //dans le cas d'un groupe //ajoute un à un chaque membre du groupe demandé (=> contact) if ($scope->scopeType == "groupe") { //pour chacun de ses groupes de contact foreach ($user["knows"] as $groupe) { //pour chaque membre du groupe demandé if ($groupe["name"] == $scope->id) { foreach ($groupe["members"] as $contact) { //recupere les donnes du contact $where = array('_id' => $contact); $allContact = PHDB::find(Person::COLLECTION, $where); $allContact = $allContact[$contact->__toString()]; //ajoute un scope de type "contact" dans la news $news["scope"][] = array("scopeType" => "contact", "at" => "@" . $allContact["name"], "id" => $contact); } } } } else { if ($scope->id == "all_contact" && $scope->scopeType == "contact") { //pour chacun de ses groupes de contact foreach ($user["knows"] as $groupe) { //pour chaque membre d'un groupe foreach ($groupe["members"] as $contact) { //recupere les donnes du contact $where = array('_id' => $contact); $allContact = PHDB::find(PHType::TYPE_CITOYEN, $where); $allContact = $allContact[$contact->__toString()]; //if(!isset($allContact["name"])) {Rest::json( "pas de name" ); Yii::app()->end(); } //ajoute un scope de type "contact" dans la news if (isset($allContact["name"])) { $news["scope"][] = array("scopeType" => "contact", "at" => "@" . $allContact["name"], "id" => $contact); } } } } else { if ($scope->id == "all_organisation" && $scope->scopeType == "organisation") { //pour chacun de ses organisations foreach ($user["memberOf"] as $organization) { //recupere les donnes de l'organisation $where = array('_id' => $organization); $allOrga = PHDB::find("organizations", $where); $allOrga = $allOrga[$organization->__toString()]; //ajoute un scope de type "organisation" dans la news $news["scope"][] = array("scopeType" => $scope->scopeType, "at" => "@" . $allOrga["name"], "id" => $organization); } } else { $news["scope"][] = $scope; } } } } } PHDB::insert(self::COLLECTION, $news); //Link::connect($id, $type, $new["_id"], PHType::TYPE_PROJECTS, $id, "projects" ); return array("result" => true, "msg" => "Votre news est enregistré.", "id" => $news["_id"], "object" => $news); } else { return array("result" => false, "msg" => "Please Fill required Fields."); } }
/** * * @return [json Map] list */ public static function checkInitData($where, $key) { $res = PHDB::find($where, array("dummyData" => $key)); return count($res); }
<div class="btn-group"> <a href="javascript:saveNews()" class="btn btn-info close-subview-button" id="btn_publish_news"> <i class="fa fa-send"></i> Publier </a> </div> </div> <div style="display:inline;" id="hashtags_list_json"></div> </form> </div> </div> <?php $where = array('_id' => new MongoId(Yii::app()->session["userId"])); $user = PHDB::find(PHType::TYPE_CITOYEN, $where); $user = $user[Yii::app()->session["userId"]]; $userCP = $user["cp"]; ?> <script type="text/javascript"> $(document).ready( function() { //scope de départ var userCP = "<?php echo $userCP; ?> "; var scope = new Array({ "scopeType" : "ville", "at" : userCP, "id" : userCP //devrait correspondre à l'id nominatim de la ville de l'utilisateur },
<div class="apiForm moderateEntry"> <select id="sessionmoderateEntry"> <option></option> <?php $Surveys = PHDB::find(PHType::TYPE_SURVEYS, array("type" => "entry", '$or' => array(array("applications.survey.cleared" => false), array("applications.survey.cleared" => "refused")))); foreach ($Surveys as $value) { echo '<option value="' . $value["_id"] . '">' . $value["name"] . " " . '</option>'; } ?> </select><br/> <select id="moderateAction"> <option></option> <option value=1>accept</option> <option value=0>refuse</option> </select><br/> <a class="btn" href="javascript:moderateEntry()">Moderate it</a><br/> <a class="btn" href="javascript:getEntry()">Get it</a><br/> <div id="moderateEntryResult" class="result fss"></div> <script> function moderateEntry(){ params = { "survey" : $("#sessionmoderateEntry").val() , "action" : $("#moderateAction").val() , "app" : "<?php echo $this->module->id; ?> "}; ajaxPost("moderateEntryResult",baseUrl+'/<?php echo $this->module->id; ?> /api/moderateentry',params); }
</select> </div> <div class="col-md-4"> <label> Séparateur de texte :</label> <select id="separateurTexte" name="separateurTexte"> <option value='"'>guillemet</option> <option value="'">cote</option> </select> </div> </div> <div class="row"> <div id="divChooseMapping" class="col-md-4"> <label> Mapping :</label> <select id="chooseMapping" name="chooseMapping"> <?php $allMapping = PHDB::find(City::COLLECTION_IMPORTHISTORY); foreach ($allMapping as $key => $value) { echo '<option value="' . $key . '">' . $value["nameFile"] . '</option>'; } ?> </select> <?php //var_dump($allMapping) ?> </div> <div class="form-group col-md-4"> <input type="submit" class="btn btn-primary" id="sumitVerification" value="Vérification"/> </div> </div> </form>
public static function getPeopleBy($params) { $where = isset($params["where"]) ? $params["where"] : array(); $fields = isset($params["fields"]) ? $params["fields"] : array(); if (isset($params["groupid"])) { $group = PHDB::findOne(PHType::TYPE_GROUPS, array("_id" => new MongoId($params["groupid"]))); $where = array(isset(CitoyenType::$types2Nodes[$group["type"]]) ? CitoyenType::$types2Nodes[$group["type"]] : "participants" => (string) $group['_id']); } if (isset($params["groupname"])) { $group = PHDB::findOne(PHType::TYPE_GROUPS, array("name" => $params["groupname"])); $where = array(isset(CitoyenType::$types2Nodes[$group["type"]]) ? CitoyenType::$types2Nodes[$group["type"]] : "participants" => (string) $group['_id']); } if (isset($params["cp"])) { $where = array("cp" => $params["cp"]); } if (isset($params["app"])) { $where = array("applications." . $params["app"] . ".usertype" => $params["app"]); } if (!isset($params["count"])) { $res = PHDB::find(self::COLLECTION, $where, $fields); } else { $res = array('count' => PHDB::count(self::COLLECTION, $where, $fields)); } return $res; }
public function run() { /* Sont pris en compte : le code postal & departement de l'utilisateur connecté + la Nature des publications Reste : tags, syncMap, groups */ //recupere le CP de l'utilisateur connecté $myEmail = Yii::app()->session["userEmail"]; $result = PHDB::find(PHType::TYPE_CITOYEN, array("email" => $myEmail)); $myCp = 0; foreach ($result as $me) { $myCp = $me['cp']; } //recupere le departement de l'utilisateur connecté if (intval($myCp) > 9999) { $myDep = substr($myCp, 0, 2); } else { $myDep = substr($myCp, 0, 1); } //debut de la requete $where = array(); $where['nature'] = $_POST['nature']; if ($_POST['geoAreaScope'] == true) { /* $where['scope.scopeType'] = 'geoArea'; $latMax = floatval($_POST['latMaxScope']); //converti strinf en float $latMin = floatval($_POST['latMinScope']); $lngMax = floatval($_POST['lngMaxScope']); $lngMin = floatval($_POST['lngMinScope']); //$where['from.latitude'] = array('$lt'=>$latMax, '$gt'=>$latMin); //$where['from.longitude'] = array('$lt'=>$lngMax, '$gt'=>$lngMin); $where['from.latitude'] = array('$gt'=>38.272688535980976, '$lt'=>58.35563036280964 ); $where['from.longitude'] = array('$gt'=> -40.95703125, //nombre négatif ne marche pas '$lt'=>18.28125); /* modele opérateur geoWithin <location field> : { $geoWithin : { $geometry : { type : "Polygon" , coordinates : [ [ [ <lng1>, <lat1> ] , [ <lng2>, <lat2> ] ... ] ] } } } }* / */ /* $where['from'] = array("$geoWithin" => array("$geometry" => array("type" => "Polygon", "coordinates" => array(array($_POST['lngMinScope'], $_POST['latMinScope']), array($_POST['lngMaxScope'], $_POST['latMinScope']), array($_POST['lngMaxScope'], $_POST['latMaxScope']), array($_POST['lngMinScope'], $_POST['latMaxScope']), array($_POST['lngMinScope'], $_POST['latMinScope'])) ) ) ); */ } $where['$or'] = array(); $where['$or'][] = array('$and' => array(array('scope.scopeType' => 'cp', 'scope.cpScope' => $myCp))); $where['$or'][] = array('$and' => array(array('scope.scopeType' => 'departement', 'scope.depScope' => $myDep))); $newsStream = PHDB::find(PHType::TYPE_NEWS, $where); $streamHtml = "</br></br>RESULTAT HTML : </br>"; $nbNews = 0; foreach ($newsStream as $news) { $streamHtml .= " _id : " . $news['_id'] . " - title : " . $news['title'] . " - cp : " . $news['scope']['cpScope'] . "</br>"; $nbNews++; } $streamHtml .= $nbNews; $res = array("_POST : ", $_POST, "<br><br>WHERE : ", $where, "<br><br>RESULTAT JSON :", $newsStream, $streamHtml); Rest::json($res); Yii::app()->end(); }
/** * Retrieve the list of events that an user is attending of * @param String $userId is the id of a citoyen * @return array list of the events the person */ public static function listEventAttending($userId) { $where = array("links.attendees." . $userId => array('$exists' => true)); $eventsAttending = PHDB::find(PHType::TYPE_EVENTS, $where); foreach ($eventsAttending as $key => $value) { $profil = Document::getLastImageByKey($key, PHType::TYPE_EVENTS, Document::IMG_PROFIL); if ($profil != "") { $value['imagePath'] = $profil; } } return $eventsAttending; }