/** * First pass of the spec: parse and stop execution on errors * @todo: introduce ValidationException * * @param SpecRest $restSpec * @return void */ public function validate(Rest $restSpec) { $apiSpec = $restSpec->getApiSpecs(); if (empty($apiSpec)) { throw new \RuntimeException('No API spec provided'); } foreach ($apiSpec as $apiSpec) { foreach ($apiSpec->getUrlSpecs() as $urlSpec) { $useCases = $urlSpec->getUseCases(); if (!$useCases) { throw new \RuntimeException('You have to specify use cases inside the URL specificetion'); } foreach ($useCases as $urlUseCaseSpec) { if (!$urlUseCaseSpec->getRequest()) { throw new \RuntimeException('You have to add request specification using givenRequest() function'); } if (!$urlUseCaseSpec->getExpectedResponseSpec()) { throw new \RuntimeException('You have to specify expected response using expectResponse() function'); } if ($urlUseCaseSpec->isATemplate() && !$urlUseCaseSpec->getExampleParameters()) { throw new \RuntimeException('To use an URL template you have to provide example parameters to call the URL with.'); } if ($exampleParams = $urlUseCaseSpec->getExampleParameters()) { foreach ($exampleParams as $name => $value) { $placeholder = $urlUseCaseSpec->buildParameterPlaceholder($name); if (strpos($urlUseCaseSpec->getUrl(), $placeholder) === false) { throw new \RuntimeException(sprintf('You specified example parameter, but the placeholder "%s" for it is missing in your URL', $placeholder)); } } } } } } }
public function actionClearInitDataPeopleAll() { //inject Data brute d'une liste de Person avec Id $import = Admin::initMultipleModuleData($this->module->id, "personNetworkingAll", true, true, true); Rest::json($import); Yii::app()->end(); }
/** * @expectedException \Exception */ public function test_request_false() { /** === Test Data === */ $PARAMS = 'params'; $PARAMS_JSON = 'JSON encoded params'; $ROUTE = 'route'; $SESS_ID = 'session id'; $CONTEXT_OPTS_JSON = 'JSON encoded context options'; $RESULT = 'result'; /** === Setup Mocks === */ // $sessId = $this->_login->getSessionId(); $this->mLogin->shouldReceive('getSessionId')->once()->andReturn($SESS_ID); // $request = $this->_adapter->encodeJson($params); $this->mAdapter->shouldReceive('encodeJson')->once()->with($PARAMS)->andReturn($PARAMS_JSON); // $context = $this->_adapter->createContext($contextOpts); $this->mAdapter->shouldReceive('createContext')->once()->andReturn($PARAMS_JSON); // this->_logger->debug("Request URI:\t$uri"); $this->mLogger->shouldReceive('debug'); // $jsonContextOpt = $this->_adapter->encodeJson($contextOpts); $this->mAdapter->shouldReceive('encodeJson')->once()->andReturn($CONTEXT_OPTS_JSON); // $contents = $this->_adapter->getContents($uri, $context); $this->mAdapter->shouldReceive('getContents')->once()->andReturn(false); // $this->_logger->critical($msg); $this->mLogger->shouldReceive('critical')->once(); /** === Call and asserts === */ $res = $this->obj->request($PARAMS, $ROUTE); $this->assertEquals($RESULT, $res); }
public function run() { $events = array(); $organization = Organization::getPublicData($id); if (isset($organization["links"]["events"])) { foreach ($organization["links"]["events"] as $key => $value) { $event = Event::getPublicData($key); $events[$key] = $event; } } foreach ($organization["links"]["members"] as $newId => $e) { if ($e["type"] == Organization::COLLECTION) { $member = Organization::getPublicData($newId); } else { $member = Person::getPublicData($newId); } if (isset($member["links"]["events"])) { foreach ($member["links"]["events"] as $key => $value) { $event = Event::getPublicData($key); $events[$key] = $event; } } } Rest::json($events); }
public function run($eventId) { if (isset(Yii::app()->session["userId"])) { Event::delete($eventId, Yii::app()->session["userId"]); } Rest::json(array('result' => true, "msg" => Yii::t("event", "Event removed"))); }
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(); }
public function __construct() { parent::__construct(); // Init parent contructor $this->dbConnect(); // Initiate Database connection }
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(); }
/** * Update an information field for an organization */ public function run() { $organizationId = ""; $res = array("result" => false, "msg" => Yii::t("common", "Something went wrong!")); if (!empty($_POST["pk"])) { $organizationId = $_POST["pk"]; } else { if (!empty($_POST["id"])) { $organizationId = $_POST["id"]; } } if ($organizationId != "") { if (!empty($_POST["name"]) && !empty($_POST["value"])) { $organizationFieldName = $_POST["name"]; $organizationFieldValue = $_POST["value"]; try { Organization::updateOrganizationField($organizationId, $organizationFieldName, $organizationFieldValue, Yii::app()->session["userId"]); $res = array("result" => true, "msg" => Yii::t("organisation", "The organization has been updated"), $organizationFieldName => $organizationFieldValue); } catch (CTKException $e) { $res = array("result" => false, "msg" => $e->getMessage(), $organizationFieldName => $organizationFieldValue); } } } Rest::json($res); }
/** * Save a job * @return an array with result and message json encoded */ public function run() { $controller = $this->getController(); //insert a new job if (empty($_POST["pk"])) { foreach ($_POST as $fieldName => $fieldValue) { $collectionName = $controller->getCollectionFieldName($fieldName); $job[$collectionName] = $fieldValue; } $res = Job::insertJob($job); if ($res["result"]) { return Rest::json(array("msg" => "insertion ok ", "id" => $res["id"], "job" => $res["job"])); } //update an existing job } else { $jobId = $_POST["pk"]; if (!empty($_POST["name"]) && !empty($_POST["value"])) { $jobFieldName = $_POST["name"]; $jobFieldValue = $_POST["value"]; $collectionName = $controller->getCollectionFieldName($jobFieldName); Job::updateJobField($jobId, $collectionName, $jobFieldValue, Yii::app()->session["userId"]); } else { return Rest::json(array("result" => false, "msg" => Yii::t("common", "Uncorrect request"))); } } return Rest::json(array("result" => true, "msg" => Yii::t("job", "Your job offer has been updated with success"), $jobFieldName => $jobFieldValue)); }
public function run($id) { $controller = $this->getController(); //get The job Id if (empty($id)) { throw new CTKException(Yii::t("job", "The job posting id is mandatory to retrieve the job posting !")); } if (empty($_POST["mode"])) { $mode = "view"; } else { $mode = $_POST["mode"]; } if ($mode == "insert") { $job = array(); $controller->title = Yii::t("job", "New Job Offer"); $controller->subTitle = Yii::t("job", "Fill the form"); } else { $job = Job::getById($id); $controller->title = $job["title"]; $controller->subTitle = isset($job["description"]) ? $job["description"] : (isset($job["type"]) ? "Type " . $job["type"] : ""); } $tags = json_encode(Tags::getActiveTags()); $organizations = Authorisation::listUserOrganizationAdmin(Yii::app()->session["userId"]); $controller->pageTitle = Yii::t("job", "Job Posting"); Rest::json(array("result" => true, "content" => $controller->renderPartial("jobSV", array("job" => $job, "tags" => $tags, "organizations" => $organizations, "mode" => $mode), true))); }
public function run($name) { if ($name) { $list = Lists::getListByName($name); } Rest::json(array("result" => true, "list" => $list)); }
public function run($type, $id, $contentKey = null, $user) { if (isset($_FILES['avatar'])) { $type = trim($type); $folder = str_replace(DIRECTORY_SEPARATOR, "/", DIRECTORY_SEPARATOR . $type . DIRECTORY_SEPARATOR . $id . DIRECTORY_SEPARATOR); $pathImage = $this->processImage($_FILES['avatar'], $id, $type); if ($pathImage) { $params = array(); $params["id"] = $id; $params["type"] = $type; $params['folder'] = $folder; $params['moduleId'] = Yii::app()->controller->module->id; $params['name'] = $pathImage["name"]; $params['doctype'] = "image"; $params['size'] = $pathImage["size"][0] * $pathImage["size"][1] / 1000; $params['author'] = $user; $params['category'] = array(); $params['contentKey'] = $contentKey; $result = Document::save($params); //Profile to check $urlBdd = str_replace(DIRECTORY_SEPARATOR, "/", DIRECTORY_SEPARATOR . "upload" . DIRECTORY_SEPARATOR . Yii::app()->controller->module->id . $folder . $pathImage["name"]); Document::setImagePath($id, $type, $urlBdd, $contentKey); $newImage = Document::getById($result["id"]); } $res = array('result' => true, 'msg' => 'The picture was uploaded', 'imagePath' => $urlBdd, "id" => $result["id"], "image" => $newImage); Rest::json($res); Yii::app()->end(); } }
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() { //affiche les villes de plus de 100 000 habitants $query = array('habitants' => array('$gt' => 100000)); $cities = iterator_to_array(Yii::app()->mongodb->cities->find($query)); Rest::json($cities); Yii::app()->end(); }
public function run() { $email = Yii::app()->session["userEmail"]; $user = Yii::app()->mongodb->citoyens->findOne(array("email" => $email)); $city = Yii::app()->mongodb->cities->findOne(array("cp" => $user['cp'])); Rest::json(array('user' => $user, 'city' => $city)); Yii::app()->end(); }
public function run() { //TODO $res = Citoyen::addNode( "applications.".$_POST['app'].".isAdmin" ,true , $_POST['id'] ); //TODO update application sadmin array $res = array('result' => true); Rest::json($res); Yii::app()->end(); }
public function run($cp) { $city = Yii::app()->mongodb->cities->findOne(array("cp" => $cp)); if ($city != null) { Rest::json(array('lat' => $city['geo']['latitude'], 'lng' => $city['geo']['longitude'])); } Yii::app()->end(); }
public function __construct() { parent::__construct(); if (!$this->managers->access('prodcuts')) { header('HTTP/1.1 401 Unauthorized'); exit; } }
public function run($email, $app) { //TODO : add a test adminUser //isAppAdminUser $user = Yii::app()->mongodb->citoyens->findAndModify(array("email" => $email), array('$set' => array("applications." . $app . ".registrationConfirmed" => true))); $user = Yii::app()->mongodb->citoyens->findOne(array("email" => $email)); Rest::json($user); Yii::app()->end(); }
/** * Delete an entry from the job table using the id */ public function run($id) { //get The job Id if (empty($id)) { throw new CTKException(Yii::t("job", "The job posting id is mandatory to retrieve the job posting !")); } $res = Job::removeJob($id, Yii::app()->session["userId"]); Rest::json($res); }
protected function init() { if (Input::post('key', $apikey, 'string') && $apikey == Config::getSecret('api', 'card')) { parent::init(); } else { $this->response(-3, 'API key无效'); exit; } }
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); }
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(); }
function header() { $this->http_mime_type = "image/svg+xml"; parent::header(); if (is_file($this->get_font_location())) { $this->body = file_get_contents($this->get_font_location()); } else { header("HTTP/1.0 404 Not Found"); } }
public function run($memberId, $memberType, $memberOfId, $memberOfType, $role) { $res = array("result" => false, "msg" => Yii::t("common", "Something went wrong!")); try { $res = Link::removeRole($memberOfId, Organization::COLLECTION, $memberId, $memberType, $role, Yii::app()->session['userId']); } catch (CTKException $e) { $res = array("result" => false, "msg" => $e->getMessage()); } return Rest::json($res); }
/** * 发送模板短信 * @param to 手机号码集合,用英文逗号分开 * @param datas 内容数据 格式为数组 例如:array('Marry','Alon'),如不需替换请填 null * @param $tempId 模板Id,测试应用和未上线应用使用测试模板请填写1,正式应用上线后填写已申请审核通过的模板ID */ function sendTemplateSMS($to, $datas, $tempId) { //主帐号,对应开官网发者主账号下的 ACCOUNT SID $accountSid = '8a48b551522ff93101523514f7e60ee8'; //主帐号令牌,对应官网开发者主账号下的 AUTH TOKEN $accountToken = '8fdb37dd47e14ce789baf8f0f4a3d067'; //应用Id,在官网应用列表中点击应用,对应应用详情中的APP ID //在开发调试的时候,可以使用官网自动为您分配的测试Demo的APP ID $appId = '8a48b551522ff931015235170d2b0ef6'; //请求地址 //沙盒环境(用于应用开发调试):sandboxapp.cloopen.com //生产环境(用户应用上线使用):app.cloopen.com $serverIP = 'sandboxapp.cloopen.com'; //请求端口,生产环境和沙盒环境一致 $serverPort = '8883'; //REST版本号,在官网文档REST介绍中获得。 $softVersion = '2013-12-26'; // 初始化REST SDK // global $accountSid, $accountToken, $appId, $serverIP, $serverPort, $softVersion; $rest = new \Rest($serverIP, $serverPort, $softVersion); $rest->setAccount($accountSid, $accountToken); $rest->setAppId($appId); // 发送模板短信 echo "Sending TemplateSMS to {$to} <br/>"; $result = $rest->sendTemplateSMS($to, $datas, $tempId); if ($result == NULL) { echo "result error!"; break; } if ($result->statusCode != 0) { echo "error code :" . $result->statusCode . "<br>"; echo "error msg :" . $result->statusMsg . "<br>"; //TODO 添加错误处理逻辑 } else { echo "Sendind TemplateSMS success!<br/>"; // 获取返回信息 $smsmessage = $result->TemplateSMS; echo "dateCreated:" . $smsmessage->dateCreated . "<br/>"; echo "smsMessageSid:" . $smsmessage->smsMessageSid . "<br/>"; //TODO 添加成功处理逻辑 } }
public function run() { $res = array(); if (Yii::app()->session["userId"]) { $res = ActivityStream::removeNotificationsByUser(); } else { $res = array('result' => false, 'msg' => 'something somewhere went terribly wrong'); } Rest::json($res); Yii::app()->end(); }
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(); }