public function updateSources($get, $post) { $sources = file_get_contents("http://api.pnd.gs/v1/sources/"); $sources = json_decode($sources, true); $my_sources = []; foreach ($sources as $source) { // get source and store it in an array $my_source = []; $my_source["panda_id"] = $source["_id"]; $my_source["key"] = $source["key"]; $my_source["name"] = $source["name"]; $my_source["description"] = $source["description"]; $my_source["category"] = $source["category"]; $my_source["type"] = $source["type"]; $my_source["icon"] = $source["icon"]; $my_source["color"] = $source["ios"]["color"]; $my_source["popularity"] = $source["stats"]["popularity"]; $my_source["popular_endpoint"] = NULL; $my_source["latest_endpoint"] = NULL; if ($source["popular"]) { $my_source["popular_endpoint"] = $source["endpoints"]["popular"]; } if ($source["latest"]) { $my_source["latest_endpoint"] = $source["endpoints"]["latest"]; } $display_settings = $source["settings"]["display"]; // meta stuff $supported_meta = []; if ($display_settings["views"]) { array_push($supported_meta, "views"); } if ($display_settings["votes"]) { array_push($supported_meta, "votes"); } if ($display_settings["comments"]) { array_push($supported_meta, "comments"); } if ($display_settings["author"]) { array_push($supported_meta, "author"); } $my_source["meta"] = implode(",", $supported_meta); $s = new Source($this->ds); $s = $s->withPandaId($my_source["panda_id"]); if (is_null($s)) { $s = new Source($this->ds); } $s->fromRow($my_source); $s->save(); array_push($my_sources, $s); } function cmp($a, $b) { if ($a->popularity == $b->popularity) { return 0; } return $a->popularity > $b->popularity ? -1 : 1; } usort($my_sources, "cmp"); $this->response->add("sources", $my_sources); }
/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionCreate() { $model = new Source(); // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (isset($_POST['Source'])) { $model->attributes = $_POST['Source']; if ($model->save()) { $this->redirect(array('view', 'id' => $model->id_source)); } } $this->render('create', array('model' => $model)); }
/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionCreate() { $model = new ExternalSource(); // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (isset($_POST['ExternalSource'])) { //Creates new Source, gets generated ID $source = new Source(); $source->save(); $model->attributes = $_POST['ExternalSource']; //Gives the new external source the generated ID $model->id_source = $source->id_source; if ($model->save()) { $this->redirect(array('view', 'id' => $model->id_source)); } else { $source->delete(); } } $this->render('create', array('model' => $model)); }
/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionCreate() { $cur_user = Yii::app()->user->id; $user = User::Model()->findAllByAttributes(array('id' => $cur_user)); if ($user[0]['superuser'] == 1 or $user[0]['superuser'] == 2) { $model = new Source(); // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (isset($_POST['Source'])) { $model->attributes = $_POST['Source']; $model->s_created = date('Y-m-d'); $model->s_modified = date('Y-m-d'); if ($model->save()) { $this->redirect(array('view', 'id' => $model->s_id)); } } $this->render('create', array('model' => $model)); } else { echo "!Error 504 Page Not Found"; } }
public static function create($path, $origin = "upload"){ $id = self::getID($path); // If a Source object for this file already exists, there is no need to recompute its attributes if(self::exists($id)) return new Source($id); $source = new Source($id); $source->origin = $origin; if(!self::analyzable($path)){ throw new SourceCreateException("There is no Analyzer defined for this file"); } $source->type = self::getType($path); $analyzerName = "{$source->type}Analyzer"; $analyzer = new $analyzerName($path); $source->features = $analyzer->analyze(); $source->save(); return $source; }