Exemple #1
0
 /**
  * Edit a category
  *
  * @return  void
  */
 public function editTask($row = null)
 {
     Request::setVar('hidemainmenu', 1);
     $this->view->wishlist = Request::getInt('wishlist', 0);
     if (!is_object($row)) {
         // Incoming
         $id = Request::getVar('id', array(0));
         if (is_array($id) && !empty($id)) {
             $id = $id[0];
         }
         // Load category
         $row = new Wish($this->database);
         $row->load($id);
     }
     $this->view->row = $row;
     if (!$this->view->row->id) {
         $this->view->row->wishlist = $this->view->wishlist;
     } else {
         if (!$this->view->wishlist) {
             $this->view->wishlist = $this->view->row->wishlist;
         }
     }
     /*
     $m = new Models\AdminWish();
     $this->view->form = $m->getForm();
     */
     $obj = new Wishlist($this->database);
     $filters = array();
     $filters['sort'] = 'title';
     $filters['sort_Dir'] = 'ASC';
     $this->view->lists = $obj->getRecords($filters);
     // who are list owners?
     $this->admingroup = $this->config->get('group', 'hubadmin');
     $objOwner = new Owner($this->database);
     $objG = new OwnerGroup($this->database);
     $this->view->ownerassignees = array();
     $this->view->ownerassignees[-1] = array();
     $none = new stdClass();
     $none->id = '-1';
     $none->name = Lang::txt('COM_WISHLIST_SELECT');
     $this->view->ownerassignees[-1][] = $none;
     $this->view->assignees = null;
     if ($this->view->lists) {
         foreach ($this->view->lists as $k => $list) {
             if ($list->category == 'resource') {
                 include_once PATH_CORE . DS . 'components' . DS . 'com_resources' . DS . 'tables' . DS . 'resource.php';
                 $list->resource = new \Components\Resources\Tables\Resource($this->database);
                 $list->resource->load($list->referenceid);
             }
             $this->view->ownerassignees[$list->id] = array();
             $none = new stdClass();
             $none->id = '0';
             $none->name = Lang::txt('COM_WISHLIST_NONE');
             $this->view->ownerassignees[$list->id][] = $none;
             $owners = $objOwner->get_owners($list->id, $this->admingroup, $list);
             if (count($owners['individuals']) > 0) {
                 $query = "SELECT a.id, a.name FROM `#__users` AS a WHERE a.block = '0' AND a.id IN (" . implode(',', $owners['individuals']) . ") ORDER BY a.name";
                 $this->database->setQuery($query);
                 $users = $this->database->loadObjectList();
                 foreach ($users as $row2) {
                     $this->view->ownerassignees[$list->id][] = $row2;
                 }
                 if ($list->id == $this->view->row->wishlist) {
                     $this->view->assignees = $this->view->ownerassignees[$list->id];
                 }
             }
         }
     }
     // Get the plan for this wish
     $objPlan = new Plan($this->database);
     $plan = $objPlan->getPlan($this->view->row->id);
     $this->view->plan = $plan ? $plan[0] : $objPlan;
     // Get tags on this wish
     include_once dirname(dirname(__DIR__)) . DS . 'models' . DS . 'tags.php';
     $tagging = new Tags($this->view->row->id);
     $this->view->tags = $tagging->render('string');
     // Set any errors
     foreach ($this->getErrors() as $error) {
         \Notify::error($error);
     }
     // Output the HTML
     $this->view->setLayout('edit')->display();
 }
Exemple #2
0
 /**
  * Authorize administrator access
  *
  * @param   integer  $listid  Wish list ID
  * @param   integer  $admin   If the use ris an admin
  * @return  void
  */
 public function authorize_admin($listid = 0, $admin = 0)
 {
     // Check if they're a site admin
     if (User::authorize($this->_option, 'manage')) {
         $admin = 1;
     }
     if ($listid) {
         $admingroup = $this->config->get('group', 'hubadmin');
         // Get list administrators
         $objOwner = new Tables\Owner($this->database);
         $owners = $objOwner->get_owners($listid, $admingroup);
         $managers = $owners['individuals'];
         $advisory = $owners['advisory'];
         if (!User::isGuest()) {
             if (in_array(User::get('id'), $managers)) {
                 $admin = 2;
                 // individual group manager
             }
             if (in_array(User::get('id'), $advisory)) {
                 $admin = 3;
                 // advisory committee member
             }
         }
     }
     $this->_admin = $admin;
 }
Exemple #3
0
 /**
  * Add one or more owners
  *
  * @param   string  $what  Owner type to add
  * @param   mixed   $data  integer|string|array
  * @return  object
  */
 public function add($what, $data)
 {
     $data = $this->_toArray($data);
     $what = strtolower($what);
     switch ($what) {
         case 'advisory':
             if ($this->config('allow_advisory', 0)) {
                 $tbl = new Tables\Owner($this->_db);
                 if (!$tbl->save_owners($this->get('id'), $this->config(), $data, 2)) {
                     $this->setError($tbl->getError());
                 }
             }
             break;
         case 'individuals':
             $tbl = new Tables\Owner($this->_db);
             if (!$tbl->save_owners($this->get('id'), $this->config(), $data)) {
                 $this->setError($tbl->getError());
             }
             break;
         case 'groups':
             $tbl = new Tables\OwnerGroup($this->_db);
             if (!$tbl->save_owner_groups($this->get('id'), $this->config(), $data)) {
                 $this->setError($tbl->getError());
             }
             break;
         default:
             //throw new \InvalidArgumentException(Lang::txt('Owner type not supported.'));
             throw new \RuntimeException("Lang::txt('Owner type not supported.')", 404);
             break;
     }
     // Reset the owners lists
     $this->_cache['owners.list0'] = null;
     $this->_cache['owners.list1'] = null;
     return $this;
 }
Exemple #4
0
 /**
  * Distribute points
  *
  * @param   integer  $wishid  Wish ID
  * @param   string   $type    Transaction type
  * @param   number   $points  Points to distribute
  * @return  void
  */
 public function distribute_points($wishid, $type = 'grant', $points = 0)
 {
     if (!$wishid) {
         return null;
     }
     require_once dirname(__DIR__) . DS . 'models' . DS . 'wishlist.php';
     $objWish = new Tables\Wish($this->_db);
     $wish = $objWish->get_wish($wishid);
     $points = !$points ? $wish->bonus : $points;
     // Points for list owners
     if ($points > 0 && $type != 'royalty') {
         // Get the component parameters
         $wconfig = Component::params('com_wishlist');
         $admingroup = $wconfig->get('group', 'hubadmin');
         // get list owners
         $objOwner = new Tables\Owner($this->_db);
         $owners = $objOwner->get_owners($wish->wishlist, $admingroup, '', 0, $wishid);
         $owners = $owners['individuals'];
         $mainshare = $wish->assigned ? $points * 0.8 : 0;
         //80%
         $commonshare = $mainshare ? ($points - $mainshare) / count($owners) : $points / count($owners);
         // give the remaining 20%
         if ($owners && $commonshare) {
             foreach ($owners as $owner) {
                 $o = User::getInstance($owner);
                 if (!is_object($o) || !$o->get('id')) {
                     continue;
                 }
                 $BTLO = new Teller($this->_db, $owner);
                 if ($wish->assigned && $wish->assigned == $owner) {
                     //$BTLO->deposit($mainshare, Lang::txt('Bonus for fulfilling assigned wish').' #'.$wishid.' '.Lang::txt('on list').' #'.$wish->wishlist, 'wish', $wishid);
                     $mainshare += $commonshare;
                 } else {
                     $BTLO->deposit($commonshare, Lang::txt('Bonus for fulfilling wish #%s on list #%s', $wishid, $wish->wishlist), 'wish', $wishid);
                 }
             }
         } else {
             $mainshare += $commonshare;
         }
         // give main share
         if ($wish->assigned && $mainshare) {
             $o = User::getInstance($wish->assigned);
             if (is_object($o) && $o->get('id')) {
                 $BTLM = new Teller($this->_db, $wish->assigned);
                 $BTLM->deposit($mainshare, Lang::txt('Bonus for fulfilling assigned wish #%s on list #%s', $wishid, $wish->wishlist), 'wish', $wishid);
             }
         }
         // Adjust credits
         $payees = $this->getPayees($wishid);
         if ($payees) {
             foreach ($payees as $p) {
                 $o = User::getInstance($p->uid);
                 if (!is_object($o) || !$o->get('id')) {
                     continue;
                 }
                 $BTL = new Teller($this->_db, $p->uid);
                 $hold = $this->getTotalPayment($wishid, $p->uid);
                 if ($hold) {
                     $credit = $BTL->credit_summary();
                     $adjusted = $credit - $hold;
                     $BTL->credit_adjustment($adjusted);
                     // withdraw bonus amount
                     $BTL->withdraw($hold, Lang::txt('Bonus payment for granted wish #%s on list #%s', $wishid, $wish->wishlist), 'wish', $wishid);
                 }
             }
         }
         // Remove holds if exist
         if ($wish->bonus) {
             $BT = new Transaction($this->_db);
             $BT->deleteRecords('wish', 'hold', $wishid);
         }
     }
     // Points for wish author (needs to be granted by another person)
     if ($wish->ranking > 0 && $wish->proposed_by != User::get('id') && $wish->proposed_by) {
         $o = User::getInstance($wish->proposed_by);
         if (is_object($o) && $o->get('id')) {
             $BTLA = new Teller($this->_db, $wish->proposed_by);
             $BTLA->deposit($wish->ranking, Lang::txt('Your wish #%s on list #%s was granted', $wishid, $wish->wishlist), 'wish', $wishid);
         }
     }
 }