Beispiel #1
0
 /**
  * Get the city label by insee code. Can throw Exception if the city is unknown.
  * @param String $codeInsee the code insee of the city
  * @return Array With all the field as the cities collection
  */
 public static function getCitiesByPostalCode($postalCode)
 {
     if (empty($postalCode)) {
         throw new InvalidArgumentException("The postal Code is mandatory");
     }
     $city = PHDB::findAndSort(self::CITIES_COLLECTION_NAME, array("cp" => $postalCode), array("name" => -1));
     return $city;
 }
Beispiel #2
0
 /**
  * Retreive a limited list of pending cron jobs 
  * and execute them 
  * @param $params : a set of information for the document (?to define)
  */
 public static function processCron($count = 5)
 {
     $where = array("status" => self::STATUS_PENDING);
     $jobs = PHDB::findAndSort(self::COLLECTION, $where, array('execDate' => 1), self::EXEC_COUNT);
     //var_dump($jobs);
     foreach ($jobs as $key => $value) {
         //TODO : cumulé plusieur message au meme email
         self::processEntry($value);
     }
 }
Beispiel #3
0
 public static function getMessagesVitBy($params)
 {
     $where = isset($params["where"]) ? $params["where"] : array();
     $fields = isset($params["fields"]) ? $params["fields"] : array();
     $sort = array("_id" => -1);
     if (!isset($params["count"])) {
         if (isset($params["limit"])) {
             $res == PHDB::findAndSort("messagevitrine", $fields, $sort, $params["limit"]);
         } else {
             $res = PHDB::findAndSort("messagevitrine", $fields, $sort);
         }
     } else {
         $res = array('count' => Yii::app()->mongodb->messagevitrine->count($where, $fields));
     }
     //$res["count"]=count($res);
     return $res;
 }
Beispiel #4
0
 /**
  * Find elements of collection based on criteria (field contains value)
  * By default the criterias will be separated bay a "OR"
  * @param array $criterias array (field=>value)
  * @param String $sortOnField sort on this field name
  * @param integer $nbResultMax number of results max to return
  * @return array of elements of collection
  */
 public static function findByCriterias($collection, $criterias, $sortOnField = "", $nbResultMax = 10)
 {
     $seprator = '$or';
     $query = array();
     //Add the criterias
     foreach ($criterias as $field => $value) {
         $aCriteria = array();
         $aCriteria[$field] = new MongoRegex("/{$value}/i");
         array_push($query, $aCriteria);
     }
     if (count($criterias) > 1) {
         $where = array($seprator => $query);
     } else {
         $where = $query;
     }
     $res = PHDB::findAndSort($collection, $where, array($sortOnField => 1), $nbResultMax);
     //$res = PHDB::find($collection, $where);
     return $res;
 }
 public function run()
 {
     //liste des tags de rangements de l'asso
     $tags_rangements = array(array("name" => "Citoyens", "ico" => "male", "color" => "yellow"), array("name" => "Entreprises", "ico" => "briefcase", "color" => "blue"), array("name" => "Collaborateurs", "ico" => "circle", "color" => "purple"), array("name" => "Chercheurs", "ico" => "male", "color" => "green"));
     //liste des tags de rangements de chaque membre
     $tagsR = array("Citoyens", "Citoyens", "Citoyens", "Entreprises", "Entreprises", "Collaborateurs", "Chercheurs", "Chercheurs", "Chercheurs", "Chercheurs");
     $where = array('geo' => array('$exists' => true));
     $citoyens = PHDB::findAndSort(PHType::TYPE_CITOYEN, $where, array('name' => 1), 10);
     $membres = array();
     $i = 0;
     foreach ($citoyens as $citoyen) {
         $membres[] = array("id" => $citoyen["_id"], "tag_rangement" => $tagsR[$i]);
         $i++;
     }
     $where = array('_id' => new MongoId(Yii::app()->session["userId"]));
     $me = PHDB::findOne(PHType::TYPE_CITOYEN, $where);
     $newAsso = array("@context" => array("@vocab" => "http://schema.org", "ph" => "http://pixelhumain.com/ph/ontology/"), "email" => $me["email"], "name" => "asso1", "type" => "association", "cp" => "75000", "address" => array("@type" => "PostalAddress", "postalCode" => "75000", "addressLocality" => "France"), "description" => "Description de l'association", "tags_rangement" => $tags_rangements, "membres" => $membres);
     $res = PHDB::insert(Organization::COLLECTION, $newAsso);
     if ($res["ok"] == 1) {
         $res = "Initialisation des données : OK</br>Rechargez la carte !";
     }
     Rest::json($res);
     Yii::app()->end();
 }
 public function run()
 {
     $query = array('$or' => array(array("email" => new MongoRegex("/" . $_POST['search'] . "/i")), array("name" => new MongoRegex("/" . $_POST['search'] . "/i"))));
     $allCitoyens = PHDB::findAndSort(PHType::TYPE_CITOYEN, $query, array("name" => 1), 6);
     $limitOrganization = 12 - count($allCitoyens);
     $allOrganization = PHDB::findAndSort(Organization::COLLECTION, $query, array("name" => 1), $limitOrganization, array("_id", "name", "type", "address", "email", "links", "imagePath"));
     foreach ($allCitoyens as $key => $value) {
         $logo = Document::getLastImageByKey($key, Person::COLLECTION, Document::IMG_LOGO);
         if ($logo != "") {
             $value["logo"] = $logo;
         }
         $allCitoyens[$key] = $value;
     }
     foreach ($allOrganization as $key => $value) {
         $logo = Document::getLastImageByKey($key, Organization::COLLECTION, Document::IMG_LOGO);
         if ($logo != "") {
             $value["logo"] = $logo;
         }
         $allOrganization[$key] = $value;
     }
     $all = array("citoyens" => $allCitoyens, "organizations" => $allOrganization);
     Rest::json($all);
     Yii::app()->end();
 }
Beispiel #7
0
 public static function getActivtyForObjectId($param, $sort = array("timestamp" => -1))
 {
     return PHDB::findAndSort(PHType::TYPE_ACTIVITYSTREAM, $param, $sort);
 }
Beispiel #8
0
 public static function getMicroFormats($params, $fields = null, $limit = 0)
 {
     $microFormats = PHDB::findAndSort(self::MICROFORMATS, $params, array("created" => 1), $limit, $fields);
     return $microFormats;
 }
Beispiel #9
0
 public static function getJobsList($organizationId = null)
 {
     $res = array();
     //List all job offers or filter by organizationId
     if ($organizationId != null) {
         $where = array("hiringOrganization" => $organizationId);
     } else {
         $where = array();
     }
     $jobList = PHDB::findAndSort(Job::COLLECTION, $where, array("datePosted" => -1));
     //Get the organization hiring detail
     if ($jobList != null) {
         foreach ($jobList as $jobId => $job) {
             if (!empty($job["hiringOrganization"])) {
                 $organization = Organization::getById($job["hiringOrganization"]);
                 $job["hiringOrganization"] = $organization;
                 array_push($res, $job);
             }
         }
     }
     return $res;
 }
Beispiel #10
0
 public static function getWhereSortLimit($params, $sort, $limit = 1)
 {
     return PHDB::findAndSort(self::COLLECTION, $params, $sort, $limit);
 }
Beispiel #11
0
 public static function getWhere($params)
 {
     $people = PHDB::findAndSort(self::COLLECTION, $params, array("created"), null);
 }
Beispiel #12
0
 /**
  * get the last images with a key
  * @param itemId is the id of the item that we want to get images
  * @param itemType is the type of the item that we want to get images
  * @param key is the type of image we want to get
  * @return return the url of a document
  */
 public static function getLastImageByKey($itemId, $itemType, $key)
 {
     $imageUrl = "";
     $sort = array('created' => -1);
     $params = array("id" => $itemId, "type" => $itemType, "contentKey" => new MongoRegex("/" . $key . "/i"));
     $listImagesofType = PHDB::findAndSort(self::COLLECTION, $params, $sort, 1);
     foreach ($listImagesofType as $key => $value) {
         //$imagePath = DIRECTORY_SEPARATOR."upload".DIRECTORY_SEPARATOR.Yii::app()->controller->module->id.DIRECTORY_SEPARATOR.$value["folder"].DIRECTORY_SEPARATOR.$value["name"];
         //$imagePath = str_replace(DIRECTORY_SEPARATOR, "/", $imagePath);
         $imageUrl = Document::getDocumentUrl($value);
     }
     return $imageUrl;
 }
Beispiel #13
0
 /**
  * @param itemId is the id of  a citizen
  * @param limit is the number of events we want to get
  * @return an array with the next event since the current day
  */
 public static function getListCurrentEventsByPeopleId($userId, $limit = 20)
 {
     $listEvent = array();
     $where = array('$and' => array(array("links.attendees." . $userId => array('$exists' => true)), array("endDate" => array('$gte' => new MongoDate(time())))));
     $eventPeople = PHDB::findAndSort(self::COLLECTION, $where, array('endDate' => 1), $limit);
     return Event::addInfoEvents($eventPeople);
 }