Esempio n. 1
0
 /**
  * @service role add
  * @return Gpf_Rpc_Form
  */
 public function add(Gpf_Rpc_Params $params)
 {
     $form = new Gpf_Rpc_Form($params);
     $origRole = new Gpf_Db_Role();
     $origRole->setId($form->getFieldValue('roleid'));
     $origRole->load();
     $newRole = new Gpf_Db_Role();
     $newRole->setName($form->getFieldValue('name'));
     $newRole->setAccountId(Gpf_Session::getInstance()->getAuthUser()->getAccountId());
     $newRole->setRoleType($origRole->getRoleType());
     $newRole->insert();
     if (strlen($origRole->getAccountId())) {
         //it is custom role, copy privileges from db
         $select = new Gpf_SqlBuilder_SelectBuilder();
         $select->select->addConstant($newRole->getId(), 'roleid');
         $select->select->add(Gpf_Db_Table_RolePrivileges::OBJECT, Gpf_Db_Table_RolePrivileges::OBJECT);
         $select->select->add(Gpf_Db_Table_RolePrivileges::PRIVILEGE, Gpf_Db_Table_RolePrivileges::PRIVILEGE);
         $select->from->add(Gpf_Db_Table_RolePrivileges::getName());
         $select->where->add(Gpf_Db_Table_Roles::ID, '=', $origRole->getId());
         $insert = new Gpf_SqlBuilder_InsertBuilder();
         $insert->setTable(Gpf_Db_Table_RolePrivileges::getInstance());
         $insert->fromSelect($select);
         $insert->execute();
     } else {
         //it is default role, copy privileges from php settings
         $privileges = Gpf_Application::getInstance()->getRoleDefaultPrivileges($origRole->getId());
         foreach ($privileges as $objectName => $privilegeList) {
             foreach ($privilegeList as $right) {
                 $privilege = new Gpf_Db_RolePrivilege();
                 $privilege->setRoleId($newRole->getId());
                 $privilege->setObject($objectName);
                 $privilege->setPrivilege($right);
                 $privilege->insert();
             }
         }
     }
     return $form;
 }
Esempio n. 2
0
    public function execute() {
        $selectBuilder = new Gpf_SqlBuilder_SelectBuilder();
        $selectBuilder->select->add(Pap_Db_Table_CommissionTypes::ID);
        $selectBuilder->from->add(Pap_Db_Table_CommissionTypes::getName());
        $selectBuilder->where->add(Pap_Db_Table_CommissionTypes::TYPE, '=', Pap_Common_Constants::TYPE_REFERRAL);
        try {
            $selectBuilder->getOneRow();
            return;
        } catch (Gpf_Exception $e) {
        }

        $insert = new Gpf_SqlBuilder_InsertBuilder();
        $insert->setTable(Pap_Db_Table_CommissionTypes::getInstance());
        $insert->add(Pap_Db_Table_CommissionTypes::ID, 'refercom');
        $insert->add(Pap_Db_Table_CommissionTypes::TYPE, Pap_Common_Constants::TYPE_REFERRAL);
        $insert->add(Pap_Db_Table_CommissionTypes::STATUS, Pap_Db_CommissionType::STATUS_ENABLED);
        $insert->add(Pap_Db_Table_CommissionTypes::APPROVAL, Pap_Db_CommissionType::APPROVAL_AUTOMATIC);
        $insert->add(Pap_Db_Table_CommissionTypes::ZEROORDERSCOMMISSION, Gpf::NO);
        try {
            $insert->execute();
        } catch (Exception $e) {
        }
    }
Esempio n. 3
0
 protected function createMailAttachments(Gpf_Db_MailTemplate $template, Gpf_Db_Mail $mail)
 {
     $select = new Gpf_SqlBuilder_SelectBuilder();
     $select->select->add('fileid', 'fileid');
     $select->select->addConstant($mail->get('mailid'), 'mailid');
     $select->select->add('is_included_image', 'is_included_image');
     $select->from->add(Gpf_Db_Table_MailTemplateAttachments::getName());
     $select->where->add('templateid', '=', $template->get('templateid'));
     $insert = new Gpf_SqlBuilder_InsertBuilder();
     $insert->setTable(Gpf_Db_Table_MailAttachments::getInstance());
     $insert->fromSelect($select);
     $insert->execute();
 }