コード例 #1
0
ファイル: relations.php プロジェクト: 01J/skazkipronebo
 /**
  * Returns a FOFDatabaseIterator based on a given relation
  *
  * @param   array    $relation   Relation definition
  *
  * @return FOFDatabaseIterator
  *
  * @throws RuntimeException
  */
 private function getIteratorFromRelation($relation)
 {
     // Get a table object from the table class name
     $tableClass = $relation['tableClass'];
     $tableClassParts = FOFInflector::explode($tableClass);
     $table = FOFTable::getInstance($tableClassParts[2], ucfirst($tableClassParts[0]) . ucfirst($tableClassParts[1]));
     // Get the table name
     $tableName = $table->getTableName();
     // Get the remote and local key names
     $remoteKey = $relation['remoteKey'];
     $localKey = $relation['localKey'];
     // Get the local key's value
     $value = $this->table->{$localKey};
     // This is required to prevent one relation from killing the db cursor used in a different relation...
     $oldDb = $this->table->getDbo();
     $oldDb->disconnect();
     // YES, WE DO NEED TO DISCONNECT BEFORE WE CLONE THE DB OBJECT. ARGH!
     $db = clone $oldDb;
     // Begin the query
     $query = $db->getQuery(true)->select('*')->from($db->qn($tableName));
     // Do we have a pivot table?
     $hasPivot = array_key_exists('pivotTable', $relation);
     // If we don't have pivot it's a straightforward query
     if (!$hasPivot) {
         $query->where($db->qn($remoteKey) . ' = ' . $db->q($value));
     } else {
         $subQuery = $db->getQuery(true)->select($db->qn($relation['theirPivotKey']))->from($db->qn($relation['pivotTable']))->where($db->qn($relation['ourPivotKey']) . ' = ' . $db->q($value));
         $query->where($db->qn($remoteKey) . ' IN (' . $subQuery . ')');
     }
     $db->setQuery($query);
     $cursor = $db->execute();
     $iterator = FOFDatabaseIterator::getIterator($db->name, $cursor, null, $tableClass);
     return $iterator;
 }
コード例 #2
0
 public function onBeforeStore($updateNulls)
 {
     if (!$this->alias) {
         $this->alias = FOFStringUtils::toSlug($this->name);
     }
     return parent::onBeforeStore($updateNulls);
 }
コード例 #3
0
 protected function onAfterLoad(&$result)
 {
     if (isset($this->params)) {
         $this->params = json_decode($this->params);
     }
     return parent::onAfterLoad($result);
 }
コード例 #4
0
ファイル: iterator.php プロジェクト: educakanchay/kanchay
 /**
  * Returns the data in $this->_current as a FOFTable instance
  *
  * @return  FOFTable
  *
  * @throws  OutOfBoundsException
  */
 protected function getTable()
 {
     if (!$this->valid()) {
         throw new OutOfBoundsException('Cannot get item past iterator\'s bounds', 500);
     }
     $this->_tableObject->bind($this->_current);
     return $this->_tableObject;
 }
コード例 #5
0
 /**
  * onBeforeDelete event - forbids deleting the default backup profile
  * 
  * @param int $oid The ID of the profile to delete
  * 
  * @return boolean True if the deletion is allowed
  */
 protected function onBeforeDelete($oid)
 {
     $result = parent::onBeforeDelete($oid);
     if ($result) {
         if ($oid == 1) {
             $this->setError(JText::_('TABLE_PROFILE_CANNOTDELETEDEFAULT'));
             $result = false;
         }
     }
     return $result;
 }
コード例 #6
0
 public function onAfterLoad(&$result)
 {
     if (!is_array($this->spsimpleportfolio_tag_id)) {
         if (!empty($this->spsimpleportfolio_tag_id)) {
             $this->spsimpleportfolio_tag_id = json_decode($this->spsimpleportfolio_tag_id, true);
         }
     }
     if (is_null($this->spsimpleportfolio_tag_id) || empty($this->spsimpleportfolio_tag_id)) {
         $this->spsimpleportfolio_tag_id = array();
     }
     return parent::onAfterLoad($result);
 }
コード例 #7
0
ファイル: relations.php プロジェクト: educakanchay/kanchay
 /**
  * Returns a FOFDatabaseIterator based on a given relation
  *
  * @param   array    $relation   Indexed array holding relation definition.
  *                                  tableClass => name of the related table class
  *                                  localKey   => name of the local key
  *                                  remoteKey  => name of the remote key
  *                                  pivotTable    => name of the pivot table (optional)
  *                                  theirPivotKey => name of the remote key in the pivot table (mandatory if pivotTable is set)
  *                                  ourPivotKey   => name of our key in the pivot table (mandatory if pivotTable is set)
  *
  * @return FOFDatabaseIterator
  *
  * @throws RuntimeException
  * @throws InvalidArgumentException
  */
 protected function getIteratorFromRelation($relation)
 {
     // Sanity checks
     if (!isset($relation['tableClass']) || !isset($relation['remoteKey']) || !isset($relation['localKey']) || !$relation['tableClass'] || !$relation['remoteKey'] || !$relation['localKey']) {
         throw new InvalidArgumentException('Missing array index for the ' . __METHOD__ . ' method. Please check method signature', 500);
     }
     if (array_key_exists('pivotTable', $relation)) {
         if (!isset($relation['theirPivotKey']) || !isset($relation['ourPivotKey']) || !$relation['pivotTable'] || !$relation['theirPivotKey'] || !$relation['ourPivotKey']) {
             throw new InvalidArgumentException('Missing array index for the ' . __METHOD__ . ' method. Please check method signature', 500);
         }
     }
     // Get a table object from the table class name
     $tableClass = $relation['tableClass'];
     $tableClassParts = FOFInflector::explode($tableClass);
     if (count($tableClassParts) < 3) {
         throw new InvalidArgumentException('Invalid table class named. It should be something like FooTableBar');
     }
     $table = FOFTable::getInstance($tableClassParts[2], ucfirst($tableClassParts[0]) . ucfirst($tableClassParts[1]));
     // Get the table name
     $tableName = $table->getTableName();
     // Get the remote and local key names
     $remoteKey = $relation['remoteKey'];
     $localKey = $relation['localKey'];
     // Get the local key's value
     $value = $this->table->{$localKey};
     // If there's no value for the primary key, let's stop here
     if (!$value) {
         throw new RuntimeException('Missing value for the primary key of the table ' . $this->table->getTableName(), 500);
     }
     // This is required to prevent one relation from killing the db cursor used in a different relation...
     $oldDb = $this->table->getDbo();
     $oldDb->disconnect();
     // YES, WE DO NEED TO DISCONNECT BEFORE WE CLONE THE DB OBJECT. ARGH!
     $db = clone $oldDb;
     // Begin the query
     $query = $db->getQuery(true)->select('*')->from($db->qn($tableName));
     // Do we have a pivot table?
     $hasPivot = array_key_exists('pivotTable', $relation);
     // If we don't have pivot it's a straightforward query
     if (!$hasPivot) {
         $query->where($db->qn($remoteKey) . ' = ' . $db->q($value));
     } else {
         $subQuery = $db->getQuery(true)->select($db->qn($relation['theirPivotKey']))->from($db->qn($relation['pivotTable']))->where($db->qn($relation['ourPivotKey']) . ' = ' . $db->q($value));
         $query->where($db->qn($remoteKey) . ' IN (' . $subQuery . ')');
     }
     $db->setQuery($query);
     $cursor = $db->execute();
     $iterator = FOFDatabaseIterator::getIterator($db->name, $cursor, null, $tableClass);
     return $iterator;
 }
コード例 #8
0
 public function post()
 {
     $input = JFactory::getApplication()->input;
     $user = $this->plugin->getUser();
     if (!$user) {
         $this->plugin->setResponse($this->getErrorResponse(404, JText::_('JERROR_ALERTNOAUTHOR')));
         return;
     }
     $authorised = $user->authorise('core.create', 'com_akeebasubs');
     $override_users = $this->getOverrideUsers();
     $is_override = in_array($user->id, array_keys($override_users));
     $allowed = $authorised || $is_override;
     if (!$allowed) {
         $this->plugin->setResponse($this->getErrorResponse(404, JText::_('JERROR_ALERTNOAUTHOR')));
         return;
     }
     // Check/create user
     $newuser['name'] = $input->get('name', '', 'STRING');
     $newuser['email'] = $input->get('email', '', 'USERNAME');
     $newuser['username'] = $newuser['email'];
     $subscriber_userid = $this->getSubscriberUserid($newuser);
     if (!$subscriber_userid) {
         $this->plugin->setResponse($this->getErrorResponse(404, 'Problem creating user. Name and email are mandatory. Make sure you use a valid email'));
         return;
     }
     // Create subscription
     $levelid = $input->get('subscription', '', 'INT');
     $enabled = $input->get('enabled', 0, 'INT');
     $state = $enabled ? 'C' : 'N';
     // Do validations
     if ($is_override && !in_array($levelid, $override_users[$user->id])) {
         $this->plugin->setResponse($this->getErrorResponse(404, 'Invalid subscription id'));
         return;
     }
     if (!$this->checkLevel($levelid)) {
         $this->plugin->setResponse($this->getErrorResponse(404, 'Invalid subscription id'));
         return;
     }
     $jNow = new JDate();
     $now = $jNow->toUnix();
     $mNow = $jNow->toSql();
     $startDate = $now;
     $nullDate = JFactory::getDbo()->getNullDate();
     $level = FOFModel::getTmpInstance('Levels', 'AkeebasubsModel')->setId($levelid)->getItem();
     if ($level->forever) {
         $jStartDate = new JDate();
         $endDate = '2038-01-01 00:00:00';
     } elseif (!is_null($level->fixed_date) && $level->fixed_date != $nullDate) {
         $jStartDate = new JDate();
         $endDate = $level->fixed_date;
     } else {
         $jStartDate = new JDate($startDate);
         // Subscription duration (length) modifiers, via plugins
         $duration_modifier = 0;
         JLoader::import('joomla.plugin.helper');
         JPluginHelper::importPlugin('akeebasubs');
         $app = JFactory::getApplication();
         $jResponse = $app->triggerEvent('onValidateSubscriptionLength', array($state));
         if (is_array($jResponse) && !empty($jResponse)) {
             foreach ($jResponse as $pluginResponse) {
                 if (empty($pluginResponse)) {
                     continue;
                 }
                 $duration_modifier += $pluginResponse;
             }
         }
         // Calculate the effective duration
         $duration = (int) $level->duration + $duration_modifier;
         if ($duration <= 0) {
             $duration = 0;
         }
         $duration = $duration * 3600 * 24;
         $endDate = $startDate + $duration;
     }
     $mStartDate = $jStartDate->toSql();
     $jEndDate = new JDate($endDate);
     $mEndDate = $jEndDate->toSql();
     $note = 'Subscription created via API.' . PHP_EOL . 'API User : %1$s' . PHP_EOL . 'API Userid : %2$s' . PHP_EOL . 'Subscriber Name : %3$s' . PHP_EOL . 'Subscriber Email : %4$s' . PHP_EOL . 'Date : %5$s' . PHP_EOL . 'Level id : %6$s';
     $subscription = FOFTable::getInstance('Subscription', 'AkeebasubsTable');
     $subscription->user_id = (int) $subscriber_userid;
     $subscription->akeebasubs_level_id = $levelid;
     $subscription->enabled = $enabled;
     $subscription->state = $state;
     $subscription->processor = 'api';
     $subscription->created_on = $mStartDate;
     $subscription->publish_up = $mStartDate;
     $subscription->publish_down = $mEndDate;
     $subscription->notes = sprintf($note, $user->name, $user->id, $newuser['name'], $newuser['email'], date('Y-m-d H:i:s'), $levelid);
     if ($subscription->store()) {
         // Send email
         //$mailer = AkeebasubsHelperEmail::getPreloadedMailer($subscription, 'plg_akeebasubs_subscriptionemails_new_active');
         //$mailer->addRecipient($newuser['email']);
         //$send = $mailer->Send();
         $this->plugin->setResponse(array('code' => 200, 'id' => $subscription->akeebasubs_subscription_id));
     } else {
         $this->plugin->setResponse($this->getErrorResponse(404, 'There was a problem creating the subscription. Make sure you use a valid level id. Name and email are mandatory.'));
     }
 }
コード例 #9
0
ファイル: table.php プロジェクト: deenison/joomla-cms
 /**
  * Add a filesystem path where FOFTable should search for table class files.
  * You may either pass a string or an array of paths.
  *
  * @param   mixed  $path  A filesystem path or array of filesystem paths to add.
  *
  * @return  array  An array of filesystem paths to find FOFTable classes in.
  */
 public static function addIncludePath($path = null)
 {
     // If the internal paths have not been initialised, do so with the base table path.
     if (empty(self::$_includePaths)) {
         self::$_includePaths = array(__DIR__);
     }
     // Convert the passed path(s) to add to an array.
     settype($path, 'array');
     // If we have new paths to add, do so.
     if (!empty($path) && !in_array($path, self::$_includePaths)) {
         // Check and add each individual new path.
         foreach ($path as $dir) {
             // Sanitize path.
             $dir = trim($dir);
             // Add to the front of the list so that custom paths are searched first.
             array_unshift(self::$_includePaths, $dir);
         }
     }
     return self::$_includePaths;
 }
コード例 #10
0
 /**
  * Method to reset class properties to the defaults set in the class
  * definition. It will ignore the primary key as well as any private class
  * properties.
  *
  * @return void
  */
 public function reset()
 {
     $this->resetTreeCache();
     parent::reset();
 }
コード例 #11
0
ファイル: relation.php プロジェクト: joshjim27/jobsglobal
 /**
  * Method to get the field options.
  *
  * @return  array  The field option objects.
  */
 protected function getOptions()
 {
     $options = array();
     $this->value = array();
     $value_field = $this->element['value_field'] ? (string) $this->element['value_field'] : 'title';
     $input = new FOFInput();
     $component = ucfirst(str_replace('com_', '', $input->getString('option')));
     $view = ucfirst($input->getString('view'));
     $relation = FOFInflector::pluralize((string) $this->element['name']);
     $model = FOFModel::getTmpInstance(ucfirst($relation), $component . 'Model');
     $table = $model->getTable();
     $key = $table->getKeyName();
     $value = $table->getColumnAlias($value_field);
     foreach ($model->getItemList(true) as $option) {
         $options[] = JHtml::_('select.option', $option->{$key}, $option->{$value});
     }
     if ($id = FOFModel::getAnInstance($view)->getId()) {
         $table = FOFTable::getInstance($view, $component . 'Table');
         $table->load($id);
         $relations = $table->getRelations()->getMultiple($relation);
         foreach ($relations as $item) {
             $this->value[] = $item->getId();
         }
     }
     return $options;
 }
コード例 #12
0
ファイル: stat.php プロジェクト: sankam-nikolya/lptt
 public function __construct($table, $key, &$db)
 {
     parent::__construct('#__ak_stats', 'id', $db);
 }
コード例 #13
0
ファイル: model.php プロジェクト: ziyou-liu/1line
 /**
  * Method to load and return a model object.
  *
  * @param   string  $name    The name of the view
  * @param   string  $prefix  The class prefix. Optional.
  * @param   array   $config  The configuration array to pass to the table
  *
  * @return  FOFTable  Table object or boolean false if failed
  */
 protected function &_createTable($name, $prefix = 'Table', $config = array())
 {
     // Make sure $config is an array
     if (is_object($config)) {
         $config = (array) $config;
     } elseif (!is_array($config)) {
         $config = array();
     }
     $result = null;
     // Clean the model name
     $name = preg_replace('/[^A-Z0-9_]/i', '', $name);
     $prefix = preg_replace('/[^A-Z0-9_]/i', '', $prefix);
     // Make sure we are returning a DBO object
     if (!array_key_exists('dbo', $config)) {
         $config['dbo'] = $this->getDBO();
     }
     $instance = FOFTable::getAnInstance($name, $prefix, $config);
     return $instance;
 }
コード例 #14
0
 /**
  * This method runs before the record with key value of $id is deleted from $table
  *
  * @param   FOFTable  $table
  *
  * @return  boolean
  */
 protected function onBeforeDelete(&$id, &$table)
 {
     list($isCLI, $isAdmin) = FOFDispatcher::isCliAdmin();
     // Let's import the plugin only if we're not in CLI (content plugin needs a user)
     if (!$isCLI) {
         JPluginHelper::importPlugin('content');
     }
     $dispatcher = JDispatcher::getInstance();
     try {
         $table->load($id);
         $name = $this->input->getCmd('view', 'cpanel');
         $context = $this->option . '.' . $name;
         $result = $dispatcher->trigger($this->event_before_delete, array($context, $table));
         if (in_array(false, $result, true)) {
             // Plugin failed, return false
             $this->setError($table->getError());
             return false;
         }
         $this->_recordForDeletion = clone $table;
     } catch (Exception $e) {
         // Oops, an exception occured!
         $this->setError($e->getMessage());
         return false;
     }
     return true;
 }