public static function updateJob($jobId, $job, $userId) { if (!Authorisation::isJobAdmin($jobId, $userId)) { throw new CTKException(Yii::t("job", "Can not update the job : you are not authorized to update that job offer !")); } foreach ($job as $jobFieldName => $jobFieldValue) { if (!Job::checkFieldBeforeUpdate($jobFieldName, $jobFieldValue)) { throw new CTKException(Yii::t("job", "Can not insert the job : unknown field ") . $jobFieldName); } //address if ($jobFieldName == "jobLocation.address") { if (!empty($jobFieldValue["postalCode"]) && !empty($jobFieldValue["codeInsee"])) { $insee = $jobFieldValue["codeInsee"]; $address = SIG::getAdressSchemaLikeByCodeInsee($insee); $job["jobLocation"] = array("address" => $address); $job["geo"] = getGeoPositionByInseeCode($insee); } else { throw new CTKException(Yii::t("job", "Error updating the Organization : address is not well formated !")); } unset($job[$jobFieldName]); } else { $job[$jobFieldName] = $jobFieldValue; } } //Manage tags : save any inexistant tag to DB if (isset($job["tags"])) { $job["tags"] = Tags::filterAndSaveNewTags($job["tags"]); } //update the job PHDB::update(Job::COLLECTION, array("_id" => new MongoId($jobId)), array('$set' => $job)); return array("result" => true, "msg" => Yii::t("job", "Your job offer has been updated with success"), "id" => $jobId); }
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(); }
/** * checks the existence of an entry in a list collection * if doesn't exist create it * else do nothing * @return [json Map] list */ public static function newEntry($listName, $entryKey, $extra = array()) { //check if usage exist otherwise create it $slug = InflectorHelper::slugify($entryKey); $exist = PHDB::findOne(self::COLLECTION, array("name" => $listName, "list." . $slug => array('$exists' => 1))); if (!$exist) { $params = array_merge(array("name" => $entryKey), $extra); PHDB::update(self::COLLECTION, array("name" => $listName), array('$set' => array("list." . $slug => $params))); } }
/** * From an array of tags (String), the new tags will be saved * Filter the array and return all the valid tags * @param array of tags (String) * @return all the valid tags */ public static function filterAndSaveNewTags($tags) { $res = array(); $existingTags = Tags::getActiveTags(); if (!empty($tags)) { foreach ($tags as $tag) { if (!in_array($tag, $existingTags)) { //TODO : Add here how to define if a tag is valid or not PHDB::update(PHType::TYPE_LISTS, array("name" => "tags"), array('$push' => array("list" => $tag))); } array_push($res, $tag); } } return $res; }
/** * 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($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); }
public static function processEntry($params) { //echo "<br/>processing entry ".$params["type"].", id".$params["_id"]; if ($params["type"] == self::TYPE_MAIL) { $res = self::processMail($params); //echo "<br/>sendmail : ".$params["subject"].", <br/>result :".((is_array($res)) ? $res["msg"] : $res); } if (!is_array($res) && $res) { //echo "<br/>processing entry ".$params["type"]; PHDB::remove(self::COLLECTION, array("_id" => new MongoId($params["_id"]))); } else { //something went wrong with the process $msg = is_array($res) && isset($res["msg"]) ? $res["msg"] : ""; PHDB::update(self::COLLECTION, array("_id" => new MongoId($params["_id"])), array('$set' => array("status" => self::STATUS_FAIL, "executedTS" => new MongoDate(), "errorMsg" => $msg))); //TODO : add notification to system admin //explaining the fail } }
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() { $id = $_POST["_id"]; $type = $_POST["type"]; $res = array("result" => false); $res["msg"] = "debut proc - "; if (PHDB::findOne($_POST["type"], array("_id" => new MongoId($_POST["_id"])))) { $res["msg"] .= "type et id ok - "; $newInfos = array(); if (isset($_POST['geo'])) { $newInfos['geo'] = $_POST['geo']; } $res["newInfos"] = $newInfos; // Yii::app()->mongodb->citoyens->update( array("_id" => $id), // array('$set' => $newInfos )); PHDB::update($_POST["type"], array("_id" => new MongoId($_POST["_id"])), array('$set' => $newInfos)); $res["result"] = true; } Rest::json($res); Yii::app()->end(); }
/** * Update the roles' list of an organization * @param $roleTab is an array with all the roles * @param type $organisationId : is the mongoId of the organisation */ public static function setRoles($roleTab, $itemId, $itemType) { PHDB::update($itemType, array("_id" => new MongoId($itemId)), array('$set' => array('roles' => $roleTab))); }
public static function removeData($collection, $type, $isDummy, $linkAllToActiveUser) { $error = null; if ($isDummy) { $rows = PHDB::find($collection, array("dummyData" => $type)); } $info = array("collection" => $collection); $userId = Yii::app()->session["userId"]; foreach ($rows as $key => $value) { if ($linkAllToActiveUser) { if ($collection == PHType::TYPE_CITOYEN) { PHDB::update(PHType::TYPE_CITOYEN, array("_id" => new MongoId($userId)), array('$unset' => array(Link::person2person . "." . $key => 1))); } elseif ($collection == PHType::TYPE_ORGANIZATIONS) { PHDB::update(PHType::TYPE_CITOYEN, array("_id" => new MongoId($userId)), array('$unset' => array(Link::person2organization . "." . $key => 1))); } elseif ($collection == PHType::TYPE_EVENTS) { PHDB::update(PHType::TYPE_CITOYEN, array("_id" => new MongoId($userId)), array('$unset' => array(Link::person2events . "." . $key => 1))); } elseif ($collection == PHType::TYPE_PROJECTS) { PHDB::update(PHType::TYPE_CITOYEN, array("_id" => new MongoId($userId)), array('$unset' => array(Link::person2projects . "." . $key => 1))); } } PHDB::remove($collection, array("_id" => new MongoId($key))); } return array("count" => count($rows)); }
/** * Add a link between the 2 actors. * @param $ownerId is the person who want to add a link * @param $targetId is the id of item we want to be link with * @param $ownerLink is the type of link between the owner and the target * @param $targetLink is the type of link between the target and the owner * @return result array with the result of the operation */ public static function connectPerson($ownerId, $ownerType, $targetId, $targetType, $ownerLink, $targetLink = null) { //0. Check if the $owner and the $target exists $owner = Link::checkIdAndType($ownerId, $ownerType); $target = Link::checkIdAndType($targetId, $targetType); $newObject = array('type' => $targetType); PHDB::update($ownerType, array("_id" => new MongoId($ownerId)), array('$set' => array("links." . $ownerLink . "." . $targetId => $newObject))); if (isset($targetLink) && $targetLink != null) { $newObject = array('type' => $ownerType); PHDB::update($targetType, array("_id" => new MongoId($targetId)), array('$set' => array("links." . $targetLink . "." . $ownerId => $newObject))); } return array("result" => true, "msg" => "The link has been added with success"); }
/** * upload the path of an image * @param itemId is the id of the item that we want to update * @param itemType is the type of the item that we want to update * @param path is the new path of the image * @return */ public static function setImagePath($itemId, $itemType, $path, $contentKey) { $tabImage = explode('.', $contentKey); if (in_array(Document::IMG_PROFIL, $tabImage)) { return PHDB::update($itemType, array("_id" => new MongoId($itemId)), array('$set' => array("imagePath" => $path))); } }
private static function saveCitizenNotification($params) { PHDB::update("citoyens", array("_id" => new MongoId($params['notifyUser'])), array('$push' => array(CitoyenType::NODE_NOTIFICATIONS => $notification))); }
/** * Saves part of an entry genericlly based on * - collection and id value */ public function actionSave() { if (Yii::app()->request->isAjaxRequest && isset(Yii::app()->session["userId"])) { //var_dump($_POST); $id = null; $data = null; $collection = $_POST["collection"]; if (!empty($_POST["id"])) { $id = $_POST["id"]; } $key = $_POST["key"]; unset($_POST['id']); if ($_POST['collection'] == PHType::TYPE_MICROFORMATS) { $_POST['collection'] = $_POST['MFcollection']; unset($_POST['MFcollection']); } else { unset($_POST['collection']); unset($_POST['key']); } //empty fields aren't properly validated and must be removed /*foreach ($_POST as $k => $v) { echo $k." => ".$v."\n"; if(empty($v)) unset($_POST[$k]); }*/ $microformat = PHDB::findOne(PHType::TYPE_MICROFORMATS, array("key" => $key)); $validate = !isset($microformat) || !isset($microformat["jsonSchema"]) ? false : true; //validation process based on microformat defeinition of the form //by default dont perform validation test $valid = array("result" => true); if ($validate) { $valid = PHDB::validate($key, json_decode(json_encode($_POST), FALSE)); } if ($valid["result"]) { if ($id) { //update a single field //else update whole map $changeMap = !$microformat && isset($key) ? array('$set' => array($key => $_POST[$key])) : array('$set' => $_POST); PHDB::update($collection, array("_id" => new MongoId($id)), $changeMap); $res = array("result" => true, "msg" => "Vos données ont été mise à jour.", "reload" => true, "map" => $_POST, "id" => (string) $_POST["_id"]); } else { $_POST["created"] = time(); PHDB::insert($collection, $_POST); $res = array("result" => true, "msg" => "Vos données ont bien été enregistré.", "reload" => true, "map" => $_POST, "id" => (string) $_POST["_id"]); } } else { $res = $valid; } echo json_encode($res); } }
public static function importMongoDB($post) { $objectImport = json_decode($post['jsonimport']); //var_dump($jsonMapping); $objectMapping = json_decode($post['jsonmapping']); //var_dump($objectMapping); $nameFile = explode(".", $objectMapping->nameFile); $files_importHistory = scandir("../../modules/cityData/importHistory/"); $i = 0; $nameFolder = false; while ($i < count($files_importHistory) && $nameFolder == false) { if (strpos($files_importHistory[$i], $nameFile[0]) !== false) { $nameFolder = $files_importHistory[$i]; } $i++; } if ($nameFolder == false) { $nameFolder = date("Ymd") . '_' . $nameFile[0]; mkdir("../../modules/cityData/importHistory/" . $nameFolder, 0775); file_put_contents("../../modules/cityData/importHistory/" . $nameFolder . "/importHistory.json", $post['jsonmapping']); file_put_contents("../../modules/cityData/importHistory/" . $nameFolder . "/cityData_1.json", $post['jsonimport']); file_put_contents("../../modules/cityData/importHistory/" . $nameFolder . "/error_1.json", $post['jsonrejet']); $textFileSh = "mongoimport --db pixelhumain --collection importHistory importHistory.json --jsonArray;\n"; $textFileSh = $textFileSh . "mongoimport --db pixelhumain --collection cityData cityData_1.json --jsonArray;\n"; file_put_contents("../../modules/cityData/importHistory/" . $nameFolder . "/importMongo.sh", $textFileSh); if (file_exists("../../modules/cityData/importHistory/importMongoAll.sh") == true) { $textImportMongoAll = file_get_contents("../../modules/cityData/importHistory/importMongoAll.sh", FILE_USE_INCLUDE_PATH); } else { $textImportMongoAll = ""; } $textImportMongoAll = $textImportMongoAll . "cd " . $nameFolder . ";\n"; $textImportMongoAll = $textImportMongoAll . "sh importMongo.sh;\n"; $textImportMongoAll = $textImportMongoAll . "cd .. ;\n"; } else { $files = scandir("../../modules/cityData/importHistory/" . $nameFolder); $count = 1; foreach ($files as $key => $value) { $name_file = explode(".", $value); if (strpos($name_file[0], "cityData") !== false) { $count++; } } file_put_contents("../../modules/cityData/importHistory/" . $nameFolder . "/importHistory.json", $post['jsonmapping']); file_put_contents("../../modules/cityData/importHistory/" . $nameFolder . "/cityData_" . $count . ".json", $post['jsonimport']); file_put_contents("../../modules/cityData/importHistory/" . $nameFolder . "/error_" . $count . ".json", $post['jsonrejet']); $textFileSh = file_get_contents("../../modules/cityData/importHistory/" . $nameFolder . "/importMongo.sh", FILE_USE_INCLUDE_PATH); $textFileSh = $textFileSh . "mongoimport --db pixelhumain --collection cityData cityData_" . $count . ".json --jsonArray;\n"; file_put_contents("../../modules/cityData/importHistory/" . $nameFolder . "/importMongo.sh", $textFileSh); if (file_exists("../../modules/cityData/importHistory/importMongoAll.sh") == true) { $textImportMongoAll = file_get_contents("../../modules/cityData/importHistory/importMongoAll.sh", FILE_USE_INCLUDE_PATH); } else { $textImportMongoAll = "cd " . $nameFolder . ";\n"; $textImportMongoAll = $textImportMongoAll . "sh importMongo.sh;\n"; $textImportMongoAll = $textImportMongoAll . "cd .. ;\n"; } } //var_dump($textImportMongoAll); file_put_contents("../../modules/cityData/importHistory/importMongoAll.sh", $textImportMongoAll); /*if($post['chooseSelected'] == "new"){ $resMapping = PHDB::insert(City::COLLECTION_IMPORTHISTORY, $objectMapping); } else { $resMapping = PHDB::update(City::COLLECTION_IMPORTHISTORY, array("_id"=>new MongoId($post['mappingSelected'])), array('$set' => array('src' => $objectMapping->src, 'date_update' => $objectMapping->date_update, 'nameFile' => $objectMapping->nameFile, 'url' => $objectMapping->url, 'separateur' => $objectMapping->separateur, 'idlien' => $objectMapping->idlien, 'fields' => $objectMapping->fields)), array("upsert" => true)); }*/ /*if(isset($objectImport->insee)) { $res = PHDB::findOne(City::COLLECTION_DATA, array("insee" => $objectImport->insee, $post["typeData"] => array( '$exists' => 1 ))); echo "</br> 1 : " ; var_dump($post["typeData"]); var_dump($res); if($res == null) { $resData = PHDB::insert(City::COLLECTION_DATA, $objectImport); } else { $resData = PHDB::update(City::COLLECTION_DATA, array("_id"=>new MongoId($res["_id"])), array('$set' => $objectImport), array("upsert" => true)); } } else { foreach ($objectImport as $key => $value) { $res = PHDB::findOne(City::COLLECTION_DATA, array("insee" => $value->insee, $post["typeData"] => array( '$exists' => 1 ))); if($res == null) { $resData = PHDB::insert(City::COLLECTION_DATA, $value); } else { $resData = PHDB::update(City::COLLECTION_DATA, array("_id"=>new MongoId($res["_id"])), array('$set' => $value), array("upsert" => true)); } } }*/ if (isset($objectImport->insee)) { $res = PHDB::findOne("cities", array("insee" => $objectImport->insee)); echo "</br> 1 : "; var_dump($post["typeData"]); var_dump($res); if ($res == null) { //$resData = PHDB::insert(City::COLLECTION_DATA, $objectImport); } else { $resData = PHDB::update("cities", array("_id" => new MongoId($res["_id"])), array('$set' => $objectImport), array("upsert" => true)); } } else { foreach ($objectImport as $key => $value) { $res = PHDB::findOne("cities", array("insee" => $value->insee)); if ($res == null) { //$resData = PHDB::insert("cities", $value); } else { $resData = PHDB::update("cities", array("_id" => new MongoId($res["_id"])), array('$set' => $value), array("upsert" => true)); } } } return true; }
/** * Update a person field value * @param String $personId The person Id to update * @param String $personFieldName The name of the field to update * @param String $personFieldValue * @param String $userId * @return boolean True if the update has been done correctly. Can throw CTKException on error. */ public static function updatePersonField($personId, $personFieldName, $personFieldValue, $userId) { if ($personId != $userId) { throw new CTKException("Can not update the person : you are not authorized to update that person !"); } $dataFieldName = Person::getCollectionFieldNameAndValidate($personFieldName, $personFieldValue); //Specific case : //Tags if ($dataFieldName == "tags") { $personFieldValue = Tags::filterAndSaveNewTags($personFieldValue); } //address if ($dataFieldName == "address") { if (!empty($personFieldValue["postalCode"]) && !empty($personFieldValue["codeInsee"])) { $insee = $personFieldValue["codeInsee"]; $address = SIG::getAdressSchemaLikeByCodeInsee($insee); $set = array("address" => $address, "geo" => SIG::getGeoPositionByInseeCode($insee)); } else { throw new CTKException("Error updating the Person : address is not well formated !"); } } else { if ($dataFieldName == "birthDate") { date_default_timezone_set('UTC'); $dt = DateTime::createFromFormat('Y-m-d H:i', $personFieldValue); if (empty($dt)) { $dt = DateTime::createFromFormat('Y-m-d', $personFieldValue); } $newMongoDate = new MongoDate($dt->getTimestamp()); $set = array($dataFieldName => $newMongoDate); } else { $set = array($dataFieldName => $personFieldValue); } } //update the person PHDB::update(self::COLLECTION, array("_id" => new MongoId($personId)), array('$set' => $set)); return true; }
public function run() { $email = $_POST["email"]; $res = null; if (Yii::app()->request->isAjaxRequest) { //creating user must exist if ($user = PHDB::findOne(PHType::TYPE_CITOYEN, array("email" => $email))) { //udate the new app specific fields $newInfos = array(); if (isset($_POST['email'])) { $newInfos['email'] = $_POST['email']; } if (isset($_POST['email']) && $_POST['email'] != Yii::app()->session["userEmail"]) { $newInfos['createdByEmail'] = Yii::app()->session["userEmail"]; } if (isset($_POST['cp'])) { $newInfos['cp'] = $_POST['cp']; } if (isset($_POST['name'])) { $newInfos['name'] = $_POST['name']; } if (isset($_POST['phoneNumber'])) { $newInfos['phoneNumber'] = $_POST['phoneNumber']; } if (isset($_POST['type'])) { $newInfos['type'] = $_POST['type']; } if (isset($_POST['tags'])) { $newInfos['tags'] = explode(",", $_POST['tags']); } if (isset($_POST['when'])) { $newInfos['date'] = $_POST['when']; } if (isset($_POST['where'])) { $newInfos['where'] = $_POST['where']; } if (isset($_POST['group'])) { $newInfos['group'] = $_POST['group']; } if (isset($_POST["app"])) { $appKey = $_POST["app"]; $newInfos['applications'] = array($appKey => array("usertype" => $_POST['type'])); $app = PHDB::findOne(PHType::TYPE_APPLICATIONS, array("key" => $appKey)); //check for application specifics defined in DBs application entry if (isset($app["registration"]) && $app["registration"] == "mustBeConfirmed") { $newInfos['applications'][$appKey]["registrationConfirmed"] = false; } } //check if group exists else create the new group if (!PHDB::findOne(PHType::TYPE_GROUPS, array("type" => $_POST['type'], "name" => $_POST['name']))) { PHDB::insert(PHType::TYPE_GROUPS, $newInfos); $res = array("result" => true, "msg" => $_POST['type'] . " has been created"); } else { //if there's an email change PHDB::update(PHType::TYPE_GROUPS, array("name" => $_POST['name']), array('$set' => $newInfos)); $res = array("result" => true, "msg" => $_POST['type'] . " has been updated"); } //TODO : confirmation email on create //TODO : notification on update } else { $res = array('result' => false, "msg" => "Connected user must exist"); } } else { $res = array('result' => false, 'msg' => 'something somewhere went terribly wrong'); } Rest::json($res); Yii::app()->end(); }
public function run() { $email = $_POST["email"]; if (Yii::app()->request->isAjaxRequest) { //if exists login else create the new user $pwd = isset($_POST["pwd"]) ? $_POST["pwd"] : null; if ($user = PHDB::findOne(PHType::TYPE_CITOYEN, array("email" => $email))) { $res = array('result' => false, 'msg' => 'Email non valid'); } else { $res = Citoyen::register($email, $pwd); } $newInfos = array(); if ($user = PHDB::findOne(PHType::TYPE_CITOYEN, array("email" => $email))) { $pos = array(); //udate the new app specific fields if (isset($_POST["position"])) { $positionObj = array(); if (is_array($_POST["position"])) { for ($i = 0; $i < count($_POST["position"]); $i++) { if ($_POST["position"][$i] != "") { array_push($positionObj, $_POST["position"][$i]); } } } else { $positionObj = $_POST["position"]; } $newInfos["positions"] = $positionObj; } if (isset($_POST['supervisor'])) { $newInfos['supervisor'] = $_POST['supervisor']; } if (isset($_POST['cp'])) { $newInfos['cp'] = $_POST['cp']; } if (isset($_POST['tel'])) { $newInfos['phoneNumber'] = $_POST['tel']; } if (isset($_POST['url'])) { $newInfos['url'] = $_POST['url']; } if (isset($_POST['skype'])) { $newInfos['skype'] = $_POST['skype']; } if (isset($_POST['birth'])) { $newInfos['birth'] = $_POST['birth']; } if (isset($_POST['name'])) { $newInfos['name'] = $_POST['name']; Yii::app()->session["user"] = array("name" => $_POST['name']); } if (isset($_POST['city'])) { $newInfos['city'] = $_POST['city']; } if (isset($_POST['imagePath'])) { $newInfos['imagePath'] = $_POST['imagePath']; } if (isset($_POST['cp'])) { $newInfos["cp"] = $_POST['cp']; $newInfos["address"] = array("@type" => "PostalAddress", "postalCode" => $_POST['cp']); } if (isset($_POST['country'])) { $newInfos["address"]["addressLocality"] = $_POST['country']; } if (isset($_POST['tags'])) { if ($_POST['tags'] != "") { $tabTags = explode(",", $_POST['tags']); $newInfos["tags"] = $tabTags; $tagsList = PHDB::findOne(PHType::TYPE_LISTS, array("name" => "tags"), array('list')); foreach (explode(",", $_POST['tags']) as $tag) { if (!in_array($tag, $tagsList['list'])) { PHDB::update(PHType::TYPE_LISTS, array("name" => "tags"), array('$push' => array("list" => $tag))); } } $newInfos["tags"] = explode(",", $_POST['tags']); } else { $newInfos["tags"] = $_POST['tags']; } } if (isset($_FILES['avatar'])) { $pathImage = $this->processImage($_FILES['avatar'], $user["_id"]["{$id}"]); if ($pathImage) { $newInfos["imagePath"] = $pathImage; } } //specific application routines if (isset($_POST["app"])) { $appKey = $_POST["app"]; //when registration is done for an application it must be registered $newInfos['applications'] = array($appKey => array("usertype" => isset($_POST['type']) ? $_POST['type'] : $_POST['app'])); $app = PHDB::findOne(PHType::TYPE_APPLICATIONS, array("key" => $appKey)); //check for application specifics defined in DBs application entry if (isset($app["registration"])) { if ($app["registration"] == "mustBeConfirmed") { $newInfos['applications'][$appKey]["registrationConfirmed"] = false; } else { if ($app["registration"] == "mailValidation") { Yii::app()->session["userId"] = $user["_id"]; Yii::app()->session["userEmail"] = null; //send validation mail //TODO : make emails as cron jobs $title = $app["name"]; $logo = isset($app["logo"]) ? $this->module->assetsUrl . $app["logo"] : Yii::app()->getRequest()->getBaseUrl(true) . '/images/logo/logo144.png'; Mail::send(array("tpl" => 'validation', "subject" => 'Confirmer votre compte ' . $title, "from" => Yii::app()->params['adminEmail'], "to" => $email, "tplParams" => array("user" => $user["_id"], "title" => $title, "logo" => $logo))); } } } } //Social Network info $socialNetwork = array(); if (isset($_POST["twitterAccount"])) { $socialNetwork["twitterAccount"] = $_POST["twitterAccount"]; } if (isset($_POST["facebookAccount"])) { $socialNetwork["facebookAccount"] = $_POST["facebookAccount"]; } if (isset($_POST["gplusAccount"])) { $socialNetwork["gplusAccount"] = $_POST["gplusAccount"]; } if (isset($_POST["gitHubAccount"])) { $socialNetwork["gitHubAccount"] = $_POST["gitHubAccount"]; } if (isset($_POST["linkedInAccount"])) { $socialNetwork["linkedInAccount"] = $_POST["linkedInAccount"]; } if (isset($_POST["skypeAccount"])) { $socialNetwork["skypeAccount"] = $_POST["skypeAccount"]; } $newInfos["socialNetwork"] = $socialNetwork; $res = PHDB::update(PHType::TYPE_CITOYEN, array("email" => $email), array('$set' => $newInfos)); //$res = array('result' => true , 'msg'=>'update profile succesfully'); } } else { $res = array('result' => false, 'msg' => 'something somewhere went terribly wrong'); } Rest::json($res); Yii::app()->end(); }
/** * Update a project field value * @param String $projectId The person Id to update * @param String $projectFieldName The name of the field to update * @param String $projectFieldValue * @param String $isAdmin or $isModerate (including after) * @return boolean True if the update has been done correctly. Can throw CTKException on error. */ public static function updateProjectField($projectId, $projectFieldName, $projectFieldValue, $userId) { if (!Authorisation::canEditItem($userId, self::COLLECTION, $projectId)) { throw new CTKException(Yii::t("project", "Can not update this project : you are not authorized to update that project !")); } $dataFieldName = self::getCollectionFieldNameAndValidate($projectFieldName, $projectFieldValue, $projectId); //Specific case : //Tags if ($dataFieldName == "tags") { $projectFieldValue = Tags::filterAndSaveNewTags($projectFieldValue); } //address if ($dataFieldName == "address") { if (!empty($projectFieldValue["postalCode"]) && !empty($projectFieldValue["codeInsee"])) { $insee = $projectFieldValue["codeInsee"]; $address = SIG::getAdressSchemaLikeByCodeInsee($insee); $set = array("address" => $address, "geo" => SIG::getGeoPositionByInseeCode($insee)); } else { throw new CTKException("Error updating the Project : address is not well formated !"); } //Start Date - End Date } else { if ($dataFieldName == "startDate" || $dataFieldName == "endDate") { date_default_timezone_set('UTC'); $dt = DateTime::createFromFormat('Y-m-d H:i', $projectFieldValue); if (empty($dt)) { $dt = DateTime::createFromFormat('Y-m-d', $projectFieldValue); } $newMongoDate = new MongoDate($dt->getTimestamp()); $set = array($dataFieldName => $newMongoDate); } else { $set = array($dataFieldName => $projectFieldValue); } } //update the project PHDB::update(self::COLLECTION, array("_id" => new MongoId($projectId)), array('$set' => $set)); return array("result" => true, "msg" => "Votre projet a été modifié avec succes", "id" => $projectId); }
/** * Update an organization field value * @param String $organisationId The organization Id to update * @param String $organizationFieldName The name of the field to update * @param String $organizationFieldValue * @param String $userId * @return boolean True if the update has been done correctly. Can throw CTKException on error. */ public static function updateOrganizationField($organizationId, $organizationFieldName, $organizationFieldValue, $userId) { if (!Authorisation::isOrganizationAdmin($userId, $organizationId)) { throw new CTKException(Yii::t("organisation", "Can not update this organization : you are not authorized to update that organization !")); } $dataFieldName = Organization::getCollectionFieldNameAndValidate($organizationFieldName, $organizationFieldValue); //Specific case : //Tags if ($dataFieldName == "tags") { $organizationFieldValue = Tags::filterAndSaveNewTags($organizationFieldValue); } //address if ($dataFieldName == "address") { if (!empty($organizationFieldValue["postalCode"]) && !empty($organizationFieldValue["codeInsee"])) { $insee = $organizationFieldValue["codeInsee"]; $address = SIG::getAdressSchemaLikeByCodeInsee($insee); $set = array("address" => $address, "geo" => SIG::getGeoPositionByInseeCode($insee)); } else { throw new CTKException("Error updating the Organization : address is not well formated !"); } } else { $set = array($dataFieldName => $organizationFieldValue); } //update the organization PHDB::update(Organization::COLLECTION, array("_id" => new MongoId($organizationId)), array('$set' => $set)); return true; }
public static function link2Users($inviterId, $invitedId) { //make sure both users exist $inviter = PHDB::findOne(self::COLLECTION, array("_id" => new MongoId($inviterId))); $invited = PHDB::findOne(self::COLLECTION, array("_id" => new MongoId($invitedId))); $res = array("result" => false); if ($inviter && $invited && $inviter != $invited) { //check if not allready linked if (!isset($inviter[CitoyenType::NODE_FRIENDS]) || isset($inviter[CitoyenType::NODE_FRIENDS]) && !isset($inviter[CitoyenType::NODE_FRIENDS][$invitedId])) { //add a relation link on the inviter //add invited to inviter friends PHDB::update(self::COLLECTION, array("_id" => new MongoId($inviterId)), array('$set' => array(CitoyenType::NODE_FRIENDS . "." . $invitedId => array("since" => time())))); //add inviter to invited friends if (!isset($invited[CitoyenType::NODE_FRIENDS]) || isset($invited[CitoyenType::NODE_FRIENDS]) && !isset($invited[CitoyenType::NODE_FRIENDS][$inviterId])) { PHDB::update(self::COLLECTION, array("_id" => new MongoId($invitedId)), array('$set' => array(CitoyenType::NODE_FRIENDS . "." . $inviterId => array("since" => time())))); } //notify the invited user for validation Notification::saveNotification(array("type" => NotificationType::NOTIFICATION_LINK_REQUEST, "notifyUser" => $invitedId, "inviter" => $inviterId, "invited" => $invitedId)); $res = array("result" => true, "invitationRequestSaved" => true, "inviterId" => $inviterId, "invitedId" => $invitedId); } else { $res = array("result" => false, "msg" => "users are allready connected", "inviterId" => $inviterId, "invitedId" => $invitedId); } } else { $res = array("result" => false, "msg" => "users must be different", "inviterId" => $inviterId, "invitedId" => $invitedId); } return $res; }
public static function updateEvent($eventId, $event, $userId) { if (!Authorisation::isEventAdmin($eventId, $userId)) { throw new CTKException("Can not update the event : you are not authorized to update that event!"); } if (isset($event["tags"])) { $event["tags"] = Tags::filterAndSaveNewTags($event["tags"]); } PHDB::update(Event::COLLECTION, array("_id" => new MongoId($eventId)), array('$set' => $event)); return array("result" => true, "msg" => "Votre evenement a été modifié avec succes", "id" => $eventId); }