示例#1
0
 public function run($id)
 {
     $controller = $this->getController();
     $project = Project::getById($id);
     $citoyens = array();
     $organizations = array();
     if (isset($project['links']["contributors"]) && !empty($project['links']["contributors"])) {
         foreach ($project['links']["contributors"] as $id => $e) {
             if (!empty($project)) {
                 if ($e["type"] == "citoyens") {
                     $citoyen = PHDB::findOne(PHType::TYPE_CITOYEN, array("_id" => new MongoId($id)));
                     array_push($citoyens, $citoyen);
                 } else {
                     if ($e["type"] == "organizations") {
                         $organization = PHDB::findOne(Organization::COLLECTION, array("_id" => new MongoId($id)));
                         array_push($organizations, $organization);
                     }
                 }
             } else {
                 // throw new CommunecterException("Données inconsistentes pour le citoyen : ".Yii::app()->session["userId"]);
             }
         }
     }
     $controller->render("edit", array('project' => $project, 'organizations' => $organizations, 'citoyens' => $citoyens));
 }
示例#2
0
 public function run($id, $type)
 {
     $controller = $this->getController();
     $item = PHDB::findOne($type, array("_id" => new MongoId($id)));
     $params = array();
     $params["itemId"] = $id;
     $params['itemType'] = $type;
     //TODO SBAR - it's not beautifull. Refactor soon
     switch ($type) {
         case Person::COLLECTION:
             $controllerId = "person";
             break;
         case Organization::COLLECTION:
             $controllerId = "organization";
             break;
         case Project::COLLECTION:
             $controllerId = "project";
             break;
         case Event::COLLECTION:
             $controllerId = "event";
             break;
         default:
             throw new CTKException("Impossible to manage this type " . $type);
             break;
     }
     if (isset(Yii::app()->session["userId"])) {
         $params["canEdit"] = Authorisation::canEditItem(Yii::app()->session["userId"], $type, $id);
     }
     $params['controllerId'] = $controllerId;
     $params['images'] = Document::getListDocumentsByContentKey($id, $controllerId, Document::DOC_TYPE_IMAGE);
     $controller->title = $item["name"] . "'s Gallery";
     $controller->subTitle = "";
     $controller->render("gallery", $params);
 }
示例#3
0
 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 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();
 }
示例#5
0
 public function run()
 {
     $res = array();
     if (Yii::app()->session["userId"]) {
         $email = $_POST["email"];
         $name = $_POST['name'];
         //if exists login else create the new user
         if (PHDB::findOne(PHType::TYPE_CITOYEN, array("email" => $email))) {
             //udate the new app specific fields
             $newInfos = array();
             $newInfos['email'] = (string) $email;
             $newInfos['name'] = (string) $name;
             if (isset($_POST['survey'])) {
                 $newInfos['survey'] = $_POST['survey'];
             }
             if (isset($_POST['message'])) {
                 $newInfos['message'] = (string) $_POST['message'];
             }
             if (isset($_POST['type'])) {
                 $newInfos['type'] = $_POST['type'];
             }
             if (isset($_POST['tags']) && !empty($_POST['tags'])) {
                 $newInfos['tags'] = explode(",", $_POST['tags']);
             }
             if (isset($_POST['cp'])) {
                 $newInfos['cp'] = explode(",", $_POST['cp']);
             }
             if (isset($_POST['urls'])) {
                 $newInfos['urls'] = $_POST['urls'];
             }
             $newInfos['created'] = time();
             //specific application routines
             if (isset($_POST["app"])) {
                 $appKey = $_POST["app"];
                 if ($app = PHDB::findOne(PHType::TYPE_APPLICATIONS, array("key" => $appKey))) {
                     //when registration is done for an application it must be registered
                     $newInfos['applications'] = array($appKey => array("usertype" => isset($_POST['type']) ? $_POST['type'] : $_POST['app']));
                     //check for application specifics defined in DBs application entry
                     if (isset($app["moderation"])) {
                         $newInfos['applications'][$appKey][SurveyType::STATUS_CLEARED] = false;
                         //TODO : set a Notification for admin moderation
                     }
                     $res['applicationExist'] = true;
                 } else {
                     $res['applicationExist'] = false;
                 }
             }
             PHDB::update(PHType::TYPE_PROJECTS, array("name" => $name), array('$set' => $newInfos), array('upsert' => true));
             $res['result'] = true;
             $res['msg'] = $this->id . "Saved";
         } else {
             $res = array('result' => false, 'msg' => "user doen't exist");
         }
     } else {
         $res = array('result' => false, 'msg' => 'something somewhere went terribly wrong');
     }
     Rest::json($res);
     Yii::app()->end();
 }
示例#6
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;
 }
示例#7
0
文件: PH.php 项目: Koulio/pixelhumain
 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();
 }
 public function run()
 {
     $controller = $this->getController();
     //$res = array( "result" => false , "content" => Yii::t("common", "Something went wrong!") );
     if (isset($_POST["id"])) {
         $project = isset($_POST["id"]) ? PHDB::findOne(PHType::TYPE_PROJECTS, array("_id" => new MongoId($_POST["id"]))) : null;
         if ($project) {
             if (preg_match('#^[\\w.-]+@[\\w.-]+\\.[a-zA-Z]{2,6}$#', $_POST['email'])) {
                 if ($_POST['type'] == "citoyens") {
                     $member = PHDB::findOne(PHType::TYPE_CITOYEN, array("email" => $_POST['email']));
                     $memberType = PHType::TYPE_CITOYEN;
                 } else {
                     $member = PHDB::findOne(Organization::COLLECTION, array("email" => $_POST['email']));
                     $memberType = Organization::COLLECTION;
                 }
                 if (!$member) {
                     if ($_POST['type'] == "citoyens") {
                         $member = array('name' => $_POST['name'], 'email' => $_POST['email'], 'invitedBy' => Yii::app()->session["userId"], 'tobeactivated' => true, 'created' => time());
                         $memberId = Person::createAndInvite($member);
                         $isAdmin = isset($_POST["contributorIsAdmin"]) ? $_POST["contributorIsAdmin"] : false;
                         if ($isAdmin == "1") {
                             $isAdmin = true;
                         } else {
                             $isAdmin = false;
                         }
                     } else {
                         $member = array('name' => $_POST['name'], 'email' => $_POST['email'], 'invitedBy' => Yii::app()->session["userId"], 'tobeactivated' => true, 'created' => time(), 'type' => $_POST["organizationType"]);
                         $memberId = Organization::createAndInvite($member);
                         $isAdmin = false;
                     }
                     $member["id"] = $memberId["id"];
                     Link::connect($memberId["id"], $memberType, $_POST["id"], PHType::TYPE_PROJECTS, Yii::app()->session["userId"], "projects", $isAdmin);
                     Link::connect($_POST["id"], PHType::TYPE_PROJECTS, $memberId["id"], $memberType, Yii::app()->session["userId"], "contributors", $isAdmin);
                     $res = array("result" => true, "msg" => Yii::t("common", "Your data has been saved"), "member" => $member, "reload" => true);
                 } else {
                     if (isset($project['links']["contributors"]) && isset($project['links']["contributors"][(string) $member["_id"]])) {
                         $res = array("result" => false, "content" => "member allready exists");
                     } else {
                         $isAdmin = isset($_POST["contributorIsAdmin"]) ? $_POST["contributorIsAdmin"] : false;
                         if ($isAdmin == "1") {
                             $isAdmin = true;
                         } else {
                             $isAdmin = false;
                         }
                         Link::connect($member["_id"], $memberType, $_POST["id"], PHType::TYPE_PROJECTS, Yii::app()->session["userId"], "projects", $isAdmin);
                         Link::connect($_POST["id"], PHType::TYPE_PROJECTS, $member["_id"], $memberType, Yii::app()->session["userId"], "contributors", $isAdmin);
                         $res = array("result" => true, "msg" => Yii::t("common", "Your data has been saved"), "member" => $member, "reload" => true);
                     }
                 }
             } else {
                 $res = array("result" => false, "content" => "email must be valid");
             }
         }
     }
     Rest::json($res);
 }
示例#10
0
 /**
  * Retrieve the active tags list
  * @return array of tags (String)
  */
 public static function getActiveTags()
 {
     $res = array();
     //The tags are found in the list collection, key tags
     $tagsList = PHDB::findOne(PHType::TYPE_LISTS, array("name" => "tags"), array('list'));
     if (!empty($tagsList['list'])) {
         $res = $tagsList['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();
 }
示例#12
0
 public static function uniqueUsername($toValidate, $objectId = null)
 {
     // Is There a association with the same name ?
     $res = "";
     $uniqueUsername = PHDB::findOne(Person::COLLECTION, array("username" => $toValidate));
     if ($uniqueUsername) {
         $res = "A user with the same username allready exists";
     }
     return $res;
 }
示例#13
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);
     }
 }
 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();
 }
示例#15
0
 /**
  * Retieve a list by name and return values 
  * @param String $name of the list
  * @return array of list value
  */
 public static function getListByName($name)
 {
     $res = array();
     //The tags are found in the list collection, key tags
     $list = PHDB::findOne(self::COLLECTION, array("name" => $name), array('list'));
     if (!empty($list['list'])) {
         $res = $list['list'];
     } else {
         throw new CTKException("Impossible to find the list name " . $name);
     }
     return $res;
 }
 public function run()
 {
     $controller = $this->getController();
     $controller->layout = "//layouts/mainSimple";
     if (Yii::app()->request->isAjaxRequest && isset($_POST['registerEmail']) && !empty($_POST['registerEmail']) && isset($_POST['registerPwd']) && !empty($_POST['registerPwd'])) {
         //check application exists
         if (isset($_POST['appKey']) && !empty($_POST['appKey']) && isset($_POST['appType']) && !empty($_POST['appType'])) {
             $type = Yii::app()->mongodb->selectCollection($_POST['appType']);
             $app = $type->findOne(array("_id" => new MongoId($_POST['appKey'])));
             if ($app) {
                 //validate isEmail
                 $email = $_POST['registerEmail'];
                 $name = "";
                 if (preg_match('#^([\\w.-])/<([\\w.-]+@[\\w.-]+\\.[a-zA-Z]{2,6})/>$#', $email, $matches)) {
                     $name = $matches[0];
                     $email = $matches[1];
                 }
                 if (preg_match('#^[\\w.-]+@[\\w.-]+\\.[a-zA-Z]{2,6}$#', $email)) {
                     //test pwd
                     if ($app["pwd"] == $_POST['registerPwd']) {
                         $account = PHDB::findOne(PHType::TYPE_CITOYEN, array("email" => $_POST['registerEmail']));
                         if ($account) {
                             //TODO : check if account is participant in the app
                             Yii::app()->session["userId"] = $account["_id"];
                             Yii::app()->session["userEmail"] = $account["email"];
                             if (!isset(Yii::app()->session["loggedIn"]) && !is_array(Yii::app()->session["loggedIn"])) {
                                 Yii::app()->session["loggedIn"] = array();
                             }
                             $tmp = Yii::app()->session["loggedIn"];
                             array_push($tmp, $_POST['appKey']);
                             Yii::app()->session["loggedIn"] = $tmp;
                             echo json_encode(array("result" => true, "msg" => "Vous êtes connecté à présent, Amusez vous bien."));
                         } else {
                             echo json_encode(array("result" => false, "msg" => "Compte inconnue."));
                         }
                     } else {
                         echo json_encode(array("result" => false, "msg" => "Accés refusé."));
                     }
                 } else {
                     echo json_encode(array("result" => false, "msg" => "Email invalide"));
                 }
             } else {
                 echo json_encode(array("result" => false, "msg" => "Application invalide"));
             }
         } else {
             echo json_encode(array("result" => false, "msg" => "Vous Pourrez pas accéder a cette application"));
         }
     } else {
         echo json_encode(array("result" => false, "msg" => "Cette requete ne peut aboutir."));
     }
     exit;
 }
 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();
 }
示例#18
0
 /**
  * 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;
     }
 }
示例#19
0
 public static function addWorkLog($project, $userEmail, $controller, $action)
 {
     if (stripos($_SERVER['SERVER_NAME'], "127.0.0.1") >= 0 || stripos($_SERVER['SERVER_NAME'], "localhost:8080") >= 0) {
         $lastUpdate = PHDB::findOne("cornerDev", array("project" => $project, "person" => $userEmail, "controller" => $controller, "action" => $action, "type" => self::ACTION_WORKLOG, "date" => date("d/m/y")));
         $timespend = 0;
         if ($lastUpdate) {
             $timespend = time() - $lastUpdate["lastUpdate"];
             //if($timespend > ) //seesion closer , maybe should be a button
             $timespend = ($timespend + $lastUpdate["timespend"] * 60) / 60;
         }
         $entry = array("project" => $project, "person" => $userEmail, "controller" => $controller, "action" => $action, "date" => date("d/m/y"), "timespend" => $timespend, "lastUpdate" => time());
         PHDB::updateWithOptions("cornerDev", array("project" => $project, "person" => $userEmail, "controller" => $controller, "action" => $action, "date" => date("d/m/y"), "type" => self::ACTION_WORKLOG), array('$set' => $entry), array("upsert" => true));
         PHDB::insert("cornerLog", array("project" => $project, "person" => $userEmail, "controller" => $controller, "action" => $action, "timestamp" => time(), "type" => self::ACTION_WORKLOG));
     }
 }
示例#20
0
 public function run($user)
 {
     $controller = $this->getController();
     $account = Person::getById($user);
     //TODO : move code below to the model Person
     if ($account) {
         Person::saveUserSessionData($user, $account["email"], array("name" => $account["name"]));
         //remove tobeactivated attribute on account
         PHDB::update(PHType::TYPE_CITOYEN, array("_id" => new MongoId($user)), array('$unset' => array("tobeactivated" => "")));
         /*Notification::saveNotification(array("type"=>NotificationType::NOTIFICATION_ACTIVATED,
           "user"=>$account["_id"]));*/
     }
     //TODO : add notification to the cities,region,departement info panel
     //TODO : redirect to monPH page , inciter le rezotage local
     $controller->redirect(Yii::app()->homeUrl);
 }
示例#21
0
 /**
  * Delete an entry from the organization table using the id
  */
 public function run()
 {
     //TODO SBAR : refactor : not use
     $result = array("result" => false, "msg" => Yii::t("common", "Uncorrect request"));
     if (Yii::app()->session["userId"]) {
         $account = Organization::getById($_POST["id"]);
         if ($account && Yii::app()->session["userEmail"] == $account['ph:owner']) {
             PHDB::remove(Organization::COLLECTION, array("_id" => new MongoId($_POST["id"])));
             //temporary for dev
             //TODO : Remove the association from all Ci accounts
             PHDB::update(PHType::TYPE_CITOYEN, array("_id" => new MongoId(Yii::app()->session["userId"])), array('$pull' => array("associations" => new MongoId($_POST["id"]))));
             $result = array("result" => true, "msg" => Yii::t("common", "Data saved"));
         }
     }
     Rest::json($result);
 }
 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();
 }
示例#23
0
 public function __construct($appId)
 {
     $this->populateDefaultAppSetting();
     // Search in the database for the application $appId
     if (isset($appId)) {
         $app = PHDB::findOne(PHType::TYPE_APPLICATIONS, array("key" => $appId));
     }
     if (!$app) {
         Yii::log("No application is set on Application collection", "info");
     }
     if (isset($app["name"])) {
         $this->name = $app["name"];
     }
     if (isset($app["logo"])) {
         $this->logoUrl = Yii::app()->getModule($app["key"])->assetsUrl . $app["logo"];
     }
 }
示例#24
0
 public function run($typePH, $object_id)
 {
     $object = PHDB::findOne($typePH, array("_id" => new MongoId($object_id)));
     if ($object != null) {
         $data = array();
         if (isset($object['cp'])) {
             $data["cp"] = $object['cp'];
         }
         if (isset($object['geo'])) {
             $data["geo"] = $object['geo'];
         }
         Rest::json($data);
     } else {
         Rest::json($typePH . " n° " . $object_id . " not found");
     }
     Yii::app()->end();
 }
示例#25
0
 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();
 }
示例#26
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;
 }
示例#27
0
 public function run($id)
 {
     $res = array("result" => false, "content" => Yii::t("common", "Something went wrong!"));
     if (Yii::app()->request->isAjaxRequest && isset($_POST["id"])) {
         $event = isset($_POST["id"]) ? PHDB::findOne(PHType::TYPE_EVENTS, array("_id" => new MongoId($_POST["id"]))) : null;
         if ($event) {
             $memberEmail = $_POST['email'];
             if ($_POST['type'] == "persons") {
                 $memberType = PHType::TYPE_CITOYEN;
             } else {
                 $memberType = Organization::COLLECTION;
             }
             if (isset($_POST["id"]) && $_POST["id"] != "") {
                 $memberEmailObject = PHDB::findOne($type, array("_id" => new MongoId($_POST["id"])), array("email"));
                 $memberEmail = $memberEmailObject['email'];
             }
             if (preg_match('#^[\\w.-]+@[\\w.-]+\\.[a-zA-Z]{2,6}$#', $memberEmail)) {
                 $member = PHDB::findOne($memberType, array("email" => $_POST['email']));
                 if (!$member) {
                     if ($_POST['type'] == "persons") {
                         $member = array('name' => $_POST['name'], 'email' => $memberEmail, 'invitedBy' => Yii::app()->session["userId"], 'tobeactivated' => true, 'created' => time(), 'links' => array('events' => array($_POST["id"] => array("type" => $type, "tobeconfirmed" => true, "invitedBy" => Yii::app()->session["userId"]))));
                         Person::createAndInvite($member);
                     } else {
                         $member = array('name' => $_POST['name'], 'email' => $memberEmail, 'invitedBy' => Yii::app()->session["userId"], 'tobeactivated' => true, 'created' => time(), 'type' => 'Group', 'links' => array('events' => array($_POST["id"] => array("type" => $type, "tobeconfirmed" => true, "invitedBy" => Yii::app()->session["userId"]))));
                         Organization::createAndInvite($member);
                     }
                     Link::connect($_POST["id"], PHType::TYPE_EVENTS, $member["_id"], $type, Yii::app()->session["userId"], "attendees");
                     $res = array("result" => true, "msg" => "Vos données ont bien été enregistré.", "reload" => true);
                 } else {
                     if (isset($event['links']["events"]) && isset($event['links']["events"][(string) $member["_id"]])) {
                         $res = array("result" => false, "content" => "member allready exists");
                     } else {
                         Link::connect($member["_id"], $type, $_POST["id"], PHType::TYPE_EVENTS, Yii::app()->session["userId"], "events");
                         Link::connect($_POST["id"], PHType::TYPE_EVENTS, $member["_id"], $type, Yii::app()->session["userId"], "attendees");
                         $res = array("result" => true, "msg" => Yii::t("common", "Your data has been saved!"), "reload" => true);
                     }
                 }
             } else {
                 $res = array("result" => false, "content" => "email must be valid");
             }
         }
     }
     Rest::json($res);
 }
示例#28
0
 public static function createMessage($emails, $msg, $module = null)
 {
     //run through emails and validate existing accounts
     $userids = array();
     $inexistantUsers = array();
     $emails = explode(",", $emails);
     foreach ($emails as $email) {
         //QUESTION : should we validate that a user is registered to the module
         if ($user = Yii::app()->mongodb->citoyens->findOne(array("email" => $email))) {
             array_push($userids, (string) $user["_id"]);
         } else {
             array_push($inexistantUsers, (string) $user["_id"]);
         }
     }
     //save message to DB
     if (count($userids)) {
         array_push($userids, Yii::app()->session["userId"]);
         $newInfos = array();
         $newInfos['from'] = Yii::app()->session["userId"];
         $newInfos['to'] = $userids;
         $newInfos['msg'] = $msg;
         if (isset($_POST["emailCopy"]) && $_POST["emailCopy"]) {
             $newInfos['emailCopy'] = "todo";
         }
         $newInfos['created'] = time();
         if (isset($_POST["app"])) {
             $appKey = $_POST["app"];
             $newInfos['applications'] = array($appKey => array("usertype" => "message"));
             $app = Yii::app()->mongodb->applications->findOne(array("key" => $appKey));
             //check for application specifics defined in DBs application entry
             if (isset($app["messages"]) && $app["messages"] == "mustBeConfirmed") {
                 $newInfos['applications'][$appKey]["messageConfirmed"] = false;
             }
         }
         PHDB::insert(PHType::TYPE_MESSAGES, $newInfos);
         $res = array("result" => true, "msg" => "message send to " . count($userids) . " users");
         if (count($inexistantUsers)) {
             $res["error"] = count($inexistantUsers) . " user doesn't have a PH account.";
         }
     } else {
         $res = array("result" => false, "msg" => "no valid user accounts ");
     }
     return $res;
 }
示例#29
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;
 }
示例#30
0
 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;
 }