コード例 #1
0
 /**
  * Attempts to extract the required id from a resource, throwing an exception if id
  * is null.
  * @param \Resource $resource
  * @return integer
  * @throws \Exception
  */
 private static function pullId(\Resource $resource)
 {
     $id = $resource->getId();
     if (empty($id)) {
         throw new \Exception(t('Id not set in Resource "%s"', get_class($resource)));
     }
     return $id;
 }
コード例 #2
0
ファイル: Serializer.php プロジェクト: linkorb/primate
 public function serializeResource(Resource $resource)
 {
     $data['id'] = $resource->getId();
     $data['_type'] = $resource->getType()->getName();
     $data['href'] = $this->primate->getBaseUrl() . '/' . $resource->getType()->getName() . '/' . $resource->getId();
     foreach ($resource->getProperties() as $name => $value) {
         switch (gettype($value)) {
             case 'array':
                 $data[$name] = '[]';
                 break;
             case 'object':
                 if (is_subclass_of($value, '\\Primate\\ResourceInterface')) {
                     $data[$name] = $this->serializeResource($value);
                 } else {
                     $data[$name] = '???';
                 }
                 break;
             default:
                 $data[$name] = $value;
                 break;
         }
     }
     return $data;
 }
コード例 #3
0
ファイル: Activity.php プロジェクト: HaldunA/phpwebsite
 /**
  * Stamps the current datestamp and ip_address.
  */
 public static function stampResource(\Resource $resource, $action)
 {
     $activity = new Activity();
     $activity->class_name = $resource->getNamespace();
     $activity->resource_id = $resource->getId();
     $activity->action = $action;
     if (\User\Current::isLoggedIn()) {
         $activity->user_id = \User\Current::getUserId();
     }
     try {
         $activity->ip_address = \Server::getUserIp();
     } catch (Exception $e) {
         $activity->ip_address = '0.0.0.0';
         \Error::log($e);
     }
     \ResourceFactory::saveResource($activity);
 }
コード例 #4
0
 public function getId()
 {
     return parent::getId();
 }
コード例 #5
0
 /**
  * Adds an object to the instance pool.
  *
  * Propel keeps cached copies of objects in an instance pool when they are retrieved
  * from the database.  In some cases -- especially when you override doSelect*()
  * methods in your stub classes -- you may need to explicitly add objects
  * to the cache in order to ensure that the same objects are always returned by doSelect*()
  * and retrieveByPK*() calls.
  *
  * @param      Resource $value A Resource object.
  * @param      string $key (optional) key to use for instance map (for performance boost if key was already calculated externally).
  */
 public static function addInstanceToPool(Resource $obj, $key = null)
 {
     if (Propel::isInstancePoolingEnabled()) {
         if ($key === null) {
             $key = (string) $obj->getId();
         }
         // if key === null
         self::$instances[$key] = $obj;
     }
 }
コード例 #6
0
 /**
  * Exclude object from result
  *
  * @param     Resource $resource Object to remove from the list of results
  *
  * @return    ResourceQuery The current query, for fluid interface
  */
 public function prune($resource = null)
 {
     if ($resource) {
         $this->addUsingAlias(ResourcePeer::ID, $resource->getId(), Criteria::NOT_EQUAL);
     }
     return $this;
 }
コード例 #7
0
ファイル: initStaticData.php プロジェクト: LordMatrix/Ochorri
    $productionMod = new ProductionMod($productionModArr[0], $productionModArr[1], $productionModArr[2], $productionModArr[3], $productionModArr[4], $productionModArr[5], $productionModArr[6]);
    $productionMods[$productionMod->getId()] = $productionMod;
    if ($productionMod->getTargetClassId() == 'Building') {
        $productionModLinks[$productionMod->getTargetId()][] = $productionMod;
    }
}
$buildingsArr = $buildingConn->getAllBuildings();
foreach ($buildingsArr as $buildingArr) {
    $buildingName = $terms[$buildingArr[1]]->getString();
    $buildingDescription = $terms[$buildingArr[13]]->getString();
    $building = new Building($buildingArr[0], $buildingName, $buildingArr[2], $buildingArr[3], $buildingArr[4], $buildingArr[5], $buildingArr[6], explode(",", $buildingArr[7]), explode(",", $buildingArr[8]), explode(",", $buildingArr[9]), explode(",", $buildingArr[10]), $buildingArr[11], $buildingArr[12], $buildingDescription, $buildingArr[14], $buildingArr[15]);
    if (isset($productionModLinks[$building->getId()])) {
        $building->setProductionMods($productionModLinks[$building->getId()]);
    }
    $buildings[$building->getId()] = $building;
}
$staticData->setBuildings($buildings);
$playersArr = $playerConn->getAllPlayers();
foreach ($playersArr as $playerArr) {
    $player = new Player($playerArr[0], $playerArr[1], $playerArr[2], $playerArr[3], $playerArr[4], $playerArr[5], $playerArr[6], $playerArr[7], explode(",", $playerArr[8]), $playerArr[9], $playerArr[10]);
    $players[$player->getId()] = $player;
}
$staticData->setPlayers($players);
$resourcesArr = $resourceConn->getAllResources();
foreach ($resourcesArr as $resourceArr) {
    $resourceName = $terms[$resourceArr[1]]->getString();
    $resource = new Resource($resourceArr[0], $resourceName, $resourceArr[2], $resourceArr[3], $resourceArr[4], $resourceArr[5]);
    $resources[$resource->getId()] = $resource;
}
$staticData->setResources($resources);
$_SESSION['staticData'] = $staticData;