예제 #1
0
 public static function insertJob($job)
 {
     foreach ($job as $jobFieldName => $jobFieldValue) {
         if (!Job::checkFieldBeforeUpdate($jobFieldName, $jobFieldValue)) {
             throw new CTKException(Yii::t("job", "Can not insert the job : unknown field ") . $jobFieldName);
         }
     }
     //Manage tags : save any inexistant tag to DB
     if (isset($job["tags"])) {
         $job["tags"] = Tags::filterAndSaveNewTags($job["tags"]);
     }
     //Manage address
     if (isset($job["jobLocation.address"])) {
         if (!empty($job["jobLocation.address"]["postalCode"]) && !empty($job["jobLocation.address"]["codeInsee"])) {
             $insee = $job["jobLocation.address"]["codeInsee"];
             $address = SIG::getAdressSchemaLikeByCodeInsee($insee);
             $job["jobLocation.address"] = $address;
             $job["geo"] = SIG::getGeoPositionByInseeCode($insee);
         }
     }
     //Insert the job
     $result = PHDB::updateWithOptions(Job::COLLECTION, array("_id" => new MongoId()), array('$set' => $job), array("upsert" => true));
     //Trick for windows : the upserted does not have the same return value
     if (isset($result["upserted"])) {
         if (is_array($result["upserted"])) {
             $newJobId = (string) $result["upserted"][0]["_id"];
         } else {
             $newJobId = (string) $result["upserted"];
         }
         $job = Job::getById($newJobId);
     } else {
         throw new CTKException(Yii::t("job", "Problem inserting the new job offer"));
     }
     return array("result" => true, "msg" => Yii::t("job", "Your job offer has been added with succes"), "id" => $newJobId, "job" => $job);
 }
예제 #2
0
 /**
  * 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);
 }
예제 #3
0
 /**
  * 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;
 }
예제 #4
0
 /**
  * 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;
 }
예제 #5
0
 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;
 }