switch ($resource) { case "dream": include_once "includes/dream.class.php"; switch ($_SERVER['REQUEST_METHOD']) { case "POST": $dream = new Dream($resourceId); $dream->alchemyApiKey = ALCHEMY_API_KEY; $dream->dateFormat = $date_format; $dream->origin = isset($_SESSION['origin']) ? $_SESSION['origin'] : null; $dream->postToTumblr = POST_TO_TUMBLR; $dream->timezone = TIME_ZONE; $dream->tumblrPostEmail = TUMBLR_POST_EMAIL; // set values to what user submitted in case there are errors $dream->setValues($_POST, isset($_FILES['image_file']) ? $_FILES['image_file'] : null, isset($_FILES['audio_file']) ? $_FILES['audio_file'] : null); // save $success = $dream->save(); if (!$success) { $response->success = 0; $response->error = $dream->status; $response->errors = $dream->getLog(); } else { $response->result = $dream; } break; } break; case "graph": switch ($_SERVER['REQUEST_METHOD']) { case "GET": include_once "includes/graph.class.json.php"; if (!isset($_GET['date_from'])) {
public function actionReststart() { $this->checkRestAuth(); //判断是否全部填写 if (!isset($_GET['openId'])) { return $this->sendResponse(400, 'missed required properties'); } $openId = $_GET['openId']; // 查询是否已经生成 $criteria = new CDbCriteria(); $criteria->compare("open_id", $openId); $dreams = Dream::model()->findAll($criteria); $dream = null; if (count($dreams) == 0) { $dream = new Dream(); $dream->open_id = $openId; $dream->bonus = 0; // 使用分为计量单位,从零开始 if (!$dream->save()) { return $this->sendResponse(500, 'faild to save dream'); } } else { $dream = $dreams[0]; } echo CJSON::encode($this->JSONMapper($dream)); }
// skip header if ($line == 0) { $line++; continue; } $dream = new Dream(); $dream->alchemyApiKey = ALCHEMY_API_KEY; $dream->dateFormat = $date_format; $dream->origin = "mona"; $dream->postToTumblr = POST_TO_TUMBLR; $dream->timezone = TIME_ZONE; $dream->tumblrPostEmail = TUMBLR_POST_EMAIL; $dream->date = array_shift($data); $dream->description = array_shift($data); $dream->color = array_shift($data); $dream->email = array_shift($data); $dream->age = array_shift($data); $dream->gender = array_shift($data); if ($dream->save()) { $successes++; } else { $errors++; } $line++; } fclose($handle); } else { echo "Problem reading file"; } echo "<br/><br/>"; echo $successes . " dreams inserted successfully, " . $errors . " errors";