Example #1
0
 /**
  * @param string $pathName
  * @param string $mode [r,w]
  * @return static
  */
 public static function create($pathName, $mode = self::MODE_READ)
 {
     $yaml = new self($pathName);
     if ($mode == self::MODE_READ) {
         $yaml->load();
     } elseif ($mode == self::MODE_WRITE) {
         try {
             touch($pathName);
         } catch (\ErrorException $e) {
             throw new ApplicationException("Error creating file '{$pathName}'");
         }
         $yaml->load();
     }
     return $yaml;
 }
Example #2
0
	/**
	 * @param bool $updateNulls
	 * @return bool
	 */
	public function store( $updateNulls = false )
	{
		global $_PLUGINS;

		$new	=	( $this->get( 'id' ) ? false : true );
		$old	=	new self();

		$this->set( 'type', preg_replace( '/[^-a-zA-Z0-9_.]/', '', $this->get( 'type' ) ) );

		if ( ! $new ) {
			$old->load( (int) $this->get( 'id' ) );

			$_PLUGINS->trigger( 'activity_onBeforeUpdateHidden', array( &$this, $old ) );
		} else {
			$_PLUGINS->trigger( 'activity_onBeforeCreateHidden', array( &$this ) );
		}

		if ( ! parent::store( $updateNulls ) ) {
			return false;
		}

		if ( ! $new ) {
			$_PLUGINS->trigger( 'activity_onAfterUpdateHidden', array( $this, $old ) );
		} else {
			$_PLUGINS->trigger( 'activity_onAfterCreateHidden', array( $this ) );
		}

		return true;
	}
 /**
  * crypt password
  * Defines whether to use bcrypt or salted MD5
  * @param $val
  * @return string
  */
 public function set_password($val)
 {
     $f3 = \Base::instance();
     if (!$val) {
         $userDetails = new self();
         $userDetails->load(array('username = ?', $f3->get('POST.username')));
         $val = $userDetails->password;
         return $val;
     } else {
         $hash_engine = $f3->get('password_hash_engine');
         switch ($hash_engine) {
             case 'bcrypt':
                 $crypt = \Bcrypt::instance();
                 $val = $crypt->hash($val);
                 break;
             case 'md5':
                 // fall-through
             // fall-through
             default:
                 $val = md5($val . $f3->get('password_md5_salt'));
                 break;
         }
         return $val;
     }
 }
 public static function isBlocked()
 {
     $ip_block_model = new self();
     $ip_block_model->setCond('ip = "' . $_SERVER['REMOTE_ADDR'] . '"');
     $ip_block = $ip_block_model->load();
     return !empty($ip_block);
 }
	/**
	 * @param bool $updateNulls
	 * @return bool
	 */
	public function store( $updateNulls = false )
	{
		global $_PLUGINS;

		$new	=	( $this->get( 'id' ) ? false : true );
		$old	=	new self();

		if ( ! $new ) {
			$old->load( (int) $this->get( 'id' ) );

			$_PLUGINS->trigger( 'gj_onBeforeUpdateNotification', array( &$this, $old ) );
		} else {
			$_PLUGINS->trigger( 'gj_onBeforeCreateNotification', array( &$this ) );
		}

		if ( ! parent::store( $updateNulls ) ) {
			return false;
		}

		if ( ! $new ) {
			$_PLUGINS->trigger( 'gj_onAfterUpdateNotification', array( $this, $old ) );
		} else {
			$_PLUGINS->trigger( 'gj_onAfterCreateNotification', array( $this ) );
		}

		return true;
	}
	/**
	 * @param bool $updateNulls
	 * @return bool
	 */
	public function store( $updateNulls = false )
	{
		global $_PLUGINS;

		$new	=	( $this->get( 'id' ) ? false : true );
		$old	=	new self();

		$this->set( 'date', $this->get( 'date', Application::Database()->getUtcDateTime() ) );

		if ( ! $new ) {
			$old->load( (int) $this->get( 'id' ) );

			$_PLUGINS->trigger( 'gj_onBeforeUpdateAttendance', array( &$this, $old ) );
		} else {
			$_PLUGINS->trigger( 'gj_onBeforeCreateAttendance', array( &$this ) );
		}

		if ( ! parent::store( $updateNulls ) ) {
			return false;
		}

		if ( ! $new ) {
			$_PLUGINS->trigger( 'gj_onAfterUpdateAttendance', array( $this, $old ) );
		} else {
			$_PLUGINS->trigger( 'gj_onAfterCreateAttendance', array( $this ) );
		}

		return true;
	}
Example #7
0
 public static function collectDay($date)
 {
     $instance = new self();
     $instance->load($date, 'date');
     $instance->setDate($date);
     $carts = Mage::getModel('adjcartalert/quotestat')->getCollection();
     $carts->getSelect()->where('`cart_abandon_date` BETWEEN \'' . $instance->getDate() . '\' AND \'' . $instance->getDate() . '\' + INTERVAL 1 DAY');
     $abandonedItemsNum = 0;
     $abandonedCartsPrice = 0;
     $recoveredCarts = 0;
     $orderedItemsNum = 0;
     $orderedCartsPrice = 0;
     $orderedCarts = 0;
     $letterStep = 0;
     //$orderTime = 0;
     $moduleCouponsUsed = 0;
     foreach ($carts as $cart) {
         $abandonedCartsPrice += $cart->getCartPrice();
         $items = unserialize($cart->getCartItems());
         foreach ($items as $item) {
             $abandonedItemsNum += $item;
         }
         if ($cart->getRecoveryDate()) {
             $recoveredCarts++;
         }
         if ($cart->getOrderDate()) {
             $orderedCarts++;
             $orderedCartsPrice += $cart->getOrderPrice();
             $items = unserialize($cart->getOrderItems());
             foreach ($items as $item) {
                 $orderedItemsNum += $item;
             }
             $letterStep += $cart->getAlertNumber();
         }
         if ($cart->getAlertCouponGenerated() != '' && $cart->getAlertCouponGenerated() == $cart->getOrderCouponUsed()) {
             $moduleCouponsUsed++;
         }
     }
     $instance->setAbandonedCartsNum(count($carts));
     $instance->setAbandonedCartsPrice($abandonedCartsPrice);
     $instance->setAbandonedItemsNum($abandonedItemsNum);
     $instance->setRecoveredCartsNum($recoveredCarts);
     $instance->setOrderedCartsNum($orderedCarts);
     $instance->setOrderedCartsPrice($orderedCartsPrice);
     $instance->setOrderedItemsNum($orderedItemsNum);
     $instance->setOrderedItemsNum($orderedItemsNum);
     $instance->setCouponsUsed($moduleCouponsUsed);
     if ($orderedCarts) {
         /*$orderTime = round($orderTime / $orderedCarts);
           $orderTimeS = $orderTime % 60;
           $orderTime = (int)$orderTime/60;
           $orderTimeM = $orderTime % 60;
           $orderTime = (int)$orderTime/60;
           $instance->setAvBackTime($orderTime.':'.$orderTimeM.':'.$orderTimeS);*/
         $instance->setTargetLetterStep($letterStep / $orderedCarts);
     }
     $instance->save();
 }
 /**
  * @param string $path_
  * @param string $storage_
  * @param string[] $schema_
  *
  * @return \Components\Media_Store
  */
 public static function create($path_, $storage_, array $schema_)
 {
     $instance = new self($path_);
     $instance->initialize();
     @file_put_contents($instance->path . '/' . self::NAME_MANIFEST, json_encode(['storage' => $storage_, 'schema' => $schema_]));
     $instance->load();
     Cache::set('components/media/store/' . md5($path_), serialize($instance));
     return $instance;
 }
Example #9
0
 public static function factory($model)
 {
     $paths = static::service('paths');
     $paths->setModel($model);
     $relations = new self();
     $relations->setRelationsTree($paths->relationsTree())->setRelationsTreeIndex($paths->relationsTreeIndex());
     $relations->load();
     return $relations;
 }
 public static function getInstance($file)
 {
     static $instance;
     if (!$instance) {
         $instance = new self();
         $instance->load($file);
     }
     return $instance;
 }
Example #11
0
 /**
  * @param $name
  * @return Config
  * @throws \Exception
  */
 public static function getByName($name)
 {
     $pipe = new self();
     $pipe->setName($name);
     if (!is_readable($pipe->getConfigFile()) || !$pipe->load()) {
         throw new \Exception("video thumbnail definition : " . $name . " does not exist");
     }
     return $pipe;
 }
 public static function getByID($avID)
 {
     $cav = new self();
     $cav->load($avID);
     if ($cav->getAttributeValueID() == $avID) {
         return $cav;
     }
     return null;
 }
Example #13
0
 /**
  * @param $name
  * @return Config
  * @throws \Exception
  */
 public static function getByName($name)
 {
     $letter = new self();
     $letter->setName($name);
     if (!$letter->load()) {
         throw new \Exception("newsletter definition : " . $name . " does not exist");
     }
     return $letter;
 }
 public static function getByHandle($akHandle)
 {
     $ak = new self();
     $ak->load($akHandle, 'akHandle');
     if ($ak->getAttributeKeyID() < 1) {
         $ak = -1;
     }
     return $ak;
 }
Example #15
0
 /**
  * @static
  * @param  $name
  * @return Tool_Tag_Config
  */
 public static function getByName($name)
 {
     $tag = new self();
     $tag->setName($name);
     if (!$tag->load()) {
         throw new Exception("tag definition : " . $name . " does not exist");
     }
     return $tag;
 }
Example #16
0
 /**
  * @param $name
  * @return Model\Tool\CustomReport\Config
  * @throws \Exception
  */
 public static function getByName($name)
 {
     $code = new self();
     $code->setName($name);
     if (!$code->load()) {
         throw new \Exception("sql report definition : " . $name . " does not exist");
     }
     return $code;
 }
Example #17
0
 /**
  * @static
  * @param  $name
  * @return Asset_Image_Thumbnail_Config
  */
 public static function getByName($name)
 {
     $pipe = new self();
     $pipe->setName($name);
     if (!$pipe->load()) {
         throw new Exception("video thumbnail definition : " . $name . " does not exist");
     }
     return $pipe;
 }
 /**
  * Get a unit by its ID
  *
  * @param int $unit_id The unit ID
  *
  * @return CObservationValueUnit
  */
 static function get($unit_id)
 {
     static $cache = array();
     if (isset($cache[$unit_id])) {
         return $cache[$unit_id];
     }
     $unit = new self();
     $unit->load($unit_id);
     return $cache[$unit_id] = $unit;
 }
Example #19
0
 public static function addNew($params)
 {
     $model = new self();
     $model->load($params);
     if ($model->validate()) {
         $model->save();
         return $model->id;
     }
     return false;
 }
Example #20
0
 function getList($count = self::PACKET_SIZE)
 {
     $list = [];
     $recordset = Registry::getInstance()->get(self::DB)->getRecordset("SELECT * FROM `" . self::TABLE . "` ORDER BY `priority` LIMIT {$count}");
     while ($record = $recordset->fetch()) {
         $entity = new self();
         $entity->load($record);
         $list[$entity->id] = $entity;
     }
     return $list;
 }
 /**
  * Get an instance from the code
  *
  * @param string $code Code CdARR
  *
  * @return CTypeActiviteCdARR
  **/
 static function get($code)
 {
     if (!$code) {
         return new self();
     }
     if ($type = SHM::get("type_activite_{$code}")) {
         return $type;
     }
     $type = new self();
     $type->load($code);
     SHM::put("type_activite_{$code}", $type);
     return $type;
 }
 /**
  * Get an instance from the code
  *
  * @param string $code Code
  *
  * @return CIntervenantCdARR
  **/
 static function get($code)
 {
     if (!$code) {
         return new self();
     }
     if ($intervenant = SHM::get("intervenant_{$code}")) {
         return $intervenant;
     }
     $intervenant = new self();
     $intervenant->load($code);
     SHM::put("intervenant_{$code}", $intervenant);
     return $intervenant;
 }
Example #23
0
 /**
  * Returns a reference to a wiki page object
  *
  * This method must be invoked as:
  *     $inst = CoursesInstance::getInstance($alias);
  *
  * @param   string  $type    The page to load
  * @param   string  $prefix  The page scope
  * @param   array   $config  Config options
  * @return  object
  */
 public static function getInstance($type, $prefix = 'JTable', $config = array())
 {
     static $instances;
     $alias = $type;
     if (!isset($instances)) {
         $instances = array();
     }
     if (!isset($instances[$alias])) {
         $inst = new self(\App::get('db'));
         $inst->load($alias);
         $instances[$alias] = $inst;
     }
     return $instances[$alias];
 }
Example #24
0
 /**
  * Returns a reference to this object
  *
  * @param   integer  $id  The record to load
  * @return  object
  */
 public static function getRecordInstance($id)
 {
     static $instances;
     if (!isset($instances)) {
         $instances = array();
     }
     if (!isset($instances[$id])) {
         $db = \App::get('db');
         $tbl = new self($db);
         $tbl->load($id);
         $instances[$id] = $tbl;
     }
     return $instances[$id];
 }
Example #25
0
 static function getListByIds($idList)
 {
     $result = [];
     if (is_array($idList) && count($idList)) {
         $ids = array_map('intval', $idList);
         foreach ($l = parent::loadByParentIds(self::TABLE, $ids) as $parentId => $l10nData) {
             $l10n = new self();
             $l10n->parentId = $parentId;
             foreach ($l10nData as $localeId => $l10nItem) {
                 $l10n->load($localeId, $l10nItem);
             }
             $result[$parentId] = $l10n;
         }
     }
     return $result;
 }
Example #26
0
 /**
  * {@inheritdoc}
  */
 public function union(RepositoryInterface $repository)
 {
     $union = function (array $r1, array $r2) use(&$union) {
         $res = $r1;
         foreach ($r2 as $k => $v) {
             if (isset($res[$k]) && is_array($r1[$k])) {
                 $res[$k] = $union($r1[$k], $v);
             } elseif (!isset($res[$k])) {
                 $res[$k] = $v;
             }
         }
         return $res;
     };
     $repo = new self();
     $repo->load($union($this->getArray(), $repository->getArray()));
     return $repo;
 }
Example #27
0
 public static function collectDay($date)
 {
     $instance = new self();
     $quoteCollection = Mage::getModel('Mage_Reports_Model_Mysql4_Quote_Collection')->prepareForAbandonedReport(0);
     $quoteCollection->getSelect()->where('`main_table`.`updated_at` BETWEEN \'' . $date . '\' AND \'' . $date . '\' + INTERVAL 1 DAY');
     foreach ($quoteCollection as $quote) {
         $instance->load($quote->getEntityId(), 'quote_id');
         $instance->setQuoteId($quote->getEntityId());
         $instance->setCartPrice($quote->getBaseGrandTotal());
         $instance->setCartAbandonDate($quote->getUpdatedAt());
         $items = array();
         foreach ($quote->getAllItems() as $item) {
             if ($item->getProductType() == 'simple') {
                 $items[$item->getProductId()] = $item->getQty();
             }
         }
         $instance->setCartItems(serialize($items));
         $historyCollection = Mage::getModel('adjcartalert/history')->getCollection();
         $historyCollection->addFieldToFilter('quote_id', $quote->getEntityId())->setOrder('sent_at', 'DESC');
         $history = $historyCollection->getFirstItem();
         $instance->setAlertNumber($instance->_followupArray[$history->getFollowUp()]);
         $instance->setAlertDate($history->getSheduledAt());
         $instance->setRecoveryDate($history->getRecoveredAt());
         $orderCollection = Mage::getModel('sales/order')->getCollection();
         $order = $orderCollection->addFieldToFilter('quote_id', $quote->getEntityId())->getFirstItem();
         if ($order->getId()) {
             $instance->setOrderDate($order->getCreatedAt());
             $instance->setOrderPrice($order->getBaseGrandTotal());
             $items = array();
             foreach ($order->getAllItems() as $item) {
                 if ($item->getProductType() == 'simple') {
                     $items[$item->getProductId()] = $item->getQtyOrdered();
                 }
             }
             $instance->setOrderItems(serialize($items));
             $instance->setOrderCouponUsed($order->getCouponCode());
         }
         $instance->save();
     }
 }
Example #28
0
 /**
  * Создание/обновление узла
  *
  * @param array  $data   массив свойств название поля=>значение поля для заполнения свойств модели
  * @param string $ignore название аттрибута для игнорирования
  *
  * @return boolean True or False
  */
 public function save(array $source, $ignore = '')
 {
     //Получаем информацию о родительском узле
     $parent = new self(array('table' => $this->_tbl));
     if (!$parent->load($source['parent_id'])) {
         $error = 'Родительский узел не найден ("' . $source['parent_id'] . '")';
         $this->_set_error($error);
         return false;
     }
     //TODO: здесь можно добавить проверку на то, сменился ли родитель и делать пересчет узла только в случаем смены
     $sql = 'UPDATE ' . $this->_tbl . ' SET `rgt` = `rgt` + 2  WHERE `rgt` >= ' . $parent->rgt;
     $this->_db->set_query($sql)->query();
     $sql = 'UPDATE ' . $this->_tbl . ' SET `lft` = `lft` + 2  WHERE `lft` > ' . $parent->rgt;
     $this->_db->set_query($sql)->query();
     $this->lft = $parent->rgt;
     $this->rgt = $parent->rgt + 1;
     $this->level = $parent->level + 1;
     $this->parent_id = $parent->id;
     parent::save($source, $ignore);
     return true;
 }
Example #29
0
 /**
  * Upon deletion of a class, restore all users of that class to the default class
  *
  * @param   integer  $id
  * @return  boolean
  */
 public function restoreDefaultClass($id)
 {
     include_once __DIR__ . DS . 'sessionclass.php';
     $class = new SessionClass($this->_db);
     $class->load(array('alias' => 'default'));
     if (!$class->id) {
         return false;
     }
     $records = self::find('list', array('class_id' => $id));
     if ($records && count($records) > 0) {
         foreach ($records as $r) {
             $quota = new self($this->_db);
             $quota->load($r->id);
             $quota->set('jobs', $class->jobs);
             $quota->set('class_id', $class->id);
             $quota->store();
         }
     }
     return true;
 }
 /**
  * Render an HTML view with the given arguments and output the view's contents.
  *
  * @since  0.1.3
  *
  * @param  string $template The template file name, relative to the includes/templates/ folder
  *                          - without .php extension
  * @param  string $name     The name of the specialised template. If array, will take the place of the $args.
  * @param  array  $args     An array of arguments to extract as variables into the template
  *
  * @return void
  */
 public static function output_template($template, $name = null, array $args = array())
 {
     $view = new self($template, $name, $args);
     $view->load(1);
 }