コード例 #1
0
ファイル: transfer.php プロジェクト: kevinwojo/hubzero-cms
 /**
  * Retrieves a row from the database
  *
  * @param      string $refid    ID of the database table row
  * @param      string $category Element type (determines table to look in)
  * @param      string $parent   If the element has a parent element
  * @return     array
  */
 public function transferItem($from_type, $from_id, $to_type, $rid = 0, $deactivate = 1)
 {
     $upconfig = Component::params('com_members');
     $this->banking = $upconfig->get('bankAccounts');
     $database = App::get('db');
     if ($from_type == NULL or $from_id == NULL or $to_type == NULL) {
         $this->setError(Lang::txt('PLG_SUPPORT_TRANSFER_ERROR_MISSING_INFO'));
         return false;
     }
     if ($from_type == $to_type) {
         $this->setError(Lang::txt('PLG_SUPPORT_TRANSFER_ERROR_CATEGORIES_MUST_BE_DIFFERENT'));
         return false;
     }
     // collectors
     $author = '';
     $subject = '';
     $body = '';
     $tags = '';
     $owner = '';
     // name of group owning the item
     $anonymous = 0;
     // get needed scripts
     include_once PATH_CORE . DS . 'components' . DS . 'com_support' . DS . 'models' . DS . 'ticket.php';
     include_once PATH_CORE . DS . 'components' . DS . 'com_answers' . DS . 'models' . DS . 'question.php';
     include_once PATH_CORE . DS . 'components' . DS . 'com_wishlist' . DS . 'models' . DS . 'wishlist.php';
     $wconfig = Component::params('com_wishlist');
     $admingroup = $wconfig->get('group') ? $wconfig->get('group') : 'hubadmin';
     // Get needed scripts & initial data
     switch ($from_type) {
         // Transfer from a Support Ticket
         case 'ticket':
             $row = new \Components\Support\Models\Ticket($from_id);
             if ($row->exists()) {
                 $author = $row->get('login');
                 $subject = $row->content('raw', 200);
                 // max 200 characters
                 $body = $row->get('summary');
                 $owner = $row->get('group');
                 // If we are de-activating original item
                 if ($deactivate) {
                     $row->set('status', 2);
                     $row->set('resolved', 'transfered');
                 }
                 $tags = $row->tags('string');
             } else {
                 $this->setError(Lang::txt('PLG_SUPPORT_TRANSFER_ERROR_ITEM_NOT_FOUND'));
                 return false;
             }
             break;
             // Transfer from a Question
         // Transfer from a Question
         case 'question':
             $row = new \Components\Answers\Models\Question($from_id);
             if ($row->exists()) {
                 $author = $row->get('created_by');
                 $subject = $row->subject('raw', 200);
                 // max 200 characters
                 $body = $row->get('question');
                 $anonymous = $row->get('anonymous');
                 // If we are de-activating original item
                 if ($deactivate) {
                     $row->set('state', 2);
                     $row->set('reward', 0);
                 }
                 $tags = $row->tags('string');
             } else {
                 $this->setError(Lang::txt('PLG_SUPPORT_TRANSFER_ERROR_ITEM_NOT_FOUND'));
                 return false;
             }
             break;
             // Transfer from a Wish
         // Transfer from a Wish
         case 'wish':
             $row = new \Components\Wishlist\Tables\Wish($database);
             $row->load($from_id);
             if ($row->id) {
                 $author = $row->proposed_by;
                 $subject = \Hubzero\Utility\String::truncate($row->subject, 200);
                 // max 200 characters
                 $body = $row->about;
                 $anonymous = $row->anonymous;
                 // If we are de-activating original item
                 if ($deactivate) {
                     $row->status = 2;
                     $row->ranking = 0;
                     // also delete all previous votes for this wish
                     $objR = new \Components\Wishlist\Tables\Rank($database);
                     $objR->remove_vote($from_id);
                 }
                 // get owner
                 $objG = new \Components\Wishlist\Tables\OwnerGroup($database);
                 $nativegroups = $objG->get_owner_groups($row->wishlist, $admingroup, '', 1);
                 $owner = count($nativegroups) > 0 && $nativegroups[0] != $admingroup ? $nativegroups[0] : '';
                 // tool group
                 $objWishlist = new \Components\Wishlist\Tables\Wishlist($database);
                 $wishlist = $objWishlist->get_wishlist($row->wishlist);
                 if (isset($wishlist->resource) && isset($wishlist->resource->alias)) {
                     $tags = $wishlist->resource->type == 7 ? 'tool:' : 'resource:';
                     $tags .= $wishlist->resource->alias ? $wishlist->resource->alias : $wishlist->referenceid;
                 }
             } else {
                 $this->setError(Lang::txt('PLG_SUPPORT_TRANSFER_ERROR_ITEM_NOT_FOUND'));
                 return false;
             }
             break;
     }
     // if no author can be found, use current administrator
     $author = User::getInstance($author);
     if (!is_object($author)) {
         $author = User::getInstance(User::get('id'));
     }
     $today = Date::toSql();
     // Where do we transfer?
     switch ($to_type) {
         // Transfer to a Support Ticket
         case 'ticket':
             $newrow = new \Components\Support\Models\Ticket();
             $newrow->set('open', 1);
             $newrow->set('status', 0);
             $newrow->set('created', $today);
             $newrow->set('login', $author->get('username'));
             $newrow->set('severity', 'normal');
             $newrow->set('summary', $subject);
             $newrow->set('report', $body ? $body : $subject);
             $newrow->set('section', 1);
             $newrow->set('type', 0);
             $newrow->set('instances', 1);
             $newrow->set('email', $author->get('email'));
             $newrow->set('name', $author->get('name'));
             // do we have an owner group?
             $newrow->set('group', $owner ? $owner : '');
             break;
         case 'question':
             $newrow = new \Components\Answers\Models\Question();
             $newrow->set('subject', $subject);
             $newrow->set('question', $body);
             $newrow->set('created', $today);
             $newrow->set('created_by', $author->get('id'));
             $newrow->set('state', 0);
             $newrow->set('anonymous', $anonymous);
             break;
         case 'wish':
             $newrow = new \Components\Wishlist\Models\Wish();
             $newrow->set('subject', $subject);
             $newrow->set('about', $body);
             $newrow->set('proposed', $today);
             $newrow->set('proposed_by', $author->get('id'));
             $newrow->set('status', 0);
             $newrow->set('anonymous', $anonymous);
             // which wishlist?
             $objWishlist = new \Components\Wishlist\Tables\Wishlist($database);
             $mainlist = $objWishlist->get_wishlistID(1, 'general');
             $listid = 0;
             if (!$rid && $owner) {
                 $rid = $this->getResourceIdFromGroup($owner);
             }
             if ($rid) {
                 $listid = $objWishlist->get_wishlistID($rid);
             }
             $newrow->set('wishlist', $listid ? $listid : $mainlist);
             break;
     }
     // Save new information
     if (!$newrow->store()) {
         $this->setError($newrow->getError());
         return;
     } else {
         // Checkin ticket
         //$newrow->checkin();
         // Extras
         if ($newrow->exists()) {
             switch ($to_type) {
                 case 'ticket':
                     // Tag new ticket
                     if ($tags) {
                         $newrow->tag($tags, User::get('id'), 0);
                     }
                     break;
                 case 'question':
                     // Tag new question
                     if ($tags) {
                         $newrow->tag($tags, User::get('id'), 0);
                     }
                     break;
             }
         }
     }
     // If we are de-activating original item
     if ($deactivate) {
         // overwrite old entry
         if (!$row->store()) {
             $this->setError($row->getError());
             exit;
         }
         // Clean up rewards if banking
         if ($this->banking) {
             switch ($from_type) {
                 case 'ticket':
                     // no banking yet
                     break;
                 case 'question':
                     $reward = \Hubzero\Bank\Transaction::getAmount('answers', 'hold', $from_id, $author->get('id'));
                     // Remove hold
                     if ($reward) {
                         \Hubzero\Bank\Transaction::deleteRecords('answers', 'hold', $from_id);
                         // Make credit adjustment
                         $BTL_Q = new \Hubzero\Bank\Teller($author->get('id'));
                         $credit = $BTL_Q->credit_summary();
                         $adjusted = $credit - $reward;
                         $BTL_Q->credit_adjustment($adjusted);
                     }
                     break;
                 case 'wish':
                     include_once PATH_CORE . DS . 'components' . DS . 'com_wishlist' . DS . 'helpers' . DS . 'economy.php';
                     $WE = new \Components\Wishlist\Helpers\Economy($database);
                     $WE->cleanupBonus($from_id);
                     break;
             }
         }
     }
     return $newrow->get('id');
 }
コード例 #2
0
ファイル: default.php プロジェクト: sumudinie/hubzero-cms
			<span>(<?php 
echo $this->rows ? count($this->rows) : '0';
?>
)</span>
		</caption>
		<tbody>
	<?php 
if ($this->rows) {
    ?>
		<?php 
    $i = 1;
    foreach ($this->rows as $row) {
        if ($i > $this->limit) {
            break;
        }
        $row = new \Components\Answers\Models\Question($row);
        $i++;
        $name = Lang::txt('PLG_RESOURCES_QUESTIONS_ANONYMOUS');
        if (!$row->get('anonymous')) {
            $name = $this->escape(stripslashes($row->creator('name', $name)));
            if ($row->creator('public')) {
                $name = '<a href="' . Route::url($row->creator()->getLink()) . '">' . $name . '</a>';
            }
        }
        $cls = $row->get('state') == 1 ? 'answered' : '';
        $cls = $row->isReported() ? 'flagged' : $cls;
        $cls .= $row->get('created_by') == User::get('username') ? ' mine' : '';
        ?>
			<tr<?php 
        echo $cls ? ' class="' . $cls . '"' : '';
        ?>
コード例 #3
0
ファイル: questions.php プロジェクト: sumudinie/hubzero-cms
 /**
  * Save a question and redirect to the main listing when done
  *
  * @return     void
  */
 private function _save()
 {
     // Login required
     if (User::isGuest()) {
         return $this->_browse();
     }
     // Check for request forgeries
     Request::checkToken();
     // Incoming
     $tags = Request::getVar('tags', '');
     $funds = Request::getInt('funds', 0);
     $reward = Request::getInt('reward', 0);
     // If offering a reward, do some checks
     if ($reward) {
         // Is it an actual number?
         if (!is_numeric($reward)) {
             App::abort(500, Lang::txt('COM_ANSWERS_REWARD_MUST_BE_NUMERIC'));
             return;
         }
         // Are they offering more than they can afford?
         if ($reward > $funds) {
             App::abort(500, Lang::txt('COM_ANSWERS_INSUFFICIENT_FUNDS'));
             return;
         }
     }
     // Initiate class and bind posted items to database fields
     $fields = Request::getVar('question', array(), 'post', 'none', 2);
     $row = new \Components\Answers\Models\Question($fields['id']);
     if (!$row->bind($fields)) {
         $this->setError($row->getError());
         return $this->_new($row);
     }
     if ($reward && $this->banking) {
         $row->set('reward', 1);
     }
     // Store new content
     if (!$row->store(true)) {
         $row->set('tags', $tags);
         $this->setError($row->getError());
         return $this->_new($row);
     }
     // Hold the reward for this question if we're banking
     if ($reward && $this->banking) {
         $BTL = new \Hubzero\Bank\Teller($this->database, User::get('id'));
         $BTL->hold($reward, Lang::txt('COM_ANSWERS_HOLD_REWARD_FOR_BEST_ANSWER'), 'answers', $row->get('id'));
     }
     // Add the tags
     $row->tag($tags);
     // Add the tag to link to the publication
     $identifier = $this->publication->get('alias') ? $this->publication->get('alias') : $this->publication->get('id');
     $tag = $this->publication->isTool() ? 'tool' . $identifier : 'publication' . $identifier;
     $row->addTag($tag, User::get('id'), $this->publication->isTool() ? 0 : 1);
     // Redirect to the question
     App::redirect(Route::url($this->publication->link() . '&active=questions'));
 }
コード例 #4
0
ファイル: questions.php プロジェクト: sumudinie/hubzero-cms
 /**
  * Save a question and redirect to the main listing when done
  *
  * @return     void
  */
 private function _save()
 {
     // Login required
     if (User::isGuest()) {
         return $this->_browse();
     }
     // Check for request forgeries
     Request::checkToken();
     Lang::load('com_answers');
     // Incoming
     $tags = Request::getVar('tags', '');
     $funds = Request::getInt('funds', 0);
     $reward = Request::getInt('reward', 0);
     // If offering a reward, do some checks
     if ($reward) {
         // Is it an actual number?
         if (!is_numeric($reward)) {
             App::abort(500, Lang::txt('COM_ANSWERS_REWARD_MUST_BE_NUMERIC'));
             return;
         }
         // Are they offering more than they can afford?
         if ($reward > $funds) {
             App::abort(500, Lang::txt('COM_ANSWERS_INSUFFICIENT_FUNDS'));
             return;
         }
     }
     // Initiate class and bind posted items to database fields
     $fields = Request::getVar('question', array(), 'post', 'none', 2);
     $row = new \Components\Answers\Models\Question($fields['id']);
     if (!$row->bind($fields)) {
         $this->setError($row->getError());
         return $this->_new($row);
     }
     if ($reward && $this->banking) {
         $row->set('reward', 1);
     }
     // Ensure the user added a tag
     /*
     if (!$tags)
     {
     	$this->setError(Lang::txt('COM_ANSWERS_QUESTION_MUST_HAVE_TAG'));
     	return $this->_new($row);
     }
     */
     // Store new content
     if (!$row->store(true)) {
         $row->set('tags', $tags);
         $this->setError($row->getError());
         return $this->_new($row);
     }
     // Hold the reward for this question if we're banking
     if ($reward && $this->banking) {
         $BTL = new \Hubzero\Bank\Teller($this->database, User::get('id'));
         $BTL->hold($reward, Lang::txt('COM_ANSWERS_HOLD_REWARD_FOR_BEST_ANSWER'), 'answers', $row->get('id'));
     }
     // Add the tags
     $row->tag($tags);
     // Add the tag to link to the resource
     $tag = $this->model->isTool() ? 'tool:' . $this->model->resource->alias : 'resource:' . $this->model->resource->id;
     $row->addTag($tag, User::get('id'), $this->model->isTool() ? 0 : 1);
     // Get users who need to be notified on every question
     $config = Component::params('com_answers');
     $apu = $config->get('notify_users', '');
     $apu = explode(',', $apu);
     $apu = array_map('trim', $apu);
     $receivers = array();
     // Get tool contributors if question is about a tool
     if ($tags) {
         $tags = explode(',', $tags);
         if (count($tags) > 0) {
             require_once PATH_CORE . DS . 'components' . DS . 'com_tools' . DS . 'tables' . DS . 'author.php';
             require_once PATH_CORE . DS . 'components' . DS . 'com_tools' . DS . 'tables' . DS . 'version.php';
             $TA = new \Components\Tools\Tables\Author($this->database);
             $objV = new \Components\Tools\Tables\Version($this->database);
             if ($this->model->isTool()) {
                 $toolname = $this->model->resource->alias;
                 $rev = $objV->getCurrentVersionProperty($toolname, 'revision');
                 $authors = $TA->getToolAuthors('', 0, $toolname, $rev);
                 if (count($authors) > 0) {
                     foreach ($authors as $author) {
                         $receivers[] = $author->uidNumber;
                     }
                 }
             }
         }
     }
     if (!empty($apu)) {
         foreach ($apu as $u) {
             $user = User::getInstance($u);
             if ($user) {
                 $receivers[] = $user->get('id');
             }
         }
     }
     $receivers = array_unique($receivers);
     // Send the message
     if (!empty($receivers)) {
         // Send a message about the new question to authorized users (specified admins or related content authors)
         $from = array('email' => Config::get('mailfrom'), 'name' => Config::get('sitename') . ' ' . Lang::txt('COM_ANSWERS_ANSWERS'), 'multipart' => md5(date('U')));
         // Build the message subject
         $subject = Lang::txt('COM_ANSWERS_ANSWERS') . ', ' . Lang::txt('new question about content you author or manage');
         // Build the message
         $eview = new \Hubzero\Mail\View(array('base_path' => PATH_CORE . DS . 'components' . DS . 'com_answers' . DS . 'site', 'name' => 'emails', 'layout' => 'question_plaintext'));
         $eview->option = 'com_answers';
         $eview->sitename = Config::get('sitename');
         $eview->question = $row;
         $eview->id = $row->get('id', 0);
         $eview->boundary = $from['multipart'];
         $message['plaintext'] = $eview->loadTemplate(false);
         $message['plaintext'] = str_replace("\n", "\r\n", $message['plaintext']);
         // HTML message
         $eview->setLayout('question_html');
         $message['multipart'] = $eview->loadTemplate();
         $message['multipart'] = str_replace("\n", "\r\n", $message['multipart']);
         if (!Event::trigger('xmessage.onSendMessage', array('new_question_admin', $subject, $message, $from, $receivers, 'com_answers'))) {
             $this->setError(Lang::txt('COM_ANSWERS_MESSAGE_FAILED'));
         }
     }
     // Redirect to the question
     App::redirect(Route::url('index.php?option=' . $this->option . '&id=' . $this->model->resource->id . '&active=' . $this->_name));
 }
コード例 #5
0
ファイル: default.php プロジェクト: sumudinie/hubzero-cms
			<span>(<?php 
echo $this->rows ? count($this->rows) : '0';
?>
)</span>
		</caption>
		<tbody>
<?php 
if ($this->rows) {
    ?>
	<?php 
    $i = 1;
    foreach ($this->rows as $row) {
        if ($i > $this->limit) {
            break;
        }
        $row = new \Components\Answers\Models\Question($row);
        $i++;
        // author name
        $name = Lang::txt('PLG_PUBLICATION_QUESTIONS_ANONYMOUS');
        if (!$row->get('anonymous')) {
            $user = User::getInstance($row->get('created_by'));
            if (is_object($user)) {
                $name = '<a href="' . Route::url('index.php?option=com_members&id=' . $user->get('id')) . '">' . $this->escape(stripslashes($user->get('name'))) . '</a>';
            } else {
                $name = Lang::txt('PLG_PUBLICATION_QUESTIONS_UNKNOWN');
            }
        }
        $cls = $row->get('state') == 1 ? 'answered' : '';
        $cls = $row->isReported() ? 'flagged' : $cls;
        $cls .= $row->get('created_by') == User::get('username') ? ' mine' : '';
        ?>