本文整理汇总了PHP中blogPostModel::select方法的典型用法代码示例。如果您正苦于以下问题:PHP blogPostModel::select方法的具体用法?PHP blogPostModel::select怎么用?PHP blogPostModel::select使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类blogPostModel
的用法示例。
在下文中一共展示了blogPostModel::select方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: execute
public function execute()
{
ob_start();
$app = $this->getApp();
$app_settings_model = new waAppSettingsModel();
$app_settings_model->set($app, 'cron_schedule', time());
waFiles::create($this->getConfig()->getPath('log') . '/' . $app . '/');
$log_file = "{$app}/cron.txt";
$post_model = new blogPostModel();
$params = array('datetime' => date("Y-m-d H:i:s"), 'status' => blogPostModel::STATUS_SCHEDULED);
$posts_schedule = $post_model->select("id,blog_id,contact_id,status,datetime")->where('datetime <= s:datetime AND status=s:status', $params)->fetchAll();
if ($posts_schedule) {
foreach ($posts_schedule as $post) {
try {
waLog::log("Attempt publishing post with id [{$post['id']}]", $log_file);
$data = array("status" => blogPostModel::STATUS_PUBLISHED);
waLog::log($post_model->updateItem($post['id'], $data, $post) ? "success" : "fail", $log_file);
} catch (Exception $ex) {
waLog::log($ex->getMessage(), $log_file);
waLog::log($ex->getTraceAsString(), $log_file);
}
}
}
$action = __FUNCTION__;
/**
* @event cron_action
* @param string $action
* @return void
*/
wa()->event('cron_action', $action);
if ($log = ob_get_clean()) {
waLog::log($log, $log_file);
}
}
示例2: isInUse
public function isInUse($value)
{
if ($this->subject == self::SUBJECT_BLOG) {
$model = new blogBlogModel();
} else {
$model = new blogPostModel();
}
$cond = $this->options['id'] ? 'url = :url AND id != i:id' : 'url = :url';
return $model->select('id')->where($cond, array('url' => $value, 'id' => $this->options['id']))->limit(1)->fetch();
}
示例3: run
public function run()
{
$app_settings_model = new waAppSettingsModel();
$contact_settings_model = new waContactSettingsModel();
$app_settings_model->set('blog', 'last_reminder_cron_time', time());
// remider settings for all users
$reminders = $contact_settings_model->select('contact_id, value')->where("app_id='blog' AND name='reminder'")->fetchAll('contact_id', true);
if (!$reminders) {
return;
}
$time = time();
// do job no more one time in 24 hours
$last_cron_times = $contact_settings_model->select('contact_id')->where("app_id='blog' AND name='last_reminder_cron_time' AND value <= " . ($time - 86400))->fetchAll('contact_id', true);
$reminders_allowed = array_keys($last_cron_times);
if (!$reminders_allowed) {
return;
}
$post_model = new blogPostModel();
$backend_url = $app_settings_model->get('blog', 'backend_url', wa()->getRootUrl(true) . wa()->getConfig()->getBackendUrl());
$message_count = 0;
foreach ($reminders_allowed as $contact_id) {
$days = $reminders[$contact_id];
// get all deadline posts for this contact
$posts = $post_model->select("id, title, datetime")->where("status='" . blogPostModel::STATUS_DEADLINE . "' AND contact_id=" . $contact_id . " AND datetime < '" . date('Y-m-d H:i:s', $time + $days * 86400) . "'")->order('datetime')->fetchAll();
if ($posts) {
$contact = new waContact($contact_id);
$email = $contact->get('email', 'default');
$message = new waMailMessage(_w('Scheduled blog posts'), $this->getMessage($posts, $time, $backend_url));
try {
$message->setTo($email);
if ($message->send()) {
$message_count++;
}
} catch (Exception $e) {
}
}
$contact_settings_model->set($contact_id, 'blog', 'last_reminder_cron_time', $time);
}
/**
* Notify plugins about sending reminder
* @event followup_send
* @return void
*/
wa()->event('reminder_send', $message_count);
}
示例4: getComments
protected function getComments($search_options)
{
if (empty($search_options['post_id'])) {
$search_options['post_id'] = null;
}
if (!isset($search_options['blog_id'])) {
$search_options['blog_id'] = array_keys(blogHelper::getAvailable());
} else {
if (is_numeric($search_options['blog_id'])) {
$search_options['blog_id'] = array((int) $search_options['blog_id']);
} else {
if (!is_array($search_options['blog_id'])) {
$search_options['blog_id'] = array();
}
}
}
if (is_numeric($search_options['filter'])) {
$search_options['filter'] = (int) $search_options['filter'];
if (in_array($search_options['filter'], $search_options['blog_id'])) {
$search_options['blog_id'] = array($search_options['filter']);
} else {
$search_options['blog_id'] = array();
}
} else {
if ($search_options['filter'] == 'myposts') {
if (empty($search_options['blog_id'])) {
$search_options['post_id'] = array();
} else {
$post_model = new blogPostModel();
$search_options['post_id'] = array_keys($post_model->select('id')->where('contact_id=? AND blig_id IN (?)', array($this->getUser()->getId(), $search_options['blog_id']))->fetchAll('id'));
}
}
}
$search_options['approved'] = true;
$comment_model = new blogCommentModel();
return $comment_model->getList($search_options, array("photo_url_20"), array('datetime' => blogActivity::getUserActivity()));
}
示例5: run
public function run($params = NULL)
{
$app = $this->getApp();
$app_settings_model = new waAppSettingsModel();
$app_settings_model->set($app, 'last_schedule_cron_time', time());
waFiles::create($this->getConfig()->getPath('log') . '/' . $app . '/');
$log_file = "{$app}/schedule.txt";
$post_model = new blogPostModel();
$params = array('datetime' => date("Y-m-d H:i:s"), 'status' => blogPostModel::STATUS_SCHEDULED);
$posts_schedule = $post_model->select("id, blog_id, contact_id, status, datetime")->where('datetime <= s:datetime AND status=s:status', $params)->fetchAll();
if ($posts_schedule) {
foreach ($posts_schedule as $post) {
try {
waLog::log("Attempt publishing post with id [{$post['id']}]", $log_file);
$data = array("status" => blogPostModel::STATUS_PUBLISHED, "datetime" => date("Y-m-d H:i:s"));
$r = $post_model->updateItem($post['id'], $data, $post);
waLog::log($r ? "success" : "fail", $log_file);
} catch (Exception $ex) {
waLog::log($ex->getMessage(), $log_file);
waLog::log($ex->getTraceAsString(), $log_file);
}
}
}
}
示例6: onCount
public function onCount()
{
$full = !func_get_args();
$app = $this->getApplication();
$user = waSystem::getInstance()->getUser();
$user_id = $user->getId();
$type = explode(':', $user->getSettings($app, 'type_items_count'));
$type = array_filter(array_map('trim', $type), 'strlen');
if (!$type) {
$type = array('posts', 'comments_to_my_post', 'overdue');
}
$activity_datetime = blogActivity::getUserActivity($user_id, false);
$blogs = array_keys(blogHelper::getAvailable(false));
$counter = array();
$post_model = new blogPostModel();
if (in_array('posts', $type) && $full && $blogs) {
$post_new_count = $post_model->getAddedPostCount($activity_datetime, $blogs);
$post_new_count = array_sum($post_new_count);
$counter['posts'] = $post_new_count;
} else {
$counter['posts'] = false;
}
if (in_array('comments', $type) && $full && $blogs) {
$comment_model = new blogCommentModel();
$counter['comments'] = $comment_model->getCount($blogs, null, $activity_datetime, 0);
} else {
$counter['comments'] = false;
}
if (in_array('comments_to_my_post', $type) && $full && $blogs) {
$comment_model = new blogCommentModel();
$counter['comments_to_my_post'] = $comment_model->getCount($blogs, null, $activity_datetime, 0, $user_id);
} else {
$counter['comments_to_my_post'] = false;
}
if (in_array('overdue', $type) && $blogs) {
if (!isset($post_model)) {
$post_model = new blogPostModel();
}
$where = "status = '" . blogPostModel::STATUS_DEADLINE . "'";
$where .= " AND blog_id IN (" . implode(', ', $blogs) . ")";
$where .= " AND contact_id = {$user_id}";
$where .= " AND datetime <= '" . waDateTime::date("Y-m-d") . "'";
$count_overdue = $post_model->select("count(id)")->where($where)->fetchField();
$counter['overdue'] = $count_overdue ? $count_overdue : 0;
} else {
$counter['overdue'] = false;
}
$count = array_sum($counter);
$url = $this->getBackendUrl(true) . $this->application . '/';
if ($count) {
switch ($count) {
case $counter['comments']:
case $counter['comments_to_my_post']:
$url .= '?module=comments';
break;
case $counter['overdue']:
$url .= '?action=calendar';
break;
}
}
//debug
//$counter['type'] = $type;
//$counter['activity_datetime'] = $activity_datetime;
//$counter['current_datetime'] = date("Y-m-d H:i:s",time());
//waLog::log('$counter = '.var_export($counter,true),"blog-counter-{$user_id}.log");
return array('count' => $count == 0 ? null : $count, 'url' => $url);
}
示例7: getComments
public function getComments($search_options, $fields, $prepare_options)
{
$comment_model = new blogCommentModel();
$post_ids = null;
$blog_ids = $search_options['blog_id'];
if (is_numeric($search_options['filter'])) {
$k = array_search((int) $search_options['filter'], $blog_ids);
if ($k !== false) {
$blog_ids = $blog_ids[$k];
} else {
$blog_ids = array();
}
$search_options['blog_id'] = $blog_ids;
} else {
if ($search_options['filter'] == 'myposts') {
$post_model = new blogPostModel();
$post_ids = array_keys($post_model->select('id')->where('contact_id=' . $this->getUser()->getId())->fetchAll('id'));
$search_options['post_id'] = $post_ids;
}
}
$counts = (array) $comment_model->getCount($blog_ids, $post_ids, null, null, null, null);
return array('comments' => $comment_model->getList($search_options, $fields, $prepare_options), 'comments_all_count' => array_sum($counts));
}
示例8: execute
public function execute()
{
$this->user = $this->getUser();
$blog_id = waRequest::get('blog', null, 'int');
$post_id = waRequest::get('id', null, 'int');
$request = waRequest::get();
$module = waRequest::get('module');
$action = waRequest::get('action');
if (!$action) {
$action = waRequest::get('module');
}
$view_all_posts = waRequest::get('all', null) !== null || empty($request);
$blog_model = new blogBlogModel();
$blogs = $blog_model->getAvailable($this->user, array(), null, array('new' => true, 'expire' => 1, 'link' => false));
$blog_ids = array_keys($blogs);
$comment_model = new blogCommentModel();
$comment_count = $comment_model->getCount($blog_ids);
$activity_datetime = blogActivity::getUserActivity();
$comment_new_count = $comment_model->getCount($blog_ids, null, $activity_datetime, 1);
$post_count = 0;
$new_post_count = 0;
$writable_blogs = false;
foreach ($blogs as $blog) {
$post_count += $blog['qty'];
if ($blog['rights'] >= blogRightConfig::RIGHT_READ_WRITE) {
$writable_blogs = true;
}
if (isset($blog['new_post']) && $blog['new_post'] > 0) {
$new_post_count += $blog['new_post'];
}
}
if ($writable_blogs) {
$post_model = new blogPostModel();
$search_options = array('status' => array(blogPostModel::STATUS_DRAFT, blogPostModel::STATUS_DEADLINE, blogPostModel::STATUS_SCHEDULED));
if (!$this->user->isAdmin($this->getApp())) {
$search_options['contact_id'] = $this->user->getId();
}
$search_options['sort'] = 'overdue';
$drafts = $post_model->search($search_options, array('status' => true, 'link' => false, 'plugin' => false, 'comments' => false), array('blog' => $blogs))->fetchSearchAll(false);
$where = "status = '" . blogPostModel::STATUS_DEADLINE . "' AND datetime <= '" . waDateTime::date("Y-m-d") . "'";
if (!$this->getUser()->isAdmin($this->getApp())) {
$where .= " AND contact_id = {$this->getUser()->getId()}";
$where .= " AND blog_id IN (" . implode(', ', array_keys($blogs)) . ")";
}
$count_overdue = $post_model->select("count(id)")->where($where)->fetchField();
$count_overdue = $count_overdue ? $count_overdue : 0;
} else {
$drafts = false;
$count_overdue = false;
}
/**
* Extend backend sidebar
* Add extra sidebar items (menu items, additional sections, system output)
* @event backend_sidebar
* @example #event handler example
* public function sidebarAction()
* {
* $output = array();
*
* #add external link into sidebar menu
* $output['menu']='<li>
* <a href="http://www.webasyst.com">
* http://www.webasyst.com
* </a>
* </li>';
*
* #add section into sidebar menu
* $output['section']='';
*
* #add system link into sidebar menu
* $output['system']='';
*
* return $output;
* }
* @return array[string][string]string $return[%plugin_id%]['menu'] Single menu items
* @return array[string][string]string $return[%plugin_id%]['section'] Sections menu items
* @return array[string][string]string $return[%plugin_id%]['system'] Extra menu items
*/
$this->view->assign('backend_sidebar', wa()->event('backend_sidebar'));
$this->view->assign('blog_id', $blog_id);
$this->view->assign('blogs', $blogs);
$this->view->assign('view_all_posts', $view_all_posts);
$this->view->assign('action', $action);
$this->view->assign('module', $module);
$this->view->assign('post_id', $post_id);
$this->view->assign('new_post', waRequest::get('action') == 'edit' && waRequest::get('id') == '');
$this->view->assign('drafts', $drafts);
$this->view->assign('comment_count', $comment_count);
$this->view->assign('comment_new_count', $comment_new_count);
$this->view->assign('post_count', $post_count);
$this->view->assign('new_post_count', $new_post_count);
$this->view->assign('count_draft_overdue', $count_overdue);
$this->view->assign('writable_blogs', $writable_blogs);
}
示例9: getPreparedPost
/**
* Prepare for saving posted post and return it
*
* @return array prepared post
*
*/
private function getPreparedPost()
{
$post = array('id' => waRequest::post('post_id', null, waRequest::TYPE_INT), 'title' => substr(waRequest::post('title', '', waRequest::TYPE_STRING_TRIM), 0, 255), 'text' => waRequest::post('text'), 'blog_id' => waRequest::post('blog_id'), 'contact_id' => waRequest::post('contact_id'), 'datetime' => waRequest::post('datetime'), 'url' => waRequest::post('url', '', waRequest::TYPE_STRING_TRIM), 'draft' => waRequest::post('draft'), 'comments_allowed' => max(0, min(1, waRequest::post('comments_allowed', 0, waRequest::TYPE_INT))), 'public' => waRequest::post('public'), 'schedule_datetime' => waRequest::post('schedule_datetime'));
$this->inline = waRequest::post('inline', false);
if (waRequest::post('scheduled') && !empty($post['schedule_datetime'])) {
$post['datetime'] = $post['schedule_datetime'];
}
if (!is_null($post['datetime'])) {
$post['datetime'] = (array) $post['datetime'];
if (count($post['datetime']) == 3) {
$post['datetime'][1] = (int) $post['datetime'][1];
$post['datetime'][2] = (int) $post['datetime'][2];
$date_time = $post['datetime'][0] . ' ' . $post['datetime'][1] . ':' . $post['datetime'][2];
} else {
$date_time = implode(' ', $post['datetime']);
}
$post['datetime'] = $date_time;
}
if (waRequest::post('draft')) {
$post['status'] = blogPostModel::STATUS_DRAFT;
$this->operation = self::OPERATION_SAVE_DRAFT;
} else {
if (waRequest::post('deadline')) {
if ($post['datetime']) {
$post['status'] = blogPostModel::STATUS_DEADLINE;
$this->operation = self::OPERATION_SET_DEADLINE;
} else {
$post['status'] = blogPostModel::STATUS_DRAFT;
$this->operation = self::OPERATION_SAVE_DRAFT;
}
} else {
if (waRequest::post('scheduled')) {
$post['status'] = blogPostModel::STATUS_SCHEDULED;
} else {
if (waRequest::post('published')) {
$post['status'] = blogPostModel::STATUS_PUBLISHED;
$this->operation = self::OPERATION_PUBLISH;
} else {
if (waRequest::post('unpublish')) {
$post['status'] = blogPostModel::STATUS_DRAFT;
$this->operation = self::OPERATION_UNPUBLISH;
} else {
if ($post['id'] && waRequest::issetPost('delete')) {
$this->operation = self::OPERATION_DELETE;
} else {
if (waRequest::issetPost("schedule_cancel")) {
$this->operation = self::OPERATION_CANCEL_SCHEDULE;
}
}
}
}
}
}
}
if (!isset($post['status'])) {
if ($post['id']) {
$post['status'] = $this->post_model->select('status')->where('id = i:id', array('id' => $post['id']))->fetchField('status');
} else {
$post['status'] = blogPostModel::STATUS_DRAFT;
}
}
$blog_model = new blogBlogModel();
$blog = $blog_model->getById($post['blog_id']);
$post['blog_status'] = $blog['status'];
$post['plugin'] = (array) waRequest::post('plugin', null);
foreach ($post['plugin'] as $k => &$plugin_data) {
if (!is_array($plugin_data)) {
$plugin_data = trim($plugin_data);
}
}
return $post;
}
示例10: execute
public function execute()
{
$this->getResponse()->setTitle(_w('Calendar'));
$this->setLayout(new blogDefaultLayout());
$blog_model = new blogBlogModel();
$post_model = new blogPostModel();
$blogs = $blog_model->getAvailable($this->getUser());
$timezone = wa()->getUser()->getTimezone();
// Y-m-d -> 2011-01-01
$month_date = waRequest::get("month");
if (!$month_date) {
$month_date = waDateTime::date("Y-m", null, $timezone);
} elseif ($month_date <= "1970" || $month_date >= "2033" || !strtotime($month_date)) {
$this->redirect("?action=calendar");
}
$month_date = strtotime($month_date);
$days_count = date("t", $month_date);
// Numeric representation of the day of the week
$first_day = date("w", $month_date);
$last_day = date("w", strtotime(date("Y-m-{$days_count}", $month_date)));
// first day is 'Sunday'
if (waLocale::getFirstDay() == 7) {
$first_day += 1;
$last_day += 1;
}
$first_day = $first_day == 0 ? 6 : $first_day - 1;
$last_day = $last_day == 0 ? 0 : 7 - $last_day;
$date_start = strtotime("-" . $first_day . " days", $month_date);
$date_end = strtotime("+" . ($days_count + $last_day) . " days", $month_date);
$search_options = array();
$search_options['datetime'] = array(date("Y-m-d", $date_start), date("Y-m-d", $date_end));
$search_options['blog_id'] = array_keys($blogs);
$search_options['status'] = false;
if (!$this->getUser()->isAdmin($this->getApp())) {
$search_options['contact_id'] = $this->getUser()->getId();
}
$extend_options = array('status' => true, 'user' => false, 'rights' => true);
$posts = $post_model->search($search_options, $extend_options, array('blog' => $blogs))->fetchSearchAll(false);
$current_date_start = $date_start;
$days = array();
do {
$week = (int) date("W", $current_date_start);
$day = (int) date("w", $current_date_start);
if (waLocale::getFirstDay() == 7 && $day == 0) {
$week = (int) date("W", strtotime("+1 week", $current_date_start));
}
if (!isset($days[$week])) {
$days[$week] = array();
}
$days[$week][$day] = array("date" => array('day' => date("j", $current_date_start), 'month' => date("n", $current_date_start), 'date' => date("Y-m-d", $current_date_start)), "posts" => array());
$current_date_start = strtotime("+1 days", $current_date_start);
} while ($date_end > $current_date_start);
foreach ($posts as $post) {
#post.datetime cast to user timezone
$week = (int) waDateTime::date("W", $post['datetime'], $timezone);
$day = (int) waDateTime::date("w", $post['datetime'], $timezone);
$days[$week][$day]["posts"][] = $post;
}
$now_date = waDateTime::date("Y-m-d", null, $timezone);
$where = '';
$search = false;
if ($this->getUser()->isAdmin($this->getApp())) {
$search = true;
} else {
$writeable = array();
$full = array();
foreach ($blogs as $id => $blog) {
if ($blog['rights'] >= blogRightConfig::RIGHT_FULL) {
$full[] = $id;
} elseif ($blog['rights'] >= blogRightConfig::RIGHT_READ_WRITE) {
$writeable[] = $id;
}
}
$contact_where = array();
if ($full) {
$contact_where[] = "blog_id IN (" . implode(', ', $full) . ")";
}
if ($writeable) {
$contact_where[] .= "contact_id = {$this->getUser()->getId()} AND blog_id IN (" . implode(', ', $writeable) . ")";
}
if ($contact_where) {
$search = true;
$where .= ' AND ( (' . implode(') OR (', $contact_where) . ' ) )';
}
}
if ($search) {
$posts_overdue_prev = $post_model->select("COUNT(*) AS 'cnt'")->where("status = '" . blogPostModel::STATUS_DEADLINE . "' AND datetime < '" . date("Y-m-d", $date_start) . "' " . $where)->limit(1)->fetchField('cnt');
$posts_overdue_next = $post_model->select("COUNT(*) AS 'cnt'")->where("status = '" . blogPostModel::STATUS_DEADLINE . "' AND datetime > '" . date("Y-m-d", $date_end) . "' AND datetime < '" . $now_date . "'" . $where)->limit(1)->fetchField('cnt');
$prev_overdue = $posts_overdue_prev ? true : false;
$next_overdue = $posts_overdue_next ? true : false;
} else {
$prev_overdue = false;
$next_overdue = false;
}
$months = array(1 => _ws('January'), 2 => _ws('February'), 3 => _ws('March'), 4 => _ws('April'), 5 => _ws('May'), 6 => _ws('June'), 7 => _ws('July'), 8 => _ws('August'), 9 => _ws('September'), 10 => _ws('October'), 11 => _ws('November'), 12 => _ws('December'));
$current_year = date('Y', $month_date);
$current_month = date('Y', $month_date);
$boundaries = $post_model->select("MIN(datetime) as min, MAX(datetime) as max")->fetch();
if ($boundaries) {
$years = range(min(date('Y', strtotime($boundaries['min'])), $current_year), max(date('Y', strtotime($boundaries['max'])), $current_year, date('Y')));
//.........这里部分代码省略.........