public function executeSchemaUserList()
 {
     $c = new Criteria();
     $c->add(SchemaHasUserPeer::SCHEMA_ID, $this->schemaId);
     $c->addAscendingOrderByColumn(UserPeer::LAST_NAME);
     $this->users = SchemaHasUserPeer::doSelectJoinUser($c);
 }
 public function executeEdit()
 {
     /** @var \myUser $sfUser */
     $sfUser = sfContext::getInstance()->getUser();
     $userId = $sfUser->getSubscriberId();
     $schemaObj = $this->getCurrentSchema();
     $CurrentCulture = $sfUser->getCulture();
     //FIXME: If the user is an admin, set the available languages to all of the schema languages
     //FIXME: if the user has no languages set, silently set their language to the default (?)
     if ($userId) {
         $c = new Criteria();
         $c->add(SchemaHasUserPeer::USER_ID, $userId);
         $c->add(SchemaHasUserPeer::SCHEMA_ID, $schemaObj->getId());
         $schemaUser = SchemaHasUserPeer::doSelectOne($c);
         if ($sfUser->hasObjectCredential($schemaObj->getId(), 'schema', array(0 => array(0 => 'administrator', 2 => 'schemaadmin')))) {
             $UserLanguages = $schemaObj->getLanguages();
             $DefaultLanguage = $schemaObj->getLanguage();
         } else {
             if ($schemaUser) {
                 $UserLanguages = $schemaUser->getLanguages();
                 $DefaultLanguage = $schemaUser->getDefaultLanguage();
             } else {
                 //set the languages from the schema
                 $UserLanguages = $schemaObj->getLanguages();
                 $DefaultLanguage = $schemaObj->getLanguage();
             }
         }
         if (is_array($UserLanguages) && !in_array($CurrentCulture, $UserLanguages)) {
             //save the current culture
             $UserCulture = $sfUser->getCulture();
             $this->getUser()->setAttribute("UserCulture", $UserCulture);
             //reset the current culture for edit
             $sfUser->setCulture($DefaultLanguage);
             $this->getUser()->setAttribute("CurrentLanguage", $DefaultLanguage);
             $culture = new sfCultureInfo($this->getUser()->getCulture());
             $this->setFlash('notice', 'Current language is not available for edit! Current editing language has been reset to: ' . $culture->getNativeName());
         }
         $this->getUser()->setAttribute("languages", $UserLanguages);
     }
     parent::executeEdit();
     /** @var $schemaProperty SchemaProperty */
     $schemaProperty = $this->schema_property;
     if ($schemaProperty) {
         $schemaObj = $this->getCurrentSchema();
         $schemaProperty->setSchemaUri($schemaObj->getNamespace());
         $lexUri = $schemaProperty->getLexicalAlias();
         if (empty($lexUri)) {
             $newURI = $schemaObj->getNamespace();
             $this->setDefaultLexicalAlias($schemaProperty, $newURI);
         }
     }
 }
/**
 * Builds a multi-dimensional array of Schemas[SchemaProperties]
 * Optionally returns a script tag
 *
 * @param integer $userId
 *
 * @param bool    $makeScript
 * @param string  $var
 *
 * @return array
 */
function schema_for_user_select_array($userId, $makeScript = FALSE, $var = '')
{
    //get the schemas for a user
    $schemasArray = SchemaHasUserPeer::getSchemasForUser($userId);
    $schemas = array();
    /** @var $schema Schema */
    foreach ($schemasArray as $schema) {
        //select schema properties to add to array
        $schemaId = $schema->getId();
        $schemas[$schemaId] = array('name' => $schema->getName(), 'uri' => $schema->getUri(), 'properties' => array());
        $schemaPropArray = SchemaPropertyPeer::getElementsForSchema($schemaId);
        /** @var $element SchemaProperty */
        foreach ($schemaPropArray as $schemaProp) {
            $schemaPropId = $schemaProp->getId();
            $schemas[$schemaId]['properties'][$schemaPropId] = array('name' => $schemaProp->getLabel(), 'uri' => $schemaProp->getUri(), 'type' => $schemaProp->getType());
        }
    }
    if ($makeScript) {
        $var = $var ? $var : "data";
        $content = "var {$var} = " . json_encode($schemas);
        return javascript_tag($content);
    }
    return $schemas;
}
Example #4
0
 /**
  * @return array
  */
 public function getMaintainerIds()
 {
     $ca = new Criteria();
     $ca->add(SchemaHasUserPeer::SCHEMA_ID, $this->getId());
     $ca->add(SchemaHasUserPeer::IS_MAINTAINER_FOR, true);
     $maintainers = SchemaHasUserPeer::doSelect($ca);
     $maintainerArray = [];
     /** @var SchemaHasUser $maintainer */
     foreach ($maintainers as $maintainer) {
         $maintainerArray[] = $maintainer->getUserId();
     }
     return $maintainerArray;
 }
Example #5
0
     if (!isset($schema)) {
         if ($schema_property) {
             sfPropelParanoidBehavior::disable();
             $schema = $schema_property->getSchema();
         }
     }
     $tab = false;
     break;
 case 'schemauser':
     $showBc = true;
     $showSchemaBc = true;
     $showSchemaUserBc = true;
     if (!isset($schema_has_user)) {
         $id = 'show' == $action ? $sf_params->get('id') : $paramId;
         if ($id) {
             $schema_has_user = SchemaHasUserPeer::retrieveByPK($id);
         }
     }
     $objectId = $schema_has_user->getID();
     if (!isset($schema)) {
         $schema = $schema_has_user->getSchema();
     }
     $tab = false;
     break;
 case 'export':
     $showBc = true;
     $showSchemaBc = true;
     $tab = true;
     $title = __('Export');
     break;
 case 'import':
 /**
  * set Schema object-level credentials
  *
  * @TODO: this should maybe be in the model?
  * @TODO The models should be defined in an array in this class,
  * along with the methods to call for each. Then we can make it more generic,
  * and much easier to add new objects to
  *
  * @return integer count of agents retrieved
  */
 public function setSchemaCredentials()
 {
     $credentials = SchemaHasUserPeer::doSelectForUser($this->getSubscriberId());
     foreach ($credentials as $credential) {
         $schemaId = $credential->getSchemaId();
         //build the  array
         $credArray[$schemaId]['maintainer'] = $credential->getIsMaintainerFor();
         $credArray[$schemaId]['registrar'] = $credential->getIsRegistrarFor();
         $credArray[$schemaId]['admin'] = $credential->getIsAdminFor();
         $credArray[$schemaId]['contact'] = true;
     }
     if (isset($credArray)) {
         $this->addObjectCredentials('schema', $credArray);
     }
     return count($credentials);
 }
    public function setUserId($userId = null)
    {
        if ($userId) {
            $this->userId = $userId;
        } else {
            $criteria = new \Criteria();
            if ('schema' == $this->type) {
                $criteria->add(\SchemaHasUserPeer::SCHEMA_ID, $this->vocabId);
                $criteria->add(\SchemaHasUserPeer::IS_ADMIN_FOR, true);
                $users = \SchemaHasUserPeer::doSelectJoinUser($criteria);
            } else {
                $criteria->add(\VocabularyHasUserPeer::VOCABULARY_ID, $this->vocabId);
                $criteria->add(\VocabularyHasUserPeer::IS_ADMIN_FOR, true);
                $users = \VocabularyHasUserPeer::doSelectJoinUser($criteria);
            }
            if ( ! $users) {
                //TODO: turn this into a real error message and exit gracefully
                exit( "No user ID found!!!!!" );
            }

            /** @var $schemaUser \SchemaHasUser */
            $schemaUser   = $users[0];
            $this->userId = $schemaUser->getUser()->getId();
        }
    }
 /**
  * Populates the object using an array.
  *
  * This is particularly useful when populating an object from one of the
  * request arrays (e.g. $_POST).  This method goes through the column
  * names, checking to see whether a matching key exists in populated
  * array. If so the setByName() method is called for that column.
  *
  * You can specify the key type of the array by additionally passing one
  * of the class type constants TYPE_PHPNAME, TYPE_COLNAME, TYPE_FIELDNAME,
  * TYPE_NUM. The default key type is the column's phpname (e.g. 'authorId')
  *
  * @param      array  $arr     An array to populate the object from.
  * @param      string $keyType The type of keys the array uses.
  * @return     void
  */
 public function fromArray($arr, $keyType = BasePeer::TYPE_PHPNAME)
 {
     $keys = SchemaHasUserPeer::getFieldNames($keyType);
     if (array_key_exists($keys[0], $arr)) {
         $this->setId($arr[$keys[0]]);
     }
     if (array_key_exists($keys[1], $arr)) {
         $this->setCreatedAt($arr[$keys[1]]);
     }
     if (array_key_exists($keys[2], $arr)) {
         $this->setUpdatedAt($arr[$keys[2]]);
     }
     if (array_key_exists($keys[3], $arr)) {
         $this->setDeletedAt($arr[$keys[3]]);
     }
     if (array_key_exists($keys[4], $arr)) {
         $this->setSchemaId($arr[$keys[4]]);
     }
     if (array_key_exists($keys[5], $arr)) {
         $this->setUserId($arr[$keys[5]]);
     }
     if (array_key_exists($keys[6], $arr)) {
         $this->setIsMaintainerFor($arr[$keys[6]]);
     }
     if (array_key_exists($keys[7], $arr)) {
         $this->setIsRegistrarFor($arr[$keys[7]]);
     }
     if (array_key_exists($keys[8], $arr)) {
         $this->setIsAdminFor($arr[$keys[8]]);
     }
     if (array_key_exists($keys[9], $arr)) {
         $this->setLanguages($arr[$keys[9]]);
     }
     if (array_key_exists($keys[10], $arr)) {
         $this->setDefaultLanguage($arr[$keys[10]]);
     }
     if (array_key_exists($keys[11], $arr)) {
         $this->setCurrentLanguage($arr[$keys[11]]);
     }
 }
 /**
  * Retrieve multiple objects by pkey.
  *
  * @param      array $pks List of primary keys
  * @param      Connection $con the connection to use
  * @throws     PropelException Any exceptions caught during processing will be
  *		 rethrown wrapped into a PropelException.
  */
 public static function retrieveByPKs($pks, $con = null)
 {
     if ($con === null) {
         $con = Propel::getConnection(self::DATABASE_NAME);
     }
     $objs = null;
     if (empty($pks)) {
         $objs = array();
     } else {
         $criteria = new Criteria();
         $criteria->add(SchemaHasUserPeer::ID, $pks, Criteria::IN);
         $objs = SchemaHasUserPeer::doSelect($criteria, $con);
     }
     return $objs;
 }
 /**
  * @return SchemaHasUser
  */
 public function getSchemaForUser()
 {
     $schemaId = $this->getSchemaId();
     $userId = sfContext::getInstance()->getUser()->getSubscriberId();
     $c = new Criteria();
     $c->add(SchemaHasUserPeer::SCHEMA_ID, $schemaId);
     $c->add(SchemaHasUserPeer::USER_ID, $userId);
     return SchemaHasUserPeer::doSelectOne($c);
 }
 /**
  * If this collection has already been initialized with
  * an identical criteria, it returns the collection.
  * Otherwise if this Schema is new, it will return
  * an empty collection; or if this Schema has previously
  * been saved, it will retrieve related SchemaHasUsers from storage.
  *
  * This method is protected by default in order to keep the public
  * api reasonable.  You can provide public methods for those you
  * actually need in Schema.
  */
 public function getSchemaHasUsersJoinUser($criteria = null, $con = null)
 {
     // include the Peer class
     include_once 'lib/model/om/BaseSchemaHasUserPeer.php';
     if ($criteria === null) {
         $criteria = new Criteria();
     } elseif ($criteria instanceof Criteria) {
         $criteria = clone $criteria;
     }
     if ($this->collSchemaHasUsers === null) {
         if ($this->isNew()) {
             $this->collSchemaHasUsers = array();
         } else {
             $criteria->add(SchemaHasUserPeer::SCHEMA_ID, $this->getId());
             $this->collSchemaHasUsers = SchemaHasUserPeer::doSelectJoinUser($criteria, $con);
         }
     } else {
         // the following code is to determine if a new query is
         // called for.  If the criteria is the same as the last
         // one, just return the collection.
         $criteria->add(SchemaHasUserPeer::SCHEMA_ID, $this->getId());
         if (!isset($this->lastSchemaHasUserCriteria) || !$this->lastSchemaHasUserCriteria->equals($criteria)) {
             $this->collSchemaHasUsers = SchemaHasUserPeer::doSelectJoinUser($criteria, $con);
         }
     }
     $this->lastSchemaHasUserCriteria = $criteria;
     return $this->collSchemaHasUsers;
 }
Example #12
0
 /**
  * gets a list of users for the selected agent that have not been assigned to the current schema
  *
  * @return array an array for select
  * @param  var_type $var
  */
 public static function getNewUsersForSchema()
 {
     $schema = myActionTools::findCurrentSchema();
     $results = array();
     if ($schema) {
         //get the users for the agent
         $c = new Criteria();
         $c->addJoin(self::ID, AgentHasUserPeer::USER_ID, Criteria::LEFT_JOIN);
         $c->add(AgentHasUserPeer::AGENT_ID, $schema->getAgentId(), Criteria::EQUAL);
         $c->addAscendingOrderByColumn(self::NICKNAME);
         $results = self::doSelect($c);
         //remove the current maintainers of the vocabulary
         $c = new Criteria();
         $c->add(SchemaHasUserPeer::SCHEMA_ID, $schema->getId(), Criteria::EQUAL);
         $schemaUsers = SchemaHasUserPeer::doSelect($c);
         foreach ($schemaUsers as $schemaUser) {
             $curId = $schemaUser->getUserId();
             foreach ($results as $key => $result) {
                 if ($result->getId() == $curId) {
                     unset($results[$key]);
                     break;
                 }
             }
         }
         $results = array_merge($results);
     }
     return $results;
 }