/**
  * @param string $key
  * @param boolean $returnObject
  * @return mixed|null
  */
 public static function get($key, $returnObject = FALSE)
 {
     $cacheKey = $key . '~~~';
     if (array_key_exists($cacheKey, self::$nameIdMappingCache)) {
         $entry = self::getById(self::$nameIdMappingCache[$cacheKey]);
         if ($returnObject) {
             return $entry;
         }
         return $entry instanceof Configuration ? $entry->getData() : NULL;
     }
     $configurationEntry = new self();
     try {
         $configurationEntry->getDao()->getByKey($key);
     } catch (\Exception $e) {
         return NULL;
     }
     if ($configurationEntry->getId() > 0) {
         self::$nameIdMappingCache[$cacheKey] = $configurationEntry->getId();
         $entry = self::getById($configurationEntry->getId());
         if ($returnObject) {
             return $entry;
         }
         return $entry instanceof Configuration ? $entry->getData() : NULL;
     }
 }
 /**
  * Import relevant properties from given exercise
  *
  * @param ilObjExercise $a_test
  * @return object
  */
 public static function createFromExercise(ilObjExercise $a_exercise, $a_user_id)
 {
     global $lng;
     $lng->loadLanguageModule("exercise");
     $newObj = new self();
     $newObj->setTitle($a_exercise->getTitle());
     $newObj->setDescription($a_exercise->getDescription());
     include_once "Services/Tracking/classes/class.ilLPMarks.php";
     $lp_marks = new ilLPMarks($a_exercise->getId(), $a_user_id);
     $newObj->setProperty("issued_on", new ilDate($lp_marks->getStatusChanged(), IL_CAL_DATETIME));
     // create certificate
     include_once "Services/Certificate/classes/class.ilCertificate.php";
     include_once "Modules/Exercise/classes/class.ilExerciseCertificateAdapter.php";
     $certificate = new ilCertificate(new ilExerciseCertificateAdapter($a_exercise));
     $certificate = $certificate->outCertificate(array("user_id" => $a_user_id), false);
     // save pdf file
     if ($certificate) {
         // we need the object id for storing the certificate file
         $newObj->create();
         $path = self::initStorage($newObj->getId(), "certificate");
         $file_name = "exc_" . $a_exercise->getId() . "_" . $a_user_id . ".pdf";
         if (file_put_contents($path . $file_name, $certificate)) {
             $newObj->setProperty("file", $file_name);
             $newObj->update();
             return $newObj;
         }
         // file creation failed, so remove to object, too
         $newObj->delete();
     }
     // remove if certificate works
     $newObj->create();
     return $newObj;
 }
 /**
  * Import relevant properties from given test
  *
  * @param ilObjTest $a_test
  * @return object
  */
 public static function createFromTest(ilObjTest $a_test, $a_user_id)
 {
     global $lng;
     $lng->loadLanguageModule("wsp");
     $newObj = new self();
     $newObj->setTitle($lng->txt("wsp_type_tstv") . " \"" . $a_test->getTitle() . "\"");
     $newObj->setDescription($a_test->getDescription());
     $active_id = $a_test->getActiveIdOfUser($a_user_id);
     $pass = ilObjTest::_getResultPass($active_id);
     $date = $a_test->getPassFinishDate($active_id, $pass);
     $newObj->setProperty("issued_on", new ilDate($date, IL_CAL_UNIX));
     // create certificate
     include_once "Services/Certificate/classes/class.ilCertificate.php";
     include_once "Modules/Test/classes/class.ilTestCertificateAdapter.php";
     $certificate = new ilCertificate(new ilTestCertificateAdapter($a_test));
     $certificate = $certificate->outCertificate(array("active_id" => $active_id, "pass" => $pass), false);
     // save pdf file
     if ($certificate) {
         // we need the object id for storing the certificate file
         $newObj->create();
         $path = self::initStorage($newObj->getId(), "certificate");
         $file_name = "tst_" . $a_test->getId() . "_" . $a_user_id . "_" . $active_id . ".pdf";
         if (file_put_contents($path . $file_name, $certificate)) {
             $newObj->setProperty("file", $file_name);
             $newObj->update();
             return $newObj;
         }
         // file creation failed, so remove to object, too
         $newObj->delete();
     }
 }
Example #4
0
 /**
  * @param Uuid $id
  * @param AddAuthor[] $authors
  * @param string $title
  * @param string $isbn
  * @return Book
  */
 public static function add(Uuid $id, array $authors, $title, $isbn)
 {
     $instance = new self($id);
     $authorsAdded = array_map(function (AddAuthor $author) use($instance) {
         $authorAdded = new AuthorAdded($instance->id, $author->getFirstName(), $author->getLastName());
         $instance->applyAuthorAdded($authorAdded);
         return $authorAdded;
     }, $authors);
     $instance->applyChange(new BookAdded($instance->getId(), $authorsAdded, $title, $isbn));
     return $instance;
 }
Example #5
0
File: Mux.php Project: kpb90/Pux
 /**
  * Mount a Mux or a Controller object on a specific path.
  *
  * @param string         $pattern
  * @param Mux|Controller $mux
  * @param array          $options
  */
 public function mount($pattern, $mux, array $options = array())
 {
     if ($mux instanceof Controller) {
         $mux = $mux->expand();
     } elseif ($mux instanceof Closure) {
         // we pass newly created Mux object to the closure to let it initialize it.
         if ($ret = $mux($mux = new self())) {
             if ($ret instanceof self) {
                 $mux = $ret;
             } else {
                 throw new LogicException('Invalid object returned from Closure.');
             }
         }
     } elseif ((!is_object($mux) || !$mux instanceof self) && is_callable($mux)) {
         $mux($mux = new self());
     }
     $muxId = $mux->getId();
     $this->add($pattern, $muxId, $options);
     $this->submux[$muxId] = $mux;
     /*
     if ($this->expand) {
         $pcre = strpos($pattern,':') !== false;
     
         // rewrite submux routes
         foreach ($mux->routes as $route) {
             // process for pcre
             if ( $route[0] || $pcre ) {
                 $newPattern = $pattern . ( $route[0] ? $route[3]['pattern'] : $route[1] );
                 $routeArgs = PatternCompiler::compile($newPattern, 
                     array_replace_recursive($options, $route[3]) );
                 $this->appendPCRERoute( $routeArgs, $route[2] );
             } else {
                 $this->routes[] = array(
                     false,
                     $pattern . $route[1],
                     $route[2],
                     isset($route[3]) ? array_replace_recursive($options, $route[3]) : $options,
                 );
             }
         }
     */
 }
Example #6
0
 public static function checkPassword($user, $login, $password)
 {
     if (is_null($user)) {
         $user = new self();
         $user->profile_id = $login;
     }
     $ldap = new MyLdap($login, $password);
     if ($ldap->isUser()) {
         $userData = $ldap->searchUser();
         $user->fullname = $userData['name_ru'];
         $user->email = $userData['email'];
         $new = $user->isNewRecord;
         if ($user->save()) {
             if ($new) {
                 $auth = Yii::$app->authManager;
                 $auth->assign($auth->getRole('guest'), $user->getId());
             }
             return true;
         }
     }
     return false;
 }
Example #7
0
 /**
  * retrieve metafolder instance by either primary key of db entry
  * or path - both relative and absolute paths are allowed
  *
  * @return MetaFolder
  */
 public static function getInstance($path = NULL, $id = NULL)
 {
     if (isset($path)) {
         $path = rtrim($path, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR;
         $lookup = Application::getInstance()->extendToAbsoluteAssetsPath($path);
         if (!isset(self::$instancesByPath[$lookup])) {
             $mf = new self($path);
             self::$instancesByPath[$mf->getFullPath()] = $mf;
             self::$instancesById[$mf->getId()] = $mf;
         }
         return self::$instancesByPath[$lookup];
     } else {
         if (isset($id)) {
             if (!isset(self::$instancesById[$id])) {
                 $mf = new self(NULL, $id);
                 self::$instancesById[$id] = $mf;
                 self::$instancesByPath[$mf->getFullPath()] = $mf;
             }
             return self::$instancesById[$id];
         } else {
             throw new MetaFolderException("Either folder id or path required.", MetaFolderException::ID_OR_PATH_REQUIRED);
         }
     }
 }
 /**
  * Import relevant properties from given learning module
  *
  * @param ilObjSAHSLearningModule $a_lm
  * @return object
  */
 public static function createFromSCORMLM(ilObjSAHSLearningModule $a_lm, $a_user_id)
 {
     global $lng;
     $lng->loadLanguageModule("sahs");
     $newObj = new self();
     $newObj->setTitle($a_lm->getTitle());
     $newObj->setDescription($a_lm->getDescription());
     include_once "Services/Tracking/classes/class.ilLPMarks.php";
     $lp_marks = new ilLPMarks($a_lm->getId(), $a_user_id);
     $newObj->setProperty("issued_on", new ilDate($lp_marks->getStatusChanged(), IL_CAL_DATETIME));
     // create certificate
     if (!stristr(get_class($a_lm), "2004")) {
         $last_access = ilObjSCORMLearningModule::_lookupLastAccess($a_lm->getId(), $a_user_id);
     } else {
         $last_access = ilObjSCORM2004LearningModule::_lookupLastAccess($a_lm->getId(), $a_user_id);
     }
     $params = array("user_data" => ilObjUser::_lookupFields($a_user_id), "last_access" => $last_access);
     include_once "Services/Certificate/classes/class.ilCertificate.php";
     include_once "Modules/ScormAicc/classes/class.ilSCORMCertificateAdapter.php";
     $certificate = new ilCertificate(new ilSCORMCertificateAdapter($a_lm));
     $certificate = $certificate->outCertificate($params, false);
     // save pdf file
     if ($certificate) {
         // we need the object id for storing the certificate file
         $newObj->create();
         $path = self::initStorage($newObj->getId(), "certificate");
         $file_name = "sahs_" . $a_lm->getId() . "_" . $a_user_id . ".pdf";
         if (file_put_contents($path . $file_name, $certificate)) {
             $newObj->setProperty("file", $file_name);
             $newObj->update();
             return $newObj;
         }
         // file creation failed, so remove to object, too
         $newObj->delete();
     }
 }
 /**
  * Delete all delivered files of user
  *
  * @param int $a_exc_id excercise id
  * @param int $a_user_id user id
  */
 static function deleteAllDeliveredFilesOfUser($a_exc_id, $a_user_id)
 {
     global $ilDB;
     include_once "./Modules/Exercise/classes/class.ilFSStorageExercise.php";
     $delete_ids = array();
     // get the files and...
     $set = $ilDB->query("SELECT * FROM exc_returned " . " WHERE obj_id = " . $ilDB->quote($a_exc_id, "integer") . " AND user_id = " . $ilDB->quote($a_user_id, "integer"));
     while ($rec = $ilDB->fetchAssoc($set)) {
         $ass = new self($rec["ass_id"]);
         if ($ass->getType() == self::TYPE_UPLOAD_TEAM) {
             // switch upload to other team member
             $team = self::getTeamMembersByAssignmentId($ass->getId(), $a_user_id);
             if (sizeof($team) > 1) {
                 $new_owner = array_pop($team);
                 while ($new_owner == $a_user_id && sizeof($team)) {
                     $new_owner = array_pop($team);
                 }
                 $ilDB->manipulate("UPDATE exc_returned" . " SET user_id = " . $ilDB->quote($new_owner, "integer") . " WHERE returned_id = " . $ilDB->quote($rec["returned_id"], "integer"));
                 // no need to delete
                 continue;
             }
         }
         $delete_ids[] = $rec["returned_id"];
         $fs = new ilFSStorageExercise($a_exc_id, $rec["ass_id"]);
         // ...delete files
         $filename = $fs->getAbsoluteSubmissionPath() . "/" . $a_user_id . "/" . basename($rec["filename"]);
         if (is_file($filename)) {
             unlink($filename);
         }
     }
     // delete exc_returned records
     if ($delete_ids) {
         $ilDB->manipulate("DELETE FROM exc_returned" . " WHERE " . $ilDB->in("returned_id", $delete_ids, "", "integer"));
     }
     // delete il_exc_team records
     $ass_ids = array();
     foreach (self::getAssignmentDataOfExercise($a_exc_id) as $item) {
         $ass_ids[] = $item["id"];
     }
     if ($ass_ids) {
         $ilDB->manipulate($d = "DELETE FROM il_exc_team WHERE " . "user_id = " . $ilDB->quote($a_user_id, "integer") . " AND " . $ilDB->in("ass_id", $ass_ids, "", "integer"));
     }
 }
Example #10
0
 public static function start($size)
 {
     $self = new self();
     return "<div class=\"col-md-{$size}\" id=\"{$self->getId()}\">";
 }
Example #11
0
 /**
  * @param string $name
  * @return self
  */
 public static function getByName($name)
 {
     $class = new self();
     try {
         $class->getDao()->getByName($name);
     } catch (\Exception $e) {
         \Logger::error($e);
         return null;
     }
     // to have a singleton in a way. like all instances of Element\ElementInterface do also, like Object\AbstractObject
     if ($class->getId() > 0) {
         return self::getById($class->getId());
     }
 }
 public function doClone($a_pool_id, $a_schedule_map = null)
 {
     $new_obj = new self();
     $new_obj->setPoolId($a_pool_id);
     $new_obj->setTitle($this->getTitle());
     $new_obj->setDescription($this->getDescription());
     $new_obj->setNrOfItems($this->getNrOfItems());
     $new_obj->setFile($this->getFile());
     $new_obj->setPostText($this->getPostText());
     $new_obj->setPostFile($this->getPostFile());
     if ($a_schedule_map) {
         $schedule_id = $this->getScheduleId();
         if ($schedule_id) {
             $new_obj->setScheduleId($a_schedule_map[$schedule_id]);
         }
     }
     $new_obj->save();
     // files
     $source = $this->initStorage($this->getId());
     $target = $new_obj->initStorage($new_obj->getId());
     ilUtil::rCopy($source, $target);
 }
Example #13
0
 /**
  * @param string $path
  * @return Object_Abstract
  */
 public static function getByPath($path)
 {
     $path = Element_Service::correctPath($path);
     try {
         $object = new self();
         if (Pimcore_Tool::isValidPath($path)) {
             $object->getResource()->getByPath($path);
             return self::getById($object->getId());
         }
     } catch (Exception $e) {
         Logger::warning($e);
     }
     return null;
 }
Example #14
0
 public static function updateAgent()
 {
     $engine = new self();
     if ($engine->getAuthSettings()) {
         try {
             $dbRes = YandexCampaignTable::getList(array('filter' => array('<LAST_UPDATE' => DateTime::createFromTimestamp(time() - YandexCampaignTable::CACHE_LIFETIME), '=ENGINE_ID' => $engine->getId()), 'select' => array('CNT'), 'runtime' => array(new ExpressionField('CNT', 'COUNT(*)'))));
             $res = $dbRes->fetch();
             if ($res['CNT'] > 0) {
                 $engine->updateCampaignManual();
             }
             $availableCampaigns = array();
             $campaignList = $engine->getCampaignList();
             foreach ($campaignList as $campaignInfo) {
                 $availableCampaigns[] = $campaignInfo['CampaignID'];
             }
             if (count($availableCampaigns) > 0) {
                 $dbRes = YandexBannerTable::getList(array('group' => array('CAMPAIGN_ID'), 'filter' => array('<LAST_UPDATE' => DateTime::createFromTimestamp(time() - YandexBannerTable::CACHE_LIFETIME), '=ENGINE_ID' => $engine->getId(), '=CAMPAIGN.XML_ID' => $availableCampaigns), 'select' => array('CAMPAIGN_ID')));
                 $campaignId = array();
                 while ($res = $dbRes->fetch()) {
                     $campaignId[] = $res['CAMPAIGN_ID'];
                 }
                 if (count($campaignId) > 0) {
                     $engine->updateBannersManual($campaignId);
                 }
             }
         } catch (YandexDirectException $e) {
         }
     }
     return __CLASS__ . "::updateAgent();";
 }
Example #15
0
 /**
  * Return id of connection context for connection.
  *
  * @param ConnectionInterface $conn
  *
  * @return string
  */
 public static function getIdFromConnection(ConnectionInterface $conn)
 {
     $context = new self($conn);
     return $context->getId();
 }
Example #16
0
 /**
  * @param string $path
  * @return Object_Abstract
  */
 public static function getByPath($path)
 {
     // remove trailing slash
     if ($path != "/") {
         $path = rtrim($path, "/ ");
     }
     // correct wrong path (root-node problem)
     $path = str_replace("//", "/", $path);
     try {
         $object = new self();
         if (Pimcore_Tool::isValidPath($path)) {
             $object->getResource()->getByPath($path);
             return self::getById($object->getId());
         }
     } catch (Exception $e) {
         Logger::warning($e);
     }
     return null;
 }
Example #17
0
 /**
  * @param string $name
  * @return Staticroute
  */
 public static function getByName($name, $siteId = null)
 {
     $cacheKey = $name . "~~~" . $siteId;
     // check if pimcore already knows the id for this $name, if yes just return it
     if (array_key_exists($cacheKey, self::$nameIdMappingCache)) {
         return self::getById(self::$nameIdMappingCache[$cacheKey]);
     }
     // create a tmp object to obtain the id
     $route = new self();
     try {
         $route->getDao()->getByName($name, $siteId);
     } catch (\Exception $e) {
         \Logger::warn($e);
         return null;
     }
     // to have a singleton in a way. like all instances of Element\ElementInterface do also, like Object\AbstractObject
     if ($route->getId() > 0) {
         // add it to the mini-per request cache
         self::$nameIdMappingCache[$cacheKey] = $route->getId();
         return self::getById($route->getId());
     }
 }
Example #18
0
 /**
  * Helper to quickly create a new asset
  *
  * @param integer $parentId
  * @param array $data
  * @return Asset
  */
 public static function create($parentId, $data = array())
 {
     $asset = new self();
     $asset->setParentId($parentId);
     foreach ($data as $key => $value) {
         $asset->setValue($key, $value);
     }
     $asset->save();
     // get concrete type of asset
     Zend_Registry::set("asset_" . $asset->getId(), null);
     $asset = self::getById($asset->getId());
     Zend_Registry::set("asset_" . $asset->getId(), $asset);
     return $asset;
 }
Example #19
0
 /**
  * Mount a Mux or a Controller object on a specific path.
  *
  * @param string         $pattern
  * @param Mux|Controller $mux
  * @param array          $options
  */
 public function mount($pattern, $mux, array $options = array())
 {
     // Save the mount path in options array
     $options['mount_path'] = $pattern;
     if ($mux instanceof Expandable) {
         $mux = $mux->expand($options);
     } else {
         if ($mux instanceof Closure) {
             // we pass the newly created Mux object to the builder closure to initialize routes.
             if ($ret = $mux($mux = new Mux())) {
                 if ($ret instanceof Mux) {
                     $mux = $ret;
                 } else {
                     throw new LogicException('Invalid object returned from Closure.');
                 }
             }
         } elseif ((!is_object($mux) || !$mux instanceof self) && is_callable($mux)) {
             $mux($mux = new self());
         }
     }
     // Save the constructed mux object in options array, so we can fetch
     // the expanded mux object in controller object later.
     $mux->setParent($this);
     $options['mux'] = $mux;
     if ($this->expand) {
         $pcre = strpos($pattern, ':') !== false;
         // rewrite submux routes
         foreach ($mux->routes as $route) {
             // process for pcre
             if ($route[0] || $pcre) {
                 $newPattern = $pattern . ($route[0] ? $route[3]['pattern'] : $route[1]);
                 $routeArgs = PatternCompiler::compile($newPattern, array_replace_recursive($options, $route[3]));
                 $this->appendPCRERoute($routeArgs, $route[2]);
             } else {
                 $this->routes[] = array(false, $pattern . $route[1], $route[2], isset($route[3]) ? array_replace_recursive($options, $route[3]) : $options);
             }
         }
     } else {
         $muxId = $mux->getId();
         $this->add($pattern, $muxId, $options);
         $this->submux[$muxId] = $mux;
     }
 }
Example #20
0
 public static function fromSlack(SlackUser $user)
 {
     $user = new self($user->getId(), $user->getName());
     return $user;
 }
Example #21
0
 public function startEdit()
 {
     if ($this->getRole() != "view") {
         throw new Exception("only worksheets with role 'view' can be edited!");
     }
     $currentUser = $GLOBALS["STEAM"]->get_current_steam_user();
     $userWorkroom = $currentUser->get_workroom();
     $newObj = \steam_factory::create_copy($GLOBALS["STEAM"]->get_id(), $this->steamObj);
     $newObj->move($userWorkroom);
     $newWorksheet = new self($newObj->get_id());
     $newWorksheet->setRole("edit");
     $name = $newWorksheet->getName();
     $name = preg_replace('!(\\ )*\\(Vorlage\\)!isU', '', $name);
     $name = preg_replace('!(\\ )*\\(Verteilkopie\\)!isU', '', $name);
     $name = $name . " (Arbeitskopie)";
     $newWorksheet->setName($name);
     $this->addEditCopy($currentUser->get_id(), $newWorksheet->getId());
     return $newWorksheet;
 }
Example #22
0
 public static function createAndAddToRepository($article, $description, $publish = true)
 {
     $product = new self($article, $description, $publish);
     $id = $product->getId();
     self::$repository[$id] = $product;
 }
Example #23
0
 /**
  * @param string $path
  * @return self
  */
 public static function getByPath($path)
 {
     $path = Model\Element\Service::correctPath($path);
     try {
         $object = new self();
         if (Tool::isValidPath($path)) {
             $object->getResource()->getByPath($path);
             return self::getById($object->getId());
         }
     } catch (\Exception $e) {
         \Logger::warning($e->getMessage());
     }
     return null;
 }
 public static function syncEwattch($_ip)
 {
     $request_http = new com_http($_ip . '/log.json?mode=10');
     $result = json_decode($request_http->exec(1, 1), true);
     foreach ($result['resource']['electricity'] as $resource) {
         $eqLogic = self::byLogicalId('electricity_' . $resource['name'], 'ewattch');
         if (!is_object($eqLogic)) {
             $eqLogic = new self();
             $eqLogic->setName('electricity_' . $resource['name']);
             $eqLogic->setEqType_name('ewattch');
             $eqLogic->setIsVisible(1);
             $eqLogic->setIsEnable(1);
             $eqLogic->setLogicalId('electricity_' . $resource['name']);
             $eqLogic->setConfiguration('ip', $_ip);
             $eqLogic->setCategory('energy', 1);
             $eqLogic->save();
         }
         $index = $eqLogic->getCmd(null, 'index');
         if (!is_object($index)) {
             $index = new ewattchCmd();
             $index->setLogicalId('index');
             $index->setIsVisible(1);
             $index->setName(__('Index', __FILE__));
         }
         $index->setUnite('wh');
         $index->setType('info');
         $index->setSubType('numeric');
         $index->setEventOnly(1);
         $index->setEqLogic_id($eqLogic->getId());
         $index->save();
         $cost = $eqLogic->getCmd(null, 'cost');
         if (!is_object($cost)) {
             $cost = new ewattchCmd();
             $cost->setLogicalId('cost');
             $cost->setIsVisible(1);
             $cost->setName(__('Coût', __FILE__));
         }
         $cost->setUnite('€');
         $cost->setType('info');
         $cost->setSubType('numeric');
         $cost->setEventOnly(1);
         $cost->setEqLogic_id($eqLogic->getId());
         $cost->save();
     }
     foreach ($result['resource']['water'] as $resource) {
         $eqLogic = self::byLogicalId('water_' . $resource['name'], 'ewattch');
         if (!is_object($eqLogic)) {
             $eqLogic = new self();
             $eqLogic->setName('water_' . $resource['name']);
             $eqLogic->setEqType_name('ewattch');
             $eqLogic->setIsVisible(1);
             $eqLogic->setIsEnable(1);
             $eqLogic->setLogicalId('water_' . $resource['name']);
             $eqLogic->setConfiguration('ip', $_ip);
             $eqLogic->setCategory('energy', 1);
             $eqLogic->save();
         }
         $index = $eqLogic->getCmd(null, 'index');
         if (!is_object($index)) {
             $index = new ewattchCmd();
             $index->setLogicalId('index');
             $index->setIsVisible(1);
             $index->setName(__('Index', __FILE__));
         }
         $index->setUnite('L');
         $index->setType('info');
         $index->setSubType('numeric');
         $index->setEventOnly(1);
         $index->setEqLogic_id($eqLogic->getId());
         $index->save();
         $cost = $eqLogic->getCmd(null, 'cost');
         if (!is_object($cost)) {
             $cost = new ewattchCmd();
             $cost->setLogicalId('cost');
             $cost->setIsVisible(1);
             $cost->setName(__('Coût', __FILE__));
         }
         $cost->setUnite('€');
         $cost->setType('info');
         $cost->setSubType('numeric');
         $cost->setEventOnly(1);
         $cost->setEqLogic_id($eqLogic->getId());
         $cost->save();
     }
     foreach ($result['resource']['heating'] as $resource) {
         $eqLogic = self::byLogicalId('heating_' . $resource['name'], 'ewattch');
         if (!is_object($eqLogic)) {
             $eqLogic = new self();
             $eqLogic->setName('heating_' . $resource['name']);
             $eqLogic->setEqType_name('ewattch');
             $eqLogic->setIsVisible(1);
             $eqLogic->setIsEnable(1);
             $eqLogic->setLogicalId('heating_' . $resource['name']);
             $eqLogic->setConfiguration('ip', $_ip);
             $eqLogic->setCategory('heating', 1);
             $eqLogic->save();
         }
         $index = $eqLogic->getCmd(null, 'index');
         if (!is_object($index)) {
             $index = new ewattchCmd();
             $index->setLogicalId('index');
             $index->setIsVisible(1);
             $index->setName(__('Index', __FILE__));
         }
         $index->setUnite('wh');
         $index->setType('info');
         $index->setSubType('numeric');
         $index->setEventOnly(1);
         $index->setEqLogic_id($eqLogic->getId());
         $index->save();
     }
     foreach ($result['resource']['environment'] as $resource) {
         $eqLogic = self::byLogicalId('environment_' . $resource['name'], 'ewattch');
         if (!is_object($eqLogic)) {
             $eqLogic = new self();
             $eqLogic->setName('environment_' . $resource['name']);
             $eqLogic->setEqType_name('ewattch');
             $eqLogic->setIsVisible(1);
             $eqLogic->setIsEnable(1);
             $eqLogic->setLogicalId('environment_' . $resource['name']);
             $eqLogic->setConfiguration('ip', $_ip);
             $eqLogic->save();
         }
         $value = $eqLogic->getCmd(null, 'value');
         if (!is_object($value)) {
             $value = new ewattchCmd();
             $value->setLogicalId('value');
             $value->setIsVisible(1);
             $value->setName(__('Valeur', __FILE__));
         }
         $value->setUnite($resource['units']);
         $value->setType('info');
         $value->setSubType('numeric');
         $value->setEventOnly(1);
         $value->setEqLogic_id($eqLogic->getId());
         $value->save();
     }
 }
Example #25
0
    /**
     * return MetaFiles identified by paths
     *
     * @param array $paths
     *
     * @return array
     */
    public static function getInstancesByPaths(array $paths)
    {
        $toRetrieveByPath = array();
        $lookupPaths = array();
        // collect paths, that must be read from db
        $lookupPaths = array();
        foreach ($paths as $path) {
            $lookup = Application::getInstance()->extendToAbsoluteAssetsPath($path);
            $lookupPaths[] = $lookup;
            if (!isset(self::$instancesByPath[$lookup])) {
                $pathinfo = pathinfo($lookup);
                $toRetrieveByPath[] = $pathinfo['basename'];
                $toRetrieveByPath[] = $pathinfo['dirname'] . DIRECTORY_SEPARATOR;
                $toRetrieveByPath[] = str_replace(Application::getInstance()->getAbsoluteAssetsPath(), '', $pathinfo['dirname']) . DIRECTORY_SEPARATOR;
            }
        }
        // build and execute query, if necessary
        if (count($toRetrieveByPath)) {
            $where = array_fill(0, count($toRetrieveByPath) / 3, 'f.File = ? AND fo.Path IN (?, ?)');
            $rows = Application::getInstance()->getDb()->doPreparedQuery('
				SELECT
					f.*,
					CONCAT(fo.Path, IFNULL(f.Obscured_Filename, f.File)) as FullPath
				FROM
					files f
					INNER JOIN folders fo ON fo.foldersID = f.foldersID
				WHERE
					' . implode(' OR ', $where), $toRetrieveByPath);
            foreach ($rows as $row) {
                $mf = new self(NULL, NULL, $row);
                self::$instancesById[$mf->getId()] = $mf;
                self::$instancesByPath[$mf->filesystemFile->getPath()] = $mf;
            }
        }
        // return instances
        $metafiles = array();
        foreach ($lookupPaths as $path) {
            $metafiles[] = self::$instancesByPath[$path];
        }
        return $metafiles;
    }
Example #26
0
 /**
  * Adds the user to the database. 
  * There are bunch of required parameters required to be passed as $params array:
  * - login: the arbitrary string which will be used as a login for the user. The checks defined in
  * {@link setLogin} method will be performed.
  * - password: user's password. The checks defined in {@link setPassword} will be performed.
  * - email: required parameter to, for example, send confirmation emails. The checks defined in 
  * {@link setEmail} method will be performed.
  *
  * Optionally, the 'state' parameter may be passed, showing the status of newly created user. 
  * If it's omitted, the "not_confirmed" or "active" state will be chosen depending on the 
  * <code>config.user.registration_confirm</code> config parameter. If the value distinguish 
  * from the described ones, make sure that this value could be held by the DB schema of the 'state' column.
  *
  * If <code>config.user.registration_confirm</code> config parameter is set to non-false value, 
  * the one time token will be added for newly created user. This could be used for example to
  * send activation email. Logic behind that should be created separately in the model/controller.
  *
  * Additionally, the profile entry for the new user will be created.
  *
  * Behavior BeforeAddNewUser is defined.
  *
  * @param array parameters for the new user as described above
  * @return User new user object
  * @throws UserException in case of errors
  */
 static function add(array $params)
 {
     if (empty($params['login']) || empty($params['password']) || empty($params['email'])) {
         throw new UserException("Login, password and email must be passed");
     }
     $config = Config::getInstance();
     if (empty($params['state'])) {
         $params['state'] = $config->user->registration_confirm ? "not_confirmed" : "active";
     }
     if (self::findBy('login', $params['login'])) {
         throw new UserException("User with the same login already exists");
     }
     $new_user = new self(null);
     $new_user->setLogin($params['login']);
     $new_user->setPassword($params['password']);
     $new_user->setState($params['state']);
     $new_user->setEmail($params['email']);
     $new_user->trigger("BeforeAddNewUser", array($new_user, &$params));
     $new_user->save();
     $one_time_token = null;
     if ($config->user->registration_confirm) {
         $one_time_token = OneTimeTokenAuth::generateAndAddToken($new_user->getId());
     }
     Profile::addUser($new_user->getId());
     return $new_user;
 }
Example #27
0
 public static function createInstance($ou_title, $ou_subtitle, $ou_import_id)
 {
     $unit = new self();
     $unit->setTitle($ou_title)->setSubTitle($ou_subtitle)->setImportId($ou_import_id)->create();
     self::$instance_cache[$unit->getId()] = $unit;
     return $unit;
 }
Example #28
0
 /**
  * @param string $name
  * @return Staticroute
  */
 public static function getByName($name)
 {
     // check if pimcore already knows the id for this $name, if yes just return it
     if (array_key_exists($name, self::$nameIdMappingCache)) {
         return self::getById(self::$nameIdMappingCache[$name]);
     }
     // create a tmp object to obtain the id
     $route = new self();
     try {
         $route->getResource()->getByName($name);
     } catch (Exception $e) {
         Logger::error($e);
         return null;
     }
     // to have a singleton in a way. like all instances of Element_Interface do also, like Object_Abstract
     if ($route->getId() > 0) {
         // add it to the mini-per request cache
         self::$nameIdMappingCache[$name] = $route->getId();
         return self::getById($route->getId());
     }
 }