<?php
class xuanxuanNotify extends notifyModel
{
    public function send($objectType, $objectID, $actionType, $actionID, $actor = '')
    {
        $messageSetting = $this->config->notify->setting;
        if(is_string($messageSetting)) $messageSetting = json_decode($messageSetting, true);
        if(isset($messageSetting['xuanxuan']))
        {
            $actions = $messageSetting['xuanxuan']['setting'];
            if(isset($actions[$objectType]) and in_array($actionType, $actions[$objectType]))
            {
                $this->loadModel('action');
                $object = $this->dao->select('*')->from($this->config->objectTables[$objectType])->where('id')->eq($objectID)->fetch();
                $app    = $this->config->action->objectAppNames[$objectType];
                $field  = $this->config->action->objectNameFields[$objectType];
                $title  = $this->app->user->realname . ' ' . $this->lang->action->label->$actionType . $this->lang->action->objectTypes[$objectType];
                $text   = $title . ' ' . "[#{$objectID}::{$object->$field}]";

                $server   = $this->loadModel('im')->getServer();
                $onlybody = isset($_GET['onlybody']) ? $_GET['onlybody'] : '';
                unset($_GET['onlybody']);
                $url = $server . helper::createLink($app . '.' . $objectType, 'view', "id=$objectID", 'html');

                $target = '';
                $target = $this->getToList($object, $objectType);
                if(empty($target)) return false;

                $target = trim($target, ',');
                $target = $this->dao->select('id')->from(TABLE_USER)->where('account')->in($target)->fetchPairs('id');
                $target = array_keys($target);

                if($target) $this->loadModel('im')->messageCreateNotify($target, $text, '', '', 'text', $url, array(), array('id' => 'zdoo', 'realname' => $this->lang->zdoo, 'name' => $this->lang->zdoo));
                if($onlybody) $_GET['onlybody'] = $onlybody;
            }
        }
    }
}
