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)); }
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); }
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(); }
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); }
/** * 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; }
/** * get a job By Id * @param type $id : String as a mongoId of the job offer * @return json format of a job */ public static function getById($id) { $job = PHDB::findOne(Job::COLLECTION, array("_id" => new MongoId($id))); //get the details of the hiring organization if (!empty($job["hiringOrganization"])) { $organization = Organization::getById($job["hiringOrganization"]); $job["hiringOrganization"] = $organization; } return $job; }
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; }
/** * Get the city 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 getCityByCodeInsee($codeInsee) { if (empty($codeInsee)) { throw new InvalidArgumentException("The Insee Code is mandatory"); } $city = PHDB::findOne(self::CITIES_COLLECTION_NAME, array("insee" => $codeInsee)); if (empty($city)) { throw new CTKException("Impossible to find the city with the insee code : " . $codeInsee); } else { return $city; } }
/** * Apply project checks and business rules before inserting * @param array $project : array with the data of the project to check * @return array Project well format : ready to be inserted */ public static function getAndCheckProject($project, $userId) { if (empty($project['name'])) { throw new CTKException(Yii::t("project", "You have to fill a name for your project")); } // Is There a association with the same name ? $projectSameName = PHDB::findOne(self::COLLECTION, array("name" => $_POST['name'])); if ($projectSameName) { throw new CTKException(Yii::t("project", "A project with the same name already exist in the plateform")); } if (empty($project['startDate']) || empty($project['endDate'])) { throw new CTKException("The start and end date of an event are required."); } //The end datetime must be after start datetime $startDate = strtotime($project['startDate']); $endDate = strtotime($project['endDate']); if ($startDate > $endDate) { throw new CTKException("The start date must be before the end date."); } $newProject = array("name" => $project['name'], 'startDate' => new MongoDate($startDate), 'endDate' => new MongoDate($endDate), 'creator' => $userId, 'created' => time()); if (!empty($project['postalCode'])) { if (!empty($project['city'])) { $insee = $project['city']; $address = SIG::getAdressSchemaLikeByCodeInsee($insee); $newProject["address"] = $address; $newProject["geo"] = SIG::getGeoPositionByInseeCode($insee); } } else { throw new CTKException(Yii::t("project", "Please fill the postal code of the project to communect it")); } //No mandotory fields if (!empty($project['description'])) { $newProject["description"] = $project['description']; } if (!empty($project['url'])) { $newProject["url"] = $project['url']; } if (!empty($project['licence'])) { $newProject["licence"] = $project['licence']; } //Tags if (isset($project['tags'])) { if (gettype($project['tags']) == "array") { $tags = $project['tags']; } else { if (gettype($project['tags']) == "string") { $tags = explode(",", $project['tags']); } } $newProject["tags"] = $tags; } return $newProject; }
/** * 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 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)); } }
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(); }
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"]; } }
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); }
/** * get an event By Id * @param type $id : is the mongoId of the event * @return type */ public static function getById($id) { $event = PHDB::findOne(PHType::TYPE_EVENTS, array("_id" => new MongoId($id))); if (!empty($event["startDate"]) && !empty($event["endDate"])) { if (gettype($event["startDate"]) == "object" && gettype($event["endDate"]) == "object") { //Set TZ to UTC in order to be the same than Mongo date_default_timezone_set('UTC'); $event["startDate"] = date('Y-m-d H:i:s', $event["startDate"]->sec); $event["endDate"] = date('Y-m-d H:i:s', $event["endDate"]->sec); } else { //Manage old date with string on date event $now = time(); $yesterday = mktime(0, 0, 0, date("m"), date("d") - 1, date("Y")); $yester2day = mktime(0, 0, 0, date("m"), date("d") - 2, date("Y")); $event["endDate"] = date('Y-m-d H:i:s', $yesterday); $event["startDate"] = date('Y-m-d H:i:s', $yester2day); } } return $event; }
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(); }
public static function removeNotifications($id) { $notif = PHDB::findOne(PHType::TYPE_ACTIVITYSTREAM, array("_id" => new MongoId($id))); $res = array("result" => false, "msg" => "Something went wrong : Activty Stream Not Found", "id" => $id); if (isset($notif) && isset($notif["notify"]) && isset($notif["notify"]["id"])) { if (count($notif["notify"]["id"]) > 1) { //remove userid from array unset($notif["notify"]); } else { unset($notif["notify"]); } try { unset($notif["_id"]); PHDB::update(PHType::TYPE_ACTIVITYSTREAM, array("_id" => new MongoId($id)), array('$unset' => array("notify" => true))); $res = array("result" => true, "msg" => "Removed succesfully"); } catch (Exception $e) { $res = array("result" => false, "msg" => "Something went wrong :" . $e->getMessage()); } } return Rest::json($res); }
public function run($type = null, $id = null) { $controller = $this->getController(); $organization = null; if (isset($id)) { $organization = Organization::getById($id); //make sure conected user is the owner if ($organization["email"] != Yii::app()->session["userEmail"] || isset($organization["ph:owner"]) && $organization["ph:owner"] != Yii::app()->session["userEmail"]) { $organization = null; } } $types = PHDB::findOne(PHType::TYPE_LISTS, array("name" => "organisationTypes"), array('list')); $tags = Tags::getActiveTags(); $detect = new Mobile_Detect(); $isMobile = $detect->isMobile(); $params = array("organization" => $organization, 'type' => $type, 'types' => $types['list'], 'tags' => json_encode($tags)); if ($isMobile) { $controller->layout = "//layouts/mainSimple"; $controller->render("addOrganizationMobile", $params); } else { $controller->renderPartial("addOrganizationSV", $params); } }
function blockHTML($pathTpl, $entry, $params, $parent) { //echo $entry["key"]; $str = "<li class='block' id='block" . $entry['key'] . "'>"; $str .= "<h4>" . $entry['label'] . "</h4>"; $actions = ""; if (isset($entry["actions"])) { foreach ($entry["actions"] as $ak => $av) { $actions .= $ak . " > " . $av . "<br/>"; } } $formInfo = isset($entry["microformat"]) ? "microformat : " . $entry["microformat"] : "file > api/views/" . $parent['key'] . "/" . $entry['key'] . ".php"; $str .= "<div class='fss fr txtright'>" . $entry['desc'] . "<br/>" . $formInfo . "<br/>" . $actions . "<br/>" . "</div>"; if (isset($entry["microformat"])) { $microformat = PHDB::findOne(PHType::TYPE_MICROFORMATS, array("key" => $entry["microformat"])); $tpl = isset($microformat["template"]) ? $microformat["template"] : "dynamicallyBuild"; $str .= "<a href='javascript:;' onclick='openModal(\"" . $entry["microformat"] . "\",\"" . $microformat["collection"] . "\",null,\"" . $tpl . "\")' class='btn'>" . $entry['microformat'] . "</a><br/>"; } else { $str .= Yii::app()->controller->renderPartial($pathTpl, $params, true); } $str .= "<div class='clear'> </div></li>"; return $str; }
public function run() { //début de la requete => scope geographique $where = array('name' => $_POST["assoName"]); $asso = PHDB::findOne(Organization::COLLECTION, $where); $orgaMembres = array(); foreach ($asso["membres"] as $membre) { if (in_array($membre["tag_rangement"], $_POST["types"])) { $where = array('geo' => array('$exists' => true), '_id' => new MongoId($membre["id"])); $newMembre = PHDB::findOne(PHType::TYPE_CITOYEN, $where); $newMembre["type"] = $membre["tag_rangement"]; foreach ($asso["tags_rangement"] as $tagR) { if ($membre["tag_rangement"] == $tagR["name"]) { $newMembre["ico"] = $tagR["ico"]; $newMembre["color"] = $tagR["color"]; break; } } $orgaMembres[] = $newMembre; } } Rest::json($orgaMembres); Yii::app()->end(); }
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 static function getNewsStreamHtml($newsList, $module) { $html = '<div class="spine"></div><ul class="columns">'; $count = 0; foreach ($newsList as $post) { //récupère les infos sur l'auteur du post / News $where = array('_id' => $post['author']); $author = PHDB::findOne(PHType::TYPE_CITOYEN, $where); $color = "white"; $color = NEWS::get_GENRE_COLOR($post['genre']); //$html .= "<div class='post'>"; $html .= "<li>" . '<div class="timeline_element partition-white">'; $html .= "<div class='info_author_post'>"; //PHOTO PROFIL $html .= "<div class='pic_profil_author_post'>" . "<img class='img_profil_round' src='" . Yii::app()->theme->baseUrl . "/assets/images/avatar-1.jpg' height=55>" . "</div>"; //ICO TYPE ACCOUNT $html .= "<div class='ico_type_account_author_post'>" . "</div>"; //PSEUDO AUTHOR if (isset($author['name'])) { $html .= "<a href='' class='pseudo_author_post'>" . $author['name'] . "</a>"; } //CITY AUTHOR if (isset($author['cp'])) { $html .= "<a href class='city_author_post'>- " . $author['cp'] . "</a>"; } $html .= "</div>"; //info_author_post $html .= "<div class='header_post " . $color . "'>"; //IL Y A $html .= "<div class='ilya' style='float:left; max-width:100%; min-width:100%;'>" . "<center><i class='fa fa-clock-o'></i>" . "</br>il y a 18 minutes<center>" . "</div>"; //ILLUSTRATION POST //if(isset($post['id_illustration'])) if ($count == 0) { $html .= "<div style='float:left; max-width:100%; min-width:100%;'>" . "<center><img src='" . $module . "/images/news/test_illu/illu_test.jpg' class='illustration_post'/></center>" . "</div>"; } $count++; $html .= "</div>"; //GENRE $html .= "<div class='nature_post'>" . "<img src='" . $module . "/images/news/natures/" . $post['genre'] . ".png' class='img_illu_publication_nature' style='margin-top:0px;' title='nature du message : " . News::get_NATURES_NAMES($post['genre']) . "' id='" . $post['genre'] . "' height=50>" . "</div>"; //FAVORITES $html .= "<a href='' class='btn_circle_post' id='btn_circle_favorites' style='margin-left:12px; color:#23D1B9'>" . "<i class='fa fa-star' title='garder en favoris'></i>" . "</a>"; //ARLERT MODERATION $html .= "<a href='' class='btn_circle_post' id='btn_circle_moderation' style='color:#E66B6B'>" . "<i class='fa fa-bell' title='signaler le contenu'></i>" . "</a>"; //LIST THEMES $html .= "<div class='list_themes_post'>"; if (isset($post['about'])) { foreach ($post['about'] as $theme) { $html .= "<div class='theme_post'>" . "<img src='" . $module . "/images/news/themes/" . $theme . ".png' class='img_illu_publication_theme' title='thème : " . News::get_THEMES_NAMES($theme) . "' id='" . $theme . "' style='margin-top:0px;' height=30>" . "</div>"; } } $html .= "</div>"; $html .= "<div class='panel-title' style='float:left; min-width:100%;'>" . "<h4 style='font-size:15px; margin:0px; margin-left:10px; padding:0px;'><b>" . News::get_NATURES_NAMES($post['genre']) . "</b></h4>" . "</div>"; //TITLE if (isset($post['name'])) { $html .= "<div class='panel-title' style='float:left; min-width:100%;'>" . "<h3 style='font-size:18px; margin:0px; margin-left:10px; padding:0px;'>" . $post['name'] . "</h3>" . "</div>"; } //CONTENT if (isset($post['text'])) { $html .= "<div class='panel-body' style='float:left; margin-bottom:10px;'><p>" . $post['text'] . "</p></div>"; } //BAR TOOL $html .= "<div class='bar_tools_post'>" . "<ul>\t\n\t\t\t\t\t\t<li><a href=''>j'aime</a></li>\n\t\t\t\t\t\t<li><a href=''>partager</a></li>\t\t\t\t\t\t\n\t\t\t\t</ul>" . "<ul style='float:left;'>" . "<li style='float:left; margin-top:2px;'>10 <i class='fa fa-comment'></i></span></li>" . "<li style='float:left; margin-top:2px;'>10 <i class='fa fa-thumbs-up'></i></span></li>" . "<li style='float:left; margin-top:2px;'>10 <i class='fa fa-share-alt'></i></span></li>" . "<li style='float:left; margin-top:2px;'>10 <i class='fa fa-eye'></i></span></li>" . "</ul>" . "</div>"; //$html .= "</div>"; //post $html .= "</li>"; //post } $html .= '</ul>'; return $html; }
<div class="fss"> <?php //TODO make generic maybe as Widget with parameters //params : // module : ex : azotlive // collection : type folder $collection = PHType::TYPE_CITOYEN; $srcModule = isset($this->module) && isset($this->module->id) ? $this->module->id : "global"; $element = PHDB::findOne($collection, array("_id" => new MongoId(Yii::app()->session["userId"]))); echo "saved to : /ph/upload/" . $srcModule . "/" . $collection . "<br/>"; ?> <div class="controls"> <img width=50 class="imageThumb" src="<?php echo $element && isset($element['image']) ? Yii::app()->createUrl($element['image']) : Yii::app()->createUrl('images/PHOTO_ANONYMOUS.png'); ?> "/></td> <?php $this->widget('yiiwheels.widgets.fineuploader.WhFineUploader', array('name' => 'imageFile', 'uploadAction' => $this->createUrl('/templates/upload/dir/' . $srcModule . '/collection/' . $collection . '/input/imageFile', array('fine' => 1)), 'pluginOptions' => array('validation' => array('allowedExtensions' => array('jpg', 'jpeg', 'png', 'gif'), 'itemLimit' => 1)), 'events' => array('complete' => "function( id, name, responseJSON, xhr){\n console.log('" . Yii::app()->createUrl('upload/' . $srcModule . '/' . $collection . '/') . "/'+xhr.name+'?d='+ new Date().getTime());\n \$('#image').val('" . Yii::app()->createUrl('upload/' . $srcModule . '/' . $collection . '/') . "/'+xhr.name);\n \$('.imageThumb').attr('src','" . Yii::app()->createUrl('upload/' . $srcModule . '/' . $collection . '/') . "/'+xhr.name+'?d='+ new Date().getTime());\n \n }"))); ?> <input type="hidden" id="image" name="image" value="<?php if (isset($element["image"])) { echo $element["image"]; } ?> "/> </div> </div>
public static function validate($key, $params) { $res = array("result" => false); if ($jsonSchema = PHDB::findOne(PHType::TYPE_MICROFORMATS, array("key" => $key))) { //hack to convert array cast into object stdClass : json_decode (json_encode ( $jsonSchema["jsonSchema"] ), FALSE) $validator = new Json\Validator(json_decode(json_encode($jsonSchema["jsonSchema"]), FALSE)); try { $validator->validate($params); $res = array("result" => true); } catch (Exception $e) { $res["msg"] = $e->getMessage(); } } else { $res["msg"] = "no json Schema found."; } return $res; }
/** * 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 function actionAbout() { $person = PHDB::findOne(PHType::TYPE_CITOYEN, array("_id" => new MongoId(Yii::app()->session["userId"]))); $tags = PHDB::findOne(PHType::TYPE_LISTS, array("name" => "tags"), array('list')); $this->render("about", array("person" => $person, 'tags' => json_encode($tags['list']))); }
echo "checked"; } ?> ></td> </tr> <tr <?php if ($account && (!isset($account['activeOnProject']) || !$account['activeOnProject'])) { ?> class="hidden" <?php } ?> id="registerHelpoutWhat"> <td class="txtright">en tant que </td> <td> <?php $cursor = PHDB::findOne(PHType::TYPE_JOBTYPES, array(), array('list')); $this->widget('yiiwheels.widgets.select2.WhSelect2', array('asDropDownList' => false, 'name' => 'helpJob', 'id' => 'helpJob', 'value' => $account && isset($account['positions']) ? implode(",", $account['positions']) : "", 'pluginOptions' => array('tags' => $cursor['list'], 'placeholder' => "Qu'aimeriez vous faire ?", 'width' => '100%', 'tokenSeparators' => array(',', ' ')))); ?> </td> </tr> <tr > <td class="txtright">Centre d'intérêt </td> <td> <?php /*$cursor = PHDB::findOne(PHType::TYPE_LISTS, array("name"=>"tags"), array('list')); $this->widget('yiiwheels.widgets.select2.WhSelect2', array( 'asDropDownList' => false, 'name' => 'tagsPA', 'id' => 'tagsPA', 'value'=>($account && isset($account['tags']) ) ? implode(",", $account['tags']) : "",
public function run($id, $type) { $item = PHDB::findOne($type, array("_id" => new MongoId($id))); echo Rest::json($item); }
?> </select> <?php //var_dump($allMapping) ?> </div> <div class="form-group col-md-4"> <input type="submit" class="btn btn-primary" id="sumitVerification" value="Vérification"/> </div> </div> </form> <div id="divmapping"> <?php if (isset($chooseMapping)) { $oneMapping = PHDB::findOne(City::COLLECTION_IMPORTHISTORY, array("_id" => new MongoId($chooseMapping))); } ?> <div class="form-group col-md-12"> <h3 class="col-md-12">Mapping</h3> <div class="form-group col-md-4"> <label for="source">Source : </label> <?php if (isset($oneMapping)) { echo '<input type="text" id="source" name="source" value="' . $oneMapping["src"] . '">'; } else { echo '<input type="text" id="source" name="source" value="">'; } if ($result == true) { echo '<input type="hidden" id="chooseSelected" value="' . $choose . '">