public function getByApps($contact_id, $apps, $after_time = null) { $settings_model = new waContactSettingsModel(); $data = $settings_model->getByField(array('contact_id' => $contact_id, 'name' => 'announcement_close', 'app_id' => $apps), true); $where = array(); foreach ($data as $row) { $where[$row['app_id']] = "(app_id = '" . $this->escape($row['app_id']) . "' AND " . "datetime > '" . $this->escape($row['value']) . "')"; } foreach ($apps as $app_id) { if (!isset($where[$app_id])) { $where[$app_id] = "app_id = '" . $this->escape($app_id) . "'"; } } if ($where) { $where = "(" . implode(" OR ", $where) . ")"; } else { $where = ""; } $sql = "SELECT * FROM " . $this->table; if ($after_time) { if ($where) { $where .= " AND "; } $where .= "datetime >= '" . $this->escape($after_time) . "'"; } if ($where) { $sql .= " WHERE " . $where; } $sql .= " ORDER BY datetime DESC"; return $this->query($sql)->fetchAll(); }
/** * Delete one or more contacts and fire event сontacts.delete * * @event contacts.delete * * @param int|array $id - contact id or array of contact ids * @return bool */ public function delete($id, $send_event = true) { if ($send_event) { // Fire @event contacts.delete allowing other applications to clean up their data if (!is_array($id)) { $id = array($id); } wa()->event(array('contacts', 'delete'), $id); } if (is_array($id)) { $nid = array(); foreach ($id as $i) { $nid[] = -(int) $i; } } else { $nid = -(int) $id; } // Delete rights $right_model = new waContactRightsModel(); $right_model->deleteByField('group_id', $nid); // Delete settings $setting_model = new waContactSettingsModel(); $setting_model->deleteByField('contact_id', $id); // Delete emails $contact_email_model = new waContactEmailsModel(); $contact_email_model->deleteByField('contact_id', $id); // Delete from groups $user_groups_model = new waUserGroupsModel(); $user_groups_model->deleteByField('contact_id', $id); // Delete from contact lists if (class_exists('contactsContactListsModel')) { // @todo: Use plugin for contacts $contact_lists_model = new contactsContactListsModel(); $contact_lists_model->deleteByField('contact_id', $id); } // Delete from contact rights $contact_rights_model = new contactsRightsModel(); $contact_rights_model->deleteByField('group_id', $nid); // Delete data $contact_data_model = new waContactDataModel(); $contact_data_model->deleteByField('contact_id', $id); $contact_data_text_model = new waContactDataTextModel(); $contact_data_text_model->deleteByField('contact_id', $id); // // Delete contact from logs // $login_log_model = new waLoginLogModel(); // $login_log_model->deleteByField('contact_id', $id); // Clear references $this->updateByField(array('company_contact_id' => $id), array('company_contact_id' => 0)); // Delete contact return $this->deleteById($id); }
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); }
/** * Update timestamp of user activity at application * @param null $id * @param bool $force * @return bool|null|string */ public static function setUserActivity($id = null, $force = true) { if (is_null($id)) { $id = wa()->getUser()->getId(); } $t = null; $storage = wa()->getStorage(); if ($id) { if (!$force && (!($app_last_datetime = $storage->get(self::$app_id . "_last_datetime")) || time() - strtotime($app_last_datetime) > 120)) { $force = 1; } if ($force) { $t = date("Y-m-d H:i:s", time() + 1); $contact = new waContactSettingsModel(); $contact->set($id, self::$app_id, self::$app_id . "_last_datetime", $t); $storage->write(self::$app_id . "_last_datetime", $t); if ($force === true) { $storage->write(self::$app_id . "_badge_datetime", $t); } } elseif ($force === false) { $storage->write(self::$app_id . "_badge_datetime", $s = date("Y-m-d H:i:s", time() + 1)); } } elseif ($force) { $storage->set(self::$app_id . "_session_datetime", $t = date("Y-m-d H:i:s", time() + 1)); } return $t; }
public function uninstall() { // check uninstall.php $file = $this->getAppConfigPath('uninstall'); if (file_exists($file)) { include $file; } $file_db = $this->getAppPath('lib/config/db.php'); if (file_exists($file_db)) { $schema = (include $file_db); $model = new waModel(); foreach ($schema as $table => $fields) { $sql = "DROP TABLE IF EXISTS " . $table; $model->exec($sql); } } // Remove all app settings $app_settings_model = new waAppSettingsModel(); $app_settings_model->del($this->application); $contact_settings_model = new waContactSettingsModel(); $contact_settings_model->deleteByField('app_id', $this->application); // Remove all rights to app $contact_rights_model = new waContactRightsModel(); $contact_rights_model->deleteByField('app_id', $this->application); // Remove logs $log_model = new waLogModel(); $log_model->deleteByField('app_id', $this->application); // Remove cache waFiles::delete($this->getPath('cache') . '/apps/' . $this->application); }
protected function deleteHash($contact_id) { $contact_settings_model = new waContactSettingsModel(); $contact_settings_model->delete($contact_id, 'webasyst', 'forgot_password_hash'); }
/** * Deletes contact's property relating to specified app. * * @param string $app_id App id * @param string $name Contact property id */ public function delSettings($app_id, $name) { $setting_model = new waContactSettingsModel(); $setting_model->delete($this->id, $app_id, $name); }
public function execute() { $user = $this->getUser(); $filter = waRequest::get('filter'); $contact_settings = new waContactSettingsModel(); if (!$filter) { $filter = $contact_settings->getOne($user->getId(), $this->getAppId(), 'comments_filter'); if (!$filter) { $filter = 'myposts'; } } else { $contact_settings->set($user->getId(), $this->getAppId(), 'comments_filter', $filter); } $contact_photo_size = 20; $comments_per_page = max(1, intval($this->getConfig()->getOption('comments_per_page'))); $page = max(1, waRequest::get('page', 1, waRequest::TYPE_INT)); $blogs = blogHelper::getAvailable(); $offset = $comments_per_page * ($page - 1); $prepare_options = array('datetime' => blogActivity::getUserActivity()); $fields = array("photo_url_{$contact_photo_size}"); $blog_ids = array_keys($blogs); $data = $this->getComments(array('offset' => $offset, 'limit' => $comments_per_page, 'blog_id' => $blog_ids, 'filter' => $filter), $fields, $prepare_options); $comments = $data['comments']; $comments_all_count = $data['comments_all_count']; $post_ids = array(); foreach ($comments as $comment) { $post_ids[$comment['post_id']] = true; } //get related posts info $post_model = new blogPostModel(); $search_options = array('id' => array_keys($post_ids)); $extend_options = array('user' => false, 'link' => true, 'rights' => true, 'plugin' => false, 'comments' => false); $extend_data = array('blog' => $blogs); $posts = $post_model->search($search_options, $extend_options, $extend_data)->fetchSearchAll(false); $comments = blogCommentModel::extendRights($comments, $posts); $comments_count = ($page - 1) * $comments_per_page + count($comments); if ($page == 1) { $this->setLayout(new blogDefaultLayout()); $this->getResponse()->setTitle(_w('Comments')); } /** * Backend comments view page * UI hook allow extends backend comments view page * @event backend_comments * @param array[int][string]mixed $comments * @param array[int][string]int $comments[%id%][id] comment id * @return array[string][string]string $return[%plugin_id%]['toolbar'] Comment's toolbar html */ $this->view->assign('backend_comments', wa()->event('backend_comments', $comments, array('toolbar'))); $this->view->assign('comments', $comments); $this->view->assign('comments_count', $comments_count); $this->view->assign('comments_total_count', $comments_all_count); $this->view->assign('comments_per_page', $comments_per_page); $this->view->assign('pages', ceil($comments_all_count / $comments_per_page)); $this->view->assign('page', $page); $this->view->assign('contact_rights', $this->getUser()->getRights('contacts', 'backend')); $this->view->assign('current_contact_id', $user->getId()); $this->view->assign('current_contact', array('id' => $user->getId(), 'name' => $user->getName(), 'photo20' => $user->getPhoto($contact_photo_size))); $this->view->assign('filter', $filter); $yet_authors_exist = false; if ($blogs) { $yet_authors_exist = !!$post_model->select('contact_id')->where('blog_id IN (' . implode(',', $blog_ids) . ') AND contact_id != ' . $user->getId())->limit(1)->fetchField(); } $this->view->assign('blogs', $blogs); $this->view->assign('yet_authors_exist', $yet_authors_exist); }
public function setLastLoginTime($datetime) { $contact_id = wa()->getUser()->getId(); $contact_settings = new waContactSettingsModel(); $contact_settings->set($contact_id, 'photos', 'last_login_time', $datetime); return $datetime; }
public function setSidebarWidth($width) { $width = max(min((int) $width, 400), 200); $settings_model = new waContactSettingsModel(); $settings_model->set(wa()->getUser()->getId(), 'shop', 'sidebar_width', $width); }