Example #1
0
    /**
     * Delete a group assignation
     * @author:     Albert PĂ©rez Monfort (aperezm@xtec.cat)
     * @param:	args   The activity identity and the group identity
     * @return:	True if success and false otherwise
     */
    public function deleteAssingGroup($args) {
        $jid = FormUtil::getPassedValue('jid', isset($args['jid']) ? $args['jid'] : null, 'POST');
        $group = FormUtil::getPassedValue('group', isset($args['group']) ? $args['group'] : null, 'POST');

        // Security check
        if (!SecurityUtil::checkPermission('IWjclic::', "::", ACCESS_ADD)) {
            throw new Zikula_Exception_Forbidden();
        }

        // Needed argument
        if ($jid == null || !is_numeric($jid)) {
            return LogUtil::registerError($this->__('Error! Could not do what you wanted. Please check your input.'));
        }

        //get jclic activity
        $jclic = ModUtil::apiFunc('IWjclic', 'user', 'get', array('jid' => $jid));
        if ($jclic == false) {
            return LogUtil::registerError($this->__('Could not find the allocation requested'));
        }

        //Check if user can edit the activity because he/she is the owner
        if ($jclic['user'] != UserUtil::getVar('uid')) {
            return LogUtil::registerError($this->__('You do not have access to edit the activity'));
        }

        $pntable = DBUtil::getTables();
        $c = $pntable['IWjclic_groups_column'];
        $where = "$c[jid]=$jid AND $c[group_id] = $group";

        if (!DBUTil::deleteObject($item, 'IWjclic_groups', $where)) {
            return LogUtil::registerError($this->__('Error! Sorry! Deletion attempt failed.'));
        }

        return true;
    }