function view()
{
    $per_page = 100;
    $page = arr_get('p', $_GET, 0);
    $offset = $page * $per_page;
    $limit = $per_page;
    $widgets = array();
    $total = 0;
    $f = new FilterForm($_GET, array(), array());
    if ($f->is_valid()) {
        $total = SubmittedArticle::count($f->cleaned_data);
        foreach (SubmittedArticle::fetch($f->cleaned_data, $offset, $limit) as $err) {
            $widgets[] = new SubmittedArticleWidget($err);
        }
    }
    $paginator = new Paginator($total, $per_page, 'p');
    $v = array('filterform' => &$f, 'widgets' => &$widgets, 'paginator' => $paginator);
    template($v);
}
 public static function dispatch()
 {
     // TODO: check adm permissions!!!
     $id = get_http_var('id');
     $action = get_http_var('action');
     $err = SubmittedArticle::fetch_single($id);
     $w = new SubmittedArticleWidget($err);
     // perform whatever action has been requested
     $w->perform($action);
     // is request ajax?
     $ajax = get_http_var('ajax') ? true : false;
     if ($ajax) {
         $w->emit_core();
     } else {
         // not an ajax request, so output a full page
         admPageHeader("Submitted Article", "SubmittedArticleWidget::emit_head_js");
         print "<h2>Submitted article</h2>\n";
         $w->emit_full();
         admPageFooter();
     }
 }
Esempio n. 3
0
 function save()
 {
     $data = $this->cleaned_data;
     $fields = array('title', 'byline', 'description', 'pubdate', 'permalink', 'srcorg', 'status');
     // if srcorg left blank, fill it out using domainname
     if (!$data['srcorg']) {
         $parts = crack_url($data['permalink']);
         $domain = strtolower($parts['host']);
         $data['srcorg'] = $this->find_or_create_publication($domain);
     }
     // all set - time to upsert!
     $params = array();
     foreach ($fields as $f) {
         $values[] = $data[$f];
         $placeholders[] = '?';
     }
     if ($data['id']) {
         // update
         $sql = "UPDATE article SET (" . join(',', $fields) . ") = (" . join(',', $placeholders) . ") WHERE id=?";
         $values[] = $data['id'];
         db_do($sql, $values);
         // make sure article_url has permalink (srcurl might be different, but we'll assume it's there already)
         db_do("DELETE FROM article_url WHERE url=? AND article_id=?", $data['permalink'], $data['id']);
         db_do("INSERT INTO article_url (url,article_id) VALUES (?,?)", $data['permalink'], $data['id']);
     } else {
         //create new
         $sql = "INSERT INTO article (id," . join(',', $fields) . ",firstseen,lastseen) VALUES (DEFAULT," . join(',', $placeholders) . ",NOW(),NOW()) RETURNING id";
         $data['id'] = db_getOne($sql, $values);
         // set up article_url
         db_do("INSERT INTO article_url (url,article_id) VALUES (?,?)", $data['permalink'], $data['id']);
     }
     // set attributed journos
     db_do("DELETE FROM journo_attr WHERE article_id=?", $data['id']);
     $authors = explode(',', $data['authors']);
     $params = array();
     $params[] = $data['id'];
     $placeholders = array();
     foreach ($authors as $a) {
         $params[] = trim($a);
         $placeholders[] = '?';
     }
     db_do("INSERT INTO journo_attr (journo_id,article_id) SELECT id,? FROM journo WHERE ref IN (" . join(',', $placeholders) . ")", $params);
     // queue for xapian indexing
     db_do("DELETE FROM article_needs_indexing WHERE article_id=?", $data['id']);
     db_do("INSERT INTO article_needs_indexing (article_id) VALUES (?)", $data['id']);
     // check for any submitted articles for this url that could now be resolved
     $submitted = SubmittedArticle::fetch_by_url($data['permalink']);
     foreach ($submitted as $s) {
         $s->update_status();
         $s->save();
     }
     # TODO:
     #  log the action
     return $data;
 }
    public static function fetch($filter = null, $offset = null, $limit = null)
    {
        $params = array();
        $sel_part = self::$sql_select;
        $from_part = self::$sql_from;
        $where_part = "reason_code NOT IN ('rejected','resolved')";
        if ($filter['expected_ref']) {
            $where_part .= " AND j.ref=?";
            $params[] = $filter['expected_ref'];
        }
        $sql = <<<EOT
        SELECT {$sel_part}
            FROM {$from_part}
            WHERE {$where_part}
            ORDER BY e.submitted DESC
EOT;
        if (!is_null($offset)) {
            $sql .= " OFFSET ?\n";
            $params[] = $offset;
        }
        if (!is_null($limit)) {
            $sql .= " LIMIT ?\n";
            $params[] = $limit;
        }
        $rows = db_getAll($sql, $params);
        $art_errs = array();
        foreach ($rows as $row) {
            $sub = new SubmittedArticle();
            $sub->from_db_row($row);
            $art_errs[] = $sub;
        }
        return $art_errs;
    }