<commit_before><?php
/**
 * Desire2Learn Web Serivces for Zend Framework
 *
 * LICENSE
 *
 * This source file is subject to the new BSD license that is bundled
 * with this package in the file LICENSE.
 * It is also available through the world-wide-web at this URL:
 * https://github.com/adamlundrigan/zfD2L/blob/0.1a0/LICENSE
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to <EMAIL> so we can send you a copy immediately.
 * 
 * @copyright  Copyright (c) 2011 Centre for Distance Learning and Innovation
 * @license    New BSD License 
 * @author     <NAME> <<EMAIL>>
 * @author     <NAME> <<EMAIL>>
 */
 
/**
 * Group OU API
 * @author <NAME> <<EMAIL>>
 */
class D2LWS_OrgUnit_Group_API extends D2LWS_Common
{
    /**
     * Find Group by OU
     * @param int $id
     * @return D2LWS_OrgUnit_Group_Model
     * @throws D2LWS_OrgUnit_Group_Exception_NotFound
     */
    public function findByID($id)
    {
        $i = $this->getInstance();        

        $result = $i->getSoapClient()
            ->setWsdl($i->getConfig('webservice.org.wsdl'))
            ->setLocation($i->getConfig('webservice.org.endpoint'))
            ->GetGroup(array(
                'OrgUnitId'=>array(
                    'Id'=>intval($id),
                    'Source'=>'Desire2Learn'
                )
            ));
        
        if ( $result instanceof stdClass && isset($result->Group) && $result->Group instanceof stdClass )
        {
            $Group = new D2LWS_OrgUnit_Group_Model($result->Group);
            return $Group;
        }
        else
        {
            throw new D2LWS_OrgUnit_Group_Exception_NotFound('Id=' . $id);
        }
    }
        
    /**
     * Find Group by Code
     * @param string $code
     * @return D2LWS_OrgUnit_Group_Model 
     */
    public function findByCode($code)
    {
        $i = $this->getInstance();        

        $result = $i->getSoapClient()
            ->setWsdl($i->getConfig('webservice.org.wsdl'))
            ->setLocation($i->getConfig('webservice.org.endpoint'))
            ->GetGroupByCode(array(
                'Code'=>$code
            ));
        
        if ( $result instanceof stdClass && isset($result->Group) && $result->Group instanceof stdClass )
        {
            $Group = new D2LWS_OrgUnit_Group_Model($result->Group);
            return $Group;
        }
        else
        {
            throw new D2LWS_OrgUnit_Group_Exception_NotFound('Code=' . $code);
        }
    }    
 
    /**
     * Save Group to D2L
     * @param D2LWS_OrgUnit_Group_Model $g
     * @return bool success?
     */
    public function save(D2LWS_OrgUnit_Group_Model &$g)
    {
        $i = $this->getInstance();     
        $arr = $this->_makeRequestStruct($g);        
        if ( is_null($g->getID()) )
        {
            $result = $i->getSoapClient()
                ->setWsdl($i->getConfig('webservice.org.wsdl'))
                ->setLocation($i->getConfig('webservice.org.endpoint'))
                ->CreateGroup($arr);
            
            if ( $result instanceof stdClass && isset($result->Group) && $result->Group instanceof stdClass )
            {
                $g = new D2LWS_OrgUnit_Group_Model($result->Group);
                return true;
            }
        }
        else
        {
            $result = $i->getSoapClient()
                ->setWsdl($i->getConfig('webservice.org.wsdl'))
                ->setLocation($i->getConfig('webservice.org.endpoint'))
                ->UpdateGroup($arr);
            
            return ( $result instanceof stdClass );
        }
        
        return false;
    }    

    /**
     * Create SOAP Request datastructure from model
     * @param D2LWS_OrgUnit_Group_Model $gm
     * @return stdClass Request Structure
     */
    protected function _makeRequestStruct(D2LWS_OrgUnit_Group_Model $gm)
    {
        $result = new stdClass();
        $result->Name = $gm->getName();
        $result->Code = $gm->getCode();
        
        $result->Description = new stdClass();
        $result->Description->Text = $gm->getDescription();
        $result->Description->IsHtml = $gm->isDescriptionHTML();
        
        $result->GroupTypeId = new stdClass();
        $result->GroupTypeId->Id = $gm->getGroupTypeID();
        $result->GroupTypeId->Source = 'Desire2Learn';

        $result->OwnerOrgUnitId = new stdClass();
        $result->OwnerOrgUnitId->Id = $gm->getOwnerOrgUnitId();
        $result->OwnerOrgUnitId->Source = 'Desire2Learn';

        // If there is an ID, format request as update
        if ( !is_null($gm->getID()) )
        {<commit_msg>Added delete method to D2LWS_OrgUnit_Group_API<commit_after><?php
/**
 * Desire2Learn Web Serivces for Zend Framework
 *
 * LICENSE
 *
 * This source file is subject to the new BSD license that is bundled
 * with this package in the file LICENSE.
 * It is also available through the world-wide-web at this URL:
 * https://github.com/adamlundrigan/zfD2L/blob/master/LICENSE
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to <EMAIL> so we can send you a copy immediately.
 * 
 * @copyright  Copyright (c) 2011 Centre for Distance Learning and Innovation
 * @license    New BSD License 
 * @author     <NAME> <<EMAIL>>
 * @author     <NAME> <<EMAIL>>
 */
 
/**
 * Group OU API
 * @author <NAME> <<EMAIL>>
 */
class D2LWS_OrgUnit_Group_API extends D2LWS_Common
{
    /**
     * Find Group by OU
     * @param int $id
     * @return D2LWS_OrgUnit_Group_Model
     * @throws D2LWS_OrgUnit_Group_Exception_NotFound
     */
    public function findByID($id)
    {
        $i = $this->getInstance();        

        $result = $i->getSoapClient()
            ->setWsdl($i->getConfig('webservice.org.wsdl'))
            ->setLocation($i->getConfig('webservice.org.endpoint'))
            ->GetGroup(array(
                'OrgUnitId'=>array(
                    'Id'=>intval($id),
                    'Source'=>'Desire2Learn'
                )
            ));
        
        if ( $result instanceof stdClass && isset($result->Group) && $result->Group instanceof stdClass )
        {
            $Group = new D2LWS_OrgUnit_Group_Model($result->Group);
            return $Group;
        }
        else
        {
            throw new D2LWS_OrgUnit_Group_Exception_NotFound('Id=' . $id);
        }
    }
        
    /**
     * Find Group by Code
     * @param string $code
     * @return D2LWS_OrgUnit_Group_Model 
     */
    public function findByCode($code)
    {
        $i = $this->getInstance();        

        $result = $i->getSoapClient()
            ->setWsdl($i->getConfig('webservice.org.wsdl'))
            ->setLocation($i->getConfig('webservice.org.endpoint'))
            ->GetGroupByCode(array(
                'Code'=>$code
            ));
        
        if ( $result instanceof stdClass && isset($result->Group) && $result->Group instanceof stdClass )
        {
            $Group = new D2LWS_OrgUnit_Group_Model($result->Group);
            return $Group;
        }
        else
        {
            throw new D2LWS_OrgUnit_Group_Exception_NotFound('Code=' . $code);
        }
    }    
 
    /**
     * Save Group to D2L
     * @param D2LWS_OrgUnit_Group_Model $g
     * @return bool success?
     */
    public function save(D2LWS_OrgUnit_Group_Model &$g)
    {
        $i = $this->getInstance();     
        $arr = $this->_makeRequestStruct($g);        
        if ( is_null($g->getID()) )
        {
            $result = $i->getSoapClient()
                ->setWsdl($i->getConfig('webservice.org.wsdl'))
                ->setLocation($i->getConfig('webservice.org.endpoint'))
                ->CreateGroup($arr);
            
            if ( $result instanceof stdClass && isset($result->Group) && $result->Group instanceof stdClass )
            {
                $g = new D2LWS_OrgUnit_Group_Model($result->Group);
                return true;
            }
        }
        else
        {
            $result = $i->getSoapClient()
                ->setWsdl($i->getConfig('webservice.org.wsdl'))
                ->setLocation($i->getConfig('webservice.org.endpoint'))
                ->UpdateGroup($arr);
            
            return ( $result instanceof stdClass );
        }
        
        return false;
    }    
    
    public function delete(D2LWS_OrgUnit_Group_Model $g)
    {
        if ( !is_null($g->getID()) )
        {
            $i = $this->getInstance();
            $result = $i->getSoapClient()
                ->setWsdl($i->getConfig('webservice.org.wsdl'))
                ->setLocation($i->getConfig('webservice.org.endpoint'))
                ->DeleteGroup(array(
                    'OrgUnitId'=>array(
                        'Id'=>$g->getID(),
                        'Source'=>'Desire2Learn'
                    )
                ));
            
            return ( $result instanceof stdClass );
        }
        return false;
    }

    /**
     * Create SOAP Request datastructure from model
     * @param D2LWS_OrgUnit_Group_Model $gm
     * @return stdClass Request Structure
     */
    protected function _makeRequestStruct(D2LWS_OrgUnit_Group_Model $gm)
    {
        $result = new stdClass();
        $result->Name = $gm->getName();
        $result->Code = $gm->getCode();
        
        $result->Description = new stdClass();
        $result->Description->Text = $gm->getDescription();
        $result->Description->IsHtml = $gm->isDescriptionHTML();
        
        $result->GroupTypeId = new stdClass();
        $result->GroupTypeId->Id = $gm->getGroupTypeID();
        $result->GroupTypeId->Source = 'Desire2Learn';

        $result->OwnerOrgUnitId = new stdClass();
        $result->OwnerOrgUnitId->Id = $gm->getOwnerOrgUnitId();
        $result->OwnerOrgUnitId->Source = 'Desire2Learn';

        // If there is an ID, format request as update
        if ( !is_null($gm->getID()) )
        {
{'fraction_non_alphanumeric': 0.13003992015968063, 'fraction_numerical': 0.005389221556886228, 'mean_word_length': 1.8771174275050244, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 167, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7302048', 'n_tokens_mistral': 3060, 'n_tokens_neox': 2900, 'n_words': 602}