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); }
/** * 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; }
/** * 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 static function updateEventField($eventId, $eventFieldName, $eventFieldValue, $userId) { if (!Authorisation::isEventAdmin($eventId, $userId)) { throw new CTKException("Can not update the event : you are not authorized to update that event!"); } $dataFieldName = self::getCollectionFieldNameAndValidate($eventFieldName, $eventFieldValue, $eventId); //address if ($eventFieldName == "address") { if (!empty($eventFieldValue["postalCode"]) && !empty($eventFieldValue["codeInsee"])) { $insee = $eventFieldValue["codeInsee"]; $address = SIG::getAdressSchemaLikeByCodeInsee($insee); $set = array("address" => $address, "geo" => SIG::getGeoPositionByInseeCode($insee)); } else { throw new CTKException("Error updating the Event : address is not well formated !"); } //Date format } else { if ($dataFieldName == "startDate" || $dataFieldName == "endDate") { date_default_timezone_set('UTC'); $dt = DateTime::createFromFormat('Y-m-d H:i', $eventFieldValue); if (empty($dt)) { $dt = DateTime::createFromFormat('Y-m-d', $eventFieldValue); } $newMongoDate = new MongoDate($dt->getTimestamp()); $set = array($dataFieldName => $newMongoDate); } else { $set = array($dataFieldName => $eventFieldValue); } } $res = Event::updateEvent($eventId, $set, $userId); return $res; }